//tickerData = document.getElementById("tickerData")
//alert(tickerData)
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 CreateXmlHttp1()
	{
		try
		{
			XmlHttp1 = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttp1 = null;
					
			}
		}
		if(!XmlHttp1 && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttp1 = new XMLHttpRequest();
		}
	}
//Home page Ticker

var xmlHttp
var browser = new Browser();

function Browser() {
  var ua, s, i;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

function ExchngTimeClock(Exchg) {
	 var time = new Date() 
	 var hour = time.getHours()
	 if (hour >= 10 && hour <= 20)
		  clockTimeoutID = setTimeout("getTickerData('"+ Exchg +"')",600000);
	}
function StartTicker()
{
	window.close();
	window.opener.document.getElementById("tickerData").style.display='inline';
}	
function startstop()
{
	/*document.getElementById("tickerData").style.display = 'none'
	var tick_win;
	getTickerData('BSE')
	tick_win = window.open("../ticker_pop.aspx","DetailNews1","status=1,height=120,width=800,resizable=0,scrollbars=0,left=50,top=100")
	tick_win.focus();*/
	
	var id=document.getElementById("StopImg");
	if (id.src.indexOf("tickerstop.gif")!=-1)
	{
		
		id.src = "../images/tickerplay.gif"
		document.getElementById("MarqueeId").stop();
		id.title = "Play";
	}
	else
	{
		id.src="../images/tickerstop.gif";
		document.getElementById("MarqueeId").start();
		id.title = "Stop";
	}

}
function getTickerData(Exchg)
	{
		//alert(Exchg);
		CreateXmlHttp1();
		document.body.style.cursor = "progress";
		var requestUrl ="../TickerData.aspx?Exchg="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		//alert(requestUrl);
		if(XmlHttp1)	
		{
					XmlHttp1.onreadystatechange = function(){getDataResponseTicker(Exchg);};
					XmlHttp1.open("GET", requestUrl,  true);
					XmlHttp1.send(null);
		}
	}

function getDataResponseTicker(Exchg)
{
	if(XmlHttp1.readyState == 4)
	{
		if(XmlHttp1.status == 200)
		{			
			var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
			if(browser.isIE)
				var MarqueeId = document.getElementById("MarqueeId1");
			else
				var MarqueeId = document.getElementById("MarqueeId");
			var Mq_Data = XmlHttp1.responseText;
			//alert("dd");
			//alert(MarqueeId);
			//alert("afterr");
			if(Mq_Data != "")
			var arrRow = Mq_Data.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='TickerGreen'>"
						}
						else if(DiffVal<0) 
						{
							clss = "<span class='TickerRed'>"
						}
						else 
						{
							clss = "<span class='TickerGreen'>"
						}
						if(i==0)
						{
							//ExchgDet = arrCol[0] +" &nbsp; "+ CompName +"&nbsp;&nbsp;"+ ClPrice  +"&nbsp;"+clss+"&nbsp;[&nbsp;"+ DiffVal +"&nbsp;]</span>&nbsp;&nbsp;&nbsp;";
							//ExchgDet = arrCol[0] +" &nbsp; "+ CompName +"&nbsp;&nbsp;"+ ClPrice  +"&nbsp;"+clss+"&nbsp;"+ DiffVal +"&nbsp;]</span>&nbsp;&nbsp;&nbsp;";
							ExchgDet = arrCol[0] +" &nbsp; "+ CompName +"&nbsp;&nbsp;"+ ClPrice  + " &nbsp; " + clss + DiffVal +"</span> &nbsp;&nbsp;&nbsp;";
						}	
						else
						{
							//stkDet += "<a href='#="+ arrCol[0] +"' class=TickerLink>" + CompName +"</a>&nbsp; "+ ClPrice +"&nbsp;"+clss+"&nbsp;"+DiffVal +")</span> &nbsp;&nbsp;&nbsp;";
							stkDet += "<a href='../CorporateInfo/Scripsearch.aspx?opt=1&id=74&cocode="+ arrCol[0] +"' class=TickerLink>" + CompName +"</a>&nbsp; "+ ClPrice +" &nbsp;&nbsp;"+ clss + DiffVal +"</span> &nbsp;&nbsp;&nbsp;";
							//stkDet += "<a href='javascript:void(&#39;0&#39;);' onclick='javascript:Encrypt(1,&#39;../CorporateInfo/Scripsearch.aspx?opt=1&id=74&cocode="+ arrCol[0] +"&#39;);' class=TickerLink>" + CompName +"</a>&nbsp; "+ ClPrice +" &nbsp;&nbsp;["+ clss + DiffVal +"</span>] &nbsp;&nbsp;&nbsp;";
							//stkDet += "<a href=javascript:RedirectPage('DetailedQuotes.aspx?cocode="+ arrCol[0] +"'); class=TickerLink>" + CompName +"</a>&nbsp; "+ ClPrice +" &nbsp;&nbsp;["+ clss + DiffVal +"</span>] &nbsp;&nbsp;&nbsp;";
							
						}	
						
				}
				if(browser.isIE)
					MarqueeId.innerHTML = "<marquee id='MarqueeId' onmouseover='javascript:OnmouseStop()'; onmouseout='javascript:OnmouseStart()'; trueSpeed scrollAmount='1' scrollDelay='35' direction='left' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
				else
					MarqueeId.innerHTML = ExchgDet + stkDet;				
					
					
					//alert(MarqueeId.innerHTML);
				document.body.style.cursor = "auto";
				ExchngTimeClock(Exchg);
		}
	}
	
}

function changeTicker(Exchg)
{
	if (Exchg == "BSE")
	{ 
		document.getElementById("BscId").src="../images/tbse_on.gif"
		document.getElementById("NscId").src="../images/tnse_off.gif"
		document.getElementById("BscId").style.cursor="default";
		document.getElementById("NscId").style.cursor="pointer";
		getTickerData('BSE');

	}
	else
	{
		document.getElementById("NscId").style.cursor="default";
		document.getElementById("BscId").style.cursor="pointer";
		document.getElementById("NscId").src="../images/tnse_on.gif"
		document.getElementById("BscId").src="../images/tbse_off.gif"
		getTickerData('NSE');
		
		
	}
	
	
}
function changeTickerpop(Exchg)
{
	if (Exchg == "BSE")
	    { 
		document.getElementById("AhrefBSE1").className="Ticksel"
		document.getElementById("AhrefNSE1").className="TickUnsel"
		getTickerData('BSE');
	}
	else
	{
		document.getElementById("AhrefBSE1").className="TickUnsel"
		document.getElementById("AhrefNSE1").className="Ticksel"
		getTickerData('NSE');
	}
}


function RedirectPage(url)
  {
	//alert("sdf");
	var newWin;
	var newWin=window.open(url,"DetailNews", "status = 1, height =370, width=620, resizable=0, scrollbars=1,left=50,top=100");	
	//alert(newWin);
	newWin.focus();
  }
  
//function OnmouseStart()
//  {
//    document.getElementById("MarqueeId").start();
//  }
//function OnmouseStop()
//  {
//    document.getElementById("MarqueeId").stop();
//  }
