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 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(Exchg)
	{
		
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "../TickerData.aspx?Exchg="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getDataResponseTicker(Exchg);};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}

function getDataResponseTicker(Exchg)
{

	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.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 = 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) 
						{
							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;&nbsp;" + clss + DiffVal +"</span> &nbsp;&nbsp;&nbsp;";
						else
							stkDet += "<a href='#' class=TickerText>" + CompName +"</a>&nbsp; "+ ClPrice +" &nbsp;&nbsp;"+ clss + [DiffVal] +"</span> &nbsp;&nbsp;&nbsp;";
							//stkDet += "<a href='../corporateInfo/ScripSearch.aspx?opt=1&id=1&cocode="+ arrCol[0] +"' class=TickerText>" + CompName +"</a>&nbsp; "+ ClPrice +" &nbsp;&nbsp;"+ clss + [DiffVal] +"</span> &nbsp;&nbsp;&nbsp;";
				}
				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
					MarqueeId.innerHTML = ExchgDet + stkDet;				
				document.body.style.cursor = "auto";
				ExchngTimeClock(Exchg);
		}
		
	}
}
 
 function Details(sno,secid,subsecid)
 {
	var wind_new;
	wind_new=window.open("../Newsdetails.aspx?sno="+sno+"&secid="+secid+"&subsecid="+subsecid+"", "DetailNews", "status = 1, height = 390, width =435, resizable = 0,scrollbars=1,left=200,top=200" )
	wind_new.focus();
 }
 
 function ChangeTab(Exchg)
			{
				var PriceChart = document.getElementById("ChartImg");			
				if(Exchg=="Bse")
					{
						document.getElementById("Bse").style.display="inline";
						document.getElementById("Nse").style.display="none";
						document.getElementById("A_B").className="TabOn";
						document.getElementById("A_N").className="TabOff";
						document.getElementById("Td_B").className="TabOn";
						document.getElementById("Td_N").className="TabOff";
						
						//PriceChart.src="http://www.cmlinks.com/pub/chart/Aadhar_BSE.png";
						PriceChart.src="http://www.cmcharts.cmlinks.com/nsebsecharts/Aadhar_BSE.png";
					}
				else
					{
						document.getElementById("Bse").style.display="none";
						document.getElementById("Nse").style.display="inline";				
						document.getElementById("A_B").className="TabOff";
						document.getElementById("A_N").className="TabOn";
						document.getElementById("Td_N").className="TabOn";
						document.getElementById("Td_B").className="TabOff";
						
						/*PriceChart.src="http://www.cmlinks.com/pub/chart/Aadhar_NSE.png";*/
						PriceChart.src="http://www.cmcharts.cmlinks.com/nsebsecharts/Aadhar_NSE.png";
						
					}
			}	
			
			function ChangeMarketHomeTab(Exchg)
			{
				var PriceChart = document.getElementById("ChartImg");			
				if(Exchg=="Bse")
					{
						document.getElementById("Bse").style.display="inline";
						document.getElementById("Nse").style.display="none";
						document.getElementById("A_B").className="TabOn";
						document.getElementById("A_N").className="TabOff";
						document.getElementById("Td_B").className="TabOn";
						document.getElementById("Td_N").className="TabOff";
						document.getElementById("AD_B").style.display ="inline";
						document.getElementById("AD_N").style.display ="none";
						//PriceChart.src="http://www.cmlinks.com/pub/chart/Aadhar_BSE.png";
						PriceChart.src="http://www.cmcharts.cmlinks.com/nsebsecharts/Aadhar_BSE.png";
					}
				else
					{
						document.getElementById("Bse").style.display="none";
						document.getElementById("Nse").style.display="inline";				
						document.getElementById("A_B").className="TabOff";
						document.getElementById("A_N").className="TabOn";
						document.getElementById("Td_N").className="TabOn";
						document.getElementById("Td_B").className="TabOff";
						document.getElementById("AD_B").style.display ="none";
						document.getElementById("AD_N").style.display ="inline";
						//PriceChart.src="http://www.cmlinks.com/pub/chart/Aadhar_NSE.png";
						PriceChart.src="http://www.cmcharts.cmlinks.com/nsebsecharts/Aadhar_NSE.png";
					}
			}	
			
			function ChangeTicker()
			{
				
				if(document.getElementById("DDL_Exchg").value =="Bse")
					{
						getTickerData('BSE');		
					}
				else
					{
						getTickerData('NSE');		
					}
				
			}	
			
function startstop()
{
	
	var id=document.getElementById("StopImg");
	if (id.src.indexOf("Tick_stop.gif")!=-1)
	{
		
		id.src = "../images/Tick_play.gif"
		document.getElementById("MarqueeId").stop();
		id.alt = "Play";
	}
	else
	{
		id.src="../images/Tick_stop.gif";
		document.getElementById("MarqueeId").start();
		id.alt = "Stop";
	}
}

//Market News & commentary 	
function GetNewsDet(secId,SrNo)
	{
		var currentDivObj = document.getElementById(SrNo);
		if(currentDivObj.style.display=='inline')
		{
				currentDivObj.style.display ='none';
				eval("document.IMG"+SrNo+".src = '../images/Menuoff.gif'");
		}
		else
		{
				//alert("ad")
				currentDivObj.style.display ='inline';
				eval("document.IMG"+SrNo+".src = '../images/Menuon.gif'");
				var tblObj=document.getElementById("NewsId").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 = '../images/Menuoff.gif'");}}

				if(currentDivObj.innerHTML=="")
				{
					currentDivObj.innerHTML ="<img src=../images/loading1.gif>";
					CreateXmlHttp();
					document.body.style.cursor = "progress";
					var requestUrl = "../News/NewsData.aspx?SecId="+ secId +"&SrNo="+ SrNo +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
					
					if(XmlHttp)	{
								XmlHttp.onreadystatechange = function(){getNewsDetResp(SrNo);};
								XmlHttp.open("GET", requestUrl,  true);
								XmlHttp.send(null);
							}
				}
			}	
	}
	
function getNewsDetResp(SrNo)
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{
			document.getElementById(SrNo).innerHTML = XmlHttp.responseText;
			document.body.style.cursor = "auto";
		}
		else
			document.getElementById(SrNo).innerHTML = "<img src='../images/loading1.gif'>";
	}
}

	function KeyingCom(Txt)
		{
		
			var Txt = Txt.value;
			if(Txt.value == "Enter Your Company Name")
				{
					Txt.value = "";
					Txt.value = String.fromCharCode(event.keyCode);
					return false;
				}
			else if(event.keyCode == 13)
			{
				SearchTextCom();
				return false;	
			}
		}
		function SearchTextCom()
		{
			var Txt = document.getElementById("CompanyList1_Txt");
			if (Txt.value == "")
				{
				alert("Enter few characters to search");
				Txt.focus();
				return false;
				}	
			else
			{
				var StrUrl = "../CorporateInfo/CompanySearch.aspx?schtxt="+Txt.value+"";
				window.location = StrUrl;
			}
			return true;
		}
		