﻿// JScript File
function Changedata(exg)
{if(exg=="BSE")
{BindChart('BSE');document.getElementById("trbse").style.display="inline";document.getElementById("trnse").style.display="none";document.getElementById("BSENSEVal").value="BSE"
document.getElementById("tdbse").className="BSENSESelct";document.getElementById("tdnse").className="BSENSEUnSelct";ChangeControl('GAIN','BSE');}
if(exg=="NSE")
{BindChart('NSE');document.getElementById("trbse").style.display="none";document.getElementById("trnse").style.display="inline";document.getElementById("BSENSEVal").value="NSE"
document.getElementById("tdnse").className="BSENSESelct";document.getElementById("tdbse").className="BSENSEUnSelct";ChangeControl('GAIN','NSE');}getTickerData(exg);}
 var XmlHttpCompTicker="";function CreateXmlHttpCompTicker()
{try
{XmlHttpCompTicker=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{try
{XmlHttpCompTicker=new ActiveXObject("Microsoft.XMLHTTP");}
catch(oc)
{XmlHttpCompTicker=null;}}
if(!XmlHttpCompTicker&&typeof XMLHttpRequest!="undefined")
{XmlHttpCompTicker=new XMLHttpRequest();}}



function BindChart(val)
{var so=new SWFObject("../amline/amline.swf","BSENSEline","230","145","8","#ffffff");so.addVariable("path","../amline/");so.addParam("wmode","opaque");so.addVariable("settings_file",encodeURIComponent("../amline/Equity_settings.xml"));so.addVariable("data_file",encodeURIComponent("../Home/BSENSEchartAjax.aspx?Exchg="+val+"&TimeStamp="+new Date().getTime()));so.write("TdChart");CallSensexNifty(val);}
var XmlHttpSensexnifty
function CreateXmlHttpSensexnifty()
{try
{XmlHttpSensexnifty=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{try
{XmlHttpSensexnifty=new ActiveXObject("Microsoft.XMLHTTP");}
catch(oc)
{XmlHttpSensexnifty=null;}}
if(!XmlHttpSensexnifty&&typeof XMLHttpRequest!="undefined")
{XmlHttpSensexnifty=new XMLHttpRequest();}}

function CallSensexNifty(Exch)
{CreateXmlHttpSensexnifty();var requestUrl="../Home/AjaxSensexNifty.aspx?Exchange="+Exch+"&timeStamp="+new Date().getTime();if(XmlHttpSensexnifty!=null)
{XmlHttpSensexnifty.onreadystatechange=function(){CallSensexNiftyResponse()}
XmlHttpSensexnifty.open('GET',requestUrl,true);XmlHttpSensexnifty.send(null);}
return false;}
function CallSensexNiftyResponse()
{if(XmlHttpSensexnifty.readyState==4)
{var td_Id=document.getElementById("tdsensex");if(XmlHttpSensexnifty.status==200)
{var sdata=XmlHttpSensexnifty.responseText;var s=sdata.split('|');td_Id.innerHTML=s[0];document.getElementById("tddatetime").innerHTML=s[1];document.body.style.cursor="auto";}
else
{td_Id.innerHTML="There was a problem retrieving data from the server.";document.body.style.cursor="auto";}}}
function ChangeControl(Opt,Exch)
{CreateXmlHttp();var currentDivObj=document.getElementById("Td_Data");document.body.style.cursor="progress";var requestUrl="../Home/AjaxDataGLVV.aspx?Option="+Opt+"&Exchange="+Exch+"&TimeStamp="+new Date().getTime();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 tdgain=document.getElementById("tdgain");var tdlos=document.getElementById("tdlos");var tdvol=document.getElementById("tdvol");var tdval=document.getElementById("tdval");switch(Opt)
{case"GAIN":Head_td.innerHTML=""+Exch+" GAINERS";tdgain.className="GLVALVOLSelect";tdlos.className="GLVALVOLUNSelect";tdvol.className="GLVALVOLUNSelect";tdval.className="GLVALVOLUNSelect";break;case"LOSE":Head_td.innerHTML=""+Exch+" LOSERS";tdgain.className="GLVALVOLUNSelect";tdlos.className="GLVALVOLSelect";tdvol.className="GLVALVOLUNSelect";tdval.className="GLVALVOLUNSelect";break;case"Vol":Head_td.innerHTML=""+Exch+" VOLUME";tdgain.className="GLVALVOLUNSelect";tdlos.className="GLVALVOLUNSelect";tdvol.className="GLVALVOLSelect";tdval.className="GLVALVOLUNSelect";break;case"Val":Head_td.innerHTML=""+Exch+" VALUE";tdgain.className="GLVALVOLUNSelect";tdlos.className="GLVALVOLUNSelect";tdvol.className="GLVALVOLUNSelect";tdval.className="GLVALVOLSelect";break;}
if(XmlHttp.readyState==4)
{var td_Id=document.getElementById("Td_Data");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";}}}
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 CreateXmlHttpCompTicker()
{
	try
	{
		XmlHttpCompTicker = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpCompTicker = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpCompTicker = null;				
		}
	}
	if(!XmlHttpCompTicker && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpCompTicker = new XMLHttpRequest();
	}
}

function getTickerData(Exchg)
{	
    CreateXmlHttpCompTicker();
	document.body.style.cursor = "progress";
	var requestUrl = "../Home/AjaxTickerData.aspx?Exchange="+ Exchg +"&timeStamp="+new Date().getTime();
	
	if(XmlHttpCompTicker)
	{
		XmlHttpCompTicker.onreadystatechange = function(){getDataResponseComp(Exchg);};
		XmlHttpCompTicker.open("GET", requestUrl,  true);
		XmlHttpCompTicker.send(null);
	}
}

function getDataResponseComp(Exchg)
{
    if(XmlHttpCompTicker.readyState == 4)
	{	
	    if(XmlHttpCompTicker.status == 200)
		{	

		    var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";
			var MarqueeId = document.getElementById("MarqueeId");
			var TickerData = XmlHttpCompTicker.responseText;
						
			if(TickerData != "")
			var arrRow = TickerData.split("|");
				
				
				
				
					var BSENSEFIN;
				
				
				if (Exchg=='BSE')
				{
				BSENSEFIN = "218474";
				}
				
				if (Exchg=='NSE')
				{
				BSENSEFIN = "217829";
				}
				
				
				
			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 width='7px' height='9px' src='../App_Themes/Common/images/TickUp.gif'>";
					clss = "<span class='HGreen'>" ;
				
				}
				else if(DiffVal<0) 
				{		DiffImg="<img width='7px' height='9px' src='../App_Themes/Common/images/TickDwn.gif'>";						
					clss = "<span class='HRed'>" ;
				}
				else if(DiffVal==0) 
				{
				DiffImg= "<img width='7px' height='9px' src='../App_Themes/Common/images/TickDwn.gif'>"
					clss = "<span class='HBlue'>"	;				
				}
				
				if(i==0)ExchgDet = "<span class='TickerText' >" + arrCol[0] +"</span> &nbsp; <a href='../CompanyProfile/QuoteFinder.aspx?id=65&FinCode="+BSENSEFIN+"&Mode=S'><span  class=TickerText>"+ CompName +": "+"</span></a><span  class=TickerText>" + ClPrice+"&nbsp;"+" ["+ clss   +"<b>"+ DiffVal+ "%</b></span>"+"] </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span class='TickerLink'>" + "<a href='../CompanyProfile/QuoteFinder.aspx?id=38&FinCode="+arrCol[0]+"&Mode=S'><span  class=TickerText>" + CompName +"</span></a>: " + "<span  class=TickerText>" + ClPrice +"&nbsp;"+" ["+ clss  +"<b>"+ DiffVal+ "%</b></span>"+"]  &nbsp;</span>&nbsp;";						
			
			}
			MarqueeId.innerHTML = "<marquee id='MarqueeIdTD'  valign='middle' style='vertical-align:bottom;display:block' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='30' direction='left' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
				
			document.getElementById("MarqueeIdTD").start();
			document.body.style.cursor = "auto";
		}
	}
}
//Creating object of XMLHTTP For AJAX Method
function CreateXmlHttpLN()
{
    //Creating object of XMLHTTP in IE 
	try
	{
	    XmlHttp_LN = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
	    try
		{
			XmlHttp_LN = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp_LN = null;	
		}
	} 
	
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp_LN && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp_LN = new XMLHttpRequest();
	}
}
function getNews_Home(secid,subsecid,type)
{
       closeallMarket();
       //document.getElementById("MM"+type).className="TabTextSelHM";
       
       var NewsTDMore = document.getElementById("NewsTDMore");
       
       var StrURL="";
           for(i=1;i<=4;i++)
       {document.getElementById("n"+i).className="";}
       document.getElementById("n"+type).className="current";
     switch(type)
         {
        case "1": 
       StrURL="../news/hot-stocks.aspx";
        break;
        case "2": 
       StrURL="../news/corporate-news.aspx";
        break;
        case "3": 
       StrURL="../news/market-pulse.aspx";
        break;
        case "4": 
       StrURL="../news/economy.aspx";
        break;
}   
       
       
      NewsTDMore.href=StrURL;
          CreateXmlHttpLN();
    
    
    
    document.getElementById("NewsTD").innerHTML = "<table align=center><tr><td ><img src =../App_Themes/Common/images/ajax-loader.gif /></td></tr></table>";
	document.body.style.cursor = "progress";

    var requestUrl="../Home/AjaxHomeNews.aspx?Sec="+secid+"&SubSec="+subsecid+"&timeStamp="+new Date().getTime();
   
	if(XmlHttp_LN)
	{
		
		XmlHttp_LN.onreadystatechange=function(){getNewsData();};
		XmlHttp_LN.open("GET",requestUrl,true);
		XmlHttp_LN.send(null);
	}
}
function closeallMarket()
{
    for(var i=1;i<=4;i++)
    {
      //  document.getElementById("MM"+i).className="TabTextUnSelHM";
    }
}function getNewsData()
{
    if(XmlHttp_LN.readyState==4)
	{
	    if(XmlHttp_LN.status == 200)
		{
   		    document.getElementById("NewsTD").innerHTML=XmlHttp_LN.responseText;
			document.body.style.cursor = "auto";		
		}
		else
		{
			document.getElementById("NewsTD").innerHTML =  "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}
}
function CreateXmlHttpNewsGlobal()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpNewsGlobal = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				XmlHttpNewsGlobal = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpNewsGlobal = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpNewsGlobal && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        XmlHttpNewsGlobal = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        XmlHttpNewsGlobal=false;
	        }
        }
        if (!XmlHttpNewsGlobal && window.createRequest) 
        {
	        try 
	        {
		        XmlHttpNewsGlobal = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpNewsGlobal=false;
	        }
        }
	}
	
    function OpenNewsGlobal(NewsID,SecID,SubSecID,FinCode,Opt)
    {
        CreateXmlHttpNewsGlobal();
        document.getElementById("divNews").style.display = "inline";
		document.body.style.cursor = "progress";
		
		var requestUrl = "../Home/AjaxNewsPopGlobal.aspx?timeStamp="+ new Date().getTime() +"&NewsID="+NewsID +"&SecID="+SecID +"&SubSecID="+SubSecID +"&FinCode="+FinCode;
		//alert(requestUrl)
		if(XmlHttpNewsGlobal)	{
					XmlHttpNewsGlobal.onreadystatechange = function(){getNewsRespGlobal()};
					XmlHttpNewsGlobal.open("GET", requestUrl,  true);
					XmlHttpNewsGlobal.send(null);
				}
    }
    
    function getNewsRespGlobal()
{

	if(XmlHttpNewsGlobal.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpNewsGlobal.status == 200)//
		{
		document.getElementById("TdNews").innerHTML=XmlHttpNewsGlobal.responseText;
		document.body.style.cursor = "auto";		
		}
		else
		{
			document.getElementById("TdNews").innerHTML =  "There was a problem retrieving data from the server.";
			document.body.style.cursor = "auto";
		}
	}
}
