/******************************************************
	FUNCTION TO ALLOW ONLY NUMBERS IN A TEXTFIELD
******************************************************/
<!--
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersdashesandpluses(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789-+").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}//-->


/******************************************************
	FUNCTION TO VALIDATE PROFILE UPDATE FORM
******************************************************/
function validate_updateform(){
	var bError = 0
	
	var formpath = document.frm_update;
	
	if(formpath.txt_title.value==""){
		if(bError==0){
			alert("Please enter your title (Mr, Mrs, Miss, Dr, etc).")
			bError=1
			return false
		}
	}
	
	if(formpath.txt_firstname.value==""){
		if(bError==0){
			alert("Please enter your first name.")
			bError=1
			return false
		}
	}
	
	if(formpath.txt_lastname.value==""){
		if(bError==0){
			alert("Please enter your last name.")
			bError=1
			return false
		}
	}
	
	/*
	if(formpath.txt_country.value=="" || formpath.txt_country.value=="0"){
		if(bError==0){
			alert("Please select your country of residence.")
			bError=1
			return false
		}
	}
	*/
	
	/*
	
	if(formpath.txt_gender.value=="" || formpath.txt_gender.value=="n"){
		if(bError==0){
			alert("Please select your gender.")
			bError=1
			return false
		}
	}
	
	if(formpath.txt_tel.value==""){
		if(bError==0){
			alert("Please enter your telephone number.")
			bError=1
			return false
		}
	}
	
	if(formpath.txt_fax.value==""){
		if(bError==0){
			alert("Please enter your fax number.")
			bError=1
			return false
		}
	}
	
	if(formpath.txt_cell.value==""){
		if(bError==0){
			alert("Please enter your cellular telephone number.")
			bError=1
			return false
		}
	}
	
	if(formpath.txt_address.value==""){
		if(bError==0){
			alert("Please enter your postal address.")
			bError=1
			return false
		}
	}
	
	if(formpath.txt_town.value==""){
		if(bError==0){
			alert("Please enter your town.")
			bError=1
			return false
		}
	}
	
	if(formpath.txt_postalcode.value==""){
		if(bError==0){
			alert("Please enter your postal code.")
			bError=1
			return false
		}
	}
	
	*/
				
	if(bError==0){
		formpath.submit()
	}
}


/******************************************************
	FUNCTION TO VALIDATE REGISTRATION FORM
******************************************************/
function validate_registrationform(){
	var bError = 0
		
	if(document.frm_register.txt_email.value==""){
		if(bError==0){
			alert("Please enter your email address.")
			bError=1
			return false
		}
	}
	
		if(echeck(document.frm_register.txt_email.value) != true){
			if(bError==0){
				alert("Please enter a valid email address.")
				bError=1
				return false
			}
		}
	
	if(document.frm_register.txt_password.value==""){
		if(bError==0){
			alert("Please enter your password.")
			bError=1
			return false
		}
	}
	
	if(document.frm_register.txt_confirmpassword.value==""){
		if(bError==0){
			alert("Please confirm your password.")
			bError=1
			return false
		}
	}
	
	if(document.frm_register.txt_confirmpassword.value != document.frm_register.txt_password.value){
		if(bError==0){
			alert("Your passwords do not match. Please re-enter.")
			bError=1
			return false
		}
	}
	
	if(document.frm_register.txt_title.value==""){
		if(bError==0){
			alert("Please enter your title.")
			bError=1
			return false
		}
	}
	
	if(document.frm_register.txt_firstname.value==""){
		if(bError==0){
			alert("Please enter your first name.")
			bError=1
			return false
		}
	}
	
	if(document.frm_register.txt_lastname.value==""){
		if(bError==0){
			alert("Please enter your surname.")
			bError=1
			return false
		}
	}
	
	if(document.frm_register.txt_country.value=="0"){
		if(bError==0){
			alert("Please select your country of residence.")
			bError=1
			return false
		}
	}
	
	if(document.frm_register.txt_verify.value==""){
		if(bError==0){
			alert("Please enter your verification code.")
			bError=1
			return false
		}
	}
	
	if(toLowerCase(document.frm_register.txt_verify.value) != 'vxqzey2'){
		if(bError==0){
			alert("Verification code is incorrect. Please re-enter.")
			bError=1
			return false
		}
	}
				
	if(bError==0){
		document.frm_register.submit()
	}
}


/******************************************************
	FUNCTION TO VALIDATE FORGOTTEN PASSWORD FORM
******************************************************/
function validate_passwordform(){
	var bError = 0
		
	if(document.frm_login.txt_email.value==""){
		if(bError==0){
			alert("Please enter your email address.")
			bError=1
			return false
		}
	}
	
		if(echeck(document.frm_login.txt_email.value) != true){
			if(bError==0){
				alert("Please enter a valid email address.")
				bError=1
				return false
			}
		}
	
	if(bError==0){
		document.frm_login.submit()
	}
}

/******************************************************
	FUNCTION TO VALIDATE LOGIN SUBMISSION
******************************************************/
function validatelogin(){
	var bError = 0
		
	if(document.frm_login.txt_username.value==""){
		if(bError==0){
			alert("Please enter your email address.")
			bError=1
			return false
		}
	}
	
	if(echeck(document.frm_login.txt_username.value) != true){
			if(bError==0){
				alert("Please enter a valid email address.")
				bError=1
				return false
			}
		}
	
		
	if(document.frm_login.txt_password.value==""){
		if(bError==0){
			alert("Please enter your password.")
			bError=1
			return false
		}
	}

				
	if(bError==0){
		document.frm_login.submit()
	}
}

/******************************************************
	FUNCTION TO VALIDATE FORM SUBMISSION
******************************************************/
function validateform(){
	var bError = 0
	
	
	notifymessage = document.getElementById('notifymessage');
	
	notifymessage.innerHTML = '';
	notifymessage.style.display = 'none';
	
	
	if(document.frm_subscribe.txt_email.checked==true && document.frm_subscribe.txt_emailaddress.value==""){
		
		alert("Please enter the email address you would like to receive email updates on.")
		
		// notifymessage.innerHTML = 'Please enter your address.';
		// notifymessage.style.display = 'block';
		
		bError=1
		return false
	}
	
	if(document.frm_subscribe.txt_email.checked==true && document.frm_subscribe.txt_emailaddress.value=="" && echeck(document.frm_subscribe.txt_emailaddress.value) != true){
			if(bError==0){
				alert("Please enter a valid email address.")
				bError=1
				return false
			}
		}
	
	/*
	
			if(document.frm_subscribe.txt_email.checked==true && document.frm_subscribe.txt_emailaddress.value!="" && isEmail(document.frm_subscribe.txt_emailaddress.value) == false){
				
				alert("The email address you have entered is invalid. Please re-enter.")
				
				// notifymessage.innerHTML = 'Please enter your address.';
				// notifymessage.style.display = 'block';
				
				bError=1
				return false
			}
			
	*/
	
	if(document.frm_subscribe.txt_sms.checked==true && document.frm_subscribe.txt_mobilenumber.value==""){
		
		alert("Please enter the mobile number you would like to receive SMS updates on.")
		
		// notifymessage.innerHTML = 'Please enter your address.';
		// notifymessage.style.display = 'block';
		
		bError=1
		return false
	}
	
	/*
	
			if(document.frm_subscribe.txt_sms.checked==true && document.frm_subscribe.txt_mobilenumber.value!="" && isAlphanumeric(document.frm_subscribe.txt_mobilenumber.value) == true){
				
				alert("The mobile number you have entered is invalid. Please re-enter.")
				
				// notifymessage.innerHTML = 'Please enter your address.';
				// notifymessage.style.display = 'block';
				
				bError=1
				return false
			}
	
	
	*/
	
	if(document.frm_subscribe.txt_address_line01.value==""){
		
		alert("Please enter your address.")
		
		// notifymessage.innerHTML = 'Please enter your address.';
		// notifymessage.style.display = 'block';
		
		bError=1
		return false
	}
	
	if (bError!=1){
		if(document.frm_subscribe.txt_city.value==""){
			
			alert("Please enter your city.")
			
			// notifymessage.innerHTML = 'Please enter your city.';
			// notifymessage.style.display = 'block';
			
			bError=1
			return false
		}
	}
	
	if (bError!=1){
		if(document.frm_subscribe.txt_zip.value==""){
			
			alert("Please enter your zip/postal code.")
			
			// notifymessage.innerHTML = 'Please enter your zip/postal code.';
			// notifymessage.style.display = 'block';
			
			bError=1
			return false
		}
	}
	
	/*	
	if (bError!=1){
		if(document.frm_subscribe.Var_Weight.value=="" || isNaN(parseInt(document.frm_subscribe.Var_Weight.value))){
			alert("Please enter the weight of your parcel.\n(Only numbers are allowed)")
			bError=1
			return
		}
	}
	*/
	
	
	if(bError==0){
		document.frm_subscribe.submit()
	}
}

/******************************************************
	FUNCTION TO ALLOW ONLY NUMBERS IN A TEXTFIELD
******************************************************/
<!--
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

/******************************************************
	FUNCTION TO VALIDATE A GIVEN EMAIL ADDRESS
******************************************************/

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){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

/******************************************************
	FUNCTION TO VALIDATE A GIVEN EMAIL ADDRESS
******************************************************/

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false;}
else {return true;}
}
}