
//Global Variables
var XmlHttp, XmlHttpFO;

//Creating object of XMLHTTP For AJAX Method
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 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 Get_Symbol(optS)
 {
        var InstName;
		if(optS=="Inn")
		  InstName = document.getElementById("_ctl0_InstrumentType");
		else
	 	  InstName = document.getElementById("GetQuotes_Home1_InstrumentType");
	 	 
	 	 
 		var Symbol = document.getElementById("Symbol");
 		var OptionType = document.getElementById("OptionType");
 		var StrikePrice = document.getElementById("StrikePrice");
 		
 	      
			if(InstName.value=="OPTIDX")
			{
			    	
				OptionType.options[1] = new Option();
				OptionType.options[1].value="PE";
				OptionType.options[1].text="PE";
				OptionType.options[2] = new Option();
				OptionType.options[2].value="CE";
				OptionType.options[2].text="CE";
			}
			else if(InstName.value=="OPTSTK")
			{
				OptionType.options[1] = new Option();
				OptionType.options[1].value="PE";
				OptionType.options[1].text="PE";
				OptionType.options[2] = new Option();
				OptionType.options[2].value="CE";
				OptionType.options[2].text="CE";
			}
			else
			{
				OptionType.length = 0;
				OptionType.options[0] = new Option();
				OptionType.options[0].value="";
				OptionType.options[0].text="Select Option Type";
				
				StrikePrice.length = 0;
				StrikePrice.options[0] = new Option();
				StrikePrice.options[0].value="";
				StrikePrice.options[0].text="Select Price";
			}
			
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "FO_Symbol.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value;
		
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getSymbolResp(Symbol)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 
 
 function NewGet_Symbol(optS,innerid)
 {
        var InstName;
        
		if(optS=="Inn")
		  InstName = document.getElementById(innerid);
		else
	 	  InstName = document.getElementById("GetQuotes_Home1_InstrumentType");
	 	 
	 	 
 		var Symbol = document.getElementById("Symbol");
 		var OptionType = document.getElementById("OptionType");
 		var StrikePrice = document.getElementById("StrikePrice");
 		
 	      
			if(InstName.value=="OPTIDX")
			{
			    	
				OptionType.options[1] = new Option();
				OptionType.options[1].value="PE";
				OptionType.options[1].text="PE";
				OptionType.options[2] = new Option();
				OptionType.options[2].value="CE";
				OptionType.options[2].text="CE";
			}
			else if(InstName.value=="OPTSTK")
			{
				OptionType.options[1] = new Option();
				OptionType.options[1].value="PE";
				OptionType.options[1].text="PE";
				OptionType.options[2] = new Option();
				OptionType.options[2].value="CE";
				OptionType.options[2].text="CE";
			}
			else
			{
				OptionType.length = 0;
				OptionType.options[0] = new Option();
				OptionType.options[0].value="";
				OptionType.options[0].text="Select Option Type";
				
				StrikePrice.length = 0;
				StrikePrice.options[0] = new Option();
				StrikePrice.options[0].value="";
				StrikePrice.options[0].text="Select Price";
			}
			
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "FO_Symbol.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value;
		
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getSymbolResp(Symbol)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 
 
 
  function Get_ExpDate(optD) {
      
 if(optD=="Inn")
		{
	 var InstName = document.getElementById("_ctl0_InstrumentType");
		}
		else
		{
 		var InstName = document.getElementById("GetQuotes_Home1_InstrumentType");
 		}
 		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpiryDate");
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "FO_ExpDate.aspx?timeStamp=" + new Date().getTime() + "&InstName=" + InstName.value + "&Symbol=" + Symbol.value;
		
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getDateResp(ExpiryDate)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 function NewGet_ExpDate(optD,innerid)
 {
     if(optD=="Inn")
	     var InstName = document.getElementById(innerid);
     else
	     var InstName = document.getElementById("GetQuotes_Home1_InstrumentType");
 	
 		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpiryDate");
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "FO_ExpDate.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value +"&Symbol="+Symbol.value;
		//alert(requestUrl)
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getDateResp(ExpiryDate)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 function Get_StrikePrice(optP)
 {
 if(optP=="Inn")
		{
	 var InstName = document.getElementById("_ctl0_InstrumentType");
		}
		else
		{
 		var InstName = document.getElementById("GetQuotes_Home1_InstrumentType");
 		}
 		
 		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpiryDate");
 		var OptionType = document.getElementById("OptionType");
 		var StrikePrice = document.getElementById("StrikePrice"); 
 			
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value +"&Symbol="+Symbol.value+"&ExpDate="+ExpiryDate.value+"&OptionType="+OptionType.value;
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){Get_StrikePriceResp(StrikePrice)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				} 
				
		
 }
 //Called when response comes back from server Only For Strike Price
function Get_StrikePriceResp(ig_)
{
	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
	//alert(XmlHttpFO.status)
		// 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 arrPrice = strData.split("|");
				ig_.length = 0; 	
				
				for(i=0; i<arrPrice.length-1; i++) {	
								
					var strPrice = arrPrice[i];
					var arrPriceCode = strPrice.split("~");
					
					ig_.options[i] = new Option();
					
					ig_.options[i].value = arrPriceCode[0];
					ig_.options[i].text = arrPriceCode[1];
				}
				
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Price 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";		
		}
	}
}
 
 
 
 
 //Called when response comes back from server Only For Symbol
function getSymbolResp(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 = "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";		
		}
	}
}

 //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
			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 ValidateForm(opt)
{
 if(opt=="Inn")
 {
     var InstType = document.getElementById("GetQuotes_Home1_InstrumentType");
 }
else
 {
  var InstType = document.getElementById("GetQuotes_Home1_InstrumentType");
 }
	var Symbol   = document.getElementById("Symbol");
	var ExpDate  = document.getElementById("ExpiryDate");
	var OptType  = document.getElementById("OptionType");
	var StkPrice = document.getElementById("StrikePrice"); 
	
		if(InstType.value=="")
		{
			alert("Please select the Instrument Type before you proceed")
			return false;
		}
		else if((InstType.value=="OPTIDX")||(InstType.value=="OPTSTK"))
		{
			if(Symbol.value=="Select Symbol")	
			{
			alert("Please select Symbol before you proceed")
			return false;
			}
			else if(OptType.value=="")
			{
			alert("Please select Option Type before you proceed")
			return false;
			}
			else if(StkPrice.value=="Select Price")
			{
			alert("Please select Price before you proceed")
			return false;
			}
		}
		else 
		{
			if(Symbol.value=="Select Symbol")	
			{
			alert("Please select Symbol before you proceed")
			return false;
			}
		}
		var url="InstType="+InstType.value+"&Symbol="+Symbol.value+"&ExpDate="+ExpDate.value+"&OptType="+OptType.value+"&StkPrice="+StkPrice.value+"";
	if(opt=="Home")
	{
	//Redirecting from home page to inner
	window.location="DerivInner.aspx?Eid=52&url="+url+"";
	}
	else
	{
	//showing data in the same page	
	getFOQuotes(url);
	}
}

//For Loading Data from FOQuotesData.aspx Using AJAX
function getFOQuotes(strUrl)
	{
	    //alert(strUrl);
		var FOQuotesTbl = document.getElementById("FOQuotesTbl");
		
		if(FOQuotesTbl.style.display=="none")FOQuotesTbl.style.display = "inline";
		document.FOPChartImg.src="FOpriceChart.aspx?"+ strUrl;

		document.getElementById("LoadingID").src = "../../images/pcLoading.gif";

		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "FOQuotesData.aspx?IpTrack=" + window.location.hostname + "&timeStamp=" + new Date().getTime() + "&" + strUrl;
		//document.write(requestUrl);

		if (XmlHttp) {
		    
					XmlHttp.onreadystatechange = function(){getFODataResp()};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
	}
	
//Called when response comes back from server Only For FO Quotes Data Response
function getFODataResp()
{
	// 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
		if(XmlHttp.status == 200)
		{
		    var FO_QuoteData = XmlHttp.responseText;
		   
			if(FO_QuoteData != "") {
				var arrRow = FO_QuoteData.split("|");
				for(i=0; i<arrRow.length-1; i++)
				 {
					if((i!='14')&&(i!='15'))
						document.getElementById("FO"+i).innerHTML = arrRow[i];
				 }
				document.getElementById("LoadingID").src = "../../images/spacer.gif";
				document.body.style.cursor = "auto";
			}	
		}
		else
			document.getElementById("LoadingID").src = "../../images/pcLoading.gif";
			//document.getElementById("LoadingID").innerHTML = "<img src='../CommonImgs/loading7.gif'>";
	}
}

//For Redirecting from home get quotes
function RedirectFOquotHom(Homeurl) {
    
	var FOQuotesTbl = document.getElementById("FOQuotesTbl");
		if(FOQuotesTbl.style.display=="none")FOQuotesTbl.style.display = "inline";
		document.FOPChartImg.src = "FOpriceChart.aspx?" + Homeurl;
		
		document.getElementById("LoadingID").src = "../../images/pcLoading.gif";

		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "FOQuotesData.aspx?IpTrack=" + window.location.hostname + "&timeStamp=" + new Date().getTime() + "&" + Homeurl;
		
		//document.write(requestUrl);
		if (XmlHttpFO) {

		    XmlHttpFO.onreadystatechange = function() { getFODataHomResp() };
		    XmlHttpFO.open("GET", requestUrl, true);
		    XmlHttpFO.send(null);
				}
}
//Called when response comes back from server Only For FO Quotes Data Response
function getFODataHomResp()
{
    // 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)
		{
		    var FO_QuoteData = XmlHttpFO.responseText;
		    
			if(FO_QuoteData != "") {
				var arrRow = FO_QuoteData.split("|");
				for(i=0; i<arrRow.length-1; i++)
				 {
					if((i!='14')&&(i!='15'))
						document.getElementById("FO"+i).innerHTML = arrRow[i];
				 }
				document.getElementById("LoadingID").src = "../../images/spacer.gif";
				document.body.style.cursor = "auto";
			}	
		}
		else
			document.getElementById("LoadingID").src = "../../images/pcLoading.gif";
			//document.getElementById("LoadingID").innerHTML = "<img src='../CommonImgs/loading7.gif'>";
	}
}
function GetUrlHome() {

    var strurl = window.location.search;
   
//alert(strurl.indexOf("InstType=") )
if(strurl!="?Eid=52") {
    
strurl=strurl.substring(10);
RedirectFOquotHom(strurl);     
}

}


function NewValidateForm(opt,innerid)
{

 var InstType;
 if(opt=="Inn")
  InstType = document.getElementById(innerid);
 else
  InstType = document.getElementById("GetQuotes_Home1_InstrumentType");

	var Symbol   = document.getElementById("Symbol");
	var ExpDate  = document.getElementById("ExpiryDate");
	var OptType  = document.getElementById("OptionType");
	var StkPrice = document.getElementById("StrikePrice"); 
	
		if(InstType.value=="")
		{
			alert("Please select the Instrument Type before you proceed")
			return false;
		}
		else if((InstType.value=="OPTIDX")||(InstType.value=="OPTSTK"))
		{
			if(Symbol.value=="Select Symbol")	
			{
			alert("Please select Symbol before you proceed")
			return false;
			}
			else if(OptType.value=="")
			{
			alert("Please select Option Type before you proceed")
			return false;
			}
			else if(StkPrice.value=="Select Price")
			{
			alert("Please select Price before you proceed")
			return false;
			}
		}
		else 
		{
			if(Symbol.value=="Select Symbol")	
			{
			alert("Please select Symbol before you proceed")
			return false;
			}
		}
	
	
	var url="InstType="+InstType.value+"&Symbol="+Symbol.value+"&ExpDate="+ExpDate.value+"&OptType="+OptType.value+"&StkPrice="+StkPrice.value+"";
	url = url.replace(" ", "");
		
	if(opt=="Home")
	{
	//Redirecting from home page to inner
	window.location="DerivInner.aspx?Eid=52&url="+url+"";
	}
	else
	{
	//showing data in the same page	
	getFOQuotes(url);
	}
}


 function NewGet_StrikePrice(optP,innerid)
 {
 if(optP=="Inn")
		{
	 var InstName = document.getElementById(innerid);
		}
		else
		{
 		var InstName = document.getElementById("GetQuotes_Home1_InstrumentType");
 		}
 		
 		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpiryDate");
 		var OptionType = document.getElementById("OptionType");
 		var StrikePrice = document.getElementById("StrikePrice"); 
 			
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value +"&Symbol="+Symbol.value+"&ExpDate="+ExpiryDate.value+"&OptionType="+OptionType.value;

		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){Get_StrikePriceResp(StrikePrice)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
				
		
 }
