﻿// JScript File
//Home News...

function ajaxUpdater(id,url) {new Ajax.Updater(id,url,{asynchronous:true}); }   
   function GetNewsListing(EXCHG)
	{	
	    var requestUrl = "CommonControl/NewListings.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime()+"EXCHG="+EXCHG;
		var ajax = new Ajax.Updater('ListTD',requestUrl)
    }
    
function SelectClass(val,secid,subsecid)
{
  for(i = 1; i<= 4 ; i++)
  {
      if(val == i)
      {
        document.getElementById("td"+i).className ="HomeSelect";
      }
      else
      {
        document.getElementById("td"+i).className ="HomeUnSelect";
      }
  }
  GetNews(secid,subsecid);

}

var XmlHttpFO;

function CreateXmlHttpNew()
	{
	
		try
		{
			XmlHttpFO = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpFO = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpFO = null;	
			}
		}
	
		if(!XmlHttpFO && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpFO = new XMLHttpRequest();
		}
	}

function Searchempty()
{
	if (document.getElementById("txtSearch").value=="Company Name")
	{
		document.getElementById("txtSearch").value="";
	}
}
function Searchfill()
{
    var getquote=document.getElementById("txtSearch").value;
    
    if (getquote=="")
    {
        document.getElementById("txtSearch").value="Company Name";
    }
}

function GetNews(secid,subsecid)
{
   CreateXmlHttpNew();
 	document.body.style.cursor = "progress";
	var requestUrl = "AjaxNews.aspx?sec="+secid+"&subsec="+subsecid;
	//alert(requestUrl);
	if(XmlHttpFO!=null)	
	{
	    XmlHttpFO.onreadystatechange = function(){ChangeResponseNews()}
		XmlHttpFO.open('GET', requestUrl,  true);
		XmlHttpFO.send(null);
	}
	return false; 
}

function ChangeResponseNews()
{
	if(XmlHttpFO.readyState == 4)
	{
	    var td_Id = document.getElementById("news");
		if(XmlHttpFO.status == 200)//
		{
	
			td_Id.innerHTML =  XmlHttpFO.responseText;
			document.body.style.cursor = "auto";		
		}
		else
		{
		    td_Id.innerHTML =  "There was a problem retrieving data from the server.";
			document.body.style.cursor = "auto";
		}
	}
}
function SearchCompanyHome()
{
    var SearchTxt = document.getElementById("txtSearch").value;
    var ddlQuote = document.getElementById("ddlQuote").value;
    if(SearchTxt =="" || SearchTxt=="Company Name")
    {
        alert("Please enter Company Name ..!!!");
        document.getElementById("txtSearch").value="";
        document.getElementById("txtSearch").focus();
        return false;
    }

    else
    {
         var StrUrl= "CompanyProfile/CompanyList.aspx?SrchQuote="+SearchTxt+"&id="+ddlQuote; 
         parent.location.href=StrUrl;
         return false;
        
    }
}


//Home Right Control..

   function ShowGraphData(id)
    {

      if(id=="E")
      {
      
        document.getElementById("TrE").style.display="";
        document.getElementById("TrOther").style.display="none";
        
      }
      else
      {
         document.getElementById("TrE").style.display="none";
        document.getElementById("TrOther").style.display="";
      }

    /// alert(id);
       var startDiv="<div id='topkNavContainer' ><div id='kNav'>";
       var endDiv ="</div></div>";
       if(id=='E'){ document.getElementById("CommTabEMCI").innerHTML=startDiv + "<ul><li class='sep'></li><li id='li_Equity' class='CursorHand'><a class='CursorNormal'>EQUITY</a></li><li class='sep'></li><li id='li_MF'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;M&#39;)'>MUTUAL FUND </a></li><li class='sep'></li><li style='display:none' id='li_IPO'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;I&#39;)'>IPO</a></li><li class='sep'></li><li id='li_Comm'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;C&#39;)'>COMMODITIES</a></li></ul>" + endDiv;  document.getElementById("li_MF").className="unsel";document.getElementById("li_Equity").className="sel";document.getElementById("li_Comm").className="unsel";document.getElementById("li_IPO").className="unsel";BindChart("BSE"); ChangeControl('GAIN','BSE');   CallSensexNifty('BSE');}
       else if(id=='M') {document.getElementById("CommTabEMCI").innerHTML=startDiv + "<ul><li class='sep'></li><li id='li_Equity' class='CursorHand'><a href='javascript:ShowGraphData(&#39;E&#39;)'>EQUITY</a></li><li class='sep'></li><li id='li_MF'class='CursorNormal'><a class='CursorNormal'>MUTUAL FUND</a></li><li class='sep'></li><li style='display:none' id='li_IPO'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;I&#39;)'>IPO</a></li><li class='sep'></li><li id='li_Comm'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;C&#39;)'>COMMODITIES</a></li></ul>" + endDiv;document.getElementById("li_MF").className="sel";document.getElementById("li_Equity").className="unsel";document.getElementById("li_Comm").className="unsel";document.getElementById("li_IPO").className="unsel";
                         document.getElementById("Graph_Td").innerHTML="<table cellpadding='0' cellspacing='0' width='100%'><tr>     <td id='tddatetime' class='NewsDate' align='left' style='width: 166px;white-space: nowrap; padding-left: 5px'></td><td style='width: 44px; height: 19px' id='tdBSE' class='BSENSESelct' onclick=loadGLData('1YEARRET','Eqt','TB','Top')>Top</td><td style='width: 3px'></td><td style='width: 44px; height: 19px;' id='tdNSE' class='BSENSESelct' onclick=loadGLData('1YEARRET','Eqt','TB','Bott')>Bottom</td></tr><tr><td valign='top' colspan='4' align='center'  style='height:130px' valign='top'><div id='MFChart' >Loading.. </div></td></tr></table>";
                                       loadGLData('1YEARRET','Eqt','TB','Top');document.getElementById("trCom").style.display="none";document.getElementById("trMf").style.display ="";   
                 } 
        else if(id=='I') {document.getElementById("CommTabEMCI").innerHTML=startDiv + "<ul><li class='sep'></li><li id='li_Equity' class='CursorHand'><a href='javascript:ShowGraphData(&#39;E&#39;)'>EQUITY</a></li><li class='sep'></li><li id='li_MF'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;M&#39;)'>MUTUAL FUND</a></li><li class='sep'></li><listyle='display:none' id='li_IPO'class='CursorNormal'><a class='CursorNormal'>IPO</a></li><li class='sep'></li><li id='li_Comm'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;C&#39;)'>COMMODITIES</a></li></ul>" + endDiv;document.getElementById("li_MF").className="unsel";document.getElementById("li_Equity").className="unsel";document.getElementById("li_Comm").className="unsel";document.getElementById("li_IPO").className="sel";
         document.getElementById("Graph_Td").innerHTML="<table cellpadding='0' cellspacing='0' width='100%'><tr><td valign='top' colspan='4'  style='height:130px' valign='top'><div id='BSENSEChart' >Loading.. </div></td></tr><tr><td id='TD_SENSEXNDATA' colspan=5></td></tr><tr><td style='height:5px'></td></tr></table>";
               ShowIPOChart(); IPOData();document.getElementById("trCom").style.display="none";document.getElementById("trMf").style.display ="none" ; 
        } 
         else if(id=='C') {document.getElementById("CommTabEMCI").innerHTML=startDiv + "<ul><li class='sep'></li><li id='li_Equity' class='CursorHand'><a href='javascript:ShowGraphData(&#39;E&#39;)'>EQUITY</a></li><li class='sep'></li><li id='li_MF'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;M&#39;)'>MUTUAL FUND</a></li><li class='sep'></li><li style='display:none' id='li_IPO'class='CursorNormal'><a href='javascript:ShowGraphData(&#39;I&#39;)'>IPO</a></li><li class='sep'></li><li id='li_Comm'class='CursorNormal'><a class='CursorNormal'>COMMODITIES</a></li></ul>" + endDiv;document.getElementById("li_MF").className="unsel";document.getElementById("li_Equity").className="unsel";document.getElementById("li_Comm").className="sel";document.getElementById("li_IPO").className="unsel";
         document.getElementById("Graph_Td").innerHTML="<table cellpadding='0' cellspacing='0' width='100%'><tr><td id='tddatetime' class='NewsDate' align='left' style='width: 166px;white-space: nowrap; padding-left: 5px'>[15 min Delay]</td><td style='width: 44px; height: 19px' id='tdBSE' class='BSENSESelct' onclick=ComData(&#39;GOLD&#39;);ShowChartCom(&#39;Gold&#39;);>Gold</td><td style='width: 3px'></td><td style='width: 44px; height: 19px;' id='tdNSE' class='BSENSESelct' onclick=ComData(&#39;Silver&#39;);ShowChartCom(&#39;Silver&#39;);>Silver</td></tr><tr><td valign='top' colspan='4'  style='height:130px' valign='top'><div id='CommChart' >Loading.. </div></td></tr><tr><td id='TD_SENSEXNDATA' colspan=5></td></tr><tr><td style='height:5px'></td></tr></table>";
          ComData('GOLD');ShowChartCom('Gold');document.getElementById("trCom").style.display="";document.getElementById("trMf").style.display ="none";
     
         } 
         
    }

  function BindChart(val)
    {
         
             if(val=='BSE')
             {
             document.getElementById("bseTab").className="BSENSESelct";
             document.getElementById("nseTab").className="BSENSEUnSelct";
             document.getElementById("hdnbsense").value=val;
            
             }
             else
             {
               document.getElementById("bseTab").className="BSENSEUnSelct";
               document.getElementById("nseTab").className="BSENSESelct";
               document.getElementById("hdnbsense").value=val;
            
             }
             var so = new SWFObject("amline/amline.swf", "BSENSEline","255", "150", "8", "#FFFFFF");
		    so.addVariable("path", "amline/");
		    so.addParam("wmode","opaque");
    		
    		
		    so.addVariable("settings_file", encodeURIComponent("amline/Equity_settings.xml"));
		    so.addVariable("data_file", encodeURIComponent("CommonControl/BSENSEchartAjax.aspx?Exchg="+val+"&TimeStamp="+new Date().getTime()));
		    //alert("BSENSEchartAjax.aspx?Exchg="+val+"&TimeStamp="+new Date().getTime());
    		
		    so.write("TdChart");
		    ChangeControl('GAIN',val);  
		    CallSensexNifty(val);
           
    }
    function loadGLData(Period,Category,TopGl,typ)
{

        if(typ=='Top')
         {
         document.getElementById("tdBSE").className="BSENSESelct";
         document.getElementById("tdNSE").className="BSENSEUnSelct CursorHand";
         }
         else
         {
         document.getElementById("tdBSE").className="BSENSEUnSelct CursorHand";
         document.getElementById("tdNSE").className="BSENSESelct";
         }
   
	var TopGl;
	if(Period=='')
		Period = "1YEAR";
	if(Category=='')	
		Category="ALL";
		
		//alert(Period)
		//alert(Category)
	 	var so = new SWFObject("amcolumn/amcolumn.swf", "Fundcolumn", "255", "125", "8", "#ffffff");
		so.addVariable("path", "amcolumn/");
		so.addParam("wmode","opaque");
		so.addVariable("settings_file", encodeURIComponent("amcolumn/MFHome_settings_Bar.xml"));
		so.addVariable("data_file", encodeURIComponent("CommonControl/AjaxFundData.aspx?Period="+ Period +"&Category="+ Category +"&TopGl="+ TopGl+"&typ="+typ+"&TimeStamp="+new Date().getTime() ));
		//alert("AjaxFundData.aspx?Period="+ Period +"&Category="+ Category +"&TopGl="+ TopGl+"&typ="+typ+"&TimeStamp="+new Date().getTime());
		
	    so.write("MFChart");
	 
	    so.addParam("wmode","opaque");
		
}
function ShowChartCom(opt)
{
/// alert(opt);
  var startDiv="<div id='topkNavContainer'><div id='kNav'>";
       var endDiv ="</div></div>";
	     if(opt=='Gold')
         {
      document.getElementById("tdBSE").className="BSENSESelct";
         document.getElementById("tdNSE").className="BSENSEUnSelct CursorHand";   }
         else
         {
           document.getElementById("tdBSE").className="BSENSEUnSelct CursorHand";
         document.getElementById("tdNSE").className="BSENSESelct";}
		var so = new SWFObject("amline/amline.swf", "Bullionline", "255", "135", "8", "#ffffff");
		so.addVariable("path", "amline/");
		so.addParam("wmode","opaque");
		so.addVariable("settings_file", encodeURIComponent("amcolumn/GoldSilverChart.xml"));
		
		///so.addVariable("data_file", encodeURIComponent(GetHostUrlForPages+"/Common/BullionchartComAjax.aspx?Exchg=MCX&Symbol="+opt+"&TimeStamp="+new Date().getTime()));
		
	so.addVariable("data_file", encodeURIComponent("Commodity/GetPriceChart.aspx?Exchg=MCX&Symbol="+opt+"&ExpDate=null&TimeStamp="+new Date().getTime()));
		
		so.write("CommChart");
}
 function ChangeControlC(Opt,Exch)
    {
   
	var requestUrl = "CommonControl/AjaxDataGLCom.aspx?typeGL="+ Opt +"&Exchange="+ Exch;	
	//alert(requestUrl);
	 var ajax = new Ajax.Updater('Td_ComData',requestUrl)
     var Head_td =document.getElementById("CHeading");
	switch (Opt)
	{
	case "G":
		Head_td.innerHTML="Gainers";
	  
		break;
		
	case "L":

		Head_td.innerHTML="Losers";
		
	break;
	
	case "Vol":
		Head_td.innerHTML="Volume";
	break;
	
	case "Val":
	    Head_td.innerHTML="Value";
	break;
	
	}
    
    
    
    }	
  function GetNFO()
	{	
	
		var requestUrl = "CommonControl/AjaxNFOData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		   var ajax = new Ajax.Updater('NFOID',requestUrl)		
    }
 function ChangeControl(Opt,Exch)
    {

   
	    var requestUrl = "CommonControl/AjaxDataGLVV.aspx?Option="+ Opt +"&Exchange="+ Exch; 
	     //alert(requestUrl);
      
      
        var ajax = new Ajax.Updater('Td_Data',requestUrl)
       //alert(ajax)
       
         var Head_td =document.getElementById("Heading");
        var More=document.getElementById("More");
        var BSE_td =document.getElementById("Td_BSE");
        var NSE_td =document.getElementById("Td_NSE");
	    switch (Opt)
	    {
	    case "GAIN":
		    Head_td.innerHTML="Gainers";
		    if(document.getElementById("Head_td"))
		    {
		    document.getElementById("Head_td").className="CursorHand";
		    }
    	    break;
    		
	    case "LOSE":
		    Head_td.innerHTML="Losers";
		    if(document.getElementById("Head_td"))
		    {
		    document.getElementById("Head_td").className="CursorHand";
		    }
       break;
    	
	    case "Vol":
		    Head_td.innerHTML="Volume";
		    if(document.getElementById("Head_td"))
		    {
		    document.getElementById("Head_td").className="CursorHand";
		    }
    	 break;
    	
	    case "Val":
	        Head_td.innerHTML="Value";
	        if(document.getElementById("Head_td"))
		    {
		    document.getElementById("Head_td").className="CursorHand";
		    }
    	  break;
    	
	    }
        
        
        
    }
    
       function CallSensexNifty(Exch)
{
//alert();
      var RequestUrl = "CommonControl/AjaxaSenNiftyHome.aspx?Exchange="+Exch+"&timeStamp="+new Date().getTime();   
     // alert(RequestUrl);
      ajaxpage(100,RequestUrl,'tdSensex');
}
  function ajaxpage(id,url, containerid)
{

    var page_request = false
        if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
        else if (window.ActiveXObject)
        { // if IE
                try {
                    page_request = new ActiveXObject("Msxml2.XMLHTTP")
                    } 
                catch (e){
                        try{
                            page_request = new ActiveXObject("Microsoft.XMLHTTP")
                            }
                        catch (e){}
                        }
        }


        page_request.onreadystatechange=function()
        {
            loadpage(page_request, containerid)
        }
     
        page_request.open('GET', url, true)
         document.body.style.cursor = "auto";	
        page_request.send(null)    
}	
function loadpage(page_request, containerid)
{
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
 {   
   var sdata=page_request.responseText;
   var s=sdata.split('|');
   
   //alert(s[1]);
   
    document.getElementById(containerid).innerHTML=s[0];
     document.getElementById("tddatetime").innerHTML=s[1];
    
    }
   
}	

function ComData(Val)
{
      var RequestUrl = "CommonControl/AjaxComData.aspx?InstType="+Val+"&J="+new Date().getTime();
           ajaxpage(100,RequestUrl,'TD_SENSEXNDATA');

}	


