// Standard Dreamweaver Functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Form Validation Functions
function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function checkcallform(){
	var ftxt = "";
	
	if (document.callform.cName.value==''){
		ftxt += '\n- Please enter your Name.';
	}
	
	if (document.callform.cTelephone.value==''){
		ftxt += '\n- Please enter your Telephone Number.';
	}
	
	if (document.callform.cTime.value==''){
		ftxt += '\n- Please select when the most convenient time would be for us to call you.'
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else{
		return true;
	}
}

function checkenquiry(){
	var ftxt = "";
	
	if (document.enquiry.Name.value==''){
		ftxt += '\n- Please enter your Name.'
	}
	
	if (document.enquiry.Telephone.value==''){
		ftxt += '\n- Please enter your Telephone Number.'
	}
	
	if (isValidEmail(document.enquiry.email.value)==false){
		ftxt += '\n- Please enter your Email Address.'
	}
	
	if (document.enquiry.Subject.value==''){
		ftxt += '\n- Please select an Enquiry Subject.'
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else{
		return true;
	}
}

function checkquote(){
	var frmtxt = "";
		
	//origin details
	var orgtxt = "";
	if (document.quote.Origin_DestinationInformation.value==''){
		orgtxt += '\n - Please enter the Destination Information.';
	}
	
	if (document.quote.Origin_ServiceRequired.value==''){
		orgtxt += '\n - Please select the Required Service.';
	}
	
	if (orgtxt!==''){
		frmtxt += '\nOrigin Details\n' + orgtxt;
	}	
	
	//senders details
	var sendtxt = "";
	if (document.quote.Sender_FullName.value==''){
		sendtxt += '\n - Please enter the Full Name.';
	}
	
	if (document.quote.Sender_CompanyName.value==''){
		sendtxt += '\n - Please enter the Company Name.';
	}
	
	if (document.quote.Sender_Postcode.value==''){
		sendtxt += '\n - Please enter the Postcode.';
	}
	
	if (sendtxt!==''){
		if (frmtxt!==''){
			frmtxt += '\n'
		}
		frmtxt += '\nSenders Details\n' + sendtxt;
	}
	
	//contact details
	var contxt = "";
	if (isValidEmail(document.quote.email.value)==false){
		contxt += '\n - Please enter your Email Address.';
	}	
	
	if (document.quote.Contact_TelephoneNumber.value==''){
		contxt += '\n - Please enter your Telephone Number.';
	}
	
	if (contxt!==''){
		if (frmtxt!==''){
			frmtxt += '\n'
		}
		frmtxt += '\nContact Details\n' + contxt;
	}
	
	//receivers details
	var rectxt = "";
	if (document.quote.Receiver_Surname.value==''){
		rectxt += '\n - Please enter a Surname.';
	}
	
	if (document.quote.Receiver_CompanyName.value==''){
		rectxt += '\n - Please enter a Company Name.';
	}
	
	if (document.quote.Receiver_PostcodeCountry.value==''){
		rectxt += '\n - Please enter a Postcode & Country.';
	}
	
	if (document.quote.Receiver_GoodsDescription.value==''){
		rectxt += '\n - Please enter a Full Description of the Goods.';
	}
	
	if (rectxt!==''){
		if (frmtxt!==''){
			frmtxt += '\n'
		}
		frmtxt += '\nReceivers Details\n' + rectxt;
	}
	
	//details of goods
	var dectxt = "";
	if (document.quote.GoodsDetails_Height.value==''){
		dectxt += '\n - Please enter a Height (cms).';		
	}
	
	if (document.quote.GoodsDetails_Width.value==''){
		dectxt += '\n - Please enter a Width (cms).';
	}
	
	if (document.quote.GoodsDetails_Length.value==''){
		dectxt += '\n - Please enter a Length (cms).';
	}
	
	if (document.quote.GoodsDetails_Quantity.value==''){
		dectxt += '\n - Please enter a Quantity.';
	}
	
	if (document.quote.GoodsDetails_TotalWeight.value==''){
		dectxt += '\n - Please enter a Total Weight (kgs).';
	}
	
	if (dectxt!==''){
		if (frmtxt!==''){
			frmtxt += '\n'
		}
		frmtxt += '\nDetails of Goods\n' + dectxt;
	}
	
	//terms conditions
	if (document.quote.TermsAgreed.checked==false){
		if (frmtxt!==''){
			frmtxt += '\n'
		}
		frmtxt += '\nTerms & Conditions\n\n - You must have read and agree to our Terms & Conditions to submit this quotation form.';
	}
	
	//handler
	if (frmtxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + frmtxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else{
		return true;
	}
}