function verifyContactForm() {

	if (document.contactForm.name.value == '') {
		alert('Please enter your name');
		document.contactForm.name.focus();
		return false;
	}

	if (document.contactForm.contact.value == '') {
		alert('Please enter your email address or telephone tumber');
		document.contactForm.contact.focus();
		return false;
	}

	if (document.contactForm.enquiry.value == '') {
		alert('Please enter your enquiry');
		document.contactForm.enquiry.focus();
		return false;
	}

	document.contactForm.submit();
}


String.prototype.RTrim = function() {return this.replace(/\s+$/, "");}
String.prototype.LTrim = function() {return this.replace(/^\s+/, "");}
String.prototype.Trim  = function() {return this.RTrim().LTrim();}

function SubmitToBasket(strProductRef, fPrice, strDescription, strProductCode, strProductWeight)
{
	if ((strProductRef.Trim() == "") || ( fPrice.Trim() == "") || (strDescription.Trim() == "")) alert("Error: Could not Add Item To Basket");
	document.DataForm.hfProductRef.value      = strProductRef.Trim();
	document.DataForm.hfPrice.value           = fPrice.Trim();
	document.DataForm.hfDescription.value     = strDescription.Trim();
	//document.DataForm.hfProductQuantity.value = document.DataForm.elements["cboQty"+strProductRef.Trim()].value;
	document.DataForm.hfProductCode.value     = strProductCode.Trim();
	document.DataForm.hfProductWeight.value     = strProductWeight.Trim();
	//alert(document.DataForm.hfProductRef.value + "\n" +	document.DataForm.hfPrice.value + "\n" + document.DataForm.hfDescription.value +"\n" + document.DataForm.hfProductQuantity.value);
	document.DataForm.submit();
}


function makeMailtoLink(oEle) {
	 var href = oEle.href;
	 var qMarkPos = href.lastIndexOf('?');
	 if(qMarkPos == -1) {
			return false;
	 }
	 var queryString = href.substr(qMarkPos+1, href.length );
	 var qVars = queryString.split('&');
	 for(var i in qVars ) {
			var pair = qVars[i].split('=');
			if(pair[0] == 'mt') {
									var mailAdd = pair[1];
									var mailAdd = mailAdd.replace(/\+/g,'.');
									var mailAdd = mailAdd.replace(/#/,'@');
									oEle.href = "mailto:" + mailAdd;
			}
	 }
}


function validateEmail(email_address) {
	if (/\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_address)){
		return true;
	}
	return false;
}


function verifyHuman(formName) {
	document[formName].h_formValidated.value = 'true'
}

function ajaxGet(urlToGet) {
	//Gets a URL and returns the response
	var xmlhttp = GetXmlHttpObject();
	if (xmlhttp == null) {
		// Check if browser is compatable
		alert("Sorry, your browser does not support HTTP Request...");
		return;
	}

	xmlhttp.open("GET",urlToGet,false);
	xmlhttp.send(null);
	return xmlhttp.responseText;
}

function GetXmlHttpObject() {
	//Returns the XML HHTP object (browser dependant)
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		//FF / Safari / Opera / Chrome Check
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		//IE Check
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}


function returnSuccess(responseMessage,errorMessage) {
	//Checks for 'Success' at end of string and returns error message if not present
	responseMessage = responseMessage.Trim();
	if (Right(responseMessage,7) == "Success") {
		return true;
	} else {
		//changeValue("pageResponse", "innerHTML", responseMessage, "", "");
		alert(errorMessage);
		return false;
	}
}


function Left (str, n) {
   return str.substring(0, n);
}

function Right (str, n) {
   len = str.length;
   return str.substring(len -n, len);
}



function verifyRegForm() {
	//NB this validation is used from the home page nad pop up (company info page)
	var onErrorAlert		= true;
	var onErrorMessage	= true;
	var errorMessages		= new Array();
	var focused					= false;
	var formObj					= document.newsRegForm;

	if (formObj.Name.value == '' || formObj.Name.value == 'Full Name') {
		errorMessages.push('Please enter your name');
		if(!focused){
			formObj.Name.focus();
			focused = true;
		}
	}

	if (!validateEmail(formObj.Email.value)) {
		errorMessages.push('Please enter a valid email address');
		if(!focused){
			formObj.Email.focus();
			focused = true;
		}
	}

	if ((errorMessages.length != 0) && (formObj.h_formValidated.value != "true")) {
		errorMessages.push('To prevent SPAM we require you to manually type your name in.');
		if(!focused){
			formObj.Name.focus();
			focused = true;
		}
	}

	if(errorMessages.length != 0){
		if(onErrorAlert){
				alert(errorMessages[0]);
		}
		return false;

	} else {
	
		var updateURL = formObj.h_relPath.value + 'firesafety/regSave.asp?name=' + formObj.Name.value
	       + '&emailAdd=' + formObj.Email.value;
	  var responseText = ajaxGet(updateURL);
	  if (returnSuccess(responseText,"There has been a problem sending your enquiry, please wait a moment and try again.")) {
			return true;
	  } else {
			alert(responseText)
			return false;
		}
	}
}


var defaultValues = new Array();
function dB(oEle) {
	 formName = oEle.form.name;
	 fieldName = oEle.name;
	 arrIndex = formName+'_'+fieldName;
	 if(oEle.value == ""){
			oEle.value = defaultValues[arrIndex];
	 }
}
function dF(oEle) {
	 formName = oEle.form.name;
	 fieldName = oEle.name;
	 arrIndex = formName+'_'+fieldName;
	 if(typeof(defaultValues[arrIndex]) == 'undefined' ) {
			defaultValues[arrIndex] = oEle.value;
	 }
	 if(oEle.value == defaultValues[arrIndex]){
			oEle.value =  "";
	 }
}