﻿// JScript File

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();
	}
}


//function sensexvalue(val)
//{

//    if(val=='BSE')
//    {
//        var BSE = document.getElementById("BSE");
//		var NSE = document.getElementById("NSE");
//		BSE.className = "TopBSEL";
//		NSE.className = "TopGLUnSN";
//        document.getElementById("chart").src="http://content.acesphere.com/charts/nirmalbangbse.png?time=" + new Date().getTime() + "";
//       // document.getElementById('Sensex').style.display="inline";
//        //document.getElementById('Nifty').style.display="none";
//        ChangeControl("GAIN","BSE");
//       
//        
//    }
//    else
//    {
//  
//      
//         
//         var BSE = document.getElementById("BSE");
//		 var NSE = document.getElementById("NSE");
//		 ChangeControl('GAIN','NSE');
//         BSE.className = "TopGLUnSN";
//		 NSE.className = "TopNSEL";
//         document.getElementById("chart").src="http://content.acesphere.com/charts/nirmalbangnse.png?time=" + new Date().getTime() + "";
//        // document.getElementById('Sensex').style.display="none";
//        // document.getElementById('Nifty').style.display="inline";
//       
//    return true;
//}


//return true;
//}


function ChangeControl(Opt,Exch)
{	    
	CreateXmlHttp();
       var currentDivObj = document.getElementById("Td_Data");
        if(Exch=='')
        {
                 if (Opt=="GAIN")
	             {

	             document.getElementById("tdGain").className="TopBSEL";
	              document.getElementById("tdLose").className="TopGLUnSN";
	              document.getElementById("GL").value = "GAIN";
	              
	             }
	            else
	            {
	              document.getElementById("tdGain").className="TopGLUnSN";
	              document.getElementById("tdLose").className="TopBSEL";
	              document.getElementById("GL").value = "LOSE"
	            }
	            }
	 else
        {
	        if(Exch=="BSE")
	        {
	          if (Opt=="GAIN")
	             {

	             document.getElementById("tdGain").className="TopBSEL";
	              document.getElementById("tdLose").className="TopGLUnSN";
	              document.getElementById("GL").value = "GAIN";
	              
	             }
	            else
	            {
	              document.getElementById("tdGain").className="TopGLUnSN";
	              document.getElementById("tdLose").className="TopBSEL";
	              document.getElementById("GL").value = "LOSE"
	            }
	        
		        document.getElementById("Exchange").value = "BSE";  
	        }
	        else
	        {
	        if (Opt=="GAIN")
	             {

	             document.getElementById("tdGain").className="TopBSEL";
	              document.getElementById("tdLose").className="TopGLUnSN";
	              document.getElementById("GL").value = "GAIN";
	              
	             }
	            else
	            
	            {
	              document.getElementById("tdGain").className="TopGLUnSN";
	              document.getElementById("tdLose").className="TopBSEL";
	              document.getElementById("GL").value = "LOSE"
	            }
        	
		        document.getElementById("Exchange").value = "NSE";

	        }
        	
        }
		//currentDivObj.innerHTML ="<img src=App_Themes/CommonTheme/Images/ajax-loader.gif>";
	document.body.style.cursor = "progress";
	
	
	var requestUrl = "../AjaxDataGL.aspx?Option="+ document.getElementById("GL").value +"&Exchange="+ document.getElementById("Exchange").value;
   // alert(requestUrl) 
	if(XmlHttp!=null)	
	        {
				XmlHttp.onreadystatechange = function(){ChangeControlResponse(Opt,Exch)}
				XmlHttp.open('GET', requestUrl,  true);
				XmlHttp.send(null);
			}
			 return false; 
}	
	
function ChangeControlResponse(Opt,Exch)
{
    //var Head_td =document.getElementById("Heading");
  //  var More=document.getElementById("More");
  //  var BSE_td =document.getElementById("Td_BSE");
  //  var NSE_td =document.getElementById("Td_NSE");
//	switch (Opt)
//	{
//	case "GAIN":
//		Head_td.innerHTML="Gainers";
//	    if(Exch=='BSE')
//	    {
//		More.innerHTML="<a class='HomeMore' href='../Equity/TopGainersAndLosers.aspx?Option=GAIN&EXCHG=BSE&id=1&index=0'>More</a>";
//		}
//		else
//		{
//		More.innerHTML="<a class='HomeMore' href='../Equity/TopGainersAndLosers.aspx?Option=GAIN&EXCHG=NSE&id=1&index=0'>More</a>";
//		}
//		
//		break;
//		
//	case "LOSE":
//		Head_td.innerHTML="Losers";
//		 if(Exch=='BSE')
//	    {
//		More.innerHTML="<a class='HomeMore' href='../Equity/TopGainersAndLosers.aspx?Option=LOSE&EXCHG=BSE&id=1&index=0'>More</a>";
//		}
//		else
//		{
//		More.innerHTML="<a class='HomeMore' href='../Equity/TopGainersAndLosers.aspx?Option=LOSE&EXCHG=NSE&id=1&index=0'>More</a>";
//		}
//	break;
//	
//	
//	
//	}

	// 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
		var td_Id = document.getElementById("Td_Data");
	    //alert(XmlHttp.status)
		if(XmlHttp.status == 200)//
		{
			td_Id.innerHTML =  XmlHttp.responseText;
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			td_Id.innerHTML =  "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}
}	

/* Indices */
var XmlHttpGLE;
function CreateXmlHttpGLE()
	{
		try
		{
			XmlHttpGLE = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpGLE = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpGLE = null;
					
			}
		}
		if(!XmlHttpGLE && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpGLE = new XMLHttpRequest();
		}
	}



function GetInternationalData()
{
	CreateXmlHttpGLE();
       var currentDivObj = document.getElementById("tdInterIndices");
       
        
		currentDivObj.innerHTML ="<img src=../App_Themes/Common/images/loading.gif>";
	document.body.style.cursor = "progress";
	
	
	var requestUrl = "AjaxInternationalIndices.aspx?timeStamp="+new Date().getTime();
   //alert(requestUrl) 
	if(XmlHttpGLE!=null)	
	        {
				XmlHttpGLE.onreadystatechange = function(){ChangeResponseInternational()}
				XmlHttpGLE.open('GET', requestUrl,  true);
				XmlHttpGLE.send(null);
			}
			 return false; 
}	
	
function ChangeResponseInternational()
{
 
	// To make sure receiving response data from server is completed
	
	if(XmlHttpGLE.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		var td_Id = document.getElementById("tdInterIndices");
	   //alert(XmlHttpGLE.responseText)
		if(XmlHttpGLE.status == 200)//
		{
			td_Id.innerHTML =  XmlHttpGLE.responseText;
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			td_Id.innerHTML =  "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}
}


 function CreateXmlHttpPop()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpPop= new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpPop = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpPop = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpPop && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpPop = new XMLHttpRequest();
		}
	}
	
    function GetNewsDetail(secId,SubSecId,NewsID,opt)
	{

		var NewsWin = document.getElementById("divNews").style.display='inline';
		var currentDivObj;	
		
			currentDivObj = document.getElementById("TdNews");
			//alert(currentDivObj);
			currentDivObj.innerHTML ="<img src=../App_Themes/Common/images/ajax-loader.gif>"; 
		
		CreateXmlHttpPop();
		document.body.style.cursor = "progress";
		var requestUrl = "../PopupNewsData.aspx?SecId="+ secId +"&SubSecId="+ SubSecId+"&NewsID="+NewsID+"&timeStamp="+new Date().getTime()+"opt="+opt;
		//alert(requestUrl);
		if(XmlHttpPop)	{
					XmlHttpPop.onreadystatechange = function(){getDetailsResp();};
					XmlHttpPop.open("GET", requestUrl,  true);
					XmlHttpPop.send(null);					
				}
	}
	
	function getDetailsResp()
	{
		// To make sure receiving response data from server is completed
		if(XmlHttpPop.readyState == 4)
		{
			// To make sure valid response is received from the server, 200 means response received is OK
			if(XmlHttpPop.status == 200)
			{
				
				
					document.getElementById("TdNews").innerHTML = XmlHttpPop.responseText;
				
				document.body.style.cursor = "auto";
			}
			else
			{
				
					document.getElementById("NewsId").innerHTML = "<img src=../App_Themes/Common/images/ajax-loader.gif>";
				
			}
		}
	}

    


 var XmlHttpBull;
    
    function CreateXmlHttpBull()
	{
		try
		{
			XmlHttpBull = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpBull = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpBull = null;
					
			}
		}
		if(!XmlHttpBull && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpBull = new XMLHttpRequest();
		}
	}


function GetBullion()
{
	CreateXmlHttpBull();
	
      var currentDivObj = document.getElementById("TD_Bullion");
        
currentDivObj.innerHTML ="<img src=App_Themes/Common/images/ajax-loader.gif>";
	document.body.style.cursor = "progress";
	
	var requestUrl = "AjaxBullion.aspx?time="+ Math.random();
	
	 // alert(requestUrl) 
	if(XmlHttpBull!=null)	
	        {
				XmlHttpBull.onreadystatechange = function(){ChangeResponseBull()}
				XmlHttpBull.open('GET', requestUrl,  true);
				XmlHttpBull.send(null);
			}
			 return false; 
}	
	
function ChangeResponseBull(Exch)
{
   
	if(XmlHttpBull.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		
		    var td_Id = document.getElementById("TD_Bullion");
		
	    //alert(XmlHttp.status)
		if(XmlHttpBull.status == 200)//
		{
			td_Id.innerHTML =  XmlHttpBull.responseText;
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			td_Id.innerHTML =  "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}
}								

/*End*/



/* News Tab */




function getTickerData(Exchg)
	{	
	//alert(Exchg);	
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		document.getElementById("MarqueeId").innerHTML = " <img src='App_Themes/CommonTheme/images/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 = "AjaxTickerData.aspx?Exchange="+ 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)
{
//alert(XmlHttp.status);	
	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 TickerData = XmlHttp.responseText;
						
			if(TickerData != "")
			var arrRow = TickerData.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='Green'>" ;
						}
						else if(DiffVal<0) 
						{							
							DiffImg="<img src='../images/down.gif'>";
							clss = "<span class='Red'>" ;
						}
						else 
						{
							DiffImg= "<img src='../images/eq.gif'>";
							clss = "<span class='Green'>"	;				
						}
						
						//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='BlackNormal'>" + arrCol[0] +" &nbsp; "+ CompName +": "+"<span  class=BlackNormal>" + ClPrice+"&nbsp;"+ clss +" ["  +"<b>"+ DiffVal+ "</b>"+"]</span> </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span class='TickerLink'>" + "<a href='http://www.16anna.com/companyinfo.asp?id=1&Fincode="+arrCol[0]+"' target='_parent'><span  class=BlackNormal>" + CompName +"</span></a>: " + "<span  class=BlackNormal>" + ClPrice +"&nbsp;"+ clss +" [" +"<b>"+ DiffVal+ "</b>"+"]</span>  &nbsp;</span>&nbsp;";						
						
				}
				
				//if(browser.isIE)
					MarqueeId.innerHTML = "<marquee id='maqid' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='50' 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(Exchg) {
	 var time = new Date()
	 var hour = time.getHours()
	 if (hour >= 10 && hour <= 20)
			  clockTimeoutID = setTimeout("getTickerData('"+ Exchg +"')",600000);
	}
	


function ChangeSpeed(Option)
	{
	
	 var Marq = document.getElementById("maqid");
	 
	 
	 
	 if(Option=="+")
	 {
	 if(Marq.scrollDelay == "10")
	 return;
	 else
	 Marq.scrollDelay = eval(Marq.scrollDelay)-10;
	 
	 }
	 
	 else
	 {
	 if(Marq.scrollDelay == "90")
	 return;
	 else
	 Marq.scrollDelay = eval(Marq.scrollDelay)+10;
	 
	 }
	 
	 if(Marq.scrollDelay == "10")
	 {
	 document.getElementById("ImgUp").style.cursor = "text";
	 //document.getElementById("ImgUp").src = "App_Themes/CommonTheme/images/plus_disable.gif";
	 }
	 else
	 {
	 document.getElementById("ImgUp").style.cursor = "hand";
	 //document.getElementById("ImgUp").src = "App_Themes/CommonTheme/images/plus_act.gif";
	 }
	 
	 if(Marq.scrollDelay == "90")
	 {
	 document.getElementById("ImgDown").style.cursor = "text";
	 //document.getElementById("ImgDown").src = "App_Themes/CommonTheme/images/minus_disable.gif";
	 }
	 else
	 {
	 document.getElementById("ImgDown").style.cursor = "hand";
	 //document.getElementById("ImgDown").src = "App_Themes/CommonTheme/images/minus_act.gif";
	 }
	 
	 
	}
	
	var XmlHttpChangeIndex;
function CreateXmlHttpChangeIndex()
	{
		try
		{
			XmlHttpChangeIndex = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpChangeIndex = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpChangeIndex = null;
					
			}
		}
		if(!XmlHttpChangeIndex && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpChangeIndex = new XMLHttpRequest();
		}
	}
	
	
	function Changecontibution(Exch)
  {
 
    CreateXmlHttpChangeIndex();
       
    var currentDivObj = document.getElementById("tdContributiontoindex");

    if(Exch=='BSE')
    {
    document.getElementById("BSETabIndex").className = "PinkTxtG ";
    document.getElementById("NSETabIndex").className = "GrayTxtG ";
    document.getElementById("ExchangeIndex").value="BSE";
	}
	 else
    {
      document.getElementById("NSETabIndex").className = "PinkTxtG ";
     document.getElementById("BSETabIndex").className = "GrayTxtG"; 
     document.getElementById("ExchangeIndex").value="NSE"; 
    	
    }
		//currentDivObj.innerHTML ="<img src=App_Themes/CommonTheme/Images/ajax-loader.gif>";
	document.body.style.cursor = "progress";
	
	
	var requestUrl = "AjaxContributiontoindex.aspx?EXCHG="+ document.getElementById("ExchangeIndex").value;
    //alert(requestUrl) 
	if(XmlHttpChangeIndex!=null)	
	        {
				XmlHttpChangeIndex.onreadystatechange = function(){ChangeControlResponseIndex(Exch)}
				XmlHttpChangeIndex.open('GET', requestUrl,  true);
				XmlHttpChangeIndex.send(null);
			}
			 return false; 
}	
	
function ChangeControlResponseIndex(Exch)
{
	if(XmlHttpChangeIndex.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		var td_Id = document.getElementById("tdContributiontoindex");
	   // alert(XmlHttpChangeIndex.status)
		if(XmlHttpChangeIndex.status == 200)//
		{
		//alert(XmlHttpChangeIndex.responseText);
			td_Id.innerHTML =  XmlHttpChangeIndex.responseText;
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			td_Id.innerHTML =  "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}
}


