/* Browser Checking */
    
    var browserName=navigator.appName;
	var TR;
	var TD;
    if(browserName=="Microsoft Internet Explorer")
    {
         TR="inline";
         TD="inline";
    }
    else if(browserName=="Netscape")
    {
         TR="table-row";
         TD="table-cell";
    }    
    
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();
		}
	}

//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 getTickerData(Exchg)
	{
	
	        document.getElementById("Ticker1_drp_FundHouse").selectedIndex=0;
//        if (Exchg == "NAV")	
//            document.getElementById("Ticker1_drp_FundHouse").style.display=TD;
//        else    
//            document.getElementById("Ticker1_drp_FundHouse").style.display="none";   
            
//		alert("check");
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl ="../TickerData.aspx?Exchg="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		//document.write(requestUrl);
		
		if(XmlHttp)	
		{
					XmlHttp.onreadystatechange = function(){getDataResponseTicker(Exchg);};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
		}
	}
function getMktTickerData(Exchg)
	{
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl ="../Markets/MktTickerData.aspx?Exchg="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		//document.write(requestUrl);
		if(XmlHttp)	
		{
					XmlHttp.onreadystatechange = function(){getMktDataResponseTicker(Exchg);};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
		}
	}
function getDataResponseTicker(Exchg)
{
//    if(XmlHttp.readyState == 1)
//    {
//    var MarqueeId = document.getElementById("MarqueeId1");
//    MarqueeId.innerHTML ="Ticker Loading.....";
//    }
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{			
			var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
            var browserName=navigator.appName; 
			if(browser.isIE )//&& browserName=="Opera") 
				var MarqueeId = document.getElementById("MarqueeId1");
			else
				var MarqueeId = document.getElementById("MarqueeId");
			var Mq_Data = XmlHttp.responseText;
//			alert(Mq_Data);
			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;:&nbsp;&nbsp;"+ ClPrice  +"&nbsp;"+clss+"&nbsp;"+ DiffVal +"&nbsp;</span>&nbsp;&nbsp;&nbsp;";
						}	
						else
						{
//							stkDet += "<a href='../Scripsearch.aspx?opt=1&id=74&cocode="+ arrCol[0] +"' class=TickerLink>" + CompName +"</a>&nbsp;&nbsp;:&nbsp; "+ ClPrice +"&nbsp;"+clss+"&nbsp;"+DiffVal +"</span> &nbsp;&nbsp;&nbsp;";
                            stkDet += "<a href='../CorporateInfo/Scripsearch.aspx?opt=1&id=401&cocode="+ arrCol[0] +"' class=TickerLink>" + CompName +"</a>&nbsp;&nbsp;:&nbsp; "+ ClPrice +"&nbsp;"+clss+"&nbsp;"+DiffVal +"</span> &nbsp;&nbsp;&nbsp;";
						}	
				}
				var browserName=navigator.appName; 
				if(browser.isIE)
					MarqueeId.innerHTML = "<marquee id='MarqueeId' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='35' direction='left' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
//				else if(browserName=="Opera")				
//					MarqueeId.innerHTML = "<marquee id='MarqueeId' onmouseover='this.stop();' onmouseout='this.start();' 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 getMktDataResponseTicker(Exchg)
{
//    if(XmlHttp.readyState == 1)
//    {
//    var MarqueeId = document.getElementById("MarqueeId1");
//    MarqueeId.innerHTML ="Ticker Loading.....";
//    }
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{			
			var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
            var browserName=navigator.appName; 
			if(browser.isIE )//&& browserName=="Opera") 
				var MarqueeId = document.getElementById("MarqueeId1");
			else
				var MarqueeId = document.getElementById("MarqueeId");
			var Mq_Data = XmlHttp.responseText;
			//alert(Mq_Data);
			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;:&nbsp;&nbsp;<span class='TickerText1'>"+ ClPrice  +"</span>&nbsp;"+clss+"&nbsp;"+ DiffVal +"&nbsp;</span>&nbsp;&nbsp;&nbsp;";
						}	
						else
						{
//							stkDet += "<a href='../Scripsearch.aspx?opt=1&id=74&cocode="+ arrCol[0] +"' class=TickerLink>" + CompName +"</a>&nbsp;&nbsp;:&nbsp; "+ ClPrice +"&nbsp;"+clss+"&nbsp;"+DiffVal +"</span> &nbsp;&nbsp;&nbsp;";
                            stkDet += "<a href='../CorporateInfo/Scripsearch.aspx?opt=1&id=401&cocode="+ arrCol[0] +"' class=TickerLink1>" + CompName +"</a>&nbsp;&nbsp;:&nbsp;<span class='TickerText1'> "+ ClPrice +"</span>&nbsp;"+clss+"&nbsp;"+DiffVal +"</span> &nbsp;&nbsp;&nbsp;";
						}	
				}
				var browserName=navigator.appName; 
				if(browser.isIE)
					MarqueeId.innerHTML = "<marquee id='MarqueeId' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='35' direction='left' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
//				else if(browserName=="Opera")				
//					MarqueeId.innerHTML = "<marquee id='MarqueeId' onmouseover='this.stop();' onmouseout='this.start();' 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 == "NAV")	
        document.getElementById("Ticker1_drp_FundHouse").style.display=TD;
    else 
    {   
        document.getElementById("Ticker1_drp_FundHouse").style.display="none"; 
        //alert(Exchg); 	
        if (Exchg == "BSE")	
            getTickerData('BSE');
        else if (Exchg == "NSE")		
            getTickerData('NSE');
     }	   
}


function ticker()
{ 
	CreateXmlHttp();
	ctype = document.getElementById("Ticker1_drp_FundHouse").value;
//	if (ctype == "" || ctype == "undefined")
//		document.getElementById("MarqueeId").innerHTML= "<marquee id='MfMarquee' class='Marquee' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount=1 scrollDelay=35 direction=left width='99%'><table cellspacing=0 cellpadding=0 border=0><tr><td nowrap height='19'><span class='TickerText1'>Select a Fund</span></td></tr></table></marquee>";
//	else
//	{
	var url="TickerData.aspx?opt=NAV&sid=" + Math.random() + "&ctype=" + document.getElementById("Ticker1_drp_FundHouse").value 
//		alert(url);
	XmlHttp.onreadystatechange = function(){stateChangedTicker();};
//	XmlHttp=GetXmlHttpObject(stateChangedTicker)
	XmlHttp.open("GET", url , true)
	XmlHttp.send(null)
//	}
} 

function stateChangedTicker() 
{ 
    if (XmlHttp.readyState==4 || XmlHttp.readyState=="complete")
	{ 
	        
			var browserName=navigator.appName; 
			if(browser.isIE )//&& browserName=="Opera") 
				var MarqueeId = document.getElementById("MarqueeId1");
			else
				var MarqueeId = document.getElementById("MarqueeId");
			var Mq_Data = XmlHttp.responseText;
			
			if(browser.isIE)
				MarqueeId.innerHTML = "<marquee id='MarqueeId' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='35' direction='left' loop='repeat' width='100%'>" + Mq_Data + "</marquee>";
            else
				MarqueeId.innerHTML = Mq_Data;	
//	alert(XmlHttp.responseText );
	//	document.getElementById("MarqueeId").innerHTML=XmlHttp.responseText 
	} 
}

 function ChangeBseNseTabInner(exchgVal,exchDef)
 {
        if(exchgVal =="BSE")
	    {		
            document.getElementById("Img_NSEL").src="../images/nse_off.gif";
            document.getElementById("Img_BSEL").src="../images/bse_on.gif";
            document.getElementById("Img_BSEL").style.cursor="default";
            document.getElementById("Img_NSEL").style.cursor="pointer";	
            getMktTickerData('BSE');
	    }
	    else 
	    {   			
            document.getElementById("Img_NSEL").src="../images/nse_on.gif";
            document.getElementById("Img_BSEL").src="../images/bse_off.gif";
            document.getElementById("Img_BSEL").style.cursor="pointer";
            document.getElementById("Img_NSEL").style.cursor="default";	
            getMktTickerData('NSE');
	    }
 }