﻿// JScript File

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 getTickerData(Exchg)
{	
    CreateXmlHttpCompTicker();
	document.body.style.cursor = "progress";
		
		var BSETickerTab = document.getElementById("BSETickerTab");
	
		var NSETickerTab = document.getElementById("NSETickerTab");
	
		
		if (Exchg=="BSE")
		{
		
		    BSETickerTab.className="TickerTabSelHM"; 
		    NSETickerTab.className="TickerTabUnSelHM"; 
		}
		else if (Exchg=="NSE")
		{
		   
	    	NSETickerTab.className="TickerTabSelHM"; 
		    BSETickerTab.className="TickerTabUnSelHM"; 
		}
		
		
		
	var requestUrl = "../Home/AjaxTickerData.aspx?Exchange="+ Exchg +"&timeStamp="+new Date().getTime();
	
	if(XmlHttpCompTicker)
	{
		XmlHttpCompTicker.onreadystatechange = function(){getDataResponseComp(Exchg);};
		XmlHttpCompTicker.open("GET", requestUrl,  true);
		XmlHttpCompTicker.send(null);
	}
}

function getDataResponseComp(Exchg)
{
    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("|");
				
				
				
				
					var BSENSEFIN;
				
				
				if (Exchg=='BSE')
				{
				BSENSEFIN = "218474";
				}
				
				if (Exchg=='NSE')
				{
				BSENSEFIN = "217829";
				}
				
				
				
			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'>" ;
				}
				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] +"</span> &nbsp; <a style='text-decoration:none; border:none' href='CompanyProfile/QuoteFinder.aspx?id=65&FinCode="+BSENSEFIN+"&Mode=S' class=TickerText>"+ CompName +": "+"</span></a><span  style='text-decoration:none; border:none' class=TickerText>" + ClPrice+"&nbsp;"+" ["+ clss   +"<b>"+ DiffVal+ "%</b></span>"+"] </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span class='TickerLink'>" + "<a  style='text-decoration:none; border:none' href='CompanyProfile/QuoteFinder.aspx?id=38&FinCode="+arrCol[0]+"&Mode=S'><span  class=TickerText>" + CompName +"</span></a>: " + "<span  class=TickerText>" + ClPrice +"&nbsp;"+" ["+ clss  +"<b>"+ DiffVal+ "%</b></span>"+"]  &nbsp;</span>&nbsp;";						
			}
			MarqueeId.innerHTML = "<marquee id='MarqueeIdTD'  valign='middle' style='vertical-align:bottom;display:block' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='30' direction='left' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
				
			document.getElementById("MarqueeIdTD").start();
			document.body.style.cursor = "auto";
		}
	}
}