function changeCoverText()
// Change the value of the 'type of cover' drop down menu according to the 'employment status' value
{
//create shortcuts names 
doc = document.quoterequest;
var employ = doc.Emp_Status;
var employWhich = employ.options[employ.selectedIndex].value;
menu2 = doc.type_cover;
quoteEng = doc.QuoteEngine;
quoteEngVal = quoteEng.value;

//checks if the quote engine is different from High Risk,
//HR quote only has one product and one rate.

if (quoteEngVal != "HR")
	{
//create the drop-down menu options according to the 'employment status' value if quote engine is diff from HR
	if (employWhich == "employed")
		{
		menu2.options.length = 1;
		//menu2.options[0].text = "Please Choose ...";
		//menu2.options[0].value = "";
		menu2.options[0].text = "Accident, Sickness or Involuntary Redundancy";
		menu2.options[0].value = "asr";
		//menu2.options[2].text = "Accident and Sickness only";
		//menu2.options[2].value = "as";
		//menu2.options[3].text = "Redundancy only";
		//menu2.options[3].value = "r";
		}//end if (employWhich == "employed")

	else if (employWhich == "self_employed")
		{
		menu2.options.length = 1;
		//menu2.options[0].text = "Please Choose ...";
		//menu2.options[0].value = "";
		//menu2.options[1].text = "Accident, Sickness or Cessation of Business";
		//menu2.options[1].value = "asr";
		menu2.options[0].text = "Accident and Sickness only";
		menu2.options[0].value = "as";
		//menu2.options[3].text = "Cessation of Business or Bankruptcy only";
		//menu2.options[3].value = "r";
		}//end else if (employWhich == "self_employed")

	else if (employWhich == "cont_director")
		{
		menu2.options.length = 1;
		//menu2.options[0].text = "Please Choose ...";
		//menu2.options[0].value = "";
		//menu2.options[1].text = "Accident, Sickness or Involuntary Liquidation";
		//menu2.options[1].value = "asr";
		menu2.options[0].text = "Accident and Sickness only";
		menu2.options[0].value = "as";
		//menu2.options[3].text = "Bankruptcy or Involuntary Liquidation only";
		//menu2.options[3].value = "r";
		}//end else if (employWhich == "cont_director")

	else
		{
		window.alert("An Error Occured, please try again");
		}// end else
	}//end if (quoteEng != "HR")

//else if (quoteEngVal == "HR")
//	{
//	if (employWhich == "employed")
//		{
//		menu2.options.length = 1;
//		menu2.options[0].text = "Accident, Sickness or Involuntary Redundancy";
//		menu2.options[0].value = "asr";
//		}//end if (employWhich == "employed")
		
//	else if (employWhich == "self_employed")
//		{
//		menu2.options.length = 1;
//		menu2.options[0].text = "Accident, Sickness or Cessation of Business";
//		menu2.options[0].value = "asr";
//		}//end else if (employWhich == "self_employed")
	
//	else if (employWhich == "cont_director")
//		{
//		menu2.options.length = 1;
//		menu2.options[0].text = "Accident or Involuntary Liquidation";
//		menu2.options[0].value = "asr";
//		}//end else if (employWhich == "self_employed")
//	else
//		{
//		window.alert("An Error Occured, please try again");
//		}// end else
//	}//end if (quoteEng == "HR"

else
	window.alert("An Error Occured, please try again");
}//end function

/////////////////////////////////////////////////////////////////////////////////////////////////////////
function maxCover()
// add any value entered in the fields and display the results in the 'max mortgage cover allowed' box
{
// create shortcuts
doc = document.quoterequest;
maxiCover = doc.maxCov;
monthSvr = doc.monthlyMortPaySvr;
//monthIns = doc.monthlyIns;
annuIncome = doc.annual_ginp;
quoteEng = doc.QuoteEngine;
quoteLimit = quoteEng.value;
totrequi = doc.tot_prot;
maxMortAllowed = 0;
maxMortAllowed1 = 0;
maxMortAllowed2 = 0;
maxMortAllowed3 = 0;

if((annuIncome.value=='') || (isNaN(annuIncome.value))){
	alert('Please enter a valid anount in the Annual Income field');
}


// gives the limit for the maximum of cover
switch (quoteLimit)
{
	//case "HR":
	//	maxMortAllowed = 1000;
	//break
	
	case "HB":
		maxMortAllowed1 = 2000;
		maxMortAllowed2 = monthSvr.value*1.25;
		maxMortAllowed3 = (0.5*(annuIncome.value))/12;
		if (maxMortAllowed1 > maxMortAllowed2){
			if (maxMortAllowed2 > maxMortAllowed3){
				maxMortAllowed = maxMortAllowed3;
			}else{
				maxMortAllowed = maxMortAllowed2;
			}
		}else
			if (maxMortAllowed1 > maxMortAllowed3){
				maxMortAllowed = maxMortAllowed3;
			}else{
				maxMortAllowed = maxMortAllowed1;
			}
	break
	
	//case "MP":
	//	maxMortAllowed1 = 1500;
	//	maxMortAllowed2 = ((monthSvr.value *1) + (monthIns.value*1))*1.25;
	//	if (maxMortAllowed1 < maxMortAllowed2)
	//		{
	//		maxMortAllowed = maxMortAllowed1;
	//		}
	//	else
	//		{
	//		maxMortAllowed = maxMortAllowed2;
	//		}
	//	if (totrequi.value > maxMortAllowed)
	//		{
	//		window.alert("The Maximum Protection you can have is " + maxMortAllowed + " per month.\nPlease alter your selection.");
	//		}
	//break
	
	//case "IP":
	//	maxMortAllowed = 0;
	//break
}

// add all the field of the standalone Form to create the Total Benefit Recommended
//maxiCover.value = ((monthSvr.value *1) + (monthIns.value*1))*1.25;

//if (maxiCover.value > maxMortAllowed){
	maxiCover.value = maxMortAllowed;
//	}

if (totrequi.value > maxMortAllowed){
	window.alert("The Maximum Protection you can have is \u00A3" + maxMortAllowed + " per month.\nPlease alter your selection.");
	return false;
}


	
}// end function

//function maxProtection()
// add any value entered in the fields and display the results in the 'max protection allowed' box
//{
//create shortcuts
//doc = document.quoterequest;
//var income = doc.annual_ginp.value;
//quoteEng = doc.QuoteEngine;
//quoteLimit = quoteEng.value;
//totrequi = doc.tot_prot;
//maxProtAllowed = 0;
//maxProtAllowed1 = 0;
//maxProtAllowed2 = 0;
// gives the limit for the maximum of cover
//switch (quoteLimit)
//{
	//case "HR":
	//	maxProtAllowed1 = 1000;
	//	maxProtAllowed2 = (income /12)*50/100;
	//	if (maxProtAllowed1 < maxProtAllowed2)
	//		{
	//		maxProtAllowed = maxProtAllowed1;
	//		}
	//	else
	//		{
	//		maxProtAllowed = maxProtAllowed2;
	//		}
	//	if (totrequi.value > maxProtAllowed)
	//		{
	//		window.alert("The Maximum Protection you can have is " + maxProtAllowed + " per month.\nPlease alter your selection.");
	//		}
	//break

	//case "HB":
	//	maxProtAllowed1 = 1500;
	//	maxProtAllowed2 = (income /12)*50/100;
	//	if (maxProtAllowed1 < maxProtAllowed2){
	//		maxProtAllowed = maxProtAllowed1;
	//	}else{
	//		maxProtAllowed = maxProtAllowed2;
	//	}
		
	//	if (totrequi.value > maxProtAllowed){
	//		window.alert("The Maximum Protection you can have is " + maxProtAllowed + " per month.\nPlease alter your selection.");
	//	}
	//break

	//case "MP":
	//	maxProtAllowed = "";
	//break

	//case "IP":
	//	maxProtAllowed1 = 1000;
	//	maxProtAllowed2 = ((income*1)/12)*0.5;
	//	if (maxProtAllowed1 < maxProtAllowed2)
	//		{
	//		maxProtAllowed = maxProtAllowed1;
	//		}
	//	else
	//		{
	//		maxProtAllowed = maxProtAllowed2;
	//		}
	//	if (totrequi.value > maxProtAllowed)
	//		{
	//		window.alert("The Maximum Protection you can have is " + maxProtAllowed + " per month.\nPlease alter your selection.");
	//		}
	//break
//}

// add all the field of the standalone Form to create the Total Benefit Recommended
//maxiProt.value = maxProtAllowed;
//}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkForm()
{
// create shortcuts
doc = document.quoterequest;
var employ = doc.Emp_Status;
var employWhich = employ.options[employ.selectedIndex].value;
var covtype = doc.type_cover;
var whichcov = covtype.options[covtype.selectedIndex].value;
var deferred = doc.deferral;
var whichdef = deferred.options[deferred.selectedIndex].value;
var mortSvr = doc.monthlyMortPaySvr.value;
var totrequi = doc.tot_prot.value;
var totreq = (totrequi/100);
premium = doc.monthPrem;

if (employWhich == ""){
	window.alert('Please select a type of employment status from the drop down menu');
	return false
}else if (whichcov == ""){
	window.alert('Please select a type of cover from the drop down menu');
	return false
}else if (whichdef == ""){
	window.alert('Please select the appropriate deferral period');
	return false
}else if (mortSvr == ""){
	window.alert('Please type in your Monthly Mortage Payment at Standard Variable Rate');
	return false
}else if (totrequi == "0.00" || totrequi == "0" || totrequi == ""){
	window.alert('Please validate your quote by clicking on the \'Click here for Premium Calculation\' button');
	return false
}else if (totrequi != ""){
	return maxCover();
}
//recalculate the quote in case info has been changed in the meantime
//choose rate according to the choice of cover and start date
// check if type of cover is selected
else{
	getQuote();
	return true
}
return true
}//end function


window.onload = function() {
//disble application buttons
if(document.getElementById('apqsingle') && document.getElementById('apqdouble')){
	var appliSbtn = document.getElementById('apqsingle');
	var appliDbtn = document.getElementById('apqdouble');
	
	appliSbtn.disabled = appliDbtn.disabled = true;

	}
}

function areBothChecked(){
	var appliSbtn = document.getElementById('apqsingle');
	var appliDbtn = document.getElementById('apqdouble');
	if ((document.quoterequest.confirmBox[0].checked==true) && (document.quoterequest.confirmBox[1].checked==true)){
		appliSbtn.disabled = appliDbtn.disabled = false;

	}else{
		appliSbtn.disabled = appliDbtn.disabled = true;
	}
}
