﻿// JScript File
var bustcachevar=1 
function ShowHomeChart(Exchg)
{
if(Exchg=="BSE")
{
document.getElementById("BSEData").style.display='inline';
document.getElementById("NSEData").style.display='none';
document.getElementById("BSECLASS").className='HomeSelTab';
document.getElementById("NSECLASS").className='HomeUnSelTab';
}
else
{
document.getElementById("BSEData").style.display='none';
document.getElementById("NSEData").style.display='inline';
document.getElementById("BSECLASS").className='HomeUnSelTab';
document.getElementById("NSECLASS").className='HomeSelTab';
}
// <![CDATA[		
		var so = new SWFObject("../amline/amline.swf", "BSENSEline", "100%", "140px", "8", "#FFFFFF");
		so.addVariable("path", "../amline/");
		so.addParam("wmode","opaque");
		so.addVariable("settings_file", encodeURIComponent("../BSENSEline_settings.xml"));
		so.addVariable("data_file", encodeURIComponent("BSENSEchartAjax.aspx?Exchg="+Exchg+"&TimeStamp="+new Date().getTime()));
		so.write("flashcontent");
		// ]]>
		
		
}
function CreateXmlHttpNewsEq()
{
	try
		{
			XmlHttpNewsEq = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				XmlHttpNewsEq = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpNewsEq = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpNewsEq && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        XmlHttpNewsEq = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        XmlHttpNewsEq=false;
	        }
        }
        if (!XmlHttpNewsEq && window.createRequest) 
        {
	        try 
	        {
		        XmlHttpNewsEq = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpNewsEq=false;
	        }
        }
}
function TabUnsel()
{
 for(var i=21;i<26;i++)
     {
     document.getElementById("td"+i).className="NewsTabSelectedWhite";
     }

}
function GetHomNews(SecID,SubSec,Id)
{	
    TabUnsel();
    document.getElementById("td"+Id).className="NewsTabSelected";
    CreateXmlHttpNewsEq();
	document.body.style.cursor = "progress";

	var requestUrl = "AjaxHomeNews.aspx?Sec="+ SecID +"&SubSec="+SubSec+"&id="+Id+"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
	//alert(requestUrl);
	if(XmlHttpNewsEq)
	{
	    XmlHttpNewsEq.onreadystatechange = function(){getEqDataResponseHot();};
		XmlHttpNewsEq.open("GET", requestUrl,  true);
		XmlHttpNewsEq.send(null);
	}
	return false;
}

function getEqDataResponseHot()
{
    if(XmlHttpNewsEq.readyState == 4)
	{	
	   var NewTd = document.getElementById("NewTd");
	    if(XmlHttpNewsEq.status == 200)
		{	
	      	NewTd.innerHTML =  XmlHttpNewsEq.responseText;
			document.body.style.cursor = "auto";
		}
		else
		{
			NewTd.innerHTML = "There was a problem retrieving data from the server.";
			document.body.style.cursor = "auto";
		}
	}
}
var XmlHttpIndCtrl;
function CreateXmlHttpIndCtrl()
	{
		try
		{
			XmlHttpIndCtrl = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpIndCtrl = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpIndCtrl = null;
					
			}
		}
		if(!XmlHttpIndCtrl && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpIndCtrl = new XMLHttpRequest();
		}
	}
	
function ChangeIndForex(type)
{
    CreateXmlHttpIndCtrl();
	  	document.body.style.cursor = "progress";

	    var requestUrl = "AjaxindFrx.aspx?Type=I&timeStamp="+new Date().getTime();	
		if(XmlHttpIndCtrl){
			XmlHttpIndCtrl.onreadystatechange = function(){getDataResponseIndForex();};
			XmlHttpIndCtrl.open("GET", requestUrl,  true);
			XmlHttpIndCtrl.send(null);
		}
		return false;
    }

	function getDataResponseIndForex()
    {
	if(XmlHttpIndCtrl.readyState == 4)
	{	
	
		if(XmlHttpIndCtrl.status == 200)
		{				
			var NewTd = document.getElementById("tdIForexData");
			var NewData = XmlHttpIndCtrl.responseText;
		
			if(NewData != "")
		    {
				NewTd.innerHTML = NewData;				
			}
				document.body.style.cursor = "auto";
				
		}
		
	}
}
var browser = new Browser();

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 dragObj = new Object();
dragObj.zIndex = 0;
function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}
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");
				
		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)
		{
		
			if(XmlHttpPop.status == 200)
			{
        	document.getElementById("TdNews").innerHTML = XmlHttpPop.responseText;
			document.body.style.cursor = "auto";
			}
		
			else
			{	
				
					
			}
		}
	}
	
	
	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 BSETickerTab = document.getElementById("BSETickerTab");
		var BSETickerImg = document.getElementById("BSETickerImg");
		var NSETickerTab = document.getElementById("NSETickerTab");
		var NSETickerImg = document.getElementById("NSETickerImg");
		
		if (Exchg=="BSE")
		{
		    NSETickerImg.style.display="none";
		    BSETickerImg.style.display="inline";
		    BSETickerTab.className="TickerTabSelHM"; 
		    NSETickerTab.className="TickerTabUnSelHM"; 
		}
		else if (Exchg=="NSE")
		{
		    BSETickerImg.style.display="none";
		    NSETickerImg.style.display="inline";
	    	NSETickerTab.className="TickerTabSelHM"; 
		    BSETickerTab.className="TickerTabUnSelHM"; 
		}
		
		
		
	var requestUrl = "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) 
				{
					clss = "<span class='Green'>" ;
				}
				else if(DiffVal<0) 
				{							
					clss = "<span class='Red'>" ;
				}
				else if(DiffVal==0) 
				{
					clss = "<span class='Blue'>"	;				
				}
				
				if(i==0)ExchgDet = "<span class='TickerText' >" + arrCol[0] +"</span> &nbsp; <a href='../CompanyProfile/QuoteFinder.aspx?id=38&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";
		}
	}
}




function MarketGLTab(Exch,val)
   {

document.getElementById("hddOption").value=val;
var MktGlTabMore = document.getElementById("MktGlTabMore");
   if(val=='GAIN')
   {
  document.getElementById("MktGlTab").innerHTML="<table cellpadding='0' cellspacing='0' width='100%'><tr><td id='tdHot' nowrap='nowrap' class='GLTabSelect'  style='height: 10px; width: 25%;'>Gainers</td><td class='GLTabUnSelect'>|</td><td id='tdMC' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;LOSE&#39;);' style='height: 10px; width: 25%;'>Losers</td><td class='GLTabUnSelect' width='2px'>|</td><td id='tdCR' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;VOL&#39;);'  style='height: 10px; width: 25%;'> Volume</td><td class='GLTabUnSelect' width='2px'>|</td><td id='tdCA' nowrap='nowrap' class='GLTabUnSelect'   onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;VAL&#39;);' style='height: 10px;  width: 25%; '> Value</td><td class='GLTabUnSelect' width='2px'>&nbsp;</td></tr></table>";
   
 //  MktGlTabMore.href="../Equity/TopGainersAndLosers.aspx?Option=GAIN&EXCHG="+Exch+"&id=1&index=0&Period=Daily&results=5";
   
   GetGLValVData(document.getElementById("hdnExch").value,'GAIN')
   }
   if(val=='LOSE')
   {
   document.getElementById("MktGlTab").innerHTML="<table cellpadding='0' cellspacing='0' width='100%'><tr><td id='tdHot' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;GAIN&#39;);' style='height: 10px; width: 25%; '>Gainers</td><td class='GLTabUnSelect' >|</td><td id='tdMC' nowrap='nowrap' class='GLTabSelect'  style='height: 10px; width: 25%;'>Losers</td><td class='GLTabUnSelect' width='2px'>|</td><td id='tdCR' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;VOL&#39;);'  style='height: 10px; width: 25%;'> Volume</td><td class='GLTabUnSelect' width='2px'>|</td><td id='tdCA' nowrap='nowrap' class='GLTabUnSelect'   onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;VAL&#39;);' style='height: 10px;  width: 25%; '>  Value</td><td class='GLTabUnSelect' width='2px'>&nbsp;</td></tr></table>";
   //  MktGlTabMore.href="../Equity/TopGainersAndLosers.aspx?id=1&Option=LOSE&EXCHG="+Exch+"&Period=Daily&Group=&Indices=2&IsAll=0&flag=1&result=5";
     GetGLValVData(document.getElementById("hdnExch").value,'LOSE')
   }
   if(val=='VOL')
   {
  document.getElementById("MktGlTab").innerHTML="<table cellpadding='0' cellspacing='0' width='100%'><tr><td id='tdHot' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;GAIN&#39;);'  style='height: 10px; width: 25%; '>Gainers</td><td class='GLTabUnSelect' >|</td><td id='tdMC' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;LOSE&#39;);' style='height: 10px; width: 25%;'>Losers</td><td class='GLTabUnSelect' width='2px'>|</td><td id='tdCR' nowrap='nowrap' class='GLTabSelect'   style='height: 10px; width: 25%;'> Volume</td><td class='GLTabUnSelect' width='2px'>|</td><td id='tdCA' nowrap='nowrap' class='GLTabUnSelect'   onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;VAL&#39;);' style='height: 10px;  width: 25%; '> Value</td><td class='GLTabUnSelect' width='2px'>&nbsp;</td></tr></table>";
   // MktGlTabMore.href="../Equity/MostActive.aspx?id=10&Option=Volume&EXCHG="+Exch+"&Group=&Indices=2&IsAll=&flag=1";
  GetGLValVData(document.getElementById("hdnExch").value,'VOL')
   }
   if(val=='VAL')
   {
   document.getElementById("MktGlTab").innerHTML="<table cellpadding='0' cellspacing='0' width='100%'><tr><td id='tdHot' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;GAIN&#39;);'  style='height: 10px; width: 25%; '>Gainers</td><td class='GLTabUnSelect'>|</td><td id='tdMC' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;LOSE&#39;);' style='height: 10px; width: 25%;'>Losers</td><td class='GLTabUnSelect' width='2px'>|</td><td id='tdCR' nowrap='nowrap' class='GLTabUnSelect'  onclick='MarketGLTab(&#39;"+document.getElementById("hdnExch").value+"&#39;,&#39;VOL&#39;);'  style='height: 10px; width: 25%;'> Volume</td><td class='GLTabUnSelect' width='2px'>|</td><td id='tdCA' nowrap='nowrap' class='GLTabSelect'   style='height: 10px;  width: 25%; '>  Value</td><td class='GLTabUnSelect'  width='2px'>&nbsp;</td></tr></table>";
   // MktGlTabMore.href="../Equity/MostActive.aspx?id=10&Option=Value&EXCHG="+Exch+"&Group=&Indices=2&IsAll=&flag=1";
     GetGLValVData(document.getElementById("hdnExch").value,'VAL')
   }

}
function GetGLValVData(Exchange,Opt)
{

   document.getElementById("hdnExch").value = Exchange;
  	var requestUrl = "AjaxGLValVol.aspx?Exchange="+ Exchange+"&Option="+Opt;
  	//alert(requestUrl);
  	ajaxpage(1,requestUrl,'Td_GLData');
}
function ajaxpage(id,url, containerid)
{

    var page_request = false
        if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
        else if (window.ActiveXObject)
        { // if IE
                try {
                    page_request = new ActiveXObject("Msxml2.XMLHTTP")
                    } 
                catch (e){
                        try{
                            page_request = new ActiveXObject("Microsoft.XMLHTTP")
                            }
                        catch (e){}
                        }
        }


        page_request.onreadystatechange=function()
        {
            loadpage(page_request, containerid)
        }
        if (bustcachevar) //if bust caching of external page
        bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
        page_request.open('GET', url+bustcacheparameter, true)
         document.body.style.cursor = "auto";	
        page_request.send(null)    
}
function loadpage(page_request, containerid)
{
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
 {   
   
    document.getElementById(containerid).innerHTML=page_request.responseText}
   
}
function GetNseBSeTab(Exchange)
{
 document.getElementById("hdnExch").value = Exchange;

MarketGLTab(Exchange,document.getElementById("hddOption").value);

}
