function checkFirst(iMode){
	$('alertholder').innerHTML = "";
	$('alertholder').style.display = "none";
	var oForm = document.forms['registration'];
	var bChecked = false;
	for(var x=0;x<oForm.elements.length;x++){
		if(oForm.elements[x].type == "radio" && oForm.elements[x].checked == true){
			bChecked=true;
		}
	}
	if(!bChecked){
		doAlert('Please indicate if you currently hold a Petplan Sanctuary policy');
		new Effect.Highlight('policy1',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.Highlight('policy2',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}else{
		//if($('policy1').checked==true){
//			if (!JSLNotNull(document.registration.policyprefix, "You have indicated you have a current Petplan Sanctuary policy. Please enter a valid policy number.")) { 
//			new Effect.Highlight('policyprefix',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
//			return false;
//		}	
//			if (!JSLNotNull(document.registration.policynumber, "You have indicated you have a current Petplan Sanctuary policy. Please enter a valid policy number.")) { 
//			new Effect.Highlight('policynumber',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
//			return false;
//			}	
//		}
	}
	if (!JSLCheckIsEMail(document.registration.email, "Please enter a correctly formatted e-mail address.")) { 
		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.registration.passw, "Please enter a password.")) { 
		new Effect.Highlight('passw',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.registration.confirmpassword, "Please confirm your password.")) { 
		new Effect.Highlight('confirmpassword',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if(document.registration.passw.value.length < 6){
		doAlert('Please enter a minimum of 6 characters for your password');
		new Effect.Highlight('passw',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if(document.registration.passw.value != document.registration.confirmpassword.value){
		doAlert('Your password and confirm password do not match, please re-enter your password.');
		document.registration.passw.value ='';
		document.registration.confirmpassword.value = '';
		new Effect.Highlight('passw',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.Highlight('confirmpassword',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if(iMode==0){
		oForm.submit();
	}else{
		return true;
	}
}

function checkFinal(){
	if(!checkFirst(1)){
		return false;
	}else{
		if (!JSLNotNull(document.registration.businessname, "Please enter your business name.")) { 
			new Effect.Highlight('businessname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
		if (!JSLIsTextOrAlphaOnlyWithHyphens(document.registration.businessname, "Please enter your business name.")) { 
			new Effect.Highlight('businessname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
		if (!JSLNotNull(document.registration.contactname, "Please enter your contact name.")) { 
			new Effect.Highlight('contactname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
		if (!JSLNotNull(document.registration.address, "Please enter your address.")) { 
			new Effect.Highlight('address',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
		if (!JSLNotNull(document.registration.town, "Please enter a town.")) { 
			new Effect.Highlight('town',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
		if (!JSLNotNull(document.registration.county, "Please enter a county.")) { 
			new Effect.Highlight('county',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
		if (document.registration.county.selectedIndex==0){
			doAlert("Please select a county.");
			new Effect.Highlight('county',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}	
		if (!JSLIsPCode(document.registration.postcode, "Please enter a postcode.")) { 
			new Effect.Highlight('postcode',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
		if (!JSLIsPhone(document.registration.telephone, "Please enter a telephone number.")) { 
			new Effect.Highlight('telephone',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
	
		document.forms['registration'].submit();
	}
	
}

function formCheckRenewal()
{

	 if (!JSLNotNull(document.requestAQuote.firstname, "Please enter the firstname.")) { 
		new Effect.Highlight('firstname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false; 
	}			
	 if (!JSLIsTextOnlyWithHyphens(document.requestAQuote.firstname, "Please enter text only in the firstname.")) { 
		new Effect.Highlight('firstname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLNotNull(document.requestAQuote.surname, "Please enter the surname.")) { 
	 	new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLIsTextOnlyWithHyphens(document.requestAQuote.surname, "Please enter text only in the surname.")) { 
	 	new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.requestAQuote.businessname, "Please enter the name of your business.")) { 
	 	new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLNotNull(document.requestAQuote.contactnumber, "Please enter a daytime phone number.")) { 
		new Effect.Highlight('contactnumber',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLIsPhone(document.requestAQuote.contactnumber, "Please enter a valid daytime phone number - i.e. 01234 123123.")) { 
		new Effect.Highlight('contactnumber',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.requestAQuote.currentinsurer, "Please enter the name of your current insurance provider.")) { 
		new Effect.Highlight('currentinsurer',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false; 
	}	
	
	if($('year').selectedIndex==0&&$('month').selectedIndex==0){
		doAlert('Please select a valid renewal date');
		new Effect.Highlight('day',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.Highlight('month',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.Highlight('year',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;	
	}
	
	//if (!JSLNotNull(document.requestAQuote.email, "Please enter your e-mail address.")) { 
//		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
//		return false;
//	}
//	 if (!JSLCheckIsEMail(document.requestAQuote.email, "Please enter a correctly formatted e-mail address.")) { 
//		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
//		return false;
//	}
	 if (!JSLSelected(document.requestAQuote.petplanproductslist, "Please select a business type.")) { 
		new Effect.Highlight('petplanproductslist',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}

	
	 document.forms['requestAQuote'].submit();
}



function formCheckrequestAQuote()
{

	 if (!JSLNotNull(document.requestAQuote.firstname, "Please enter the firstname.")) { 
		new Effect.Highlight('firstname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false; 
	}			
	 if (!JSLIsTextOnly(document.requestAQuote.firstname, "Please enter text only in the firstname.")) { 
		new Effect.Highlight('firstname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLNotNull(document.requestAQuote.surname, "Please enter the surname.")) { 
	 	new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLIsTextOnly(document.requestAQuote.surname, "Please enter text only in the surname.")) { 
	 	new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLNotNull(document.requestAQuote.contactnumber, "Please enter the a contact number.")) { 
		new Effect.Highlight('contactnumber',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLIsPhone(document.requestAQuote.contactnumber, "Please enter a valid contact number - i.e. 01234 123123.")) { 
		new Effect.Highlight('contactnumber',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLNotNull(document.requestAQuote.address, "Please enter an address.")) { 
		new Effect.Highlight('address',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLNotNull(document.requestAQuote.postcode, "Please enter the postcode.")) { 
		new Effect.Highlight('postcode',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLIsPCode(document.requestAQuote.postcode, "Please enter the postcode.")) { 
		new Effect.Highlight('postcode',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false; 
	}
	 if (!JSLNotNull(document.requestAQuote.email, "Please enter your e-mail address.")) { 
		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLCheckIsEMail(document.requestAQuote.email, "Please enter a correctly formatted e-mail address.")) { 
		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLSelected(document.requestAQuote.preferredcalltime, "Please select a preferred time for us to call you.")) { 
		new Effect.Highlight('preferredcalltime',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLSelected(document.requestAQuote.petplanproductslist, "Please select a Petplan products.")) { 
		new Effect.Highlight('petplanproductslist',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLSelected(document.requestAQuote.aboutpetplanlist, "Please select where you heard about Petplan Sanctuary.")) { 
		new Effect.Highlight('aboutpetplanlist',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	
	 document.forms['requestAQuote'].submit();
}

function formCheckcontactus(){
	 if (!JSLNotNull(document.contactus.firstname, "Please enter the firstname.")) { 
		new Effect.Highlight('firstname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		return false; 
	}
	 if (!JSLIsTextOnly(document.contactus.firstname, "Please enter text only in the firstname.")) { 
	 	new Effect.Highlight('firstname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false; 
	}
	 if (!JSLNotNull(document.contactus.surname, "Please enter the surname.")) { 
		new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLIsTextOnly(document.contactus.surname, "Please enter text only in the surname.")) { 
	 	new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLNotNull(document.contactus.contactnumber, "Please enter the a contact number.")) { 
	 	new Effect.Highlight('contactnumber',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	 if (!JSLIsPhone(document.contactus.contactnumber, "Please enter a valid contact number - i.e. 01234 123123.")) { 
	 	new Effect.Highlight('contactnumber',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false 
	}			 
	 if (!JSLNotNull(document.contactus.email, "Please enter your e-mail address.")) { 
		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false 
	}
	 if (!JSLCheckIsEMail(document.contactus.email, "Please enter a correctly formatted e-mail address.")) { 
		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		return false;
	}
	 if (!JSLNotNull(document.contactus.subject, "Please enter your an e-mail subject.")) { 
		new Effect.Highlight('subject',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	 
	 	return false 
	}
	 if (!JSLSelected(document.contactus.preferredcalltime, "Please select a preferred time for us to call you.")) { 
	 	new Effect.Highlight('preferredcalltime',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false 
	}
	 if (!JSLNotNull(document.contactus.emailcontent, "Please enter e-mail contents here.")) { 
		new Effect.Highlight('emailcontent',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
	 	return false 
	}
	 document.forms['contactus'].submit();
}

function doCancel(){
	$('formaction').value='cancel';
	document.forms['addnewadvert'].submit();
}

function doSubmit(btID){
	$('formaction').value='update';
	if(checkAdvertForm(btID)){
		document.forms['addnewadvert'].submit();
	}
}

function doPreview(btID){
	$('formaction').value='preview';
	$('addform').action = "index.cfm";
	if(checkAdvertForm(btID)){
		document.forms['addnewadvert'].submit();
	}
}

function checkAdvertForm(btID){
	$('alertholder').style.display = 'none';
	if(document.addnewadvert.alttel.value.length > 0){
		if (!JSLIsPhone(document.addnewadvert.alttel, "Please enter a valid alternative telephone number.")) { 
			new Effect.Highlight('alttel',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
	}
	
	if(document.addnewadvert.email.value.length > 0){
		if (!JSLCheckIsEMail(document.addnewadvert.email, "Please enter a valid email address.")) { 
			new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}
	}
//	alert(document.addnewadvert.webaddress.value.indexOf('.'));
//	alert(document.addnewadvert.webaddress.value.length);
	if(document.addnewadvert.webaddress.value.length > 0){
		if(document.addnewadvert.webaddress.value.indexOf('.') == -1) {
			doAlert('Please enter a valid URL.');
			new Effect.Highlight('webaddress',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}else{
			pattern = /^([ ]|[a-zA-Z-0-9\&\?\/\.\=\%\;])+[a-zA-Z-0-9\&\?\/\.\=\%\;]+([ ]|[a-zA-Z-0-9\&\?\/\.\=\%\;])*$/;
			if(pattern.test(document.addnewadvert.webaddress.value.replace(/\./g,''))==false||(document.addnewadvert.webaddress.value.indexOf('.')==(document.addnewadvert.webaddress.value.length-1))){
				doAlert('Please enter a valid URL.');
				new Effect.Highlight('webaddress',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
				return false;	
			}
		}
	}
	
	if (!JSLNotNull(document.addnewadvert.description, "Please enter a description of your services.")) { 
		new Effect.Highlight('description',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	
	if (document.addnewadvert.description.value.length > 600){
		doAlert("Please enter a maximum of 600 characters for your description.") 
		new Effect.Highlight('description',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if(btID==1&&$('smallanimals').checked==false&&$('cats').checked==false&&$('dogs').checked==false){
		doAlert('Please indicate which type of animals are boarded');
		return false;
	}
	
	if($('smallanimals').checked==true&&$('txtsmallanimals').value.length==0){
		doAlert('Please indicate which small animals you board.');
		return false;
	}
	if($('txtsmallanimals').value.length>0&&$('smallanimals').checked==false){
		doAlert('You have specified small animals but not indicated they are boarded.');
		return false;
	}

	return true;
}

function checkBusinessForm(){
	if (!JSLNotNull(document.mybusiness.businessname, "Please enter a business name.")) { 
		new Effect.Highlight('businessname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLIsTextOnlyWithHyphensAndSingleQuotes(document.mybusiness.businessname, "Please enter a business name.")) { 
		new Effect.Highlight('businessname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.mybusiness.contactname, "Please enter a contact name.")) { 
		new Effect.Highlight('contactname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.mybusiness.address1, "Please enter an address.")) { 
		new Effect.Highlight('address1',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.mybusiness.town, "Please enter a town.")) { 
		new Effect.Highlight('town',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (document.mybusiness.county.selectedIndex==0){
		doAlert("Please select a county.");
		new Effect.Highlight('county',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}	
	if (!JSLNotNull(document.mybusiness.postcode, "Please enter a postcode.")) { 
		new Effect.Highlight('postcode',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLIsPhone(document.mybusiness.telephone, "Please enter a valid telephone number.")) { 
		new Effect.Highlight('telephone',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if($('email').value.length > 0){
		if (!JSLCheckIsEMail(document.mybusiness.email, "Please enter a valid email address.")) { 
			new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
			return false;
		}	
	}

	if (!JSLCheckIsEMail(document.mybusiness.loginemail, "Please enter a valid login email address.")) { 
		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}	

	
	document.forms['mybusiness'].submit();
}

function checkGetInTouch(){
	if (!JSLNotNull(document.getintouchform.contactname, "Please enter a contact name.")) { 
		new Effect.Highlight('contactname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLIsPhone(document.getintouchform.telephone, "Please enter a valid telephone number.")) { 
		new Effect.Highlight('telephone',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.getintouchform.subject, "Please enter a subject.")) { 
		new Effect.Highlight('subject',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	if (!JSLNotNull(document.getintouchform.message, "Please enter a message.")) { 
		new Effect.Highlight('message',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		return false;
	}
	document.forms['getintouchform'].submit();
}