// JavaScript Document


/******************************************************************function to validate postcode************************/
function isValidPostcode(postcode) {
    return (/^\s*[a-z]{1,2}[0-9][a-z0-9]?\s*[0-9][a-z]{2}\s*$/i).test(postcode);
}

/******************************************************************function to validate postcode************************/





/**********************************************************************function to check select options******************************************/
function validSelect(field){
 	if(field > 0) { 
 	return true;
 
	 } 
 	else { 
 	return false;
 
 	}	
}

/**********************************************************************function to check select options******************************************/



/********************************************************function to check field is in alpha format********************************************************/
function isAlpha(elem){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
	return true;
	}
	else{
	return false;
	}
}
/********************************************************function to check field is in alpha format********************************************************/






/********************************************************function to check phone number format********************************************************/
function ValidPhoneMobile(aphone)
{
// declare valid variable as a string with all valid characters (digits from 0 to 9 )
    var valid = "0123456789";
//if phone field is empty - display a warning and return false
    
//if number of character in phone field is not equal 10 - display warning and return false
         if(aphone.length !=11)
         {
    alert("Invalid mobile number length! Please try again.");
         return false;
         }
        //check each character entered in the phone field
         for (var i=0; i < aphone.length; i++)
         {
         //put in temp variable each character, one at a time.
         temp = "" + aphone.substring(i, i+1);
    //check index of a phone character in the "valid" variable.
    // if temp contains a character which is not in "valid" variable,
    //then valid.indexOf(temp) will be -1, otherwise it may be 0.1.2.3.4.5.6.7.8 or 9

         if (valid.indexOf(temp) == "-1")
         {
    alert("Invalid characters in your mobile number. Please try again.");
          return false;
         }
    }
    //if all conditions are passed, then return true
    return true
}




/********************************************************function to check phone number format********************************************************/



/********************************************************function to check phone number format********************************************************/
function ValidPhoneHome(aphone)
{
// declare valid variable as a string with all valid characters (digits from 0 to 9 )
    var valid = "0123456789";
//if phone field is empty - display a warning and return false
         if(aphone=="")
         {
    alert ("This field is required. Please enter home number without dashes!");
         return false;
         }
//if number of character in phone field is not equal 10 - display warning and return false
         if(aphone.length !=10)
         {
    alert("Invalid home number length! Please try again.");
         return false;
         }
        //check each character entered in the phone field
         for (var i=0; i < aphone.length; i++)
         {
         //put in temp variable each character, one at a time.
         temp = "" + aphone.substring(i, i+1);
    //check index of a phone character in the "valid" variable.
    // if temp contains a character which is not in "valid" variable,
    //then valid.indexOf(temp) will be -1, otherwise it may be 0.1.2.3.4.5.6.7.8 or 9

         if (valid.indexOf(temp) == "-1")
         {
    alert("Invalid characters in your home number. Please try again.");
          return false;
         }
    }
    //if all conditions are passed, then return true
    return true
}




/********************************************************function to check phone number format********************************************************/







/********************************************************function to validate email********************************************************/
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;
	}
}
}



/********************************************************function to validate email********************************************************/




/*******************************************************************function to check if field is empty *********************************************/

 function valid_required(field){
         if(field=="") {
         return false;
         }
    return true;
	}


/******************************************************************function to check if field is empty *********************************************/












