﻿// JScript File

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 browser = new Browser();
var clockTimeoutID;
//Global Variables
var XmlHttp,XmlHttpNews,XmlHttpFII,XmlHttpIPO;

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 ChangeBseNSeVal(val,Period)
{
//alert(val);
    if(val=='BSE')
    {
       
    
       var tdbse = document.getElementById("imgBSE").className="RedBgcolor WhiteBold";
      
       var tdnse = document.getElementById("imgNSE").className="GrayBgcolor WhiteBold";  
       // document.getElementById('Sensex').style.display="inline";
      //  document.getElementById('Nifty').style.display="inline";
       // ChangeControl("GAIN","BSE");
       // GetADVDEC('BSE');
        
    }
    else
    { 
     
      var tdbse = document.getElementById("imgBSE").className="GrayBgcolor WhiteBold";  
      var tdnse = document.getElementById("imgNSE").className=" RedBgcolor WhiteBold";     
   // document.getElementById('Sensex').style.display="inline";
    //document.getElementById('Nifty').style.display="inline";
   // ChangeControl('GAIN','NSE');
   // GetADVDEC('NSE');
}
    document.getElementById("hdnbsense").value=val;
    sensexvaluechart(val,Period)
}





function sensexvaluechart(val,Period)
{
//	var currentDivObj;	
//	currentDivObj = document.getElementById("MKTChart");
//	currentDivObj.innerHTML ="<img src=../App_Themes/Common/images/loading.gif>"; 
var StrUrl="MarketChartAjax.aspx?Exchg="+val+"&Period="+Period+"&timeStamp="+ new Date().getTime()
var so = new SWFObject("amline1/amline.swf", "BSENSEline", "180px", "203px", "4", "#ffffff");
so.addVariable("path", "amline1/");
so.addParam("wmode","opaque");		
so.addVariable("settings_file", encodeURIComponent("amline1/BSENSEline_settings.xml"));	
so.addVariable("data_file", encodeURIComponent(StrUrl+"&TimeStamp="+new Date().getTime()));
so.write("MKTChart");
		
}

function ChangeControl(Opt,Exch)
{
	CreateXmlHttp();
       var currentDivObj = document.getElementById("Td_Data");
        
		//currentDivObj.innerHTML ="<img src=App_Themes/CommonTheme/Images/ajax-loader.gif>";
	document.body.style.cursor = "progress";
	
	
	var requestUrl = "../AjaxDataGLVV.aspx?Option="+ Opt +"&Exchange="+ Exch;
   // 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;
	
	case "Vol":
		Head_td.innerHTML="Volume";
		 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";
	     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";
		}
	}
}	
var XmlHttpADVDEC;
function CreateXmlHttpADVDEC()
{
	try
	{
		XmlHttpADVDEC = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpADVDEC = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpADVDEC = null;				
		}
	}
	if(!XmlHttpADVDEC && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpADVDEC = new XMLHttpRequest();
	}
}


function GetADVDEC(exchange)
	{	
	//alert(Exchg);	
		CreateXmlHttpADVDEC();
		document.body.style.cursor = "progress";
		//document.getElementById("tdAdvDec").innerHTML = " <img src='../App_Themes/Common/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 = "../equity/AjaxAdvanceDeclines.aspx?exchange="+exchange+"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		//alert(requestUrl);
		if(XmlHttpADVDEC){
			XmlHttpADVDEC.onreadystatechange = function(){getDataResponseADVDEC();};
			XmlHttpADVDEC.open("GET", requestUrl,  true);
			XmlHttpADVDEC.send(null);
		}
}
function getDataResponseADVDEC()
{
	if(XmlHttpADVDEC.readyState == 4)
	{	
	
		if(XmlHttpADVDEC.status == 200)
		{				
		
			
			var tdAdvDec = document.getElementById("tdAdvDec");
			var ADVDECData = XmlHttpADVDEC.responseText;
			//alert(NewData);
						
			if(ADVDECData != "")
		
				tdAdvDec.innerHTML = ADVDECData;				
				document.body.style.cursor = "auto";
				
		}
		
		//else
			//MarqueeId.innerHTML = "<img src='../CommonImgs/loading1.gif'>";
	}
}


function CreateXmlHttpNews()
{
	try
	{
		XmlHttpNews = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpNews = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpNews = null;				
		}
	}
	if(!XmlHttpNews && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpNews = new XMLHttpRequest();
	}
}


function GetNewsHot(SecID,SubSec)
	{	
	//alert(Exchg);	
		CreateXmlHttpNews();
		document.body.style.cursor = "progress";
		document.getElementById("NewTd").innerHTML = " <img src='../App_Themes/Common/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 = "HotnewsAjax.aspx?Sec="+ SecID +"&SubSec="+SubSec+"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		//alert(requestUrl);
		if(XmlHttpNews){
			XmlHttpNews.onreadystatechange = function(){getDataResponse();};
			XmlHttpNews.open("GET", requestUrl,  true);
			XmlHttpNews.send(null);
		}
}
function getDataResponse()
{
	if(XmlHttpNews.readyState == 4)
	{	
	
	    var NewTd = document.getElementById("NewTd");
	    
		if(XmlHttpNews.status == 200)
		{	
			var NewData = XmlHttpNews.responseText;
			//alert(NewData);
						
		  
			NewTd.innerHTML = NewData;				
			document.body.style.cursor = "auto";
				
		}
		
		else
		{
			NewTd.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/loading.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>";
				
			}
		}
	}
	
	
	
	
	function CreateXmlHttpFII()
{
	try
	{
		XmlHttpFII = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpFII = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpFII = null;				
		}
	}
	if(!XmlHttpFII && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpFII = new XMLHttpRequest();
	}
}


function GetFIIMF(Type)
	{	
	//alert(Exchg);	
		CreateXmlHttpFII();
		document.body.style.cursor = "progress";
		//alert(Type);
		if(Type=='FII')
		{
		document.getElementById("tdFII").className="TopBorder";
		document.getElementById("tdMF").className="BottomBorder"
		document.getElementById("tdFII").style.cursor="pointer";
		document.getElementById("tdMF").style.cursor="hand";
		//alert(document.getElementById("tdFII").className);
		}
		else
		{
		document.getElementById("tdFII").className="BottomBorder";
		document.getElementById("tdMF").className="TopBorderL"
		document.getElementById("tdFII").style.cursor="hand";
		document.getElementById("tdMF").style.cursor="pointer";
		}
		//document.getElementById("FIIMF").innerHTML = " <img src='App_Themes/Common/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 = "FIIMFAjax.aspx?Type="+ Type +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		//alert(requestUrl);
		if(XmlHttpFII){
			XmlHttpFII.onreadystatechange = function(){getDataResponseFIIMF();};
			XmlHttpFII.open("GET", requestUrl,  true);
			XmlHttpFII.send(null);
		}
}
function getDataResponseFIIMF()
{
	if(XmlHttpFII.readyState == 4)
	{	
	
		if(XmlHttpFII.status == 200)
		{				
		
			
			var FIIMF = document.getElementById("FIIMF");
			var FIIMFData = XmlHttpFII.responseText;
			//alert(NewData);
						
			if(FIIMFData != "")
		
				FIIMF.innerHTML = FIIMFData;				
				document.body.style.cursor = "auto";
				
		}
		
		//else
			//MarqueeId.innerHTML = "<img src='../CommonImgs/loading1.gif'>";
	}
}


	function CreateXmlHttpIPO()
{
	try
	{
		XmlHttpIPO = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpIPO = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpIPO = null;				
		}
	}
	if(!XmlHttpIPO && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpIPO = new XMLHttpRequest();
	}
}


function GetIPO()
	{	
	//alert(Exchg);	
		CreateXmlHttpIPO();
		document.body.style.cursor = "progress";
		
		var requestUrl = "IpoAjaxData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
//		alert(requestUrl);
		if(XmlHttpIPO){
			XmlHttpIPO.onreadystatechange = function(){getDataResponseIPO();};
			XmlHttpIPO.open("GET", requestUrl,  true);
			XmlHttpIPO.send(null);
		}
}
function getDataResponseIPO()
{
	if(XmlHttpIPO.readyState == 4)
	{	
	
		if(XmlHttpIPO.status == 200)
		{				
		
			
			var tdIpoData = document.getElementById("IPOdata");
			var IPOData = XmlHttpIPO.responseText;
			//alert(IPOData);
						
			if(IPOData != "")
		
				tdIpoData.innerHTML = IPOData;				
				document.body.style.cursor = "auto";
				
		}
		
		//else
			//MarqueeId.innerHTML = "<img src='../CommonImgs/loading1.gif'>";
	}
}




