// JavaScript for All Functions
// (created by Shagin K Sasi)


//-------------------------------------------------------------------------------------
	 //This Function ..required for showing Symbol
 	// invoke the server side program.... only for the selection of Instname
    // wrong combinations will not fill the Symbol
function ChangeComp(opt){
	if(opt !='')
	{
	var objRS = RSGetASPObject("GetSymbol.asp"); 
	var objResult = objRS.fillsymbol(opt); 
	var strNames = objResult.return_value; 
	document.getq_form.Symbol.length=0;
	if(strNames != "undefined")
	{	
		document.getq_form.Symbol.options[0] = new Option(); 
		document.getq_form.Symbol.options[0].value='';
		document.getq_form.Symbol.options[0].text='Select symbol Type';
			
		var arrCatNames = strNames.split("|"); 	
		for(i=0; i<arrCatNames.length-1; i++)
		{	
			var strid=arrCatNames[i];
			document.getq_form.Symbol.options[i+1] = new Option(); 
			document.getq_form.Symbol.options[i+1].value=strid;
			document.getq_form.Symbol.options[i+1].text=strid;
		}
	}
	}	
}


//-------------------------------------------------------------------------------------
	 //This Function ..required for showing Expiry Date
 	// invoke the server side program.... only for the selection of symbol
    // wrong combinations will not fill the strike price
function ChangeExpDate(sym){
	var opt=document.getq_form.InstType[document.getq_form.InstType.selectedIndex].value;
	if(opt !='' && sym != '')
	{
	var objRS = RSGetASPObject("GetExpDate.asp"); 
	var objResult = objRS.fillexpdate(sym); 
	var strNames = objResult.return_value; 
	document.getq_form.ExpDate.length=0;
	if(strNames != "undefined")
	{	
		document.getq_form.ExpDate.options[0] = new Option(); 
		document.getq_form.ExpDate.options[0].value='';
		document.getq_form.ExpDate.options[0].text='Select Expiry Date';
		var arrCatNames = strNames.split("|"); 
			
		for(i=0; i<arrCatNames.length-1; i++)
		{	
			var strid=arrCatNames[i];
			document.getq_form.ExpDate.options[i+1] = new Option(); 
			document.getq_form.ExpDate.options[i+1].value=strid;
			document.getq_form.ExpDate.options[i+1].text=strid;
		}
	}
	}	
}
//-------------------------------------------------------------------------------------
	 //This Function ..required for showing Option Types
 	// This Function invokes  only the combinations (InstName = OPTIDX or  InstName = OPTSTK ) it shows the table id named "OptTable"
	// if the instname equals OPTIDX then opttype is PE or CE Else OptType is PA or CA
    // wrong combinations will not shows the table			
function ShowTypes(opt){
	if(opt=='OPTIDX' || opt=='OPTSTK')
	{
		OptTable.style.display='inline';
			if(opt =='OPTIDX')
			{
					document.getq_form.OptType.length=3;
					document.getq_form.OptType.options[0].value="";
					document.getq_form.OptType.options[0].text='Select Option Type';
					document.getq_form.OptType.options[1].value='PE';
					document.getq_form.OptType.options[1].text='PE';
					document.getq_form.OptType.options[2].value='CE';
					document.getq_form.OptType.options[2].text='CE';					
			 }	
			 else
			 {
					document.getq_form.OptType.length=3;
					document.getq_form.OptType.options[0].value="";
					document.getq_form.OptType.options[0].text='Select Option Type';
					document.getq_form.OptType.options[1].value='PA';
					document.getq_form.OptType.options[1].text='PA';
					document.getq_form.OptType.options[2].value='CA';
					document.getq_form.OptType.options[2].text='CA';			 
			 }
	 }
	 else
	 {
		OptTable.style.display='none';
	 }	
}

//-------------------------------------------------------------------------------------
	 //This Function ..required for showing Strike Prices
 	// invoke the server side program.... only the combinations (InstName, Symbol, ExpDate, OptType) not equal to space 
    // wrong combinations will not fill the strike price
function ShowStrikes(){
	var OptType = document.getq_form.OptType[document.getq_form.OptType.selectedIndex].value;
	var InstName = document.getq_form.InstType[document.getq_form.InstType.selectedIndex].value;
	var Symbol = document.getq_form.Symbol[document.getq_form.Symbol.selectedIndex].value;
	var ExpDate = document.getq_form.ExpDate[document.getq_form.ExpDate.selectedIndex].value;
	if(InstName != '' && Symbol !='' && ExpDate != '' && OptType !='')
	{
		var OptStr = InstName +"|"+ Symbol +"|"+ ExpDate +"|"+ OptType
		var objRS = RSGetASPObject("GetStkPrice.asp"); 
		var objResult = objRS.fillstkprice(OptStr); 
		var strNames = objResult.return_value; 
		document.getq_form.StkPrice.length=0;
		if(strNames != "undefined")
		{	
			document.getq_form.StkPrice.options[0] = new Option(); 
			document.getq_form.StkPrice.options[0].value="";
			document.getq_form.StkPrice.options[0].text='Select Stroke Price';
			
			var arrCatNames = strNames.split("|"); 	
			for(i=0; i<arrCatNames.length-1; i++)
			{	
				var strid=arrCatNames[i];
				document.getq_form.StkPrice.options[i+1] = new Option(); 
				document.getq_form.StkPrice.options[i+1].value=strid;
				document.getq_form.StkPrice.options[i+1].text=strid;
			}
		}
	}
}

//-------------------------------------------------------------------------------------
	 //This function used for left menu
function showSubmenu(opt){
switch (opt){ 
	case 'mw' : 
		mwSubmenu.style.display='inline';
		macSubmenu.style.display='none'
		macalSubmenu.style.display='none';
		maputSubmenu.style.display='none'; 
		mktrptSubmenu.style.display='none';
	break; 
	case 'co' : 
		mwSubmenu.style.display='none';
		macSubmenu.style.display='inline';
		macalSubmenu.style.display='none';
		maputSubmenu.style.display='none'; 		
		mktrptSubmenu.style.display='none';
	break; 			
	case 'ca' : 
		mwSubmenu.style.display='none';
		macSubmenu.style.display='none';
		macalSubmenu.style.display='inline';
		maputSubmenu.style.display='none'; 		
		mktrptSubmenu.style.display='none';
	break; 
	case 'pu' : 
		mwSubmenu.style.display='none';
		macSubmenu.style.display='none';
		macalSubmenu.style.display='none';	
		maputSubmenu.style.display='inline';  
		mktrptSubmenu.style.display='none';
	break; 
	case 'mr' : // mr - Market Report 
		mwSubmenu.style.display='none';
		macSubmenu.style.display='none';
		macalSubmenu.style.display='none';	
		maputSubmenu.style.display='none';  
		mktrptSubmenu.style.display='inline';
	break; 	
   } 
}

//-------------------------------------------------------------------------------------
	 //final check ..required since any change during final submission will
 	// unnecessarily invoke the server side program.... only the combinations
    // wrong combinations will shows the alert message
function validate(){
	var InstType = document.getq_form.InstType.options[document.getq_form.InstType.selectedIndex].value
	var Symbol =  document.getq_form.Symbol.options[document.getq_form.Symbol.selectedIndex].value
	var ExpDate =  document.getq_form.ExpDate.options[document.getq_form.ExpDate.selectedIndex].value
	var OptType =  document.getq_form.OptType.options[document.getq_form.OptType.selectedIndex].value
	var StkPrice =  document.getq_form.StkPrice.options[document.getq_form.StkPrice.selectedIndex].value
	var msg = "Please select "		
		if(InstType==""){
			alert(msg + "Instrument Type ...!")
			return false;
		}
		if(Symbol==""){
			alert(msg + "Symbol ...!")
			return false;
		}
		if(ExpDate==""){
			alert(msg + "Expiry Date ...!")
			return false;
		}
		if(InstType=='OPTIDX' || InstType=='OPTSTK'){
			if(OptType==""){
				alert(msg + "Otion Type ...!")
				return false;
			}
			if(StkPrice==""){
				alert(msg + "Strike Price ...!")
				return false;
			}
		}					
}


function onChangeSymbol(pgName){
   document.frmMain.action = pgName
   document.frmMain.submit();
}

function submitMktRpt(InstName,Sym) {
	window.location = "foMktReport.asp?InstType="+ InstName +"&Sym="+ Sym
}



