// for market commentary
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();
	}
}



// Ajax used for Market commentry of home page
function getMarketNews(srno,secid,subsecid)
{	
	CreateXmlHttp();
	document.body.style.cursor = "Auto";		
	var MktCom = document.getElementById("HeadLine");
	document.getElementById(srno).className="TablinkSel";	
	MktCom.innerHTML = "<img src=../images/loading1.gif>";
	var requestUrl = "../GetMktCommentary.aspx?secno="+secid+"&srno="+srno+"&subsecid="+ subsecid+"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();    
	if(XmlHttp)	
	{			
		XmlHttp.onreadystatechange = function(){getNewsData(MktCom);};
		XmlHttp.open("GET", requestUrl,  true);
		XmlHttp.send(null);
	}
}

function getNewsData(id)
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{
		    
			id.innerHTML = XmlHttp.responseText;
		}
	}
}

/* For NCDEX & MCX Live Quotes*/
var exchng1;
var secs;
var timerID = null;
var timerRunning = false;

function InitializeTimer()
{	
    secs = 60;
    StopTheClock();
    StartTheTimer();
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}

function StartTheTimer()
{
    if (secs==0)
    {		
        getncdexlivequote(exchng1);
        InitializeTimer();       
    }
    else
    {
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", 1000);
    }      
}

var XmlHttpQuote;
function CreateXmlHttpQuote()
{
	try
	{
		XmlHttpQuote = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpQuote = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpQuote = null;
				
		}
	}
	if(!XmlHttpQuote && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpQuote = new XMLHttpRequest();
	}
}

function getncdexlivequotedetails(exchng)
{
	var  ncdexquotetd1= document.getElementById("ncdexquotetd");
	if(XmlHttpQuote.readyState == 4)
	{
		//alert(XmlHttpQuote.responseText);	
		if(XmlHttpQuote.status == 200)
			ncdexquotetd1.innerHTML = XmlHttpQuote.responseText;					
		else
			ncdexquotetd1.innerHTML = "<img src=../images/loading1.gif>";		
	}

}


function getncdexlivequote(exchng)
{	
	exchng1=exchng;
	if(exchng == 'NCDEX')
	{
		document.getElementById("TR_NCDEX").style.display="inline";
		document.getElementById("TR_MCX").style.display="none";		
	}
	else
	{
		document.getElementById("TR_NCDEX").style.display="none";
		document.getElementById("TR_MCX").style.display="inline";		
	}
	
	CreateXmlHttpQuote();
	document.body.style.cursor = "progress";	
	var requestUrl = "../Commodity/NCDEXQuotesAjax.aspx?Exchng="+exchng;
	if(XmlHttpQuote)
	{
		XmlHttpQuote.onreadystatechange = function(){getncdexlivequotedetails(exchng);};
		XmlHttpQuote.open("GET", requestUrl,  true);
		XmlHttpQuote.send(null);
	}		
}

function Txtempty()
{   
	if (document.getElementById("TxtUname").value=="username")
	{
  		document.getElementById("TxtUname").value="";
	}
}
function Txtempty1()
{   
	if (document.getElementById("TxtPwd").value=="password")
	{
  		document.getElementById("TxtPwd").value="";
	}
}

function Txtfill()
{
   	var GetUname=document.getElementById("TxtUname").value;   
	if (GetUname=="")
	{
		document.getElementById("TxtUname").value="username";
	}		
}
function Txtfill1()
{   	
   	var GetPwd=document.getElementById("TxtPwd").value;
	if (GetPwd=="")
	{
		document.getElementById("TxtPwd").value="password";
	}
}