<!--

var objF;

function validate(strForm){
	objF = document.forms['aForm'];
	if(strForm == 'page'){
		return validatePage();
	}
	else if(strForm == 'news'){
		return validateNews();
	}
	else if(strForm == 'contact'){
		return validateContact();
	}
	else if(strForm == 'booking'){
		return validateBooking();
	}
	else if(strForm == 'checkout'){
		return validateCheckout();
	}
	else if(strForm == 'mailing'){
		return validateMailing();
	}
	else if(strForm == 'globali'){
		return validateGlobalI();
	}
	else if(strForm == 'subscribe'){
		return validateSubscribe();
	}
	else if(strForm == 'unsubscribe'){
		return validateUnsubscribe();
	}
	else if(strForm == 'search'){
		return validateSearch();
	}
	else if(strForm == 'register'){
		return validateRegister();
	}
	else if(strForm == 'resource'){
		return validateResource();
	}
	else if(strForm == 'applyform'){
		return validateApplyForm();
	}
	else if(strForm == 'reminder'){
		return validateReminder();
	}
	else if(strForm == 'user'){
		return validateUser();
	}
	else if(strForm == 'quote'){
		return validateQuote();
	}
	else if(strForm == 'logo'){
		return validateLogo();
	}
	else if(strForm == 'link'){
		return validateLink();
	}
	else if(strForm == 'delivery'){
		return validateDelivery();
	}
	else if(strForm == 'homeimg'){
		return validateHomeImg();
	}
}

function validateBuy(objF){
	if(typeof(objF.opt) != 'undefined'){
		if(!objF.opt.value){
			alert('Please select an option');
			objF.opt.focus();
			return false;
		}
	}
}

function validateContact(){
	if(!objF.name.value){
		alert('Please enter your name');
		objF.name.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objF.email.value)){
			alert('Please enter a valid email address');
		objF.email.focus();
		return false;
	}
	if(!objF.subject.value){
		alert('Please enter a subject for your enquiry');
		objF.subject.focus();
		return false;
	}
	if(!objF.enquiry.value){
		alert('Please specify the details of your enquiry');
		objF.enquiry.focus();
		return false;
	}
	if(!objF.captcha_code.value){
		alert('Please enter the letters displayed on the form');
		objF.captcha_code.focus();
		return false;
	}
}

function validateBooking(){
	if(!objF.company.value){
		alert('Please enter the company name');
		objF.company.focus();
		return false;
	}
	if(!objF.name.value){
		alert('Please enter the contact name');
		objF.name.focus();
		return false;
	}
	if(!objF.telephone.value){
		alert('Please enter the contact telephone number');
		objF.telephone.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objF.email.value)){
			alert('Please enter a valid email address');
		objF.email.focus();
		return false;
	}
	if(!objF.captcha_code.value){
		alert('Please enter the letters displayed on the form');
		objF.captcha_code.focus();
		return false;
	}
}

function validateSubscribe(){
	if(!objF.name.value){
		alert('Please enter your name');
		objF.name.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objF.email.value)){
			alert('Please enter a valid email address');
		objF.email.focus();
		return false;
	}
	if(!objF.captcha_code.value){
		alert('Please enter the letters displayed on the form');
		objF.captcha_code.focus();
		return false;
	}
}

function validateUnsubscribe(){
	if(!objF.name.value){
		alert('Please enter your name');
		objF.name.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objF.email.value)){
			alert('Please enter a valid email address');
		objF.email.focus();
		return false;
	}
}

function validateHomeImg(){
	if(!objF.name.value){
		alert('Please enter a name for this image');
		objF.name.focus();
		return false;
	}
	if(!objF.order.value){
		alert('Please specify a display order for this image');
		objF.order.focus();
		return false;
	}
}

function validatePage(){
	if(!objF.heading.value){
		alert('Please enter a heading for this page');
		objF.heading.focus();
		return false;
	}
}

function validateMailing(){
	if(!objF.name.value){
		alert('Please enter the name of this subscriber');
		objF.name.focus();
		return false;
	}
	if (!validateEmail(objF.email.value)){
		alert('Please enter a valid email address');
		objF.email.focus();
		return false;
	}
}

function validateReminder(){
	if (!validateEmail(objF.email.value)){
		alert('Please enter a valid email address');
		objF.email.focus();
		return false;
	}
}

function validateGlobalI(){
	if(!objF.country.value){
		alert('Please enter a name for this country');
		objF.country.focus();
		return false;
	}
}

function validateNews(){
	if(!objF.headline.value){
		alert('Please enter a headline for this article');
		objF.headline.focus();
		return false;
	}
	if((!objF.date_day.value)||(!objF.date_month.value)||(!objF.date_year.value)){
		alert('Please assign a date to this article');
		objF.date_day.focus();
		return false;
	}
}

function validateQuote(){
	if(!objF.name.value){
		alert('Please enter the company name.');
		objF.name.focus();
		return false;
	}
	if(!objF.text.value){
		alert('Please enter the testimonial text.');
		objF.text.focus();
		return false;
	}
}

function validateLink(){
	if(!objF.name.value){
		alert('Please enter the name of the site.');
		objF.name.focus();
		return false;
	}
	if(!objF.section.value){
		alert('Please select where this link should appear.');
		objF.section.focus();
		return false;
	}
	if(!objF.url.value){
		alert('Please enter the website\'s address.');
		objF.url.focus();
		return false;
	}
}

function validateLogo(){
	if(!objF.name.value){
		alert('Please enter the company name.');
		objF.name.focus();
		return false;
	}
	if(!objF.order.value){
		alert('Please specify the display order.');
		objF.order.focus();
		return false;
	}
}

function validateResource(){
	if(!objF.name.value){
		alert('Please enter a name for this resource.');
		objF.name.focus();
		return false;
	}
	if(!objF.cat.value){
		alert('Please select a category for this resource.');
		objF.cat.focus();
		return false;
	}
	if(objF.upload_file_1.value){
		if (!/\.pdf$|\.doc+$/.test(objF.upload_file_1.value)){
			alert('Please upload .doc or .pdf documents only.');
			objF.upload_file_1.focus();
			return false;
		}
	}
}

function validateCheckout(){
	if(!validateBilling(objF)){
		return false;
	}
	if(!validateDeliveryC(objF)){
		return false;
	}
	if(typeof(objF.terms) == 'checkbox' && !objF.terms.checked){
		alert('Please tick the terms and conditions box.')
			objF.terms.focus();
		return false;
	}
}

function copyAddress(objT){
	if(objT.checked == true){
		objF = document.getElementById('aForm')
			if(!validateBilling(objF)){
				return false;
		}
		objF.delivery_name.value = objF.billing_name.value
			objF.delivery_address_1.value = objF.billing_address_1.value
			objF.delivery_address_2.value = objF.billing_address_2.value
			objF.delivery_city.value = objF.billing_city.value
			objF.delivery_county.value = objF.billing_county.value
			objF.delivery_country.value = objF.billing_country.value
			objF.delivery_postcode.value = objF.billing_postcode.value
			objF.delivery_telephone.value = objF.billing_telephone.value
			objF.delivery_email.value = objF.billing_email.value;
	}
	return true;
}

function validateBilling(objF){
	
	if(!objF.billing_name.value){
		alert('Please enter your name (BILLING).');
		objF.billing_name.focus();
		return false;
	}
	
	if(!objF.billing_address_1.value){
		alert('Please enter your address (BILLING).');
		objF.billing_address_1.focus();
		return false;
	}
	
	if(!objF.billing_city.value){
		alert('Please enter your town/city (BILLING).');
		objF.billing_city.focus();
		return false;
	}
	
	if(!objF.billing_county.value){
		alert('Please enter your county (BILLING).');
		objF.billing_county.focus();
		return false;
	}
	
	if(!objF.billing_country.value){
		alert('Please select your country (BILLING).');
		objF.billing_country.focus();
		return false;
	}
	
	if(!objF.billing_postcode.value){
		alert('Please enter your postcode (BILLING).');
		objF.billing_postcode.focus();
		return false;
	}
	
	if(!objF.billing_telephone.value){
		alert('Please enter your telephone (BILLING).');
		objF.billing_telephone.focus();
		return false;
	}
	
	if (!validateEmail(objF.billing_email.value)){
		alert('Please enter a valid email address (BILLING).');
		objF.billing_email.focus();
		return false;
	}
	return true;
}

function validateDeliveryC(objF){
	if(!objF.delivery_name.value){
		alert('Please enter your name (DELIVERY).');
		objF.delivery_name.focus();
		return false;
	}
	
	if(!objF.delivery_address_1.value){
		alert('Please enter your address (DELIVERY).');
		objF.delivery_address_1.focus();
		return false;
	}
	
	if(!objF.delivery_city.value){
		alert('Please enter your town/city (DELIVERY).');
		objF.delivery_city.focus();
		return false;
	}
	
	if(!objF.delivery_county.value){
		alert('Please enter your county (DELIVERY).');
		objF.delivery_county.focus();
		return false;
	}
	
	if(!objF.delivery_country.value){
		alert('Please select your country (DELIVERY).');
		objF.delivery_country.focus();
		return false;
	}
	
	if(!objF.delivery_postcode.value){
		alert('Please enter your postcode (DELIVERY).');
		objF.delivery_postcode.focus();
		return false;
	}
	
	if(!objF.delivery_telephone.value){
		alert('Please enter your telephone (DELIVERY).');
		objF.delivery_telephone.focus();
		return false;
	}
	
	if (!validateEmail(objF.delivery_email.value)){
		alert('Please enter a valid email address (DELIVERY).');
		objF.delivery_email.focus();
		return false;
	}
	return true;
}

function validateSearch(){
	if(objF.search.value.length < 4){
		alert('Please enter a search phrase of at least 4 character');
		objF.search.focus();
		return false;
	}
}

function validateRegister(){
	if(!objF.name.value){
		alert('Please provide your name');
		objF.name.focus();
		return false;
	}
	if(!validateEmail(objF.email.value)){
		alert('Please provide a valid email address.');
		objF.email.focus();
		return false;
	}
	if(objF.username.value.length < 5){
		alert('Your username should be at least 5 letters in length.');
		objF.username.focus();
		return false;
	}
	if(objF.password.value.length < 5){
		alert('Your password should be at least 5 letters in length.');
		objF.password.focus();
		return false;
	}
	else{
		if(objF.password.value != objF.confirm.value){
			alert('Password and confirmation do not match.');
			objF.confirm.focus();
			return false;
		}
	}
	if(!objF.captcha_code.value){
		alert('Please enter the letters displayed on the form');
		objF.captcha_code.focus();
		return false;
	}
}

function validateUser(){
	if(!objF.name.value){
		alert('Please provide a name.');
		objF.name.focus();
		return false;
	}
	if(!validateEmail(objF.email.value)){
		alert('Please provide a valid email address.');
		objF.email.focus();
		return false;
	}
	if(objF.username.value.length < 5){
		alert('Username should be at least 5 letters in length.');
		objF.username.focus();
		return false;
	}
	if(objF.password.value.length < 5){
		alert('Password should be at least 5 letters in length.');
		objF.password.focus();
		return false;
	}
	if(!objF.level.value){
		alert('Please select an access level,');
		objF.level.focus();
		return false;
	}
}

function validateApplyForm(){
	if(!objF.surname.value || !objF.forename.value){
		alert('Please provide your full name.');
		objF.surname.focus();
		return false;
	}
	if(!objF.telephone.value){
		alert('Please provide a contact telephone number.');
		objF.telephone.focus();
		return false;
	}
	if(!validateEmail(objF.email.value)){
		alert('Please provide a valid contact email address.');
		objF.email.focus();
		return false;
	}
	if(!objF.dob_day.value || !objF.dob_month.value || !objF.dob_year.value){
		alert('Please provide your date of birth.');
		objF.dob_day.focus();
		return false;
	}
	if(!objF.nationality.value){
		alert('Please select your nationality.');
		objF.nationality.focus();
		return false;
	}
	if(!objF.service.value){
		alert('Please select your service experience.');
		objF.service.focus();
		return false;
	}
	if(!objF.enlist_day.value || !objF.enlist_month.value || !objF.enlist_year.value){
		alert('Please provide your date of enlistment.');
		objF.enlist_day.focus();
		return false;
	}
	if(!objF.lastday_day.value || !objF.lastday_month.value || !objF.lastday_year.value){
		alert('Please provide your last date of service.');
		objF.lastday_day.focus();
		return false;
	}
	if(!objF.rank.value){
		alert('Please select your military rank.');
		objF.rank.focus();
		return false;
	}
	if(!objF.unit_type.value){
		alert('Please select your unit type.');
		objF.unit_type.focus();
		return false;
	}
	if(!objF.special_forces.value){
		//alert('Please select the special forces you have been involved with.');
		//objF.special_forces.focus();
		//return false;
	}
	
	if(!objF.conviction.value){
		alert('Please specify if you have had any criminal convictions.');
		objF.conviction.focus();
		return false;
	}
	else{
		if(objF.conviction.value == 1 && !objF.conviction_details.value){
			alert('Please specify details of your convictions.');
			objF.conviction_details.focus();
			return false;
		}
	}
	intL = 0;
	for(i=1;i<=4;i++){
		if(objF['lang_'+i].value){
			intL++;
			if(!objF['level_'+i].value){
				alert('Please specify your level of experience (language '+i+').');
				objF['level_'+i].focus();
				return false;
			}
		}
	}
	if(intL == 0 && !objF.lang_other.value){
	//	alert('Please specify details of the languages you speak.');
	//	objF.lang_other.focus();
	//	return false;
	}
	if(!objF.cp_completed.value){
		alert('Please specify if you have completed a CP course.');
		objF.cp_completed.focus();
		return false;
	}
	else{
		if(objF.cp_completed.value == 1 && !objF.cp_course.value){
			alert('Please select the CP course you have completed.');
			objF.cp_course.focus();
			return false;
		}
	}
	if(!objF.private_sector.value){
		alert('Please select your experience in the private sector.');
		objF.private_sector.focus();
		return false;
	}
	if(!objF.private_sector_details.value){
		alert('Please detail your experience in the private sector.');
		objF.private_sector_details.focus();
		return false;
	}
	if(!objF.qualifications.value){
		alert('Please detail your qualifications.');
		objF.qualifications.focus();
		return false;
	}
	if(!objF.position.value){
		alert('Please specify the position you are applying for.');
		objF.position.focus();
		return false;
	}
	if (!/\.pdf$|\.doc$/i.test(objF.file_cv.value)){
		alert('Please upload your CV in .doc or .pdf format.');
		objF.file_cv.focus();
		return false;
	}
	
}

function validateDelivery(){
	if(!objF.zone.value){
		alert('Please enter a name for this shipping zone.');
		objF.zone.focus();
		return false;
	}
	if(!objF.flat_rate.value){
		alert('Please enter a flat-rate shipping fee.');
		objF.flat_rate.focus();
		return false;
	}
}

function validateEmail(strEmail){
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(strEmail)){
			return false;
	}
	return true;
}

function preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.p) d.p=new Array();
			var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore() { //v3.0
		var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.01
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
		var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
		if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


-->
