
function Validate_giftCertificateForm01(){
if(isBlank(document.giftCertificateForm01.AbsRecipientName.value)){alert('Please enter the recipient name');document.giftCertificateForm01.AbsRecipientName.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsMessage.value)){alert('Please enter occasion or message');document.giftCertificateForm01.AbsMessage.focus();return false;};
if(isLengthOrGreater(document.giftCertificateForm01.AbsMessage.value, 61)){alert('Your message cannot exceed 60 characters');document.giftCertificateForm01.AbsMessage.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsPurchaserName.value)){alert('Please enter the purchaser name');document.giftCertificateForm01.AbsPurchaserName.focus();return false;};
if(!isSelected(document.giftCertificateForm01.AbsDeliveryTitle)){alert('Please select the the delivery title');document.giftCertificateForm01.AbsDeliveryTitle.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsDeliveryFirstName.value)){alert('Please enter the delivery first name');document.giftCertificateForm01.AbsDeliveryFirstName.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsDeliverySurname.value)){alert('Please enter the delivery surname');document.giftCertificateForm01.AbsDeliverySurname.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsDeliveryAddress.value)){alert('Please enter the delivery address');document.giftCertificateForm01.AbsDeliveryAddress.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsDeliverySuburb.value)){alert('Please enter the delivery suburb');document.giftCertificateForm01.AbsDeliverySuburb.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsDeliveryState.value)){alert('Please enter the delivery state');document.giftCertificateForm01.AbsDeliveryState.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsDeliveryPostcode.value)){alert('Please enter the delivery postcode');document.giftCertificateForm01.AbsDeliveryPostcode.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsDeliveryCountry.value)){alert('Please enter the delivery country');document.giftCertificateForm01.AbsDeliveryCountry.focus();return false;};
if(!isSelected(document.giftCertificateForm01.AbsPurchaseFrom)){alert('Please select the hotel where you like to purchase your gift certificate');document.giftCertificateForm01.AbsPurchaseFrom.focus();return false;};
if(!isSelected(document.giftCertificateForm01.AbsCertificateType)){alert('Please select the type of gift certificate you wish to purchase.');document.giftCertificateForm01.AbsCertificateType.focus();return false;};
if(!isInteger(document.giftCertificateForm01.AbsOpenVoucher.value)){alert('Please enter a valid amount for the open voucher');document.giftCertificateForm01.AbsOpenVoucher.focus();return false;};
if(!validateVoucher()){return false};if(!isSelected(document.giftCertificateForm01.AbsPurchaserTitle)){alert('Please select the the purchaser title');document.giftCertificateForm01.AbsPurchaserTitle.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsPurchaserFirstName.value)){alert('Please enter the purchaser first name');document.giftCertificateForm01.AbsPurchaserFirstName.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsPurchaserSurname.value)){alert('Please enter the purchase surname');document.giftCertificateForm01.AbsPurchaserSurname.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsPurchaserAddress.value)){alert('Please enter the purchase address');document.giftCertificateForm01.AbsPurchaserAddress.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsPurchaserSuburb.value)){alert('Please enter the purchase suburb');document.giftCertificateForm01.AbsPurchaserSuburb.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsPurchaserState.value)){alert('Please enter the purchaser state');document.giftCertificateForm01.AbsPurchaserState.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsPurchaserPostcode.value)){alert('Please enter the purchaser postcode');document.giftCertificateForm01.AbsPurchaserPostcode.focus();return false;};
if(isBlank(document.giftCertificateForm01.AbsPurchaserCountry.value)){alert('Please enter the purchaser country');document.giftCertificateForm01.AbsPurchaserCountry.focus();return false;};
if(!isEmail(document.giftCertificateForm01.AbsPurchaserEmail.value)){alert('Please enter a valid email address');document.giftCertificateForm01.AbsPurchaserEmail.focus();return false;};
document.giftCertificateForm01.AbsPurchaserEmail.value = trimEmail(document.giftCertificateForm01.AbsPurchaserEmail.value);
if(!passEmail()){return false};if(isBlank(document.giftCertificateForm01.AbsPurchaserPhone.value)){alert('Please enter the purchaser phone number');document.giftCertificateForm01.AbsPurchaserPhone.focus();return false;};
if(!isInteger(document.giftCertificateForm01.AbsPurchaserPhone.value)){alert('Please enter a valid purchaser phone number');document.giftCertificateForm01.AbsPurchaserPhone.focus();return false;};

disableSubmit(document.giftCertificateForm01, var_DisableButtonText)
}

function isInteger(src) {
	// only allow numbers to be entered
	var checkOK = "0123456789";
	 
	var checkStr = src;
	var allValid = true;
	var allNum = "";
 
	for (i = 0;  i < checkStr.length;  i++){
		 
		ch = checkStr.charAt(i);
		 
		for (j = 0;  j < checkOK.length;  j++) {
			//alert('ch='+ch+'\ncheckOK.charAt(j)='+checkOK.charAt(j))
			if (ch != checkOK.charAt(j)) {
				allValid = false;
			} else {
				allValid = true;
				break;
			}
		}
		if (allValid==false) {
			break;
		}
	}
	return allValid
}
function isBlank(src) {
	
	if (src=='') {
		return true;
	} else {
		return false;
	}
}
function isEmail(emailStr) {
	// checks if the e-mail address is valid
	emailStr = trimEmail(emailStr)
	var emailPat = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) {return false;}

	// make sure the IP address domain is valid
	var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255)
				return false;
		}
	}
	return true;
}
function trimEmail(inputString) {

	if (typeof inputString != "string") { return inputString; }

	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	   
	// Check for spaces at the beginning of the string
	while (ch == " ") { 
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	// Check for spaces at the end of the string
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") { 
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
	 	retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	// Return the trimmed string back to the user
	return retValue; 

}
function isLengthOrGreater(src, theLength) {
	// src must be at least theLength chars long
	if (src.length>=theLength)  {
		return true
	} else {
		return false
	}
}
function isSelected(el) {
	if(el.selectedIndex==0)
		return false
	else
		return true
}
function disableSubmit(formObj, btnValue) {
	var nav = false;
	if ( (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3) ) {nav = true}
	if ( document.all || document.getElementById || nav ) {
		var tempobj = "";
		for ( i = 0; i < formObj.length; i++ ) {
			tempobj = formObj.elements[i];
			if ( (tempobj.type.toLowerCase() == "submit") || (tempobj.type.toLowerCase() == "reset") || (tempobj.type.toLowerCase() == "button") ) { 
				tempobj.disabled = true; 
				if (btnValue!='') {tempobj.value = btnValue}
			}
		}
		formObj.submit();
	} else {
		alert("Your form has not been submitted as you're not using IE 4+ or NS 4+. Please, upgrade your browser.");
		return false;
	}
}

