// Validate Your Parcel Form
function validateYPF() {
//	alert('hello');
	var yPF = document.yPF;
	fWeight=yPF.weight.value;
	fLength=yPF.length.value;
	fWidth=yPF.width.value;
	fHeight=yPF.height.value;
	fContents=yPF.contents.value;
	if (
	(fWeight=='') || 
	(fLength=='') || 
	(fWidth=='') || 
	(fHeight=='') || 
	(fContents=='')) {
		alert('Please complete all fields');
		//event.returnValue=false;
		return false;
	}
	// check numbers are valid
	if (
	isNaN(parseFloat(fWeight)) || 
	isNaN(parseFloat(fLength)) || 
	isNaN(parseFloat(fWidth)) || 
	isNaN(parseFloat(fHeight))) {
		alert('Please ensure you have entered valid numbers in the weight and dimensions fields');
		//event.returnValue=false;
		return false;
	}
	// normal weight limit calc
	if (fWeight>=29.91) {
		alert('Sorry, we can only deliver parcels up to 29.9kg');
		//event.returnValue=false;
		return false;	
	}
	// max dimensions limit calc
	var dDim = parseFloat(fLength) + parseFloat(fHeight*2) + parseFloat(fWidth*2);
	//alert(dDim);
	if (dDim>300 || fLength>150 || fHeight>150 || fWidth>150) {
		alert('Sorry, your parcel dimensions are too large. We can deliver parcels up to 150cm in any dimension, or up to 300cm across, to most countries. We recommend you either try to split your parcel into smaller parcels (if possible!), or select a specialist delivery service.');
		return false;
	}	
	// dimensional weight limit calc
	var dWeight = (fLength*fWidth*fHeight)/5000
	if (dWeight>=29.9) { 
		alert('Sorry, your parcel dimensions are too large for delivery via our services. We recommend you either try to split your parcel into smaller parcels (if possible!), or select a specialist delivery service.');
		return false;
	}
	// no negative or zero values!!
	if (
	(fWeight<=0) || 
	(fLength<=0) || 
	(fWidth<=0) || 
	(fHeight<=0)) {
		alert('Please ensure all weight and dimensions data is greater than zero.');
		//event.returnValue=false;
		return false;
	}
	
}

// Validate Sender Details Form
function validateSender() {
//	alert('hello');
	var fTF = document.fTF;
	fName=fTF.name.value;
	fAddress=fTF.address.value;
	fPostcode=fTF.postcode.value;
	fTel=fTF.tel.value;
	emailID=fTF.email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}

	if (
	(fName=='') || 
	(fAddress=='') || 
	(fPostcode=='') || 
	(fTel=='')) {
		alert('Please complete all fields');
		return false;
	}
}

// Validate Sender Details Form
function validateEmailQuote() {
//	alert('hello');
	var fTF = document.emailquoteform;
	emailID=fTF.emailquote;
	
	// only validate email if has value
	if ((emailID.value!=null)||(emailID.value!="")){
		if (echeck(emailID.value)==false){
			emailID.value="";
			emailID.focus();
			return false;
		}
	}

	if (
	(fName=='') || 
	(fAddress=='') || 
	(fPostcode=='') || 
	(fTel=='')) {
		alert('Please complete all fields');
		return false;
	}
}

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("Please enter a valid email address");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			alert("Please enter a valid email address");
			return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   	alert("Please enter a valid email address");
			return false;
		}

		if (str.indexOf(at,(lat+1))!=-1){
			alert("Please enter a valid email address");
			return false;
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Please enter a valid email address");
			return false;
		}

		if (str.indexOf(dot,(lat+2))==-1){
			alert("Please enter a valid email address");
			return false;
		}
		
		if (str.indexOf(" ")!=-1){
			alert("Please enter a valid email address");
			return false;
		}

		return true;				
}


// Validate Recipient Details Form
function validateRecipient() {
//	alert('hello');
	var fTF = document.fTF;
	fToName=fTF.toname.value;
	fToAddress=fTF.toaddress.value;
	fToPostcode=fTF.topostcode.value;
	fToType=fTF.totype.value;
	fToTel=fTF.totel.value;
	if (
	(fToName=='') || 
	(fToAddress=='') || 
	(fToPostcode=='') || 
	(fToTel=='')) {
		alert('Please complete all fields');
		return false;
	} 
}

// Validate Drop-off Form
/*
function validateDropoff() {
//	alert('hello');
	var fTF = document.fTF;
	if(fTF.store.selectedIndex!=0) {
		if(fTF.dropoffon.selectedIndex==0) {
			alert('Please complete all fields');
			return false;
		}
	} else if(fTF.pickupon.selectedIndex!=0) {
		if(fTF.pickupaddress.value=='' ||
		fTF.pickuptel.value=='') {
			alert('Please complete all fields. Only \'Notes for pickup\' is optional.');
			return false;
		}			
	}
}*/

function validateDropoff() {
//	alert('Validating');
	var fTF = document.fTF;
	switch(fTF.dropofforpickup.value) { 
	case 'pickup':
//		alert('Pick Up');
		if(fTF.pickupaddress.value=='' || fTF.pickuptel.value=='') {
			alert('Please complete all fields. Only \'Notes for pickup\' is optional.');
			return false;
		}			
		break;
	default:
//		alert('Drop Off');
		if(fTF.dropoffon.selectedIndex==0) {
			alert('Please complete all fields ya bas');
			return false;
		}
		break;
	}
}

// Validate Payment Details Form
function validatePayment() {
//	alert('hello');
	var fTF = document.fTF;
	fTerms=fTF.agreeterms.checked;
//	alert(fTerms);

	if (fTerms==false) { 
		alert('You must agree to the terms and conditions before you proceed.');
		return false;
	}

}

function showPickUpForm() {
//	alert('hello');
	document.getElementById('dropOffForm').style.display='none';
	document.getElementById('pickUpForm').style.display='block';
	var fTF = document.fTF;
	fTF.dropofforpickup.value = 'pickup';
//	fTF.pickupcharge.value = 1;
}

function showDropOffForm() {
//	alert('hello');
	document.getElementById('pickUpForm').style.display='none';
	document.getElementById('dropOffForm').style.display='block';
	var fTF = document.fTF;
	fTF.dropofforpickup.value = 'dropoff';
//	fTF.pickupcharge.value = 0;
}

function answer(obj) { 
	if(obj.className=='sel') { obj.className=''; } else { obj.className='sel'; }
}

function showTip(tip) {
	document.getElementById(tip).style.display='block';
}

function hideTip(tip) {
	document.getElementById(tip).style.display='none';
}


