
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email")
		    return false
		 }

 		 return true					
	}

// this function checks the entire form		
	function ValidateForm(){
		var emailID=document.contact_form.email
		var fullName=document.contact_form.fullname
		
		if ((fullName.value==null)||(fullName.value=="")){
							alert("Please enter your full name")
							fullName.focus()
							return false
		}
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please enter your email")
			emailID.focus()
			return false
		}
		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}
		return true
	 }
 		
	// If a price is selected, the month, on that row,  automatically gets selected too	
	
	function set_pbcp2(x){
		if (x.checked)
			document.contact_form.parent_board[2].checked=true;
		else
			document.contact_form.parent_board[2].checked=false;
	}
	
	function set_divsubs2(x){
		if (x.checked)
			document.contact_form.div_and_sub[2].checked=true;
		else
			document.contact_form.div_and_sub[2].checked=false;
	}	
	
	function set_pay(x){
		if (x.checked)
			document.contact_form.pay_incentives.checked=true;
		else
			document.contact_form.pay_incentives.checked=false;
	}
	
	function set_annual(x){
		if (x.checked)
			document.contact_form.annual_lt_incentives.checked=true;
		else
			document.contact_form.annual_lt_incentives.checked=false;
	}
	
	function set_pensions(x){
		if (x.checked)
			document.contact_form.pensions.checked=true;
		else
			document.contact_form.pensions.checked=false;
	}
	
	function set_co_car(x){
		if (x.checked)
			document.contact_form.co_car.checked=true;
		else
			document.contact_form.co_car.checked=false;
	}
	
	function set_NED(x){
		if (x.checked)
			document.contact_form.NED.checked=true;
		else
			document.contact_form.NED.checked=false;
	}
	
	// If a qty is selected, the month, on that row, automatically gets selected too	
		
	function select_pbcp2(y){
		if (y.selectedIndex)
			document.contact_form.parent_board[2].checked=true;
		else
			document.contact_form.parent_board[2].checked=false;
	}
		
	function select_divsubs2(y){
		if (y.selectedIndex)
			document.contact_form.div_and_sub[2].checked=true;
		else
			document.contact_form.div_and_sub[2].checked=false;
	}
	
	function select_pay(y){
		if (y.selectedIndex)
			document.contact_form.pay_incentives.checked=true;
		else
			document.contact_form.pay_incentives.checked=false;
	}
	
	function select_annual(y){
		if (y.selectedIndex)
			document.contact_form.annual_lt_incentives.checked=true;
		else
			document.contact_form.annual_lt_incentives.checked=false;
	}
	
	function select_pensions(y){
		if (y.selectedIndex)
			document.contact_form.pensions.checked=true;
		else
			document.contact_form.pensions.checked=false;
	}
	
	function select_co_car(y){
		if (y.selectedIndex)
			document.contact_form.co_car.checked=true;
		else
			document.contact_form.co_car.checked=false;
	}
	
	function select_NED(y){
		if (y.selectedIndex)
			document.contact_form.NED.checked=true;
		else
			document.contact_form.NED.checked=false;
	}
	
	// Checks that publications with choice of month has one selected
	function set_pbcp1(x){
		if (((!document.contact_form.parent_board[0].checked==true) && (!document.contact_form.parent_board[1].checked==true)) && (x.checked))
			alert("Please select the month of the Parent Board and Corporate Posts publication you require");
	}
	
	function select_pbcp1(y){
		if (((!document.contact_form.parent_board[0].checked==true) && (!document.contact_form.parent_board[1].checked==true)) && (y.selectedIndex>0))
			alert("Please select the month of the Parent Board and Corporate Posts publication you require");
	}
	
	function set_divsubs1(x){
		if (((!document.contact_form.div_and_sub[0].checked==true) && (!document.contact_form.div_and_sub[1].checked==true)) && (x.checked))
			alert("Please select the month of the Divisions and Subsidiaries publication you require");
	}
	
	function select_divsubs1(y){
		if (((!document.contact_form.div_and_sub[0].checked==true) && (!document.contact_form.div_and_sub[1].checked==true)) && (y.selectedIndex>0))
			alert("Please select the month of the Divisions and Subsidiaries publication you require");
	}
	
	// For publications with two rows of options, this disables the row not in use
	function disablepbcp1(x){
		if (x.checked)
		document.contact_form.price_parent_board[0].disabled=true;
		document.contact_form.price_parent_board[1].disabled=true;
		document.contact_form.price_parent_board[0].checked=false;
		document.contact_form.price_parent_board[1].checked=false;
		document.contact_form.qty_parent_board1.disabled=true;
		document.contact_form.qty_parent_board1.selectedIndex=0;
		document.contact_form.price_parent_board[2].disabled=false;
		document.contact_form.price_parent_board[3].disabled=false;
		document.contact_form.qty_parent_board2.disabled=false;
	}
	
	function disablepbcp2(x){
		if (x.checked)
		document.contact_form.price_parent_board[2].disabled=true;
		document.contact_form.price_parent_board[3].disabled=true;
		document.contact_form.price_parent_board[2].checked=false;
		document.contact_form.price_parent_board[3].checked=false;
		document.contact_form.qty_parent_board2.disabled=true;
		document.contact_form.qty_parent_board2.selectedIndex=0;
		document.contact_form.price_parent_board[0].disabled=false;
		document.contact_form.price_parent_board[1].disabled=false;
		document.contact_form.qty_parent_board1.disabled=false;
	}	
	
		function disableDivSub1(x){
		if (x.checked)
		document.contact_form.price_div_and_sub[0].disabled=true;
		document.contact_form.price_div_and_sub[1].disabled=true;
		document.contact_form.price_div_and_sub[0].checked=false;
		document.contact_form.price_div_and_sub[1].checked=false;
		document.contact_form.qty_div_and_sub1.disabled=true;
		document.contact_form.qty_div_and_sub1.selectedIndex=0;
		document.contact_form.price_div_and_sub[2].disabled=false;
		document.contact_form.price_div_and_sub[3].disabled=false;
		document.contact_form.qty_div_and_sub2.disabled=false;
	}
	
	function disableDivSub2(x){
		if (x.checked)
		document.contact_form.price_div_and_sub[2].disabled=true;
		document.contact_form.price_div_and_sub[3].disabled=true;
		document.contact_form.price_div_and_sub[2].checked=false;
		document.contact_form.price_div_and_sub[3].checked=false;
		document.contact_form.qty_div_and_sub2.disabled=true;
		document.contact_form.qty_div_and_sub2.selectedIndex=0;
		document.contact_form.price_div_and_sub[0].disabled=false;
		document.contact_form.price_div_and_sub[1].disabled=false;
		document.contact_form.qty_div_and_sub1.disabled=false;
	}
	
	function resetDisabledFields(x){
		if (x.reset)
		document.contact_form.price_parent_board[0].disabled=false;
		document.contact_form.price_parent_board[0].disabled=false;
		document.contact_form.price_parent_board[1].disabled=false;
		document.contact_form.price_parent_board[2].disabled=false;
		document.contact_form.price_parent_board[3].disabled=false;
		document.contact_form.qty_parent_board1.disabled=false;
		document.contact_form.qty_parent_board2.disabled=false;
		document.contact_form.price_div_and_sub[0].disabled=false;
		document.contact_form.price_div_and_sub[1].disabled=false;
		document.contact_form.price_div_and_sub[2].disabled=false;
		document.contact_form.price_div_and_sub[3].disabled=false;		
		document.contact_form.qty_div_and_sub1.disabled=false;
		document.contact_form.qty_div_and_sub2.disabled=false;
	}
	
// this function validates the entire order_pay_uk.html form		
	function ValidateFormOrderPay(){

	var pbcpApr=document.contact_form.parent_board[0]
	var pbcpSep=document.contact_form.parent_board[1]
	var pbcpFullPrice=document.contact_form.price_parent_board[0]
	var pbcpPartPrice=document.contact_form.price_parent_board[1]
	var pbcpAprSep=document.contact_form.parent_board[2]
	var pbcpAprSepFullPrice=document.contact_form.price_parent_board[2]
	var pbcpAprSepPartPrice=document.contact_form.price_parent_board[3]
	var pbcpQty=document.contact_form.qty_parent_board1
	var pbcpAprSepQty=document.contact_form.qty_parent_board2
	
	var divsubsApr=document.contact_form.div_and_sub[0]
	var divsubsSep=document.contact_form.div_and_sub[1]
	var divsubsFullPrice=document.contact_form.price_div_and_sub[0]
	var divsubsPartPrice=document.contact_form.price_div_and_sub[1]
	var divsubsAprSep=document.contact_form.div_and_sub[2]
	var divsubsAprSepFullPrice=document.contact_form.price_div_and_sub[2]
	var divsubsAprSepPartPrice=document.contact_form.price_div_and_sub[3]
	var divsubsQty=document.contact_form.qty_div_and_sub1
	var divsubsAprSepQty=document.contact_form.qty_div_and_sub2
	
	var payDate=document.contact_form.pay_incentives
	var payFullPrice=document.contact_form.price_pay_incentives[0]
	var payPartPrice=document.contact_form.price_pay_incentives[1]
	var payQty=document.contact_form.qty_pay_incentives1
	
	var annualDate=document.contact_form.annual_lt_incentives
	var annualFullPrice=document.contact_form.price_annual_lt_incentives[0]
	var annualPartPrice=document.contact_form.price_annual_lt_incentives[1]
	var annualQty=document.contact_form.qty_annual_lt_incentives1
	
	var pensionsDate=document.contact_form.pensions
	var pensionsFullPrice=document.contact_form.price_pensions[0]
	var pensionsPartPrice=document.contact_form.price_pensions[1]
	var pensionsQty=document.contact_form.qty_pensions1
	
	var carDate=document.contact_form.co_car
	var carFullPrice=document.contact_form.price_co_car[0]
	var carPartPrice=document.contact_form.price_co_car[1]
	var carQty=document.contact_form.qty_co_car1
	
	var nedDate=document.contact_form.NED
	var nedFullPrice=document.contact_form.price_NED[0]
	var nedPartPrice=document.contact_form.price_NED[1]
	var nedQty=document.contact_form.qty_NED1
	
	
		if (((pbcpApr.checked==true) || (pbcpSep.checked==true)) && ((!pbcpFullPrice.checked==true) && (!pbcpPartPrice.checked==true))){
							alert("Please select the price of the Parent Board and Corporate Posts publication")
							return false
		}

		if ((pbcpAprSep.checked==true) && ((!pbcpAprSepFullPrice.checked==true) && (!pbcpAprSepPartPrice.checked==true))){
							alert("Please select the price of the Parent Board and Corporate Posts publication")
							return false
		}
		
		if (((pbcpApr.checked==true) || (pbcpSep.checked==true)) && ((pbcpQty.selectedIndex==0))){
							alert("Please select the amount of Parent Board and Corporate Posts publications you require")
							pbcpQty.focus()
							return false
		}
		
		if ((pbcpAprSep.checked==true) && (pbcpAprSepQty.selectedIndex==0)){
							alert("Please select the amount of Parent Board and Corporate Posts publications you require")
							pbcpAprSepQty.focus()
							return false
		}
			
	// Validation for order fields - Divisions and subsidiaries

		if (((divsubsApr.checked==true) || (divsubsSep.checked==true)) && ((!divsubsFullPrice.checked==true) && (!divsubsPartPrice.checked==true))){
							alert("Please select the price of the Divisions and subsidiaries publication")
							return false
		}

		if ((divsubsAprSep.checked==true) && ((!divsubsAprSepFullPrice.checked==true) && (!divsubsAprSepPartPrice.checked==true))){
							alert("Please select the price of the Divisions and subsidiaries publication")
							return false
		}
		
		if (((divsubsApr.checked==true) || (divsubsSep.checked==true)) && ((divsubsQty.selectedIndex==0))){
							alert("Please select the amount of Divisions and subsidiaries publications you require")
							divsubsQty.focus()
							return false
		}
		
		if ((divsubsAprSep.checked==true) && (divsubsAprSepQty.selectedIndex==0)){
							alert("Please select the amount of Divisions and subsidiaries publications you require")
							divsubsAprSepQty.focus()
							return false
		}
		
	// Validation for order fields - Pay
	
		if ((payDate.checked==true) && ((!payFullPrice.checked==true) && (!payPartPrice.checked==true))){
							alert("Please select the price of the Pay, Incentives and Benefits in Smaller Companies publication")
							return false
		}
		
		if ((payDate.checked==true) && (payQty.selectedIndex==0)){
							alert("Please select the amount of Pay, Incentives and Benefits in Smaller Companies publications you require")
							payQty.focus()
							return false
		}
		
	// Validation for order fields - Annual
	
		if ((annualDate.checked==true) && ((!annualFullPrice.checked==true) && (!annualPartPrice.checked==true))){
							alert("Please select the price of the Annual and Long-Term Incentives publication")
							return false
		}
		
		if ((annualDate.checked==true) && (annualQty.selectedIndex==0)){
							alert("Please select the amount of Annual and Long-Term Incentives publications you require")
							annualQty.focus()
							return false
		}
		
	// Validation for order fields - Pensions
	
		if ((pensionsDate.checked==true) && ((!pensionsFullPrice.checked==true) && (!pensionsPartPrice.checked==true))){
							alert("Please select the price of the Pensions and Benefits publication")
							return false
		}
		
		if ((pensionsDate.checked==true) && (pensionsQty.selectedIndex==0)){
							alert("Please select the amount of Pensions and Benefits publications you require")
							pensionsQty.focus()
							return false
		}
		
	// Validation for order fields - Company Car UK
	
		if ((carDate.checked==true) && ((!carFullPrice.checked==true) && (!carPartPrice.checked==true))){
							alert("Please select the price of the Company Car UK publication")
							return false
		}
		
		if ((carDate.checked==true) && (carQty.selectedIndex==0)){
							alert("Please select the amount of Company Car UK publications you require")
							carQty.focus()
							return false
		}
		
	// Validation for order fields - Non-Executive Director Practice and Fees
	
		if ((nedDate.checked==true) && ((!nedFullPrice.checked==true) && (!nedPartPrice.checked==true))){
							alert("Please select the price of the Non-Executive Director Practice and Fees publication")
							return false
		}
		
		if ((nedDate.checked==true) && (nedQty.selectedIndex==0)){
							alert("Please select the amount of Non-Executive Director Practice and Fees publications you require")
							nedQty.focus()
							return false
		}
		
		
	// At least one publication must be selected for the form to be submitted	
			if ((!pbcpApr.checked==true) && (!pbcpSep.checked==true) && (!pbcpAprSep.checked==true) && (!divsubsApr.checked==true) && (!divsubsSep.checked==true) && (!divsubsAprSep.checked==true) && (!payDate.checked==true) && (!annualDate.checked==true) && (!pensionsDate.checked==true) && (!document.contact_form.co_car.checked==true) && (!document.contact_form.NED.checked==true)){
				alert("Please select a publication before submitting this form")
				return false
		}
		
	// Validates delivery/invoicing fields	
		var companyName=document.contact_form.companyname_delivery
		var streetName=document.contact_form.streetname_delivery
		var town=document.contact_form.town_delivery
		var postcode=document.contact_form.postcode_delivery
		var emailID=document.contact_form.email
		var telephone=document.contact_form.telephone
		var fullName=document.contact_form.fullname
		var companyNameDelivery=document.contact_form.companyname
		var streetNameDelivery=document.contact_form.streetname
		var townDelivery=document.contact_form.town
		var postcodeDelivery=document.contact_form.postcode
		
		if ((companyName.value==null)||(companyName.value=="")){
							alert("Please enter your Company Name for delivery")
							companyName.focus()
							return false
		}
		
		if ((streetName.value==null)||(streetName.value=="")){
							alert("Please enter your Street Name/Number for delivery")
							streetName.focus()
							return false
		}
		
		if ((town.value==null)||(town.value=="")){
							alert("Please enter your Town/City for delivery")
							town.focus()
							return false
		}
		
		if ((postcode.value==null)||(postcode.value=="")){
							alert("Please enter your Post Code for delivery")
							postcode.focus()
							return false
		}
		
		if ((fullName.value==null)||(fullName.value=="")){
							alert("Please enter your full name")
							fullName.focus()
							return false
		}
		
		if ((telephone.value==null)||(telephone.value=="")){
							alert("Please enter your Telephone number")
							telephone.focus()
							return false
		}
		
		if ((emailID.value==null)||(emailID.value=="")){
							alert("Please enter your email")
							emailID.focus()
							return false
		}
		
		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}
	 	 
		if ((companyNameDelivery.value==null)||(companyNameDelivery.value=="")){
							alert("Please enter your Company Name for invoicing")
							companyNameDelivery.focus()
							return false
		}
		
		if ((streetNameDelivery.value==null)||(streetNameDelivery.value=="")){
							alert("Please enter your Street Name/Number for invoicing")
							streetNameDelivery.focus()
							return false
		}
		
		if ((townDelivery.value==null)||(townDelivery.value=="")){
							alert("Please enter Town/City for invoicing")
							townDelivery.focus()
							return false
		}
		
		if ((postcodeDelivery.value==null)||(postcodeDelivery.value=="")){
							alert("Please enter your Post Code for invoicing")
							postcodeDelivery.focus()
							return false
		}
		
		return true
	}	
		
// Makes second hald of order form match details above
function checkBoxAddress() {
	document.contact_form.companyname.value=document.contact_form.companyname_delivery.value;
//	document.contact_form.del_address.value=document.contact_form.cc_address.value;
	document.contact_form.streetname.value=document.contact_form.streetname_delivery.value;
	document.contact_form.town.value=document.contact_form.town_delivery.value;
	document.contact_form.postcode.value=document.contact_form.postcode_delivery.value;
	document.contact_form.country.selectedIndex=document.contact_form.country_delivery.selectedIndex;
    document.contact_form.c1.checked=1;
}
function updateBox(s) {
	if(s<=0){
		document.contact_form.companyname.value = "";
//		document.contact_form.del_address.value = "";
		document.contact_form.streetname.value = "";
		document.contact_form.town.value = "";
		document.contact_form.postcode.value = "";
		document.contact_form.country.selectedIndex=0;
		checkBoxOpen();
		}
	if((s>-1)&&(s<userName.length)) {
		document.contact_form.companyname.value = userName[s];
//		document.contact_form.del_address.value = userAddress[s];
		document.contact_form.streetname.value = userAddressLineOne[s];
		document.contact_form.town.value = userAddressLineTwo[s];
		document.contact_form.postcode.value = userAddressLineThree[s];
		document.contact_form.country.selectedIndex = userCountry[s];
		checkBoxOpen();
		}	
	if(s >=userName.length) {
		checkBoxClose();
		checkBoxAddress();
		}
	}
function checkBoxOpen() {
	document.contact_form.c1.checked=0;
	}
function checkBoxClose() {
	document.contact_form.c1.checked=1;
	}
function EditOpen() {
	checkBoxOpen();
	}


function CheckBox(){  
	if(document.contact_form.streetname.value=="")
		document.contact_form.streetname.focus();
		}



	
//-->


// JavaScript on/off script 
	 function revealContactName() {
		 //This will exit the function if JS not fully supported
		 if (!document.getElementById) return false;

		 //This will exit the function if the two required DIV's are not on the page
		 if (!document.getElementById("contact_name_display_No")) return false;
		 if (!document.getElementById("contact_name_display_Yes")) return false;
		 

		 //Find & hold the targetted DIVs
		 var contactNameHide = document.getElementById("contact_name_display_No");
		 var contactNameShow = document.getElementById("contact_name_display_Yes");
		

		 //The magic (not really)
		 contactNameHide.style.display = 'none';
		 contactNameShow.style.display = 'inline';
		
}
window.onload = revealContactName;

	
// this function retrieves the contact name
function getContactName() {

	var contactName = getParm('contact_name');
	
	var contactField = document.getElementById('contact_name_field');
	contactField.value = contactName;
	var contactDiv = document.getElementById('contact_name_display');
	contactDiv.innerHTML = contactName;	
} 

function getSubject() {

	var subject = getParm('subject');

	var subjectField = document.getElementById('subject_name_field');
	subjectField.value = subject;
	var subjectDiv = document.getElementById('subject_name_display');
	subjectDiv.innerHTML = subject;	
}

function getParm(paramName) {

	var idx1, idx2;
	var qs;

	qs = location.search;
	idx1 = qs.indexOf(paramName + '=');
	if (idx1 != -1) {
		idx1 += paramName.length + 1;
		idx2 = qs.indexOf('&', idx1);
		if (idx2 == -1) idx2 = qs.length;
	}

	return unescape(qs.substring(idx1, idx2));

}