﻿// JScript File


 function SelectClassLive(val,secid,subsecid)
{
  for(i = 1; i<= 4 ; i++)
  {
      if(val == i)
      {
        document.getElementById("tdd"+i).className ="HomeSelect";
      }
      else
      {
        document.getElementById("tdd"+i).className ="HomeUnSelect";
      }
  }
  GetNews(secid,subsecid);

}

function SelectClass(val,secid,subsecid)
{
  for(i = 1; i<= 4 ; i++)
  {
      if(val == i)
      {
          if(i==4)
          {
             document.getElementById("td"+i).className ="HomeNewsSelectLast";
          }
          else
          {
             document.getElementById("td"+i).className ="HomeNewsSelect";
          }
      }
      else
      {
     
        if(i==4)
          {
             document.getElementById("td"+i).className =" HomeNewsUnSelectLast";
          }
          else
          {
             document.getElementById("td"+i).className ="HomeNewsUnSelect";
          }
        
      }
  }
  GetNews(secid,subsecid);

}

var XmlHttpNews;

function CreateXmlHttpNew()
	{
	
		try
		{
			XmlHttpNews = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpNews = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpNews = null;	
			}
		}
	
		if(!XmlHttpNews && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpNews = new XMLHttpRequest();
		}
	}

function GetNews(secid,subsecid)
{
   CreateXmlHttpNew();
 	document.body.style.cursor = "progress";
	var requestUrl = HostUrlForPages+"/Home/AjaxNews.aspx?sec="+secid+"&subsec="+subsecid+"&TimeStamp="+new Date().getTime();
	
	if(XmlHttpNews!=null)	
	{
	    XmlHttpNews.onreadystatechange = function(){ChangeResponseNews()}
		XmlHttpNews.open('GET', requestUrl,  true);
		XmlHttpNews.send(null);
	}
	return false; 
}

function ChangeResponseNews()
{
	if(XmlHttpNews.readyState == 4)
	{//alert( XmlHttpNews.responseText);
	    var td_Id = document.getElementById("tdnews");
		if(XmlHttpNews.status == 200)//
		{
		
	//alert(td_Id);
			td_Id.innerHTML =  XmlHttpNews.responseText;
			document.body.style.cursor = "auto";		
		}
		else
		{
		    td_Id.innerHTML =  "There was a problem retrieving data from the server.";
			document.body.style.cursor = "auto";
		}
	}
}


var XmlHttp

function CreateXmlHttp()
{
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttp = null;				
		}
	}
	if(!XmlHttp && typeof XMLHttpRequest != "undefined")
	{
		XmlHttp = new XMLHttpRequest();
	}
}


function ChangeControl(Opt,Exch)
{
	CreateXmlHttp();
       var currentDivObj = document.getElementById("Td_Data");
        
		//currentDivObj.innerHTML ="<img src=App_Themes/CommonTheme/Images/ajax-loader.gif>";
	document.body.style.cursor = "progress";
	
	
	var requestUrl = HostUrlForPages+"/Home/AjaxDataGLVV.aspx?Option="+ Opt +"&Exchange="+ Exch+"&TimeStamp="+new Date().getTime();
   //alert(requestUrl) 
	if(XmlHttp!=null)	
	        {
				XmlHttp.onreadystatechange = function(){ChangeControlResponse(Opt,Exch)}
				XmlHttp.open('GET', requestUrl,  true);
				XmlHttp.send(null);
			}
			 return false; 
}	
	
function ChangeControlResponse(Opt,Exch)
{
    var Head_td =document.getElementById("Heading");
     
     var tdgain =document.getElementById("tdgain");
     var tdlos =document.getElementById("tdlos");
     var tdvol =document.getElementById("tdvol");
     var tdval =document.getElementById("tdval");
    
    
    
    

	switch (Opt)
	{
	case "GAIN":
		Head_td.innerHTML="BSE GAINERS";
	   
		 tdgain.className ="GLVALVOLSelect";
		 tdlos.className="GLVALVOLUNSelect";
		 tdvol.className="GLVALVOLUNSelect";
		 tdval.className="GLVALVOLUNSelect";
		break;
		
	case "LOSE":
		Head_td.innerHTML="BSE LOSERS";
		 tdgain.className ="GLVALVOLUNSelect";
		 tdlos.className="GLVALVOLSelect";
		 tdvol.className="GLVALVOLUNSelect";
		 tdval.className="GLVALVOLUNSelect";
//		 if(Exch=='BSE')
//	    {
//		More.innerHTML="<a class='HomeMore' href='../Equity/TopGainersAndLosers.aspx?Option=LOSE&EXCHG=BSE&id=1&index=0'>More</a>";
//		}
//		else
//		{
//		More.innerHTML="<a class='HomeMore' href='../Equity/TopGainersAndLosers.aspx?Option=LOSE&EXCHG=NSE&id=1&index=0'>More</a>";
//		}
	break;
	
	case "Vol":
		Head_td.innerHTML="BSE VOLUME";
		 tdgain.className ="GLVALVOLUNSelect";
		 tdlos.className="GLVALVOLUNSelect";
		 tdvol.className="GLVALVOLSelect";
		 tdval.className="GLVALVOLUNSelect";
//		 if(Exch=='BSE')
//	    {
//		More.innerHTML="<a class='HomeMore' href='../Equity/MostActive.aspx?id=2&Option=Volume&EXCHG=BSE&index=0'>More</a>";
//		}
//		else
//		{
//		    More.innerHTML="<a class='HomeMore' href='../Equity/MostActive.aspx?id=2&Option=Volume&EXCHG=NSE&index=0'>More</a>";
//		}
	break;
	
	case "Val":
	    Head_td.innerHTML="BSE VALUE";
	     tdgain.className ="GLVALVOLUNSelect";
		 tdlos.className="GLVALVOLUNSelect";
		 tdvol.className="GLVALVOLUNSelect";
		 tdval.className="GLVALVOLSelect";
//	     if(Exch=='BSE')
//	    {
//		More.innerHTML="<a class='HomeMore' href='../Equity/MostActive.aspx?id=2&Option=Value&EXCHG=BSE&index=0'>More</a>";
//		}
//		else
//		{
//		    More.innerHTML="<a class='HomeMore' href='../Equity/MostActive.aspx?id=2&Option=Value&EXCHG=NSE&index=0'>More</a>";
//		}
	break;
	
	}

	// To make sure receiving response data from server is completed
	
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		var td_Id = document.getElementById("Td_Data");
	  // alert( XmlHttp.responseText)
		if(XmlHttp.status == 200)//
		{
			td_Id.innerHTML =  XmlHttp.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 BindChart(val)
    {
         
            
             var so = new SWFObject(HostUrlForPages+"/amline/amline.swf", "BSENSEline","219", "150", "8", "#f1f1f1");
		    so.addVariable("path", HostUrlForPages+"/amline/");
		    so.addParam("wmode","opaque");
    		
    		
		    so.addVariable("settings_file", encodeURIComponent(HostUrlForPages+"/amline/Equity_settings.xml"));
		    so.addVariable("data_file", encodeURIComponent(HostUrlForPages+"/Home/BSENSEchartAjax.aspx?Exchg="+val+"&TimeStamp="+new Date().getTime()));
		    //alert("BSENSEchartAjax.aspx?Exchg="+val+"&TimeStamp="+new Date().getTime());
    		
		    so.write("TdChart");

         CallSensexNifty(val);
           
    }
    
    
    
    var XmlHttpSensexnifty

function CreateXmlHttpSensexnifty()
{
	try
	{
		XmlHttpSensexnifty = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpSensexnifty = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpSensexnifty = null;				
		}
	}
	if(!XmlHttpSensexnifty && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpSensexnifty = new XMLHttpRequest();
	}
}

    
    
    
    function CallSensexNifty(Exch)
    {
        CreateXmlHttpSensexnifty();
      var requestUrl = HostUrlForPages+"/Home/AjaxSensexNifty.aspx?Exchange="+Exch+"&timeStamp="+new Date().getTime();   
      
      	if(XmlHttpSensexnifty!=null)	
	        {
				XmlHttpSensexnifty.onreadystatechange = function(){CallSensexNiftyResponse()}
				XmlHttpSensexnifty.open('GET', requestUrl,  true);
				XmlHttpSensexnifty.send(null);
			}
			 return false; 
    }
function CallSensexNiftyResponse()
{
	if(XmlHttpSensexnifty.readyState == 4)
	{//alert( XmlHttpSensexnifty.responseText);
	    var td_Id = document.getElementById("tdsensex");
		if(XmlHttpSensexnifty.status == 200)//
		{
		   var sdata=XmlHttpSensexnifty.responseText;
	       var s=sdata.split('|');
   
   
   
          td_Id.innerHTML=s[0];
          document.getElementById("tddatetime").innerHTML=s[1];
			//td_Id.innerHTML =  XmlHttpSensexnifty.responseText;
			document.body.style.cursor = "auto";		
		}
		else
		{
		    td_Id.innerHTML =  "There was a problem retrieving data from the server.";
			document.body.style.cursor = "auto";
		}
	}
}
var XmlHttpCompTicker="";
 function CreateXmlHttpCompTicker()
{
	try
	{
		XmlHttpCompTicker = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpCompTicker = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpCompTicker = null;				
		}
	}
	if(!XmlHttpCompTicker && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpCompTicker = new XMLHttpRequest();
	}
}

function getTickerDataCom(Exchg)
{	
    CreateXmlHttpCompTicker();
	
		//var BSEImg = document.getElementById("BSEImg");
		//var NSEImg = document.getElementById("NSEImg");
		var Direc;
		
		if (Exchg=="BSE")
		{
		   //document.getElementById('BSEImg').className = "TickerOn";
		  // document.getElementById('NSEImg').className = "TickerOff";
		   Direc = "left";
		}
		else if (Exchg=="NSE")
		{
		   // document.getElementById('BSEImg').className = "TickerOff";
		   //document.getElementById('NSEImg').className = "TickerOn";
		    Direc = "left";
		}
		
		
		
	var requestUrl = HostUrlForPages+"/Home/AjaxTickerData.aspx?Exchange="+ Exchg +"&timeStamp="+new Date().getTime();
	
	if(XmlHttpCompTicker)
	{
		XmlHttpCompTicker.onreadystatechange = function(){getDataResponseComp(Exchg,Direc);};
		XmlHttpCompTicker.open("GET", requestUrl,  true);
		XmlHttpCompTicker.send(null);
	}
}  

function getDataResponseComp(Exchg,Direc)
{
//alert(XmlHttpCompTicker.responseText);
    if(XmlHttpCompTicker.readyState == 4)
	{	
	    if(XmlHttpCompTicker.status == 200)
		{	

		    var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
			var MarqueeId = document.getElementById("MarqueeId");
			var TickerData = XmlHttpCompTicker.responseText;
						
			if(TickerData != "")
			var arrRow = TickerData.split("|");
				
			for(i=0; i<arrRow.length-1; i++)
			{
			    arrCol = arrRow[i].split("~");
				CompName = arrCol[1];
				ClPrice  = arrCol[2];
				DiffVal  = arrCol[3];
				
				if(DiffVal>0) 
				{
					clss = "<span class='Green'>" ;
					DiffVal="+"+DiffVal;
				}
				else if(DiffVal<0) 
				{							
					clss = "<span class='Red'>" ;
				}
				else if(DiffVal==0) 
				{
					clss = "<span class='Blue'>"	;				
				} 
				
				if(i==0)
			   ExchgDet = "<span class='TickerText'>" + arrCol[0] +" &nbsp; "+ CompName +": "+"<span  class=TickerText>" + ClPrice+"&nbsp;"+" :"+ clss + DiffVal+ "%</span>"+" </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span >" + "<a target='_parent' class='LinkNew' href='#'><span  class=TickerText>" + CompName +"</span></a>: " + "<span  class=TickerText>" + ClPrice +"&nbsp;"+" :"+ clss  + DiffVal+ "%</span>"+"  &nbsp;</span>&nbsp;";																					
			//	ExchgDet = "<span class='TickerText'>" + arrCol[0] +" &nbsp; "+ CompName +": "+"<span  class=TickerText>" + ClPrice+"&nbsp;"+" ["+ clss + DiffVal+ "%</span>"+"] </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span >" + "<span  class=TickerText>" + CompName +"</span>: " + "<span  class=TickerText>" + ClPrice +"&nbsp;"+" ["+ clss  + DiffVal+ "%</span>"+"]  &nbsp;</span>&nbsp;";																					
			
			}
			//http://tatasecserver.accordhostings.com/markets/company-profile/quotes-home.aspx?id=65&FinCode=132540
			MarqueeId.innerHTML = "<marquee id='MarqueeIdTD' style='vertical-align:middle;text-decoration:none;' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='30' direction='"+Direc+"' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
			document.getElementById("MarqueeIdTD").start();
			document.body.style.cursor = "auto";
		}
	}
}


function ShowHideHomeTab(first,second,third,fourth)
{
    document.getElementById(first).style.display="";
    document.getElementById(second).style.display="none";
    document.getElementById(third).style.display="none";
    if(fourth=="EqHome")
    {
      document.getElementById(fourth).style.display="";
      document.getElementById('MfHome').style.display="none";
      document.getElementById('IPOHome').style.display="none";
    }
    else if(fourth=="MfHome")
    {
      document.getElementById(fourth).style.display="";
       document.getElementById('EqHome').style.display="none";
      document.getElementById('IPOHome').style.display="none";
    }
      else if(fourth=="IPOHome")
    {
      document.getElementById(fourth).style.display="";
        document.getElementById('EqHome').style.display="none";
      document.getElementById('MfHome').style.display="none";
    
    }
}


function ShowIPOChart()
{
        
	    var so = new SWFObject(HostUrlForPages+"/amcolumn/amcolumn.swf", "Fundcolumn", "219px", "200", "8", "#f1f1f1");
		so.addVariable("path", HostUrlForPages+"/amcolumn/");
		so.addParam("wmode","opaque");
		so.addVariable("settings_file", encodeURIComponent(HostUrlForPages+"/amcolumn/Fundcolumn_settings_Bar.xml"));
		so.addVariable("data_file", encodeURIComponent(HostUrlForPages+"/Home/AjaxIPOChart.aspx?timeStamp="+ new Date().getTime() ));
	    so.write("Graph_Td");
	    so.addParam("wmode","opaque");
}
 function ShowPopupHome()
 {
 var url = "Static/LiveStrming.aspx";
 window.open(url,'SIC','x=0,y=0,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=505px,height=500,screenX=0,screenY=0,left=210,top=200');
 
}
