﻿// / JScript File

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;
  }

  // Treat any other "Gecko" browser as NS 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}
var browser = new Browser();
var clockTimeoutID;
//Global Variables
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 getTickerData()
	{	
		
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		document.getElementById("MarqueeId").innerHTML = " <img src='../App_Themes/CommonTheme/images/ajax-loader.gif'>";
	
		var requestUrl = "../commoncontrols/AjaxTickerData.aspx?timeStamp="+new Date().getTime();

		
		if(XmlHttp){
			XmlHttp.onreadystatechange = function(){getDataResponse();};
			XmlHttp.open("GET", requestUrl,  true);
			XmlHttp.send(null);
		}
}
function getDataResponse()
{

	if(XmlHttp.readyState == 4)
	{	
	
		if(XmlHttp.status == 200)
		{	
				
	
			var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
			var MarqueeId = document.getElementById("MarqueeId");
			var TickerData = XmlHttp.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) 
						{
							DiffImg= "<img src='../images/up.gif'>";
							clss = "<span class='Green'>" ;
						}
						else if(DiffVal<0) 
						{							
							DiffImg="<img src='../images/down.gif'>";
							clss = "<span class='Red'>" ;
						}
						else 
						{
							DiffImg= "<img src='../images/eq.gif'>";
							clss = "<span class='Green'>"	;				
						}
							
						//if(i==0)ExchgDet = arrCol[0] +" &nbsp; "+ CompName +": "+ ClPrice +" ["+ DiffVal +"] "+ DiffImg +" &nbsp; ";else stkDet += "<a href='getQuotes.aspx?code="+ arrCol[0] +"' class=TickerLink>" + CompName +"</a>: "+ ClPrice +" ["+ DiffVal +"] "+ DiffImg +" &nbsp; ";    href='../profile/CorpInfo.aspx?id=1&code="+ arrCol[0] +"'
						if(i==0)ExchgDet = "<span class='BlackNormal'>" + arrCol[0] +" &nbsp; "+ CompName +": "+"<span  class=BlackNormal>" + ClPrice+"&nbsp;"+ clss +" ["  +"<b>"+ DiffVal+ "</b>"+"]</span> </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span class='TickerLink'>" + "<a href='../companyprofile/compsnapshot.aspx?FinCode="+arrCol[0]+"'><span  class=BlackNormal>" + CompName +"</span></a>: " + "<span  class=BlackNormal>" + ClPrice +"&nbsp;"+ clss +" [" +"<b>"+ DiffVal+ "</b>"+"]</span>  &nbsp;</span>&nbsp;";						
						
				}
				
				if(browser)
				
					MarqueeId.innerHTML = "<marquee id='maqid' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='50' direction='left' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
	
					
				else
					MarqueeId.innerHTML = ExchgDet + stkDet;				
				document.body.style.cursor = "auto";
				ExchngTimeClock();
		}
		
		//else
			//MarqueeId.innerHTML = "<img src='../CommonImgs/loading1.gif'>";
	}
}

function ExchngTimeClock() {
	 var time = new Date()
	 var hour = time.getHours()
	 if (hour >= 10 && hour <= 20)
			  clockTimeoutID = setTimeout("getTickerData()",600000);
	}
	
	
	function ChangeSpeed(Option)
	{
	
	 var Marq = document.getElementById("maqid");
	 
	 
	 
	 if(Option=="+")
	 {
	 if(Marq.scrollDelay == "10")
	 return;
	 else
	 Marq.scrollDelay = eval(Marq.scrollDelay)-10;
	 
	 }
	 
	 else
	 {
	 if(Marq.scrollDelay == "90")
	 return;
	 else
	 Marq.scrollDelay = eval(Marq.scrollDelay)+10;
	 
	 }
	 
	 if(Marq.scrollDelay == "10")
	 {
	 document.getElementById("ImgUp").style.cursor = "text";
	 document.getElementById("ImgUp").src = "../App_Themes/CommonTheme/images/plus_disable.gif";
	 }
	 else
	 {
	 document.getElementById("ImgUp").style.cursor = "hand";
	 document.getElementById("ImgUp").src = "../App_Themes/CommonTheme/images/plus_act.gif";
	 }
	 
	 if(Marq.scrollDelay == "90")
	 {
	 document.getElementById("ImgDown").style.cursor = "text";
	  document.getElementById("ImgDown").src = "../App_Themes/CommonTheme/images/minus_disable.gif";
	 }
	 else
	 {
	 document.getElementById("ImgDown").style.cursor = "hand";
	 document.getElementById("ImgDown").src = "../App_Themes/CommonTheme/images/minus_act.gif";
	 }
	 
	 
	}
