﻿
var m_names = new Array("Jan", "Feb", "Mar", 
"Apr", "May", "June", "July", "Aug", "Sep", 
"Oct", "Nov", "Dec");

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
             
// AJAX API For Loading the Market Page

var xmlReq = new Array(); // ARRAY OF XML-HTTP REQUESTS 
var xmlIndex = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xmlIndex[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE


function xhrRequest(type) 
{
    if (!type) 
    {
        type = 'html';
    }
    // xhrsend IS THE xmlIndex POSITION THAT GETS PASSED BACK
    // INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
    var xhrsend = xmlIndex.length;

    // GO THROUGH AVAILABLE xi VALUES
    for (var i=0; i<xmlIndex.length; i++) 
    {
        // IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
        if (xmlIndex[i] == 1) 
        {
            xmlIndex[i] = 0;
            xhrsend = i;
            break;
        }
    }
    // SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
    xmlIndex[xhrsend] = 0;


    // SET UP THE REQUEST
    if (window.ActiveXObject) 
    {
        try 
        {
            xmlReq[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
                xmlReq[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) 
            {
                
            }
        }
    } 
    else if (window.XMLHttpRequest) 
    {
        xmlReq[xhrsend] = new XMLHttpRequest();
        if (xmlReq[xhrsend].overrideMimeType) 
        {
            xmlReq[xhrsend].overrideMimeType('text/' + type);
        }
    }
    return (xhrsend);
}

var strHTML = "";
function LoadRequest(url, reqType) 
{
    var xhri = xhrRequest('html');
    xmlReq[xhri].open('GET', url, true);
    //
    //alert(url);
    var qrStr = url;
    var spQrStr = qrStr.substring(1);
    var arrQrStr = new Array();
    // splits each of pair
    var arr = spQrStr.split('&');
    for (var i=0;i<arr.length;i++)
    {
        // splits each of field-value pair
        var index = arr[i].indexOf('=');
        var key = arr[i].substring(0,index);
        var val = arr[i].substring(index+1);
        // saves each of field-value pair in an array variable
        arrQrStr[key] = val;
    }  
    var url1=url.split('&');
    var url=url1[0];
   
  // 
    //
    //var indid=document.getElementById("indcode").value;
    xmlReq[xhri].onreadystatechange = function() 
    {                     
        if (xmlReq[xhri].readyState == 4 && xmlReq[xhri].status == 200) 
        {           
           
            //Logic to create Chartxmlfile
             var Output="";
             var indcode;
            if(url == "AJAX/GetQuoteDtl.aspx?compname=State")
            {      
            
            
                Output = xmlReq[xhri].responseText;
                 var arOutput = Output.split('##');
                 document.getElementById("compname").innerHTML=arOutput[0];
                 document.getElementById("Bsecode").innerHTML=arOutput[1];
                 document.getElementById("Nsecode").innerHTML=arOutput[2];
                 document.getElementById("IsinDmt").innerHTML=arOutput[6];
                 document.getElementById("Industry").innerHTML=arOutput[3];
                 document.getElementById("Group").innerHTML=arOutput[5];
               //indcode=arOutput[7]; 
               //alert(document.getElementById("indcode").value) ;
              
            }  
             if(url == "AJAX/GetQuoteDtl.aspx?Page=State")
            {           
                Output = xmlReq[xhri].responseText;
               
                 //var arOutput = Output.split('##');
                 document.getElementById("opdata").innerHTML=Output;
                
                 
                 
            }
            //Peer data  
             if(url == "AJAX/GetQuoteDtl.aspx?Peer=Peer")
            {   //alert(document.getElementById("indcode").value);
               //url="AJAX/GetQuoteDtl.aspx?Peer=Peer&indid="+document.getElementById("indcode").value        
                Output = xmlReq[xhri].responseText;
                 //var arOutput = Output.split('##');
                 document.getElementById("peerdata").innerHTML=Output;
                 
                 
            }
             if(url == "AJAX/GetQuoteDtl.aspx?EpsDiv=EpsDiv")
            {  
                  Output = xmlReq[xhri].responseText;
                 var arOutput = Output.split('##');
                 document.getElementById("MarketCap").innerHTML=arOutput[0].substring(0,8);
                 document.getElementById("divyeild").innerHTML=arOutput[1];
                 document.getElementById("Epsttm").innerHTML=arOutput[2];
                 document.getElementById("PETtm").innerHTML=arOutput[3];
                 document.getElementById("BVval").innerHTML=arOutput[4];
                 document.getElementById("FVval").innerHTML=arOutput[5];
                 
                 
            }
            
             if(url=="AJAX/GetQuoteDtl.aspx?Financial=Financial")
             {           
                Output = xmlReq[xhri].responseText;
                 //var arOutput = Output.split('##');
                 document.getElementById("financial").innerHTML=Output;
             }  
            
            if(url=="AJAX/GetQuoteDtl.aspx?News=News")
             {           
                Output = xmlReq[xhri].responseText;
                 //var arOutput = Output.split('##');
                 document.getElementById("newsdtl").innerHTML=Output;
             }  
            if(url=="AJAX/GetQuoteDtl.aspx?Chart=Chart")
             {           
                Output = xmlReq[xhri].responseText;
               // document.getElementById("graph").innerHTML=Output;
                 //var arOutput = Output.split('##');
                 //document.getElementById("newsdtl").innerHTML=Output;
                 //document.getElementById("")= 
            }
             if(url == "AJAX/GetQuoteDtl.aspx?Indices=Indices")
            {           
                Output = xmlReq[xhri].responseText;
                var mainOutput=Output.split(';');
                 var arOutput = mainOutput[0].split('##');
                 document.getElementById("NSEvalue").innerHTML=arOutput[1];
                 document.getElementById("NSEachng").innerHTML=arOutput[2];
                 document.getElementById("NSEpchng").innerHTML="(" + arOutput[3] + "%)";
                 document.getElementById("NSEdt").innerHTML=arOutput[4];
                 document.getElementById("NSEtime").innerHTML=arOutput[5];
                 if (arOutput[6]=="1")
                 {
                 document.getElementById("NSEvalue").style.color="#339933";
                 document.getElementById("NSEachng").style.color="#339933";
                 document.getElementById("NSEpchng").style.color="#339933";
                 document.getElementById("NSEimg").src="images/green_trangle.jpg";
                 }
                 else
                 {
                  document.getElementById("NSEvalue").style.color="red";
                  document.getElementById("NSEachng").style.color="red";
                 document.getElementById("NSEpchng").style.color="red";
                   document.getElementById("NSEimg").src="images/red_trangle.jpg";
                 }
                 //for BSE
                 var brOutput=mainOutput[1].split('##');
                 
                 document.getElementById("BSEvalue").innerHTML=brOutput[1];
                 document.getElementById("BSEachng").innerHTML=brOutput[2];
                 document.getElementById("BSEpchng").innerHTML="(" + brOutput[3] + "%)";
                 document.getElementById("BSEdt").innerHTML=brOutput[4];
                 document.getElementById("BSEtime").innerHTML=brOutput[5];
                 if (brOutput[6]=="1")
                 {
                  document.getElementById("BSEvalue").style.color="#339933";
                  document.getElementById("BSEachng").style.color="#339933";
                 document.getElementById("BSEpchng").style.color="#339933";
                 document.getElementById("BSEimg").src="images/green_trangle.jpg";
                 
                 }
                 else
                 {
                  document.getElementById("BSEvalue").style.color="red";
                  document.getElementById("BSEachng").style.color="red";
                 document.getElementById("BSEpchng").style.color="red";
                   document.getElementById("BSEimg").src="images/red_trangle.jpg";
                 }
            }  
            
           xmlIndex[xhri] = 1;
            xmlReq[xhri] = null;
        }
        else
        {        
            //displayStaticMessage('<img src=images/Progress/kms_progress.gif alt=\"\" /> <span style=\"font-size:10px\">Please wait.......</span>',false);                             
        }
    };
    xmlReq[xhri].send(null);
}
// Method Called during the Page Load
function loadMulti() 
{    
//debugger;
 var qrStr = window.location.search;
    var spQrStr = qrStr.substring(1);
    var arrQrStr = new Array();
    // splits each of pair
    var arr = spQrStr.split('&');
    for (var i=0;i<arr.length;i++)
    {
        // splits each of field-value pair
        var index = arr[i].indexOf('=');
        var key = arr[i].substring(0,index);
        var val = arr[i].substring(index+1);
        // saves each of field-value pair in an array variable
        arrQrStr[key] = val;
    }  
    //alert(arrQrStr["id"]);   
    document.getElementById('CS').href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=CS"; 
    document.getElementById('BOD').href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=BOD"; 
      document.getElementById('BS').href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=BS";  
       document.getElementById('FR').href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=FR";
        document.getElementById('SP').href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=SP";   
         document.getElementById('PL').href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=PL";     
          document.getElementById('QR').href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=QR";   
          //document.getElementById('EODchart').href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=C";   
            
    // CALL A FUNCTION THAT USES xmlHttp MULTIPLE TIMES 
  //LoadRequest('AJAX/GetCompanyName.aspx?Page=State'); 
  //LoadRequest("AJAX/GetQuoteDtl.aspx?Chart=Chart&BseId="+arrQrStr["id"]);  
 // document.getElementById("chart").innerHTML="<table width=100% height='220px'><tr><td align=center style=padding-left:10px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
   document.getElementById("newsdtl").innerHTML="<table width=100% height='220px'><tr><td align=center style=padding-left:10px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    document.getElementById('opdata').innerHTML = "<table width=100% height='150px'><tr><td align=center style=padding-left:10px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";  
    document.getElementById("peerdata").innerHTML = "<table width=100% height='150px'><tr><td align=center style=padding-left:10px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";  
     document.getElementById("financial").innerHTML="<table width=100% height='150px'><tr><td align=center style=padding-left:10px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";  
     //document.getElementById("chart1div").innerHTML="<table width=100% height='150px'><tr><td align=center style=padding-left:10px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";  
    LoadRequest("AJAX/GetQuoteDtl.aspx?compname=State&BseId="+arrQrStr["id"]+"&Peer="+arrQrStr["Peer"] );
  LoadRequest("AJAX/GetQuoteDtl.aspx?Page=State&BseId="+arrQrStr["id"]);
  LoadRequest("AJAX/GetQuoteDtl.aspx?Indices=Indices&BseId="+arrQrStr["id"]);
 LoadRequest("AJAX/GetQuoteDtl.aspx?News=News&BseId="+arrQrStr["id"]);
document.getElementById('BSEid').value=arrQrStr["id"];
 //alert(document.getElementById('BSEid').value);
 LoadRequest("AJAX/GetQuoteDtl.aspx?Peer=Peer&BseId="+arrQrStr["id"]);
 LoadRequest("AJAX/GetQuoteDtl.aspx?EpsDiv=EpsDiv&BseId="+arrQrStr["id"]);
 LoadRequest("AJAX/GetQuoteDtl.aspx?Financial=Financial&BseId="+arrQrStr["id"]);
document.getElementById("financemore").href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=BS";
document.getElementById("newslink").href="GetQuotesAjax.aspx?id="+arrQrStr["id"]+"&menu=CN";

//document.getElementById("Weekchart").style.display='none';
//document.getElementById("Month").style.display='none';
//document.getElementById("Months").style.display='none';
//document.getElementById("Year").style.display='none';
}

// Navigating to the Get Quotes Page
function GetQuotes()
{
    if(document.getElementById("txtGetQuote").value == "")
    {
        alert("Please enter Company Name");
        document.getElementById("txtGetQuote").focus();
        return false;
    }
    else
    {
        var URL = "GetQuoteNew.aspx?id=" + document.getElementById("txtGetQuote_hidden").value;        
        window.open(URL,'_parent');
        return false;
    }
}
//Navigetting to peercompare page
function ComparePeer()
{
    if(document.getElementById("peerid").value == "")
    {
        alert("Please Select Company Name");
        //document.getElementById("txtGetQuote").focus();
        return false;
    }
    else
    {
        var URL = "peercompare1.aspx?id=" + document.getElementById("peerid").value+"&hostid="+ document.getElementById("hostid").value+"&Peer=Peer";        
        window.open(URL,'_parent');
        return false;
    }
}


///////////////////////////  Seprate AJAX Object for Loading 52 Week and Current Status //////////////////////////
var xmlHttp;
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
function setpeerid(id,hostid)
{
 document.getElementById("peerid").value=id;
 document.getElementById("hostid").value=hostid;
//alert(document.getElementById("peerid").value);
}
//function showweekchart()
//{
//document.getElementById("chart").style.display='none';
//document.getElementById("weeklyli").className='selected';
//document.getElementById("Intday").className='';
//document.getElementById("Weekchart").style.display='block';
//document.getElementById("1monthli").className='';
//document.getElementById("Month").style.display='none';
//document.getElementById("Months").style.display='none';
//document.getElementById("6monthli").className='';
//document.getElementById("Year").style.display='none';
//document.getElementById("1yearli").className='';
////alert('6month');
//}
//function showIntchart()
//{
//document.getElementById("chart").style.display='block';
//document.getElementById("weeklyli").className='';
//document.getElementById("Intday").className='selected';
//document.getElementById("Weekchart").style.display='none';
//document.getElementById("1monthli").className='';
//document.getElementById("Month").style.display='none';
//document.getElementById("Months").style.display='none';
//document.getElementById("6monthli").className='';
//document.getElementById("Year").style.display='none';
//document.getElementById("1yearli").className='';
////alert('6month');
//}
//function show1monthchart()
//{
//document.getElementById("chart").style.display='none';
//document.getElementById("weeklyli").className='';
//document.getElementById("Intday").className='';
//document.getElementById("Weekchart").style.display='none';
//document.getElementById("1monthli").className='selected';
//document.getElementById("Month").style.display='block';
//document.getElementById("Months").style.display='none';
//document.getElementById("6monthli").className='';
//document.getElementById("Year").style.display='none';
//document.getElementById("1yearli").className='';
////alert('6month');
//}
//function show6monthchart()
//{
//document.getElementById("chart").style.display='none';
//document.getElementById("weeklyli").className='';
//document.getElementById("Intday").className='';
//document.getElementById("Weekchart").style.display='none';
//document.getElementById("1monthli").className='';
//document.getElementById("Month").style.display='none';
//document.getElementById("Months").style.display='block';
//document.getElementById("6monthli").className='selected';
//document.getElementById("Year").style.display='none';
//document.getElementById("1yearli").className='';

////alert('6month');
//}
//function show1yearchart()
//{
//document.getElementById("chart").style.display='none';
//document.getElementById("weeklyli").className='';
//document.getElementById("Intday").className='';
//document.getElementById("Weekchart").style.display='none';
//document.getElementById("1monthli").className='';
//document.getElementById("Month").style.display='none';
//document.getElementById("Months").style.display='none';
//document.getElementById("6monthli").className='';
//document.getElementById("Year").style.display='block';
//document.getElementById("1yearli").className='selected';
////alert('6month');
//}
function Popupchart()
{
var id=document.getElementById('BSEid').value;
var u="EODcsvcreation.aspx?id="+id;
window.open(u, '_blank', 'width=880,height=600,titlebar=no,scrollbars=no');
}

//14 Jan TAb javascript

//function SetMMTab(a) 
//{
//    document.getElementById('TDIF').className = "txtNewsBottom";
//    document.getElementById('TDIO').className = "txtNewsBottom";
//    document.getElementById('TDSF').className = "txtNewsBottom"; 
//    document.getElementById('TDSO').className = "txtNewsBottom";
//    document.getElementById('aIF').style.fontWeight = "";  
//    document.getElementById('aIO').style.fontWeight = ""; 
//    document.getElementById('aSF').style.fontWeight = ""; 
//    document.getElementById('aSO').style.fontWeight = "";
//    if (a == "IF") 
//    {
//        document.getElementById('TDIF').className = "txtNewsBottomBold";       
//        document.getElementById('aIF').style.fontWeight = "bold";         
//        document.getElementById('spnMostActive').innerHTML = "<table width=430px height='120px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
//        LoadRequest('AJAXMarket/DerivativeAjaxAPI.aspx?PageName=MostActive&Flag=IF&ExpDate=' + document.getElementById('ddlMostActive').value);           
//        document.getElementById('aIF').className = "Links";      
//    }
//    else if (a == "IO")
//    {
//       document.getElementById('TDIO').className = "txtNewsBottomBold"; 
//       document.getElementById('aIO').style.fontWeight = "bold";       
//       document.getElementById('spnMostActive').innerHTML = "<table width=430px height='120px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
//       LoadRequest('AJAXMarket/DerivativeAjaxAPI.aspx?PageName=MostActive&Flag=IO&ExpDate=' + document.getElementById('ddlMostActive').value);          
//       document.getElementById('aIO').className = "Links";           
//    }   
//    else if (a == "SF")
//    {
//       document.getElementById('TDSF').className = "txtNewsBottomBold"; 
//       document.getElementById('aSF').style.fontWeight = "bold";       
//       document.getElementById('spnMostActive').innerHTML = "<table width=430px height='120px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
//       LoadRequest('AJAXMarket/DerivativeAjaxAPI.aspx?PageName=MostActive&Flag=SF&ExpDate=' + document.getElementById('ddlMostActive').value);          
//       document.getElementById('aSF').className = "Links";           
//    } 
//    else
//    {
//        document.getElementById('TDSO').className = "txtNewsBottomBold";  
//        document.getElementById('aSO').style.fontWeight = "bold";        
//        document.getElementById('spnMostActive').innerHTML = "<table width=430px height='120px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
//        LoadRequest('AJAXMarket/DerivativeAjaxAPI.aspx?PageName=MostActive&Flag=SO&ExpDate=' + document.getElementById('ddlMostActive').value);           
//        document.getElementById('aSO').className = "Links";              
//    }
//}

//End 14 Jan