﻿-// 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();


function CreateXmlHttp()
	{
		//Creating object of XmlHttp in IE
		try
		{
			XmlHttp1 = new ActiveXObject("Msxml2.XmlHttp");
		}
		catch(e)
		{
			try
			{
				XmlHttp1 = new ActiveXObject("Microsoft.XmlHttp");
			} 
			catch(oc)
			{
				XmlHttp1 = null;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if(!XmlHttp1 && typeof XmlHttpRequest != "undefined") 
		{
			XmlHttp1 = new XmlHttpRequest();
		}
	}
	
	function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 

function CreateXmlHttpSymb()
	{
		//Creating object of XmlHttp in IE
		try
		{
			XmlHttpSymb = new ActiveXObject("Msxml2.XmlHttp");
		}
		catch(e)
		{
			try
			{
				XmlHttpSymb = new ActiveXObject("Microsoft.XmlHttp");
			} 
			catch(oc)
			{
				XmlHttpSymb = null;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if(!XmlHttpSymb && typeof XmlHttpRequest != "undefined") 
		{
			XmlHttpSymb = new XmlHttpRequest();
		}
	}

function CreateXmlHttp()
	{
		//Creating object of XmlHttp in IE
		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") 
		{
			XmlHttp = new XmlHttpRequest();
		}
	}
	
	
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 CreateXmlHttp1()
	{
		//Creating object of XmlHttp in IE
		try
		{
			XmlHttp1 = new ActiveXObject("Msxml2.XmlHttp");
		}
		catch(e)
		{
			try
			{
				XmlHttp1 = new ActiveXObject("Microsoft.XmlHttp");
			} 
			catch(oc)
			{
				XmlHttp1 = null;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if(!XmlHttp1 && typeof XmlHttpRequest != "undefined") 
		{
			XmlHttp1 = new XmlHttpRequest();
		}
	}	
	


function LookUpData(str,typ)
{ 

        if (str=="MCX")
        {
        	
            
	        document.getElementById("BtnMcx").src="../App_Themes/CommonTheme/images/MCXOn.gif" 
	        document.getElementById("BtnNcdex").src="../App_Themes/CommonTheme/images/NCDEXOff.gif"
	        HomeTicker('MCX','F');
	        ShowVolumeValue('MCX','Val');
	        ShowBseGL('MCX','G')
        }
        else
        {
        //	alert('F');

	        document.getElementById("BtnMcx").src="../App_Themes/CommonTheme/images/MCXOff.gif" 
	        document.getElementById("BtnNcdex").src="../App_Themes/CommonTheme/images/NCDEXOn.gif"
	        HomeTicker('NCDEX','F');
	        ShowVolumeValue('NCDEX','Val');
	        ShowBseGL('NCDEX','G')
        }
	
} 


 
 
 function HomeTicker(ex,typ)
{
    if (ex == "")
    {
	
	    if (typ=="S")
	    {
	
	    document.getElementById("SF").value = "S"
	    }
	    else
	    {
	
	    document.getElementById("SF").value = "F"
	    }
    }
        else
        {
	        if(ex=="MCX")
	        {

		        document.getElementById("Ech").value = "MCX"
	        }
	        else
	        {
        	
		        document.getElementById("Ech").value = "NCDEX"
	        }
        	
        }
        CreateXmlHttp1();
	var requestUrl="CommTicker.aspx?sid=" + Math.random() + "&Exchg="+document.getElementById("Ech").value+"&type="+document.getElementById("SF").value
	
	if(XmlHttp1)	
			{
					//alert("hi");
					XmlHttp1.onreadystatechange = function(){ShowTickerData();}; 
					XmlHttp1.open("GET", requestUrl,  true);
					XmlHttp1.send(null);
			}
	
}

function ShowTickerData() 
{ 

if(XmlHttp1.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp1.status == 200)
		{			
			var TikerData   = document.getElementById("TikerData");
		var strData = XmlHttp1.responseText;
			//alert(strData);
			if(strData != "")
			{
				TikerData.innerHTML   =  "<marquee onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='40' height='125px' direction='up' loop='repeat' width='100%'>" +strData + "</marquee>";
			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			TikerData.innerHTML = "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}

	
} 

// for Gainers & Losers

 function ShowBseGL(ex,glctrl)
{

 if (ex == "")
    {
      //  ex=="NCDEX";
         if (glctrl=="G")
	    {
	         document.getElementById("select").className="TopBSEL";
	         document.getElementById("unselect").className="TopGLUnSN";
	     
	  
	        document.getElementById("GL").value = "G"
	    }
	    else
	    {
	    document.getElementById("select").className="TopGLUnSN";
	      document.getElementById("unselect").className="TopNSEL";
	    document.getElementById("GL").value = "L"
	    }
	 }
	 else
        {
	        if(ex=="MCX")
	        {

		        document.getElementById("MCXNCD").value = "MCX"
	        }
	        else
	        {
        	
		        document.getElementById("MCXNCD").value = "NCDEX"
	        }
        	
        }
   
        CreateXmlHttp();
        //alert(document.getElementById("GL").value);

	var requestUrl="AjaxGainerLoser.aspx?sid=" + Math.random() + "&Exchg="+document.getElementById("MCXNCD").value+"&typeGL="+document.getElementById("GL").value;
	
	
	if(XmlHttp)	
			{
					//alert("hi");
					XmlHttp.onreadystatechange = function(){ShowShowGLData();}; 
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
			}
	
}

function ShowShowGLData() 
{ 

if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			var ShowGLData   = document.getElementById("ShowGLData");
		var strData = XmlHttp.responseText;
			//alert(strData);
			if(strData != "")
			{
				ShowGLData.innerHTML   =  strData;
			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			ShowGLData.innerHTML = "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}

	
} 



// For High & Low

 function ShowVolumeValue(ex,glctrl)
{

 if (ex == "")
    {
         if (glctrl=="Val")
	    {
	     document.getElementById("ValSel").className="TopBSEL";
	      document.getElementById("VolSel").className="TopGLUnSN";
	     
	  
	    document.getElementById("VV").value = "Val"
	    }
	    else
	    {
	    document.getElementById("ValSel").className="TopGLUnSN";
	      document.getElementById("VolSel").className="TopNSEL";
	    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";
		}
	}

	
}




/// Get Quotes


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();
		}
	}

function GetExpDate()
 {
        var Excha = document.getElementById("Exchg");
  		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpDate");
 		//alert(ExpiryDate);
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "GetExpDateAjax.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_)
{
alert(XmlHttpFO.readyState);
	// 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";		
		}
	}
}
var XmlHttpSym;

function CreateXmlHttpSym()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpSym = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpSym = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpSym = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpSym && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpSym = new XMLHttpRequest();
		}
	}


// function fillSymbol()
// {
//		
//	 var Excha = document.getElementById("Exchg");
//	// alert(Excha);
//	
// 		var Symbol = document.getElementById("Symbol");		
//		CreateXmlHttpSym();
//		document.body.style.cursor = "progress";
//		var requestUrl = "CmGetSymbolAjax.aspx?timeStamp="+ new Date().getTime() +"&Excha="+document.getElementById("Exchg").value;
//		//alert(requestUrl)
//		if(XmlHttpSym)	{
//					XmlHttpSym.onreadystatechange = function(){fillSymbolResp(Symbol)};
//					XmlHttpSym.open("GET", requestUrl,  true);
//					XmlHttpSym.send(null);
//				}
//		
// }
// 
// //Called when response comes back from server Only For Symbol
//function fillSymbolResp(ig_)
//{
// //var txtSymbol = document.getElementById("txtSymbol");
//		
//	// To make sure receiving response data from server is completed
//	if(XmlHttpSym.readyState == 4)
//	{
//	// var txtIndex = document.getElementById("txtSymbol");
//	 //alert(txtIndex);
//		
//		// To make sure valid response is received from the server, 200 means response received is OK
//		if(XmlHttpSym.status == 200)
//		{		
//			//alert(ig_)
//			//var availSchemes   = document.getElementById(ig_);
//			var strData = XmlHttpSym.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];
//					
//				}
//				//alert(ig_.selectedvalue);
//				//ig_.options[ig_.selectedIndex].value=txtSymbol.value;
//				
//			
//				
//			}
//			else {
//					ig_.length = 0;
//					ig_.options[0] = new Option(); 
//					ig_.options[0].value = "";
//					ig_.options[0].text = "Symbol 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";		
//		}
//	}
//}