var XmlHttpFO;
function showChart()
{
	var ExpDate= document.getElementById("Pform_drp_ExpDate").value;
	var Symbol = document.getElementById("Pform_drp_Symbol").value;
	var InstName,OptType,OptType1;
	if(Symbol=="NIFTY" || Symbol=="BANKNIFTY" || Symbol=="CNXIT"){
		InstName = "OPTIDX";
		OptType = "CE";
		OptType1 = "PE";
		}
	else {
		InstName = "OPTSTK";
		OptType = "CA";
		OptType1 = "PA";					
	}	
	var urlText = "MaximumPainChart.aspx?ExpDate="+ ExpDate +"&Symbol="+ Symbol +"&InstName="+ InstName +"&OptType="+ OptType +"&OptType1="+ OptType1;
	//alert(urlText);
	document.MaxPainChart.src = urlText;
}
//Creating object of XMLHTTP For AJAX Method
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(InstName)
{
 	var InstName = document.getElementById('DForm_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="PA";
		OptionType.options[1].text="PA";
		OptionType.options[2] = new Option();
		OptionType.options[2].value="CA";
		OptionType.options[2].text="CA";
	}
	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 Strike Price";
	//}			
	CreateXmlHttpNew();	
	document.body.style.cursor = "progress";
	var requestUrl = "FO_Symbol.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value;	
	//alert(requestUrl);
	if(XmlHttpFO)	{
				XmlHttpFO.onreadystatechange = function(){getSymbolResp(Symbol,InstName)};
				XmlHttpFO.open("GET", requestUrl,  true);
				XmlHttpFO.send(null);
			}
 }
 
 //Called when response comes back from server Only For Symbol
function getSymbolResp(ig_,ig_2)
{
	// 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 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 = "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";		
		}
		Get_Options(ig_2);
	}
}
/*Start By Anuradha*/
function Get_Options(Inst)
{
	var InstName =document.getElementById("DForm_InstrumentType");//document.getElementById("Foquotes1_InstrumentType");		
	var Symbol = document.getElementById("Symbol"); 	
	var OptionType = document.getElementById("OptionType");
	var StrikePrice = document.getElementById("StrikePrice");   		
	  	
	        
	CreateXmlHttpNew();
	var requestUrl = "FO_Option.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value;	
	//alert(requestUrl);	
	document.body.style.cursor = "progress";		
	if(XmlHttpFO)	
	{
		XmlHttpFO.onreadystatechange = function(){getOptionResp(OptionType)};
		XmlHttpFO.open("GET", requestUrl,  true);
		XmlHttpFO.send(null);
	}		
}
function getOptionResp(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)
		{			
			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 = "Option 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 By Anuradha*/
 function Get_ExpDate()
 { 
 		var InstName = document.getElementById('DForm_InstrumentType'); 		
 		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpiryDate");
 		
 		Symbol=Symbol.value;
 		Symbol=Symbol.replace('&','*');
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "FO_ExpDate.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value +"&Symbol="+Symbol;		
		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
	//alert(XmlHttpFO.responseText)
	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 Get_StrikePrice()
 {
 
 		var InstName = document.getElementById('DForm_InstrumentType');
 		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpiryDate");
 		var OptionType = document.getElementById("OptionType");
 		var StrikePrice = document.getElementById("StrikePrice"); 
 		
 		Symbol=Symbol.value;
 		Symbol=Symbol.replace('&','*');
 		
 		//alert(ExpiryDate.value)		
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "FO_StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value +"&Symbol="+Symbol+"&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;			
			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";		
		}
	}
} 
// On Go Click
function ValidateForm(Val)
{
	var InstType = document.getElementById('DForm_InstrumentType');
	var Symbol   = document.getElementById("Symbol");
	var ExpDate  = document.getElementById("ExpiryDate");
	var OptType  = document.getElementById("OptionType");
	var StkPrice = document.getElementById("StrikePrice"); 
	
	    Symbol = Symbol.value;
 	 	Symbol = Symbol.replace('&','*');
 	 	
		if(InstType.value=="")
		{
			 alert("Please select the Instrument Type before you proceed")
			 InstType.focus();
			 return false;
		}
		else if((InstType.value=="OPTIDX")||(InstType.value=="OPTSTK"))
		{
			if(Symbol=="Select Symbol")	
			//if(Symbol=="Select Symbol" || Symbol=="")	
			{
				alert("Please select Symbol before you proceed")
				document.getElementById("Symbol").focus();
				return false;
			}
			else if(ExpDate.value=="Select Expiry Date")
			//else if(ExpDate.value=="Select Expiry Date" || ExpDate.value=="")
			{
				 alert("Please select Expiry before you proceed")
				 ExpDate.focus();
				 return false;
			}	
			else if(OptType.value=="Select Option Type")
			//else if(OptType.value=="" || OptType.value=="Select Option Type")
			{
				 alert("Please select Option Type before you proceed")
				 OptType.focus();
				 return false;
			}
			//else if(StkPrice.value=="Select Strike Price"||StkPrice.value=="")
			else if(StkPrice.value=="Select Strike Price")
			{
				 alert("Please select Price before you proceed")
				 StkPrice.focus();
				 return false;
			}					
		}
		else 
		{
			if(Symbol=="Select Symbol" || Symbol=="")	
			{
				alert("Please select Symbol before you proceed")
				document.getElementById("Symbol").focus();
				return false;
			}
			else if(ExpDate.value=="Select Expiry Date" || ExpDate.value=="")
			{
				alert("Please select Price before you proceed")
				ExpDate.focus();
				return false;
			}				
		}
		var url="InstType="+InstType.value+"&Symbol="+Symbol+"&ExpDate="+ExpDate.value+"&OptType="+OptType.value+"&StkPrice="+StkPrice.value+"";
	if(Val=="Home")
	{
	  window.location="DerivativesInner.aspx?id=1&url="+url+"";
	}
	else
	{	
	getFOQuotes(url);
	}
}
function GetUrlHome()
{

var strurl=window.location.search;
//alert(strurl.indexOf("InstType=") )
if(strurl!="?id=1")
{
strurl=strurl.substring(10);
getFOQuotes(strurl);
}
}
//For Loading Data from FOQuotesData.aspx Using AJAX
function getFOQuotes(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/loadig1.gif";

		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "FO_QuotesData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&"+ strUrl;
		//alert(requestUrl);
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getFODataResp()};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.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(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/shadw.gif";
				document.body.style.cursor = "auto";
			}	
		}
	
	}
}

/* For Derivative Home Gainer/Loser */
/*function FillGL()
{
	var HomeGLUrl = "../Derivatives/DeriGL.aspx";		
	var ajax = new Ajax.Updater('TDGainLose',HomeGLUrl);
}*/

function ShowGL(Ex1,opt1,Ex2,opt2)
{
	if(opt1 != "")
	{
		if(opt1 == "G")
		{
			document.getElementById("TblFutG").style.display = 'inline';
			document.getElementById("TblFutL").style.display = 'none';
		}
		else if(opt1 == "L")
		{
			document.getElementById("TblFutG").style.display = 'none';
			document.getElementById("TblFutL").style.display = 'inline';
		}
		document.getElementById("opt1").value = opt1;
	}
	
	if(opt2 != "")
	{
		if(opt2 == "G")
		{
			document.getElementById("TblOptG").style.display = 'inline';
			document.getElementById("TblOptL").style.display = 'none';
		}
		else if(opt2 == "L")
		{
			document.getElementById("TblOptG").style.display = 'none';
			document.getElementById("TblOptL").style.display = 'inline';
		}
		document.getElementById("opt2").value = opt2;
	}
	
	var HomeGLUrl = "../Derivatives/DeriGL.aspx?opt1="+document.getElementById("opt1").value +"&opt2="+document.getElementById("opt2").value ;
	var ajax = new Ajax.Updater('TDGainLose',HomeGLUrl);
}


