﻿// JScript File

var XmlHttpTicker;

function CreateXmlHttp()
{
	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') 
		{
       	       try 
              {
	           XmlHttp = new XMLHttpRequest();
              } 
              catch (e) 
              {
	            XmlHttp=false;
              }
         }
         if (!XmlHttp && window.createRequest) 
         {
	        try 
	        {
		        XmlHttp = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttp=false;
	        }
         }
}


function CreateXmlHttpInterIndices()
{
	try
	{
		XmlHttpInterIndices = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpInterIndices = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpInterIndices = null;				
		}
	}
	
	//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpInterIndices && typeof XMLHttpRequest!='undefined') 
		{
       	       try 
              {
	           XmlHttpInterIndices = new XMLHttpRequest();
              } 
              catch (e) 
              {
	            XmlHttpInterIndices=false;
              }
         }
         if (!XmlHttpInterIndices && window.createRequest) 
         {
	        try 
	        {
		        XmlHttpInterIndices = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpInterIndices=false;
	        }
         }
}


function CreateXmlHttpFundPer()
{
	try
	{
		XmlHttpFundPer = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpFundPer = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpFundPer = null;				
		}
	}
	
	//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpFundPer && typeof XMLHttpRequest!='undefined') 
		{
       	       try 
              {
	           XmlHttpFundPer = new XMLHttpRequest();
              } 
              catch (e) 
              {
	            XmlHttpFundPer=false;
              }
         }
         if (!XmlHttpFundPer && window.createRequest) 
         {
	        try 
	        {
		        XmlHttpFundPer = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpFundPer=false;
	        }
         }
}

function CreateXmlHttpTicker()
{
  	try
	{
		XmlHttpTicker = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpTicker = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpTicker = null;				
		}
	}
	
	//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpTicker && typeof XMLHttpRequest!='undefined') 
		{
       	       try 
              {
	           XmlHttpTicker = new XMLHttpRequest();
              } 
              catch (e) 
              {
	            XmlHttpTicker=false;
              }
         }
         if (!XmlHttpTicker && window.createRequest) 
         {
	        try 
	        {
		        XmlHttpTicker = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpTicker=false;
	        }
         }
}

function ChangeControl(Opt,Exch)
{
	CreateXmlHttp();
       var currentDivObj = document.getElementById("Td_Data");
      
		//currentDivObj.innerHTML ="<img src=App_Themes/Common/images/ajax-loader.gif>";
	document.body.style.cursor = "progress";
	
	
	var requestUrl = "AjaxDataGLVV.aspx?Option="+ Opt +"&Exchange="+ Exch;
	
   // window.open(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";
	
		More.innerHTML="<a class='HomeMore' href='../Equity/GainersAndLoosers.aspx?Option=GAIN&EXCHG=BSE&id=1&index=0'>more...</a>";
		//More.innerHTML="more..";
		/**/
		
	    if(Exch=='BSE')
	    {
		More.innerHTML="<a class='HomeMore' href='../Equity/GainersAndLoosers.aspx?Option=GAIN&EXCHG=BSE&id=1&index=0'>more...</a>";
		}
		else
		{
		More.innerHTML="<a class='HomeMore' href='../Equity/GainersAndLoosers.aspx?Option=GAIN&EXCHG=NSE&id=1&index=0'>more...</a>";
		}
		
		break;
		
	case "LOSE":
	
		Head_td.innerHTML="Losers";
        /**/
		More.innerHTML="<a class='HomeMore' href='Equity/GainersAndLoosers.aspx?Option=LOSE&EXCHG=BSE&id=1&index=0'>more...</a>";
		//More.innerHTML="more..";
		/**/
        
		 if(Exch=='BSE')
	    {
		More.innerHTML="<a class='HomeMore' href='Equity/GainersAndLoosers.aspx?Option=LOSE&EXCHG=BSE&id=1&index=0'>more...</a>";
		}
		else
		{
		More.innerHTML="<a class='HomeMore' href='Equity/GainersAndLoosers.aspx?Option=LOSE&EXCHG=NSE&id=1&index=0'>more...</a>";
		}
	break;
	
	case "Vol":
		Head_td.innerHTML="Volume";
        /**/
		More.innerHTML="<a class='HomeMore' href='Equity/MostActive.aspx?id=2&Option=Volume&EXCHG=BSE&index=0'>more...</a>";
		//More.innerHTML="more..";
		/**/
		 if(Exch=='BSE')
	    {
		More.innerHTML="<a class='HomeMore' href='Equity/MostActive.aspx?id=2&Option=Volume&EXCHG=BSE&index=0'>more...</a>";
		}
		else
		{
		    More.innerHTML="<a class='HomeMore' href='Equity/MostActive.aspx?id=2&Option=Volume&EXCHG=NSE&index=0'>more...</a>";
		}
	break;
	
	case "Val":
	    Head_td.innerHTML="Value";
	    /**/
		More.innerHTML="<a class='HomeMore' href='Equity/MostActive.aspx?id=2&Option=Value&EXCHG=BSE&index=0'>more...</a>";
		//More.innerHTML="more..";
		/**/
	     if(Exch=='BSE')
	    {
		More.innerHTML="<a class='HomeMore' href='Equity/MostActive.aspx?id=2&Option=Value&EXCHG=BSE&index=0'>more...</a>";
		}
		else
		{
		    More.innerHTML="<a class='HomeMore' href='Equity/MostActive.aspx?id=2&Option=Value&EXCHG=NSE&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";
		}
	}
}


function GetInterIndices(Content)
{
 
  	CreateXmlHttpInterIndices();
       var currentDivObj = document.getElementById("Td_InterIndices");
        
		//currentDivObj.innerHTML ="<img src=App_Themes/Common/images/ajax-loader.gif>";
		//currentDivObj.innerHTML ="<img src=App_Themes/Common/images/ajax-loader.gif>";
	document.body.style.cursor = "progress";
	
	
	var requestUrl = "AjaxInterIndices.aspx?content="+Content;
	
   // window.open(requestUrl) 
	if(XmlHttpInterIndices!=null)	
	        {
				XmlHttpInterIndices.onreadystatechange = function(){ResponseGetInterIndices()}
				XmlHttpInterIndices.open('GET', requestUrl,  true);
				XmlHttpInterIndices.send(null);
			}
			 return false; 
}

function ResponseGetInterIndices()
{
  var td_Id = document.getElementById("Td_InterIndices");

	if(XmlHttpInterIndices.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		
		if(XmlHttpInterIndices.status == 200)//
		{
		
			td_Id.innerHTML =  XmlHttpInterIndices.responseText;
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			td_Id.innerHTML =  "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}
	
}

//For top performers data
function loadGLData(Category,TopGl)
{
	CreateXmlHttpFundPer();
	var FundPerformance = document.getElementById("FundPerformance");
	document.body.style.cursor = "progress";
	//FundPerformance.innerHTML ="<img src=App_Themes/Common/images/ajax-loader.gif>";
	var requestUrl = "AjaxFundData.aspx?Period=1YEARRET&Category="+ Category;

	
	if(XmlHttpFundPer)	{
				XmlHttpFundPer.onreadystatechange = function(){GLResponse(TopGl)}
				XmlHttpFundPer.open("GET", requestUrl,  true);
				XmlHttpFundPer.send(null);
			}
}	
	
	function GLResponse(TopGl)
    {
            var FundPerformance = document.getElementById("FundPerformance");
			
	// To make sure receiving response data from server is completed
	if(XmlHttpFundPer.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK

		if(XmlHttpFundPer.status == 200)
		{	
			var strGlData = XmlHttpFundPer.responseText
			
				FundPerformance.innerHTML = strGlData;
			 
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			
				FundPerformance.innerHTML = "There was a problem retrieving data from the server.";
			
			
			document.body.style.cursor = "auto";
		}
	}
}



function getTickerData(Exchg)
{	
	CreateXmlHttpTicker();
	document.body.style.cursor = "progress";
	document.getElementById("MarqueeId").innerHTML = " <img src='../App_Themes/Common/images/ajax-loader.gif'>";

if(Exchg == "BSE")
{
 document.getElementById("Td_ExchgRight").onclick = function() {getTickerData('NSE')}
 document.getElementById("Td_ExchgRight").innerHTML = "NSE";
 document.getElementById("Td_ExchgLeft").innerHTML = "BSE";  
}
else
{
  document.getElementById("Td_ExchgRight").onclick = function() {getTickerData('BSE')}
  document.getElementById("Td_ExchgRight").innerHTML = "BSE"
  document.getElementById("Td_ExchgLeft").innerHTML = "NSE"; 
}

	var requestUrl = "AjaxTickerData.aspx?Exchange="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		
	if(XmlHttpTicker)
	{
		XmlHttpTicker.onreadystatechange = function(){getDataResponse(Exchg);};
		XmlHttpTicker.open("GET", requestUrl,  true);
		XmlHttpTicker.send(null);
	}
}

function getDataResponse(Exchg)
{
    if(XmlHttpTicker.readyState == 4)
	{	
	    if(XmlHttpTicker.status == 200)
		{	
		    var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
			var MarqueeId = document.getElementById("MarqueeId");
			var TickerData = XmlHttpTicker.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 = "<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='../companyprofile/QuoteFinder.aspx?id=1&Fincode="+arrCol[0]+"'><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);
		}
	}
}

function ExchngTimeClock(Exchg) 
{
    var time = new Date()
	var hour = time.getHours()
	
	if (hour >= 10 && hour <= 20)
	    clockTimeoutID = setTimeout("getTickerData('"+ Exchg +"')",600000);
}

