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;

//for home ticker

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 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 Loading ticker from TickerData.aspx Using AJAX
function getTickerData(Exchg)
{	
	var ImgBSE= document.getElementById("HomeTop1_TickerCtrl1_ImgBSE");
	var ImgNSE= document.getElementById("HomeTop1_TickerCtrl1_ImgNSE");
				
	if (Exchg =='BSE')
	{
		ImgBSE.src="../images/TikkerBSEon.gif"
		ImgNSE.src="../images/TikkerNSEon.gif"
		ImgBSE.className="Nsehand"
		ImgNSE.className="Bsehand"
	}
			   
	else{
		ImgNSE.src="../images/TikkerNSE.gif"
		ImgBSE.src="../images/TikkerBSE.gif"
		ImgNSE.className="Nsehand"
		ImgBSE.className="Bsehand"
	}
	
	CreateXmlHttp1();
	document.body.style.cursor = "progress";
	document.getElementById("MarqueeId").innerHTML = " <img src='../images/loading1.gif'>";
		
	var requestUrl = "../Ajax/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);
	}
}

//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='TickerGreen'>"
					DiffImg= "<img align='absmiddle' src='../images/up.gif'>";
				}
				else if(DiffVal<0) 
				{
					clss = "<span class='TickerRed'>"
					DiffImg="<img align='absmiddle' src='../images/down.gif'>";
				}
				else 
				{
					clss = "<span class='TickerGreen'>"
					DiffImg= "<img align='absmiddle' src='../images/eq.gif'>";						
				}								
				if(i==0)ExchgDet = arrCol[0] +" &nbsp; "+ CompName +": "+ ClPrice +" [" + DiffImg + " &nbsp;" + clss + DiffVal +"</span>] &nbsp;&nbsp;&nbsp;";else stkDet += "<a href='../profile/ScripSearch.aspx?opt=0&cocode=" + arrCol[0] + "&id=12' class='TickerText'>" + CompName + "</a> &nbsp; " + ClPrice +" ["+ DiffImg +" &nbsp;"+ 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";
			ExchngTimeClock(Exchg);
		}
	}
}

//**** Function ExchngTimeClock Is used 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);
}

/// ************* To Get News data of Hot new section in home page ******//

function GetNewsDetail(SrNo,secId,SubSecId,opt)
	{
		var NewsWin = document.getElementById("cm_window").style.display='inline';
		var currentDivObj
		if(opt=="main")
		{
			currentDivObj = document.getElementById("NewsId");
			currentDivObj.innerHTML ="<img src=../CommonImgs/loading1.gif>";
		}
		else if(opt=="in")
		{
			currentDivObj = document.getElementById("NewsId1");
			currentDivObj.innerHTML ="<img src=../CommonImgs/loading1.gif>";
		}
		else
		{
			currentDivObj = document.getElementById("NewsId2");
			currentDivObj.innerHTML ="<img src=../CommonImgs/loading1.gif>";
		}
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "../NewsData.aspx?SecId="+ secId +"&SubSecId="+ SubSecId+"&SrNo="+ SrNo +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getDetails(opt);};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);					
				}
	}
	
	function getDetails(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='../CommonImgs/loading1.gif'>";
				else if(opt=="in")
					document.getElementById("NewsId1").innerHTML = "<img src='../CommonImgs/loading1.gif'>";
				else
					document.getElementById("NewsId2").innerHTML = "<img src='../CommonImgs/loading1.gif'>";
			}
		}
	}	
	
		
	//Market Analysis - news function
	function GetNews(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 = '../images/minus.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/plus.gif'");}}
						
			if(currentDivObj.innerHTML=="")
			{
				currentDivObj.innerHTML ="<img src=../images/loading1.gif>";
				CreateXmlHttp();
				document.body.style.cursor = "progress";
				
				var requestUrl = "../Ajax/DataNews.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);
				}
			}
		}		
	}
	
//Called when response comes back from server Only For NewsData
function getNewsDetResp(SrNo)
{
	// To make sure receiving response data from server is completed
	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/loading.gif'>";
	}
}



//For Loading  MF_SchemeData.aspx Using AJAX
//function SelectScheme(ig_,ig_a,ig_b)
function SelectScheme(opt)
	{	
		var fund = document.getElementById("_ctl0_FundCat1_drp_FundHouse");
		var category = document.getElementById("_ctl0_FundCat1_drp_Category");
		var scheme = document.getElementById("_ctl0_FundCat1_drp_Scheme");
		var Period=document.getElementById("_ctl0_FundCat1_drp_Period");
		var Month =document.getElementById("_ctl0_FundCat1_MonthDrop");
		var requestUrl
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		//alert(opt);
		//alert(scheme);
		if(opt==1)
			{
				requestUrl = "../Ajax/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value ;
			}
		if(opt==3)
			{
				 requestUrl = "../Ajax/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value +"&Category="+category.value;
			
			 }
		else if(opt==2)
		{
				 requestUrl = "../Ajax/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Category="+category.value;
			
			 }
		
		else if(opt==9)
			{
			 requestUrl = "../Ajax/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value +"&Category="+category.value+"&scheme="+scheme.value;
			 if(XmlHttpCom)	{
					XmlHttpCom.onreadystatechange = function(){getSchemeResp(scheme)};
					XmlHttpCom.open("GET", requestUrl,  true);
					XmlHttpCom.send(null);
				}
			 
			 }
		
		else if(opt==5)
			{
			 requestUrl = "../Ajax/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value +"&Category="+category.value+"&scheme="+scheme.value;
			 if(XmlHttpCom)	{
					XmlHttpCom.onreadystatechange = function(){getSchemeResp(scheme)};
					XmlHttpCom.open("GET", requestUrl,  true);
					XmlHttpCom.send(null);
				}
			 
			 }
		else if(opt==6)
			{
				 requestUrl = "../Ajax/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value +"&Category="+category.value+"&Month="+Month.value;
			
			 }
		else
			{
			
			/*requestUrl = "../Ajax/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value +"&Category="+category.value+"&scheme="+scheme.value+"&Period="+Period.value;
			 if(XmlHttpCom)	{
					XmlHttpCom.onreadystatechange = function(){getSchemeResp(scheme)};
					XmlHttpCom.open("GET", requestUrl,  true);
					XmlHttpCom.send(null);}*/
					requestUrl = "../Ajax/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value +"&Category="+category.value+"&Period="+Period.value;				
			
			}
	
		//if(XmlHttpCom)	{
				//	XmlHttpCom.onreadystatechange = function(){getSchemeResp(scheme)};
				//	XmlHttpCom.open("GET", requestUrl,  true);
				//	XmlHttpCom.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(XmlHttpCom.readyState == 4)
	{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpCom.status == 200)
		{
			
			
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttpCom.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";		
		}
	}
}
	

//Creating object of XMLHTTP For AJAX Method
function CreateXmlHttpNew()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpCom = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpCom = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpCom = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpCom && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpCom = new XMLHttpRequest();
		}
		
	}
	
	//For Loading FOQuotesData.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.getElementById("LoadingID").src = "../images/loading7.gif";

		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "../Ajax/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 Get 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++)
				 {
					if((i!='14')&&(i!='15'))
						document.getElementById("FO"+i).innerHTML = arrRow[i];
				 }
				document.getElementById("LoadingID").src = "../images/spacer.gif";
				document.body.style.cursor = "auto";
			}	
		}
		else
			document.getElementById("LoadingID").src = "../images/loading7.gif";
			//document.getElementById("LoadingID").innerHTML = "<img src='../CommonImgs/loading7.gif'>";
	}
}


