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;
//Creating object of XMLHTTP For AJAX Method
function CreateXmlHttp()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttp = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttp = new XMLHttpRequest();
		}
	}
//**** Function ExchngTimeClock Is used for to find out the market hours --- The ticker will automatically refresh only in market timings *****//			
function ExchngTimeClock(Exchg) {
	 var time = new Date()
	 var hour = time.getHours()
	 if (hour >= 10 && hour <= 20)
			  clockTimeoutID = setTimeout("getTickerData('"+ Exchg +"')",600000);
	}
	
//**** Function killClock Is used for killing clock timer  *****//
function killClock(){
	clearTimeout(clockTimeoutID);
	}		

//For Loading Inner ticker from TickerData.aspx Using AJAX
function getInnerTicker(Exchg)
	{
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		document.getElementById("MarqueeId").innerHTML = " <img src='../CommonImgs/cm_loading.gif'>";
		var requestUrl = "../TickerData.aspx?Exchg="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getDataResponse(Exchg);};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}
		
//For Loading ticker from TickerData.aspx Using AJAX
function getTickerData(Exchg)
	{
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		document.getElementById("MarqueeId").innerHTML = " <img src='../CommonImgs/cm_loading.gif'>";
		if(Exchg=="NSE"){document.TickImg.src="images/NseTickOn.gif";ExchgImg="BSE";}else{document.TickImg.src="images/BseTickOn.gif";ExchgImg="NSE";}
		var requestUrl = "../TickerData.aspx?Exchg="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getDataResponse(Exchg);};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}
	
//Called when response comes back from server Only For Ticker
function getDataResponse(Exchg)
{
	// 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
		if(XmlHttp.status == 200)
		{			
			var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
			var MarqueeId = document.getElementById("MarqueeId");
			var Mq_Data = XmlHttp.responseText;
			
			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) DiffImg= " <img src='../CommonImgs/up.gif'> <span class=TextGr>"+ DiffVal +"</span>";else if(DiffVal<0) DiffImg="<img src='../CommonImgs/down.gif'> <span class=TextRd>"+ DiffVal +"</span>";else DiffImg= "<img src='../CommonImgs/eq.gif'> <span class=TextBl>"+ DiffVal +"</span>";						
						if(i==0)ExchgDet = arrCol[0] +" &nbsp; "+ CompName +": "+ ClPrice +" ["+ DiffImg +"] &nbsp; ";else stkDet += "<a href='Profile/ScripSearch.aspx?cocode="+ arrCol[0] +"&pnav=PI3_PI0' class=TickerLink>" + CompName +"</a>: "+ ClPrice +" ["+ DiffImg +"] &nbsp; ";
				}
				if(browser.isIE)
					MarqueeId.innerHTML = "<marquee 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;				
				document.body.style.cursor = "auto";
				ExchngTimeClock(Exchg);
		}
		else
		{
			MarqueeId.innerHTML = "<img src='../CommonImgs/cm_loading.gif'>";
		}
	}
}	


//For Loading ticker from NewsData.aspx Using AJAX
function GetNewsDet(secId,SrNo)
	{
		var currentDivObj = document.getElementById(SrNo);
		if(currentDivObj.style.display=='inline'){
				currentDivObj.style.display ='none';eval("document.IMG"+SrNo+".src = '../CommonImgs/plus.gif'");}
			else
			{
				currentDivObj.style.display ='inline';
				eval("document.IMG"+SrNo+".src = '../CommonImgs/minus.gif'");
				var tblObj = document.getElementById("NewsId").getElementsByTagName("td");
				//var tblObj=document.getElementsByTagName("td");
				var IdName;
				for(var i=1;i<tblObj.length;i++){
					IdName = tblObj[i].id;
					if(IdName)
						if(IdName!=SrNo){
							document.getElementById(IdName).style.display = "none";eval("document.IMG"+IdName+".src = '../CommonImgs/plus.gif'");}}

				if(currentDivObj.innerHTML=="")
				{
					currentDivObj.innerHTML ="<img src=../CommonImgs/loading1.gif>";
					CreateXmlHttp();
					document.body.style.cursor = "progress";
					var requestUrl = "../NewsData.aspx?SecId="+ secId +"&SrNo="+ SrNo +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
					if(XmlHttp)	{
								XmlHttp.onreadystatechange = function(){getNewsDet(SrNo);};
								XmlHttp.open("GET", requestUrl,  true);
								XmlHttp.send(null);
							}
				}
			}	
	}

	
//For Loading ticker from CompNewsData.aspx Using AJAX
function GetCompNewsDet(SrNo)
	{
		var currentDivObj = document.getElementById(SrNo);
		if(currentDivObj.style.display=='inline'){
				currentDivObj.style.display ='none';eval("document.IMG"+SrNo+".src = '../CommonImgs/plus.gif'");}
			else
			{
				currentDivObj.style.display ='inline';
				eval("document.IMG"+SrNo+".src = '../CommonImgs/minus.gif'");
				var tblObj = document.getElementById("NewsId").getElementsByTagName("td");
				//var tblObj=document.getElementsByTagName("td");
				var IdName;
				for(var i=1;i<tblObj.length;i++){
					IdName = tblObj[i].id;
					if(IdName)
						if(IdName!=SrNo){
							document.getElementById(IdName).style.display = "none";eval("document.IMG"+IdName+".src = '../CommonImgs/plus.gif'");}}

				if(currentDivObj.innerHTML=="")
				{
					currentDivObj.innerHTML ="<img src=../CommonImgs/loading1.gif>";
					CreateXmlHttp();
					document.body.style.cursor = "progress";
					var requestUrl = "CompNewsData.aspx?SrNo="+ SrNo +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
					if(XmlHttp)	{
								XmlHttp.onreadystatechange = function(){getNewsDet(SrNo);};
								XmlHttp.open("GET", requestUrl,  true);
								XmlHttp.send(null);
							}
				}
			}	
	}	
	
//Called when response comes back from server Only For NewsData
function getNewsDet(SrNo)
{
	// 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
		if(XmlHttp.status == 200)
		{
			document.getElementById(SrNo).innerHTML = XmlHttp.responseText;
			document.body.style.cursor = "auto";
		}
		else
			document.getElementById(SrNo).innerHTML = "<img src='../CommonImgs/loading1.gif'>";
	}
}


//For Loading ticker from MfTopGLData.aspx Using AJAX
function loadGLData(Period,Category,TopGl)
		{				
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var TopGl;
		if(Period=='')
			Period = "1YEAR";
		if(Category=='')	
			Category="ALL";
		//var requestUrl = "MfTopGLData.aspx?Period="+ Period +"&Cat="+ Category +"&TopGL="+ TopGl;
		var requestUrl = "MFtopglData.aspx?Period="+ Period +"&Cat="+ Category +"&TopGl="+ TopGl;		
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){GLResponse(TopGl)}
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}	

//Called when response comes back from server Only For Gainers/Loser
function GLResponse(TopGl)
{
	// 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
		if(XmlHttp.status == 200)
		{	
			var GainerId = document.getElementById("GainerLoserCtrl1_GainerId");
			var LoserId  = document.getElementById("GainerLoserCtrl1_LoserId");
			var strGlData = XmlHttp.responseText
			if(TopGl=='T')
				GainerId.innerHTML = strGlData;
			  else
				LoserId.innerHTML = strGlData;
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			if(TopGl=='T')
				GainerId.innerHTML = "There was a problem retrieving data from the server.";
			else
				LoserId.innerHTML =  "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}
}		

//For Loading ticker from CategoryRetData.aspx Using AJAX
function loadCatRet(Period)
	{		
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		if(Period=='')
			Period = "1YEAR";
		var requestUrl = "CategoryRetData.aspx?Period="+Period;
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = CatRetResponse;
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}	
	
	//Called when response comes back from server Only For Category Return
function CatRetResponse()
{
	// 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
		if(XmlHttp.status == 200)
		{			
			var EquityId   = document.getElementById("CategoryRetCtrl1_TopNavTab0View");
			var DebtId     = document.getElementById("CategoryRetCtrl1_TopNavTab1View");
			var BalancedId = document.getElementById("CategoryRetCtrl1_TopNavTab2View");
			//window.alert(XmlHttp.responseText);
			var strData = XmlHttp.responseText
			if(strData != "")
			{
				var arrDateSplit = strData.split("|");
				EquityId.innerHTML   = arrDateSplit[0];
				DebtId.innerHTML     = arrDateSplit[1];
				BalancedId.innerHTML = arrDateSplit[2];
			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			EquityId.innerHTML = "There was a problem retrieving data from the server.";
			DebtId.innerHTML = "There was a problem retrieving data from the server.";
			BalancedId.innerHTML = "There was a problem retrieving data from the server.";
			document.body.style.cursor = "auto";
		}
	}
}

//For Loading News Flash data  Using AJAX
function NewsFlash()
		{	
					
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		document.getElementById("cm_windowNews").style.display='inline';		
		//var requestUrl = "MFtopglData.aspx?Period="+ Period +"&Cat="+ Category +"&TopGl="+ TopGl;	
		var requestUrl = "../FlashNewsText.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();		
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){NewsFlashResponse()}
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}	
	
function NewsFlashResponse()
{
	// 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
		if(XmlHttp.status == 200)
		{
			document.getElementById("TdNewsText").innerHTML = XmlHttp.responseText;
			document.body.style.cursor = "auto";
		}
		else
			document.getElementById("TdNewsText").innerHTML = "<img src='../CommonImgs/loading1.gif'>";
	}
}


