
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;
}
var XmlHttpComp;
function CreateXmlHttpComp()
{
	
		try
		{
			XmlHttpComp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpComp= new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpComp= null;
					
			}
		}
		if(!XmlHttpComp && typeof XMLHttpRequest != "undefined")
    {
        XmlHttpComp= new XMLHttpRequest();
    }
    return XmlHttpComp;
}
var XmlHttp;
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();
	}
}

var XmlHttpPolicy;
function CreateXmlHttpPolicy()
{
	try
	{
		XmlHttpPolicy = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpPolicy = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpPolicy = null;				
		}
	}
	if(!XmlHttpPolicy && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpPolicy = new XMLHttpRequest();
	}
}
//For Loading ticker from TickerData.aspx Using AJAX


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();
	}
}
//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);		
	}
}
//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;
		}
	}
}

function searchcomp()
 {
	var txtGQuotes= document.getElementById("txtGQuotes");
		if(txtGQuotes.value=="Enter Company Name")
		{
			alert("Please Enter some text");
		}
		else
		{
 			var SearchResult = document.getElementById("complist");
			document.getElementById("complist").style.display="inline";
		
			CreateXmlHttpComp();
			document.body.style.cursor = "progress";
			var requestUrl = "../Ajax/GetQuote.aspx?schtxt="+txtGQuotes.value;
		
			if(XmlHttpComp) 
			{
				XmlHttpComp.onreadystatechange = function(){fillCompResp(SearchResult)};
				XmlHttpComp.open("GET", requestUrl, true);
				XmlHttpComp.send(null);
			}
		}
	}

	function fillCompResp(ig_)	
	{	
		if(XmlHttpComp.readyState == 4)
		{
			if(XmlHttpComp.status == 200)
			{
			 var strData = XmlHttpComp.responseText;
				if(strData != "") 
				{
					var arrComp = strData.split("|");
					ig_.length = 0;

					for(i=0; i<arrComp.length-1; i++) 
					{	
					var strComp = arrComp[i];
					var arrCoCode = strComp.split("~");
	
					ig_.options[i] = new Option();
					ig_.options[i].value = arrCoCode[0];
					ig_.options[i].text = arrCoCode[1];
				}

			}
			else
			{
				ig_.length = 0;
				ig_.options[0] = new Option();
				ig_.options[0].value = "";
				ig_.options[0].text = "No Data Found";
			}
			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";
		 }
		}
	}
/*Insurance dropdownlists*/
function Get_Plan(id,DD_AMC,DD_type,PlanID)
{
	//var DD_AMC = document.getElementById("<%=DD_AMC.ClientID%>");
	//var DD_Type = document.getElementById("<%=DD_Type.ClientID%>");
	//var DD_Plan = document.getElementById("<%=DD_Plan.ClientID%>");
	CreateXmlHttp();	
	document.body.style.cursor = "progress";
	if(id == "3")
	{
		var requestUrl = "Plan_DropDown.aspx?AMC="+document.getElementById(DD_AMC).value+"&Type="+document.getElementById(DD_type).value;
	}
	else
	{
		var requestUrl = "Plan_DropDown.aspx?AMC="+DD_AMC.value;
	}	
	if(XmlHttp)	{
				XmlHttp.onreadystatechange = function(){getSymbolResp(PlanID)};
				XmlHttp.open("GET", requestUrl, true);
				XmlHttp.send(null);				
			}
}

function getSymbolResp(ig_)
{
	var ig1_=document.getElementById(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)
		{
			 var strData = XmlHttp.responseText;
				if(strData != "") 
				{
					var arrComp = strData.split("|");
					ig1_.length = 0;

					for(i=0; i<arrComp.length-1; i++) 
					{	
					var strComp = arrComp[i];
					var arrCoCode = strComp.split("~");
	
					ig1_.options[i] = new Option();
					ig1_.options[i].value = arrCoCode[0];
					ig1_.options[i].text = arrCoCode[1];
					}
					document.body.style.cursor = "auto";
				}
				else
				{
				ig1_.length = 0;
				ig1_.options[0] = new Option();
				ig1_.options[0].value = "";
				ig1_.options[0].text = "No Plans available";
				}
				document.body.style.cursor = "auto";

		}
		else 
		{
					ig1_.length = 0;
					ig1_.options[0] = new Option();
					ig1_.options[0].value = "";
					ig1_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";
		}
	}
}


function Get_Policy(DD_Plan,PolicyID)
{
	CreateXmlHttpPolicy();	
	document.body.style.cursor = "progress";
	var requestUrl1 = "Policy_DropDown.aspx?plan="+DD_Plan;
	if(XmlHttpPolicy)	{
				XmlHttpPolicy.onreadystatechange = function(){getSymbolRespPolicy(PolicyID)};
				XmlHttpPolicy.open("GET", requestUrl1, true);
				XmlHttpPolicy.send(null);				
			}
}

function getSymbolRespPolicy(ig_)
{
	var ig1_=document.getElementById(ig_);
	// To make sure receiving response data from server is completed
	if(XmlHttpPolicy.readyState == 4)
	{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpPolicy.status == 200)
		{
			 var strData = XmlHttpPolicy.responseText;
				if(strData != "") 
				{
					var arrComp = strData.split("|");
					ig1_.length = 0;

					for(i=0; i<arrComp.length-1; i++) 
					{	
					var strComp = arrComp[i];
					var arrCoCode = strComp.split("~");
	
					ig1_.options[i] = new Option();
					ig1_.options[i].value = arrCoCode[0];
					ig1_.options[i].text = arrCoCode[1];
					}
					document.body.style.cursor = "auto";
				}
				else
				{
				ig1_.length = 0;
				ig1_.options[0] = new Option();
				ig1_.options[0].value = "";
				ig1_.options[0].text = "No Policy available";
				}
				document.body.style.cursor = "auto";

		}
		else 
		{
					ig1_.length = 0;
					ig1_.options[0] = new Option();
					ig1_.options[0].value = "";
					ig1_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";
		}
	}
}
/*Insurance end*/
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 section="";
    if(title!="heading")
		 document.getElementById("cm_window").style.left = tempX + "px";
    else
		document.getElementById("cm_window").style.left = "320px";
 	document.getElementById("cm_window").style.top = tempY + "px";
 	document.getElementById("cm_window").style.display = "inline";
 	m_show = 1;
	var currentDivObj;
	if(opt=="main" ||opt=="comnews")
	{  	   
		currentDivObj = document.getElementById("NewsId");
		currentDivObj.innerHTML ="<img src=../images/loading1.gif>";
	}	
	if(opt=="comnews")
		section="comnews";
	
	CreateXmlHttp();
	document.body.style.cursor = "progress";
	
	var requestUrl = "../Ajax/NewsData.aspx?section="+section+"&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 GetAnnounceDetails(cocode,exchange,titl)
{
    var NewsWin = document.getElementById("cm_window").style.display='inline';	
       if(titl!="heading")
		 document.getElementById("cm_window").style.left = tempX + "px";
    else
		document.getElementById("cm_window").style.left = "320px";
    //document.getElementById("cm_window").style.left = tempX + "px";
 	document.getElementById("cm_window").style.top = tempY + "px";
 	document.getElementById("cm_window").style.display = "inline";
 	m_show = 1;
	var currentDivObj;
	currentDivObj = document.getElementById("NewsId");
	currentDivObj.innerHTML ="<img src=../images/loading1.gif>";
	
	CreateXmlHttp();
	document.body.style.cursor = "progress";
	
	var requestUrl = "../Ajax/BSENSEAnnounement.aspx?Exchg="+ exchange +"&cocode="+ cocode;	
	if(XmlHttp)	
	{
				XmlHttp.onreadystatechange = function(){getannoDetails();};
				XmlHttp.open("GET", requestUrl,  true);
				XmlHttp.send(null);
	}
}
function getannoDetails()
{
	// 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("NewsId").innerHTML = XmlHttp.responseText;
			document.body.style.cursor = "auto";
		}
		else
		{
			document.getElementById("NewsId").innerHTML = "<img src='../images/loading1.gif'>";			
		}
	}
}

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" ||opt=="comnews")
				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'>";			
		}
	}
}
var tempX = 0;
 var tempY = 0;
 var m_show = 0;
 var f_sc_id = "";
 var f_sc_dispid = "";
 var f_sc_comp = "";
 var f_topic_id = 0;
 var f_buy_id =0;
 
  var IE = document.all?true:false
 
 if (!IE) document.captureEvents(Event.MOUSEMOVE)
 document.onmousemove = getMouseXY; 
 
 function getMouseXY(e) 
 {
 	if(IE)
 	{
 	    tempX = event.clientX + document.body.scrollLeft;
 		tempY = event.clientY + document.body.scrollTop+5;
 	}
 	else
 	{
 		tempX = e.pageX;
 	    tempY = e.pageY+5;
 	}
 	return true;
 }


function show_popup1(m_im_id, m_im_shortdesc, m_im_desc, m_ff_desc, m_ff_id, m_fundclass)
 { 
 	f_im_id = m_im_id;
 	f_im_shortdesc = m_im_shortdesc;
 	f_im_desc = m_im_desc;
 	f_ff_desc = m_ff_desc;
 	f_ff_id = m_ff_id;
 	f_fundclass = m_fundclass;

 	document.getElementById("popup").style.left = tempX + "px";
 	document.getElementById("popup").style.top = tempY + "px";
 	document.getElementById("popup").style.display = "inline";
 	m_show = 1;
 }
 
 function hide_popup1()
 {
 	if(m_show == 0)
 	{
 		document.getElementById("popup").style.display = "none";
 	}
 }
 function hide_popup2()
 {
 	if(m_show == 0)
 	{
 		document.getElementById("cm_window").style.display = "none";
 	}
 }
 
 function id_click(m_id)
 {
 	window.location = "../CompanyProfile/Corporateinner.aspx?id="+m_id+"&cocode=" + f_im_id; 	
 }
