var xmlHttp
var browser = new Browser();

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();
		}
	}

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;
  }
}
		
function details(sno,secid,subsecid)
	{
	var wind_new;
	wind_new=window.open("../newsdetails.aspx?sno="+sno+"&secid="+secid+"&subsecid="+subsecid+"", "DetailNews", "status = 1, height = 350, width =500, resizable = 0,scrollbars=1,left=200,top=200" )
	wind_new.focus();
	}
//End of Common


//For Loading ticker from TickerData.aspx Using AJAX
function getTickerData(Exchg)
	{	
	//alert(Exchg);	
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		//document.getElementById("MarqueeId").innerHTML = " <img src='../CommonImgs/loading1.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);
		}
}
function getDataResponse(Exchg)
{
	if(XmlHttp.readyState == 4)
	{			
		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'>";
							clss = "<span class='TickerGreen'>" ;
						}
						else if(DiffVal<0) 
						{							
							DiffImg="<img src='../images/down.gif'>";
							clss = "<span class='TickerRed'>" ;
						}
						else 
						{
							DiffImg= "<img src='../images/eq.gif'>";
							clss = "<span class='TickerGreen'>"	;				
						}
						
						//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; ";    href='../profile/CorpInfo.aspx?id=1&code="+ arrCol[0] +"'
						if(i==0)ExchgDet = "<span class='TickerLink'>" + arrCol[0] +" &nbsp; "+ CompName +": "+ ClPrice+ clss +" [" + DiffImg + "&nbsp;"  + DiffVal +"]</span> </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span class='TickerLink'>" + "<a href='../profiles/CorpInfo.aspx?pnav=PI4_PI7&code="+ arrCol[0] +"'><span  class=TickerLink>" + CompName +"</span></a>: "+ ClPrice + clss +" ["+ DiffImg +"&nbsp;" + DiffVal +"]</span>  &nbsp;</span>&nbsp;";						
						
				}
				if(browser.isIE)
					MarqueeId.innerHTML = "<marquee onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='30' 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='../CommonImgs/loading1.gif'>";
	}
}

//**** 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);
	}



//News Details
function details(sno,secid,subsecid,pnav)
	{
	var wind_new;
	wind_new="../Newsdetails.aspx?sno="+sno+"&secid="+secid+"&subsecid="+subsecid+"&pnav="+pnav+"";
	window.location=wind_new;
	}
	
//This is for bulletin
 function ShowA2Z(redUrl_,Index)
 {
 	var A2ZIndexId = document.getElementById("A2ZTd");
	if(A2ZIndexId.innerHTML=="")
	{
		var A2Z="";A2ZClass ="";
			for(i=65; i<=90; i++)				
			{
				var Alpha = String.fromCharCode(i);
				A2ZClass = (Index==Alpha) ? "IndexLinkSel1" : "IndexLink";
				A2Z += "<a href='"+redUrl_+"&Index="+ Alpha +"' class="+ A2ZClass+ ">"+ Alpha +"</a> <span class='Divider'> | </span>";
			}
			A2ZClass = (Index=="0-9") ? "IndexLinkSel" : "IndexLink";	
			A2ZIndexId.innerHTML = A2Z + "<a href='"+redUrl_+"&Index=0-9' class="+ A2ZClass +">0-9</a><span class='Divider'> | </span>";
	}
	else
		A2ZIndexId.innerHTML = "";			
}	



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();
		}
		
	}



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");
		
		CreateXmlHttpNew();
		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(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)
		{
			//alert(ig_)
			//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";		
		}
	}
}


//MF-Hist Nav

function CreateXmlHttpScheme()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttpSch = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpSch = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpSch = null;	
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttpSch && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpSch = new XMLHttpRequest();
	}
}



function SelectSchemeFund(pnav)
	{	
		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
		CreateXmlHttpScheme();
		document.body.style.cursor = "progress";

		 if(pnav=="PI6_PI4")
		{
			requestUrl = "../MutualFund/MF_SchemeData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value +"&Category="+category.value+"&scheme="+scheme.value;

			if(XmlHttpSch)	{
				XmlHttpSch.onreadystatechange = function(){getSchemeRespFund(scheme)};
				XmlHttpSch.open("GET", requestUrl,  true);
				XmlHttpSch.send(null);
			}
		}
		
		
	}
	
	//Called when response comes back from server Only For MF_SchemeData
	function getSchemeRespFund(ig_)
	{
		// To make sure receiving response data from server is completed
		if(XmlHttpSch.readyState == 4)
		{
			// To make sure valid response is received from the server, 200 means response received is OK
			if(XmlHttpSch.status == 200)
			{
				var strData = XmlHttpSch.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";
			}
		}
	}
	
	
/*for search company*/

	
function SearchQuote()
	{
	
		var SrchQuote = document.getElementById("txt_Symbol").value;
		var PageId = document.getElementById("DD_Options").value;	
		
		if(SrchQuote =="" || SrchQuote=="Enter Company Name")
		{
			alert("Please enter company name ..!!!");
			return false;
		}
		
		else
		{
			var strReplaceAll =SrchQuote;
			var intIndexOfMatch = strReplaceAll.indexOf( "'" );
			while (intIndexOfMatch != -1)
			{
				strReplaceAll = strReplaceAll.replace( "'", "" )
				intIndexOfMatch = strReplaceAll.indexOf( "'" );
				
			}
			
			var StrUrl = "CompSearch.aspx?schtxt="+strReplaceAll+"&pnav="+PageId;
			
			window.location = StrUrl;
		}
				
   }
   
   function Compempty()
	{
		if (document.getElementById("txt_Symbol").value=="Enter Company Name")
		{
  			document.getElementById("txt_Symbol").value="";
		}
	}

function Compfill()
{
	var getquote=document.getElementById("txt_Symbol").value;
	if (getquote=="")
	{
		document.getElementById("txt_Symbol").value="Enter Company Name";
	}
}

function CompValidate()
{					
		var SrchQuote = document.getElementById("txt_Quote2").value;
	//	var PageId = document.getElementById("DD_Options").value;
		var pnav = document.getElementById('<%=pnav%>.ClientID');
		//alert(pnav);
		if(SrchQuote =="" ||SrchQuote=="Enter Company...!!!" ||  SrchQuote=="Enter Company Name...!!!" || SrchQuote=="Change Company")
		{
			alert("Please enter company name ..!!!");
			return false;
		}
		else 
		{
				var strReplaceAll =SrchQuote;
				var intIndexOfMatch = strReplaceAll.indexOf( "'" );
				while (intIndexOfMatch != -1)
				{
					strReplaceAll = strReplaceAll.replace( "'", "" )
					intIndexOfMatch = strReplaceAll.indexOf( "'" );
					
				}
				var StrUrl = "../Profiles/CompSearch.aspx?schtxt="+strReplaceAll+"&pnav="+pnav;						
				window.location=StrUrl;
		}		
}

function QuoteCompValidate()
{					
		var SrchQuote = document.getElementById("txt_Symbol").value;
		var PageId = document.getElementById("DD_Options").value;
		alert(SrchQuote);
		alert(PageId);
		if(SrchQuote =="" || SrchQuote=="Enter Company Name...!!!" )
		{
			alert("Please enter company name ..!!!");
			return false;
		}
		else 
		{
				var strReplaceAll =SrchQuote;
				var intIndexOfMatch = strReplaceAll.indexOf( "'" );
				while (intIndexOfMatch != -1)
				{
					strReplaceAll = strReplaceAll.replace( "'", "" )
					intIndexOfMatch = strReplaceAll.indexOf( "'" );
					
				}
				var StrUrl = "../Profiles/CompSearch.aspx?schtxt="+strReplaceAll+"&pnav="+PageId;						
				window.location=StrUrl;
		}		
}


function QuoteEnterScript1(e,id)
{
	if(e.keyCode==13)	
	{
		var Scripid = document.getElementById(id);
		Scripid.click();
	}
}


		function winPopup(fileName)
		{
		  var newWin=window.open(fileName,'win1','x=0,y=0,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=270,height=100,screenX=0,screenY=0,left=200,top=230');//280
		  newWin.focus();		   
		}	
		
		
		
		
		function SelectScheme1(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");
		
		CreateXmlHttpNew();
		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(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)
		{
			//alert(ig_)
			//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";		
		}
	}
}
	
	
	function SelectNewScheme()
	{
		var fund = document.getElementById("_ctl0_FundCat1_drp_Category");
		var category = document.getElementById("_ctl0_FundCat1_drp_Category");
		var scheme = document.getElementById("_ctl0_FundCat1_drp_Scheme");
		scheme.length = 0;
		scheme.options[0] = new Option(); 
		scheme.options[0].value = "";
		scheme.options[0].text = "Select Scheme";	
		CreateXmlHttpNew();		
		document.body.style.cursor = "progress";
		var requestUrl = "MF_CategoryData.aspx?Fund="+ fund.value;
		if(XmlHttpCom)	{
					XmlHttpCom.onreadystatechange = function(){getSchemeResp1(category);};
					XmlHttpCom.open("GET", requestUrl,  true);
					XmlHttpCom.send(null);
				}
	}
	
	
	
	function getSchemeResp1(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)
		{
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttpCom.responseText
			if(strData != "") {	
				var arrSchm = strData.split("|");
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Select Category";	
				for(i=1; i<arrSchm.length; 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 = "No Categories 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";		
		}
	}
}
		
		
	//test
	
function setElementColor(id, color){
	xoopsGetElementById(id).style.color = "#" + color;
	}
function setVisible(id){
	xoopsGetElementById(id).style.visibility = "visible";
}

function setHidden(id){
	xoopsGetElementById(id).style.visibility = "hidden";
}



function Reckoner(url,opt,title)
{
    window.scroll(0,0);
	var Win;
	Win = document.getElementById("cm_window2").style.display='inline';

	var currentDivObj,currentTitle
	currentTitle = document.getElementById("Title");

	if(opt=="in")
	{
		currentDivObj = document.getElementById("NLIDetails");
		currentDivObj.innerHTML ="<table cellspacing=0 cellpadding=0 height=140px align='center'><tr><td><img src=../images/loading7.gif ></td></tr></table>";
	}
	
	CreateXmlHttp();
	document.body.style.cursor = "progress";
	var requestUrl = url;

	if(XmlHttp)
	{
		XmlHttp.onreadystatechange = function(){NLIDetails(opt);};
		XmlHttp.open("GET", requestUrl,  true);
		XmlHttp.send(null);
	}   
}

function NLIDetails(opt)
{
	// To make sure receiving response data from server is completed
	//alert(XmlHttp.readyState)
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
	//alert(XmlHttp.responseText)
		if(XmlHttp.status == 200)
		{
			if(opt=="in")
			{
				document.getElementById("NLIDetails").innerHTML = XmlHttp.responseText;				
				document.body.style.cursor = "auto";
			}
		}
		else
		{
			if(opt=="in")
			{
				document.getElementById("NLIDetails").innerHTML = "<img src='../images/loading7.gif'>";
		    }
		}

	}
}



