
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();

function CreateXmlHttpCom()
{
	var XmlHttpCom;
		try
		{
			XmlHttpCom = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpCom = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpCom = null;
					
			}
		}
		if(!XmlHttpCom && typeof XMLHttpRequest != "undefined")
    {
        XmlHttpCom = new XMLHttpRequest();
    }
    return XmlHttpCom;
}

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();
	}
}

//for home ticker
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 Market Chart */

function ChangeIndex(Exchg)
{
  if(Exchg=="BSE")
  {
   document.getElementById("BSE1Tab").style.display="inline";
   document.getElementById("BSETab").style.display="inline";
   document.getElementById("NSETab").style.display="none";
   document.getElementById("NSE1Tab").style.display="none";
   var url=location.href;  
   url=url.toLowerCase();				
	if((url.indexOf("/index.aspx")!=-1) ||(url.indexOf(".aspx")==-1))	
	{					
		if(document.getElementById("tblNSEGL")!=null)					
		{				
			document.getElementById("tblBSEGL").style.display="inline";
			document.getElementById("tblNSEGL").style.display="none";						
		}
	}
   GetNewsDetail("BSE");
  }
  else
  {
   document.getElementById("BSETab").style.display="none";
   document.getElementById("BSE1Tab").style.display="none";
   document.getElementById("NSE1Tab").style.display="inline";
   document.getElementById("NSETab").style.display="inline";   
   
	var url=location.href;
	url=url.toLowerCase();	

	if((url.indexOf("/index.aspx")!=-1) ||(url.indexOf(".aspx")==-1))	
	{	
		if(document.getElementById("tblNSEGL")!=null)					
		{							
			document.getElementById("tblNSEGL").style.display="inline";
			document.getElementById("tblBSEGL").style.display="none";			
		}
	}	
   GetNewsDetail("NSE");
  }
}
/*Market home news*/
var XmlHttpnews;
function CreateXmlHttpnews()
{
	try
	{
		XmlHttpnews = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpnews = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpnews = null;
				
		}
	}
	if(!XmlHttpnews && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpnews = new XMLHttpRequest();
	}
}

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 getMainNews1(srno,secid,subsecid)
{	
	CreateXmlHttpnews();
	document.body.style.cursor = "progress";	
	var requestUrl1 = "../GetMFNews.aspx?secno="+secid+"&srno="+srno+"&subsecid="+ subsecid+"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();    
	if(XmlHttpnews)	
	{			
		XmlHttpnews.onreadystatechange = function(){getNewsData1();};
		XmlHttpnews.open("GET", requestUrl1,  true);
		XmlHttpnews.send(null);
	}
}
function getNewsData1()
{
	var  MktCom1= document.getElementById("HeadLine1");
	if(XmlHttpnews.readyState == 4)
	{
		if(XmlHttpnews.status == 200)
		{
			MktCom1.innerHTML = XmlHttpnews.responseText;
			document.body.style.cursor = "auto";
		}
		else
			MktCom1.innerHTML = "<img src=../images/loading1.gif>";		
	}
}

/*Market home news end*/

function getlivequotedetails(cocode)
{
	var  quotetd1= document.getElementById("quotetd");
	if(XmlHttpQuote.readyState == 4)
	{
		if(XmlHttpQuote.status == 200)
			quotetd1.innerHTML = XmlHttpQuote.responseText;
		else
			quotetd1.innerHTML = "<img src=../images/loading1.gif>";		
	}
}


function getlivequote(cocode)
{	
	CreateXmlHttpQuote();
	document.body.style.cursor = "progress";	
	var requestUrl = "../CompanyProfile/QuoteAjax.aspx?cocode="+cocode;
	if(XmlHttpQuote)
	{
		XmlHttpQuote.onreadystatechange = function(){getlivequotedetails(cocode);};
		XmlHttpQuote.open("GET", requestUrl,  true);
		XmlHttpQuote.send(null);
	}
}

function GetNewsDetail(Exchng)
{	
	CreateXmlHttp();
	document.body.style.cursor = "progress";	
	var requestUrl = "../BNAjax.aspx?Exchng="+ Exchng +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
	if(XmlHttp)	{
				XmlHttp.onreadystatechange = function(){getDetailsMktSnap();};
				XmlHttp.open("GET", requestUrl,  true);
				XmlHttp.send(null);
			}
}

function GetNewsDetails(SrNo,secId,SubSecId,opt,title)
{

        
	var NewsWin = document.getElementById("cm_window").style.display='inline';	
	var currentDivObj;
	if(opt=="main")
	{  
	   
		currentDivObj = document.getElementById("NewsId");
		currentDivObj.innerHTML ="<img src=../images/loading1.gif>";
	}	
	
	CreateXmlHttp();
	document.body.style.cursor = "progress";
	
	var requestUrl = "../Ajax/NewsData.aspx?SecId="+ secId +"&SubSecId="+ SubSecId+"&SrNo="+ SrNo +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
    
	
	if(XmlHttp)	
	{
				XmlHttp.onreadystatechange = function(){getnewDetails(opt);};
				XmlHttp.open("GET", requestUrl,  true);
				XmlHttp.send(null);
	}
}

function Reckoner(url)
{
	window.open(url,"","status =no, height =175, width =550px, resizable = 0,scrollbars=1,left=200,top=200" )
}

function ChangeIndex1(Exchg)
{
  if(Exchg=="BSE")
  {
   document.getElementById("BSE1Tab").style.display="inline";
   document.getElementById("BSETab").style.display="inline";
   document.getElementById("NSETab").style.display="none";  
   document.getElementById("NSE1Tab").style.display="none";
   				
	if(document.getElementById("tblNSEGL")!=null)					
	{				
		document.getElementById("tblBSEGL").style.display="inline";
		document.getElementById("tblNSEGL").style.display="none";						
	}
	if(document.getElementById("tblNSEHILO")!=null)					
	{				
		document.getElementById("tblBSEHILO").style.display="inline";
		document.getElementById("tblNSEHILO").style.display="none";						
	}	
	
  }
  else
  {
   document.getElementById("BSETab").style.display="none";
   document.getElementById("BSE1Tab").style.display="none";
    document.getElementById("NSE1Tab").style.display="inline";
   document.getElementById("NSETab").style.display="inline";  
  	
	if(document.getElementById("tblNSEGL")!=null)					
	{							
		document.getElementById("tblNSEGL").style.display="inline";
		document.getElementById("tblBSEGL").style.display="none";			
	}
	if(document.getElementById("tblNSEHILO")!=null)					
	{				
		document.getElementById("tblNSEHILO").style.display="inline";
		document.getElementById("tblBSEHILO").style.display="none";						
	}
	
  }
}

function getnewDetails(opt)
{
	// 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)
		{
			if(opt=="main")
				document.getElementById("NewsId").innerHTML = XmlHttp.responseText;
			else if(opt=="in")
				document.getElementById("NewsId1").innerHTML = XmlHttp.responseText;
			else
				document.getElementById("NewsId2").innerHTML = XmlHttp.responseText;
			document.body.style.cursor = "auto";
		}
		else
		{
			if(opt=="main")
				document.getElementById("NewsId").innerHTML = "<img src='../images/loading1.gif'>";			
		}
	}
}

function getDetailsMktSnap()
{	
	// 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("BSETbl").innerHTML = XmlHttp.responseText;			
			document.body.style.cursor = "auto";
		}
		/*else
		{		
			document.getElementById("Mktchart_BSETbl").innerHTML = "<img src='../images/loading1.gif'>";
			document.body.style.cursor = "auto";
	    }*/
	}
}

//For Loading ticker from TickerData.aspx Using AJAX
function getTickerData(Exchg)
	{	
		if(Exchg=="BSE")
		{	
			document.getElementById("TDBseTicker").style.backgroundColor="#0769A8";
			document.getElementById("TDNseTicker").style.backgroundColor="#9B9B9B";		
			document.getElementById("TDBseTicker").style.cursor="default";
			document.getElementById("TDNseTicker").style.cursor="pointer";
		}
		else if(Exchg=="NSE")
		{
			document.getElementById("TDBseTicker").style.backgroundColor="#9B9B9B";
			document.getElementById("TDNseTicker").style.backgroundColor="#0769A8";		
			document.getElementById("TDBseTicker").style.cursor="pointer";
			document.getElementById("TDNseTicker").style.cursor="default";			
		}
	
		CreateXmlHttp1();
		document.body.style.cursor = "progress";
		//document.getElementById("MarqueeId").innerHTML = " <img src='../images/loading1.gif'>";
		
		var requestUrl = "../TickerData.aspx?Exchg="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		if(XmlHttp1)
			{
					XmlHttp1.onreadystatechange = function(){getDataResponse(Exchg);};
					XmlHttp1.open("GET", requestUrl,  true);
					XmlHttp1.send(null);
			}
	}


function CreateXmlHttpDate()
{
	//Creating object of XMLHTTP in IE
	
	try
	{
		XmlHttpDate = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpDate = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpDate = null;	
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttpDate && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpDate = new XMLHttpRequest();
	}
}

//Called when response comes back from server Only For ExpDateData
function getDateResp()
{   // To make sure receiving response data from server is completed
	if(XmlHttpDate.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpDate.status == 200)
		{
			var ExpDate   = document.getElementById("ExpDate");
			var strData = XmlHttpDate.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";
		}
	}		
}
	
	//Called when response comes back from server Only For Ticker
function getDataResponse(Exchg)
{
	
	// 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 arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
			var MarqueeId = document.getElementById("MarqueeId");
			var Mq_Data = XmlHttp1.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='Ticker_GreenTxt'>"
						}
						else if(DiffVal<0) 
						{
							clss = "<span class='Ticker_RedTxt'>"							
						}
						else 
						{
							clss = "<span class='Ticker_GreenTxt'>"											
						}
						//if(i==0)ExchgDet = arrCol[0] +"&nbsp; "+ CompName + " " + ClPrice + "&nbsp;(" + clss + DiffVal +"</span>) &nbsp;&nbsp;&nbsp;";else stkDet += "<a href='#' class='BlueLinkDark'>" + CompName + "</a> &nbsp; " + ClPrice +" (" + clss + DiffVal +"</span>)  &nbsp;";						
						if(i==0)ExchgDet = arrCol[0] +"&nbsp; "+ CompName + " " + ClPrice + "&nbsp;(" + clss + DiffVal +"</span>) &nbsp;&nbsp;&nbsp;";else stkDet += "<a href=../CompanyProfile/Corporateinner.aspx?id=31&cocode="+ arrCol[0] + " class='BlueLinkDark'>" + CompName + "</a> &nbsp; " + ClPrice +" (" + clss + DiffVal +"</span>)  &nbsp;";						
				}
				if(browser.isIE)
					MarqueeId.innerHTML = "<marquee onmouseover='this.stop();' id='marq' 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";			
		}
		//else
			//MarqueeId.innerHTML = "<img src='../images/loading1.gif'>";
	}
}

function getCommQuotes()
{
	var Exchg   = document.getElementById("Exchg").value;
	var Symbol   = document.getElementById("Symbol").value;
	var ExpDate   = document.getElementById("ExpDate").value;
	
	//var StrUrl = "Review.aspx?mno=4&index=4&id=1&Exchg="+ Exchg +"&Symbol="+ Symbol +"&ExpDate="+ ExpDate
	var StrUrl = "Review.aspx?mno=4&index=4&Exchg="+ Exchg +"&Symbol="+ Symbol +"&ExpDate="+ ExpDate + "&PgOpt=1"
	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 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;
		}
	}
}

//commodity exp date	
function GetExpDate(Exchg,Symbol)
{
	CreateXmlHttpDate();
	document.body.style.cursor = "progress";
	var requestUrl = "../Ajax/ExpDateData.aspx?Exchg="+ Exchg +"&Symbol="+Symbol;	
	if(XmlHttpDate)
	{
		XmlHttpDate.onreadystatechange = function(){getDateResp()};
		XmlHttpDate.open("GET",requestUrl,true);
		XmlHttpDate.send(null);		
	}
}

