﻿// JScript File
//Global Variables
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 containerid="contentarea";
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""
var browser = new Browser();
var XmlHttp;

//Creating object of XMLHTTP For AJAX Method

function CreateXmlHttpVV()
	{
		//Creating object of XmlHttp in IE
		try
		{
			XmlHttpVV = new ActiveXObject("Msxml2.XmlHttp");
		}
		catch(e)
		{
			try
			{
				XmlHttpVV = new ActiveXObject("Microsoft.XmlHttp");
			} 
			catch(oc)
			{
				XmlHttpVV = null;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if(!XmlHttpVV && typeof XmlHttpRequest != "undefined") 
		{
			XmlHttpVV = new XmlHttpRequest();
		}
	}


function CreateXmlHttpNew()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpFO = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpFO = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpFO = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpFO && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpFO = new XMLHttpRequest();
		}
	}
	
	
	
	
	
	//For Getting Symbol Drop Down Contains fillCategory
	function NullExpiryDate(ig_)
	{
	                ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Select Expiry Date";	
	}
	
	
	 function fillSymbol()
	 {
     
 	
	 var Excha = document.getElementById("Exchg");
	 var Symbol = document.getElementById("Symbol");		
     var ExpiryDate = document.getElementById("ExpDate");    
     NullExpiryDate(ExpiryDate);
		
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "CmGetSymbolAjax.aspx?timeStamp="+ new Date().getTime() +"&Excha="+Excha.value;
		//alert(requestUrl)
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){fillSymbolResp(Symbol)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 //Called when response comes back from server Only For Symbol
function fillSymbolResp(ig_)
{

	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpFO.status == 200)
		{		
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			    for (var count = ExpiryDate.options.length-1; count >-1; count--)
	            {
		            ExpiryDate.options[count] = null;
	            }
			var strData = XmlHttpFO.responseText
			//alert(strData)
			if(strData != "") {	
			    
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				
				for(i=0; i<arrSchm.length-1; i++) {	
								
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					
					ig_.options[i] = new Option();
					
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
				
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Select Symbol";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}

//End of Symbol Function///////////////////////////////////////////////////////////





//For Getting Symbol Drop Down Contains 
	
	 function fillCategory()
    {
		
	    var Excha = document.getElementById("ctl00_ContentPlaceHolder1_Exchg");
	    var Symbol = document.getElementById("ctl00_ContentPlaceHolder1_ddlCategory");
		
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "CmGetCategoryAjax.aspx?timeStamp="+ new Date().getTime() +"&Excha="+Excha.value;
		//alert(requestUrl)
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){fillSymbolResp(Symbol)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
    }
 
 //Called when response comes back from server Only For Symbol
function fillSymbolResp(ig_)
{

	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpFO.status == 200)
		{		
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttpFO.responseText
			//alert(strData)
			if(strData != "") {	
			    
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				
				for(i=0; i<arrSchm.length-1; i++) {	
								
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					
					ig_.options[i] = new Option();
					
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
				
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Category not available";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}

//End of Symbol Function///////////////////////////////////





//For Getting Expiry Date

//For Getting Expiry Date

function GetExpDate()
 {
        var Excha = document.getElementById("Exchg");
  		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpDate"); 
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "CmGetExpDateAjax.aspx?timeStamp="+ new Date().getTime() +"&Excha="+Excha.value +"&Symbol="+Symbol.value;
	
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getDateResp(ExpiryDate)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 //Called when response comes back from server Only For Symbol
function getDateResp(ig_)
{

	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpFO.status == 200)
		{
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttpFO.responseText
			//alert(strData);
			if(strData != "") {	
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				for(i=0; i<arrSchm.length-1; i++) {	
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					ig_.options[i] = new Option();
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Date not available";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}

function ShowMCXNDEXVoVal()
{ 
     var ex=   document.getElementById("CommValVolCtrl1_Exchg");
     var valvol =document.getElementById("VV").value;
    
        if (ex.value=="MCX")
        {
        	
            

	        ShowVolumeValue('MCX',valvol);
	     
        }
        else
        {
      
	        ShowVolumeValue('NCDEX',valvol);
	       
        }
	
} 







 function ShowVolumeValue(ex,glctrl)
{

 if (ex == "")
    {
         if (glctrl=="Val")
	    {
	     document.getElementById("ValSel").className="TopGLUnSN";
	      document.getElementById("VolSel").className="TopBSEL";
	     
	  
	    document.getElementById("VV").value = "Val"
	    }
	    else
	    {
	    document.getElementById("ValSel").className="TopBSEL";
	      document.getElementById("VolSel").className="TopGLUnSN";
	    document.getElementById("VV").value = "Vol"
	    }
	 }
	 else
        {
	        if(ex=="MCX")
	        {
	        
		        document.getElementById("MCXNCD").value = "MCX"
	        }
	        else
	        {
        	
		        document.getElementById("MCXNCD").value = "NCDEX"
	        }
        	
        }
   
        CreateXmlHttpVV();
	var requestUrl="AjaxValueVol.aspx?sid=" + Math.random() + "&Exchg="+document.getElementById("MCXNCD").value+"&typeGL="+document.getElementById("VV").value;
	//alert(requestUrl);
	
	
	if(XmlHttpVV)	
			{
					//alert("hi");
					XmlHttpVV.onreadystatechange = function(){ShowVolumeValueData();}; 
					XmlHttpVV.open("GET", requestUrl,  true);
					XmlHttpVV.send(null);
			}
	
}

function ShowVolumeValueData() 
{ 

if(XmlHttpVV.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpVV.status == 200)
		{			
			var ShowVolumeValueData   = document.getElementById("ShowVVData");
		var strData = XmlHttpVV.responseText;
			//alert(strData);
			if(strData != "")
			{
				ShowVolumeValueData.innerHTML   =  strData;
			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			ShowVolumeValueData.innerHTML = "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}

	
}

function ShowBseGL(ex,glctrl)
{

 if (ex == "")
    {
       ex=="NCDEX";
         if (glctrl=="G")
	    {
	        document.getElementById("GL").value = "G"
	    }
	    else
	    {
	    document.getElementById("GL").value = "L"
	    }
	 }
	 else
        {
	        if(ex=="MCX")
	        {

		        document.getElementById("MCXID").value = "MCX"
		      
	        }
	        else
	        {
        	
		        document.getElementById("MCXID").value = "NCDEX"
	        }
        	
        }
   
        CreateXmlHttpVV();
        //alert(document.getElementById("GL").value);

	var requestUrl="AjaxGainerLoser.aspx?sid=" + Math.random() + "&Exchg="+document.getElementById("MCXID").value+"&typeGL="+document.getElementById("GL").value;

	
	
	if(XmlHttpVV)	
			{
					//alert("hi");
					XmlHttpVV.onreadystatechange = function(){ShowShowGLData();}; 
					XmlHttpVV.open("GET", requestUrl,  true);
					XmlHttpVV.send(null);
			}
	
}

function ShowShowGLData() 
{ 
//alert(XmlHttpVV.status);
if(XmlHttpVV.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpVV.status == 200)
		{			
			var ShowGLData   = document.getElementById("ShowGLData");
		var strData = XmlHttpVV.responseText;
		//alert(strData);
			if(strData != "")
			{
				ShowGLData.innerHTML   =  strData;
			}
			document.body.style.cursor = "auto";	
		}
		else
		{var ShowGLData   = document.getElementById("ShowGLData");
			ShowGLData.innerHTML = "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}

	
} 
function ShowMCXNDEXBseGL()
{
     var ex=   document.getElementById("CommGainLooser1_Exchg");
     var valvol =document.getElementById("VV").value;
    
      document.getElementById("MCXID").value = 
     ShowBseGL(ex.value,'G');
}


// News Funtion////////////////



function GetTalkingStockHot(SecID,SubSec)
	{	
	alert("");	
		CreateXmlHttpVV();
		document.body.style.cursor = "progress";
		document.getElementById("TalkingStockTD").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 = "TalkingStockAjax.aspx?Sec="+ SecID +"&SubSec="+SubSec+"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		//alert(requestUrl);
		if(XmlHttpVV){
			XmlHttpVV.onreadystatechange = function(){getDataResponseTalkingStock();};
			XmlHttpVV.open("GET", requestUrl,  true);
			XmlHttpVV.send(null);
		}
}
function getDataResponseTalkingStock()
{
	if(XmlHttpVV.readyState == 4)
	{	
	
		if(XmlHttpVV.status == 200)
		{				
		
			
			var TalkingStockTD = document.getElementById("TalkingStockTD");
			var NewData = XmlHttpVV.responseText;
			//alert(NewData);
						
			if(NewData != "")
		
				TalkingStockTD.innerHTML = NewData;				
				document.body.style.cursor = "auto";
				
		}
		
		//else
			//MarqueeId.innerHTML = "<img src='../CommonImgs/loading1.gif'>";
	}
}


    