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 ticker from TickerData.aspx Using AJAX
function getTickerData(Exchg)
	{
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		document.getElementById("MarqueeId").innerHTML = " <img src='../images/cm_loading.gif'>";
		if(Exchg=="NSE"){document.NseTickImg.src="../images/NSEon.gif";document.BseTickImg.src="../images/BSEoff.gif";}else{document.NseTickImg.src="../images/NSEoff.gif";document.BseTickImg.src="../images/BSEon.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 src='../images/up.gif'>";else if(DiffVal<0) DiffImg="<img src='../images/down.gif'>";else DiffImg= "<img src='../images/eq.gif'>";						
						if(i==0)ExchgDet = arrCol[0] +" &nbsp; "+ CompName +": "+ ClPrice +" ["+ DiffVal +"] "+ DiffImg +" &nbsp; ";else stkDet += "<a href='../getQuotes.aspx?code="+ arrCol[0] +"' class=TickerLink>" + CompName +"</a>: "+ ClPrice +" ["+ DiffVal +"] "+ 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='../images/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 = '../images/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 = '../images/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);
							}
				}
			}	
	}
	
//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 FoGetQuotesData.aspx Using AJAX
function getFOQuotes(strUrl)
	{
		var FOQuotesTbl = document.getElementById("FOQuotesTbl");
		if(FOQuotesTbl.style.display=="none")FOQuotesTbl.style.display = "inline";
		document.FOPChartImg.src="FOPriceChart.aspx?"+ strUrl;
		//document.FOVChartImg.src="FOVolChart.aspx?"+ strUrl;
		document.LoadingID.src = "../CommonImgs/loading7.gif";

		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "FOQuotesData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&"+ strUrl;
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getFODataResp()};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}
	
//Called when response comes back from server Only For FO Quotes Data Response
function getFODataResp()
{
	// 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 FO_QuoteData = XmlHttp.responseText;
			if(FO_QuoteData != "") {
				var arrRow = FO_QuoteData.split("|");
				for(i=0; i<arrRow.length-1; i++)
				 {
					document.getElementById("FO"+i).innerHTML = arrRow[i];
				 }
				document.LoadingID.src = "../images/spacer.gif";
				document.body.style.cursor = "auto";
			}	
		}
		else
			document.LoadingID.src = "../CommonImgs/loading7.gif";
			//document.getElementById("LoadingID").innerHTML = "<img src='../CommonImgs/loading7.gif'>";
	}
}



//For Loading ticker from MF_SchemeData.aspx Using AJAX
function SelectScheme(ig_,ig_a,ig_b)
	{
	
		var fund = document.getElementById("_ctl0_drp_FundHouse");
		var category = document.getElementById("_ctl0_drp_Category");
		var scheme = document.getElementById("_ctl0_drp_Scheme");
		
		
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value +"&Category="+category.value;
		
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getSchemeResp(scheme)};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}
	
//Called when response comes back from server Only For MF_SchemeData
function getSchemeResp(ig_)
{
	// 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)
		{
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttp.responseText
			if(strData != "") {	
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				for(i=0; i<arrSchm.length-1; i++) {	
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					ig_.options[i] = new Option();
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Scheme is not available";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}

//function popup()
// {
   ////	window.open("http://www.mail.mastermarts.com", "mail", "status = 1, height = 150, width =200, resizable = 1,scrollbars=1" )
 //}





//For Commodity ExpDate Using AJAX
function GetExpDate(Exchg,Symbol)
	{
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "ExpDateData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Exchg="+ Exchg +"&Symbol="+Symbol;
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getDateResp()};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.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(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{
			var ExpDate   = document.getElementById("ExpDate");
			var strData = XmlHttp.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 = "ExpDate is not available";			
			}
			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";		
		}
	}
}



//For Loading Commodity Quotes Using AJAX
function getCommQuotes()
	{
		var CommQuotesTbl = document.getElementById("CommQuotesTbl");
		var Exchg   = document.getElementById("Exchg").value;
		var Symbol   = document.getElementById("Symbol").value;
		var ExpDate   = document.getElementById("ExpDate").value;
		if(Exchg=="")
			alert("Please Select Commodity Exchange..!");
		else if(Symbol=="")
			alert("Please Select a Commodity..!");
		else if(ExpDate=="")
			alert("Please Select Contract Date..!");
		else {
			if(CommQuotesTbl.style.display=="none")CommQuotesTbl.style.display = "inline";
			
			var strUrl = "Exchg="+ Exchg +"&Symbol="+ Symbol +"&ExpDate="+ ExpDate;			
			document.CommPChartImg.src="CommPriceChart.aspx?"+ strUrl;
			//document.CommVChartImg.src="CommVolChart.aspx?"+ strUrl;
			document.LoadingID.src = "../CommonImgs/loading7.gif";

			CreateXmlHttp();
			document.body.style.cursor = "progress";
			var requestUrl = "CommQuotesData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&"+ strUrl;
			if(XmlHttp)	{
						XmlHttp.onreadystatechange = function(){getCommDataResp()};
						XmlHttp.open("GET", requestUrl,  true);
						XmlHttp.send(null);
			}
		}			
	}
	
//Called when response comes back from server Only For Comm Quotes Data Response
function getCommDataResp()
{
	// 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 Comm_QuoteData = XmlHttp.responseText;
			if(Comm_QuoteData != "") {
				var arrRow = Comm_QuoteData.split("|");
				for(i=0; i<arrRow.length-1; i++)
				 {
					document.getElementById("Comm"+i).innerHTML = arrRow[i];
				 }
				document.LoadingID.src = "../images/spacer.gif";
				document.body.style.cursor = "auto";
			}	
		}
		else
			document.LoadingID.src = "../CommonImgs/loading7.gif";
			//document.getElementById("LoadingID").innerHTML = "<img src='../CommonImgs/loading7.gif'>";
	}
}

