function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 


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();

//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();
		}
	}
	
var XmlHttp1	
function CreateXmlHttp1()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttp1 = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttp1 = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttp1 && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttp1 = new XMLHttpRequest();
		}
	}
	
	//For Home Corporate News
	function CreateXmlHttp2()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttp2 = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttp2 && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttp2 = 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 ticker from TickerData.aspx Using AJAX
function getTickerData(Exchg)
	{
	
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		//document.getElementById("MarqueeId").innerHTML = " <img src='../imagess/loading1.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);
				}
	}
	
	//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 align='absmiddle' src='../images/TickUp.gif'>";
							}
						else if(DiffVal < 0)
							{
							 DiffImg="<img align='absmiddle' src='../images/Tickdown.gif'>";	
							}
						else
						 {
						  DiffImg="<img align='absmiddle' src='../images/eq.gif'>";
						 }
						
						if(i==0)ExchgDet = arrCol[0] +" &nbsp; <a href='#' class=GreyTickerLink>"+ CompName +"</a>&nbsp;:"+ClPrice+" ["+DiffImg+"&nbsp;" + DiffVal + "] &nbsp;&nbsp;&nbsp;";else stkDet += "<a href='../Profiles/CorpInfo.aspx?&id=12&code="+ arrCol[0] +"' class=GreyTickerLink>" + CompName +"</a>&nbsp;:"+ClPrice+" ["+DiffImg+"&nbsp;" + DiffVal + "]  &nbsp;";
				}
				if(browser.isIE)
					MarqueeId.innerHTML = "<marquee onmouseover='this.stop();' id='marq' onmouseout='this.start();' class=GreyTxtTicker 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='../images/loading1.gif'>";
	}
}

//Home page Corporate news
function NewsCorporate(newsid)
{	var TdId;
	if(newsid=='corR')
	{
	document.getElementById("NewsTd").style.display="inline";
	document.getElementById("AnnTd").style.display="none";
	document.getElementById("corNTd").style.display="none";
	
	document.getElementById("ResTab").className="newsTable";
	document.getElementById("AnnTab").className="newsTableOff";
	document.getElementById("CorTab").className="newsTableOff";
	TdId="NewsCor";
	}
else if(newsid=='corAnn')
	{
	document.getElementById("NewsTd").style.display="none";
	document.getElementById("AnnTd").style.display="inline";
	document.getElementById("corNTd").style.display="none";
	
	document.getElementById("ResTab").className="newsTableOff";
	document.getElementById("AnnTab").className="newsTable";
	document.getElementById("CorTab").className="newsTableOff";
	TdId="NewsAnn";
	}
else if(newsid=='corN')
	{
	document.getElementById("NewsTd").style.display="none";
	document.getElementById("AnnTd").style.display="none";
	document.getElementById("corNTd").style.display="inline";
	
	document.getElementById("ResTab").className="newsTableOff";
	document.getElementById("AnnTab").className="newsTableOff";
	document.getElementById("CorTab").className="newsTable";
	TdId="NewsCorN";
	//document.getElementById("moreLink3").innerHTML = "<img src=../imagess/bullet_more01.gif align=absmiddle> &nbsp;<a target=_parent href=http://202.154.164.250/News/IntNews.aspx?Heading=InternationalMarkets&Query=http://www.hdfcsec.cmlinks.com/NewsHotList.aspx?secid=1&subsecid=8>More</a>";
	}
	
	
var currDivObj;
currDivObj = document.getElementById(""+TdId+"");
currDivObj.innerHTML="<img src=../images/loading1.gif>";
CreateXmlHttp2();

document.body.style.cursor = "progress";
var reqUrl="../NewsCorpData.aspx?NewsId="+ newsid +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();

if(XmlHttp2)	{
				XmlHttp2.onreadystatechange = function(){NewsCorpDetails(newsid,TdId);};
				XmlHttp2.open("GET", reqUrl, true);
				XmlHttp2.send(null);
			}
}

function NewsCorpDetails(id,td)
{
// To make sure receiving response data from server is completed
if(XmlHttp2.readyState == 4)
		{
		
			// To make sure valid response is received from the server, 200 means response received is OK
			if(XmlHttp2.status == 200)
			{
			var strNewsData = XmlHttp2.responseText;
			
			if(id=="corR")
			{
			document.getElementById("NewsCor").innerHTML = strNewsData;
			}
			else if(id=="corAnn")
			{
				document.getElementById("NewsAnn").innerHTML = strNewsData;
			}
			else if(id=="corN")
			{
				document.getElementById("NewscorN").innerHTML = strNewsData;
			}
			document.body.style.cursor="auto";
			}
			else
				document.getElementById(""+td+"").innerHTML = "<img src='../images/loading7.gif'>";
		}
}

function TickerData(ex,typ)
{ 
if (ex == "")
{
	document.getElementById("Foff").src = "../images/futureoff1.gif"
	document.getElementById("Son").src = "../images/spotoff.gif"
	var spot1 = document.getElementById("spot1");
	var spot2 = document.getElementById("spot2");
	var fut1 = document.getElementById("fut1");
	var fut2 = document.getElementById("fut2");
	if (typ=="S")
	{
	document.getElementById("Son").src = "../images/spoton.gif"
	document.getElementById("SF").value = "S"
	spot1.style.display = "inline";
	spot2.style.display = "none";
	fut1.style.display = "none";
	fut2.style.display = "inline";
	}
	else
	{
	document.getElementById("Foff").src = "../images/futureon1.gif"
	document.getElementById("SF").value = "F"
	spot1.style.display = "none";
	spot2.style.display = "inline";
	fut1.style.display = "inline";
	fut2.style.display = "none";
	}
}
else
{
	if(ex=="MCX")
	{
		document.getElementById("MCX").src = "../images/mcxon.gif"
		document.getElementById("NCDEX").src = "../images/ncdexoff.gif"
		
		document.getElementById("Ech").value = "MCX"
	}
	else
	{
		document.getElementById("MCX").src = "../images/mcxoff.gif"
		document.getElementById("NCDEX").src = "../images/ncdexon.gif"
		
		document.getElementById("Ech").value = "NCDEX"
	}
	
}

var url="tickerds.aspx?sid=" + Math.random() + "&Exchg="+document.getElementById("Ech").value+"&typ="+document.getElementById("SF").value
xmlHttp=GetXmlHttpObject(LoadTickerData)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
} 


function LoadTickerData() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
	document.getElementById("QuickLinks1_TD1").innerHTML=xmlHttp.responseText 
} 
else
{
	document.getElementById("QuickLinks1_TD1").innerHTML = "<img src=../images/loading1.gif>";
}
} 

function fillSymbol(Exchg)
	{
		var arrSymbol;
		var Symbol = document.getElementById("Symbol");
		cnt=1;
		if(Exchg!=''){
			if(Exchg=='MCX'){
				arrSymbol     = arrM_Symbol;
				arrSymbolText = arrM_CommName;
			}
			else if(Exchg=='NCDEX'){
				arrSymbol	  = arrN_Symbol;
				arrSymbolText = arrN_CommName;
			}
			Symbol.length = 0;
			Symbol.options[0] = new Option();
			Symbol.options[0].value = "";
			Symbol.options[0].text = "SELECT SYMBOL";
			for(var i=0; i < arrSymbol.length; i++)
			{
					Symbol.options[cnt] = new Option(); 
					Symbol.options[cnt].value = arrSymbol[i];
					Symbol.options[cnt].text = arrSymbolText[i];
					cnt = cnt + 1;
			}
		}	
  }
  
   //For Commodity ExpDate Using AJAX
function GetExpDate(Exchg,Symbol)
	{
		CreateXmlHttp1();
		document.body.style.cursor = "progress";
		var requestUrl = "ExpDateData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Exchg="+ Exchg +"&Symbol="+Symbol;
		if(XmlHttp1)	{
					XmlHttp1.onreadystatechange = function(){getDateResp()};
					XmlHttp1.open("GET", requestUrl,  true);
					XmlHttp1.send(null);
				}
	}
	
//Called when response comes back from server Only For ExpDateData
function getDateResp()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp1.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp1.status == 200)
		{
			var ExpDate   = document.getElementById("ExpDate");
			var strData = XmlHttp1.responseText
			if(strData != "") {	
				var arrExpDate = strData.split("|");
				ExpDate.length = 0; 	
				for(i=0; i<arrExpDate.length-1; i++) {	
					var strDate = arrExpDate[i];
					var arrExpDateCode = strDate.split("~");
					ExpDate.options[i] = new Option();
					ExpDate.options[i].value = arrExpDateCode[0];
					ExpDate.options[i].text = arrExpDateCode[1];
				}
			}
			else {
					ExpDate.length = 0;
					ExpDate.options[0] = new Option(); 
					ExpDate.options[0].value = "";
					ExpDate.options[0].text = "No Exp Date";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ExpDate.length = 0;
					ExpDate.options[0] = new Option(); 
					ExpDate.options[0].value = "";
					ExpDate.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}

function getCommQuotes()
	{
		var Exchg   = document.getElementById("Exchg").value;
		var Symbol   = document.getElementById("Symbol").value;
		var ExpDate   = document.getElementById("ExpDate").value;
		
		var StrUrl = "COMMODITY.aspx?id=2&Exchg="+ Exchg +"&Symbol="+ Symbol +"&ExpDate="+ ExpDate
		
		if(Exchg=="")
			alert("Please Select Exchange..!");
		else if(Symbol=="")
			alert("Please Select a Symbol..!");
		else if(ExpDate=="")
			alert("Please Select Expiry Date..!");
		else
		{
			window.location = StrUrl;
		}
 }
 
 
 //Function For Derivative Summary
function redUrl_FandO(ig_,ig_a,ig_b){
		var in_="",s_="";
		var qr_Str = ig_a.split("|");
		in_ = "&InstName="+ qr_Str[0]
		if(qr_Str.length==2)
			s_ = "&Symbol="+ qr_Str[1]
		document.location = ig_+ig_b+in_+s_;
}

function OptChange_FandO(ig_,ig_a){
		var Index = document.getElementById(ig_);
		Index.length = 0;
		for(var i=0; i < arrFAO.length; i++)
		{
			Index.options[i] = new Option(); 
			Index.options[i].value = arrFAOCode[i];
			Index.options[i].text = arrFAO[i];
			if(ig_a==arrFAOCode[i])
				Index.options[i].selected = true;
		}
}



 