/// error functions

function isSpecialCharacter(field) {
		
  for (var i = 0; i < field.length; i++)
   {
  		if ( field.charCodeAt(i) < 1 || field.charCodeAt(i) >126 )
  		 {
  			return false;
  		}
  }
  
  return true;
}


function highlightField(field) {
field.focus();
if (field.select) field.select();
}

function fieldError(field, msg) {
	highlightField(field);
	alert(msg);
	return false;
}

// validation utilities
function hasNumbers(str) {
	var exp = new RegExp("[0-9]");
	return exp.test(str);
}

function isRadiogroupChecked(radioGroup) {
	for (var i=0;i<radioGroup.length;i++) if (radioGroup[i].checked) return true;
	return false;
}

function isNumeric(str) {
	var num=parseFloat(str);
	return (!isNaN(num)||str=="");
}

function isNotNumeric(str) {
	var exp = new RegExp("[^0-9]");
	return exp.test(str);
}

function isInteger(str) {
	var num=parseInt(str);
	return (str.indexOf(".")<0 && (!isNaN(num)||str==""));
}

function isPhoneNumber(str) {
	var exp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
	return exp.test(str);
}

function inRange(num, lower, upper) {
	if (isNaN(num)) num=0;
	return (num>=lower&&num<=upper);
}

function isAlpha(str) {
	var exp = new RegExp("[^A-Za-z]");
	return !exp.test(str);
}

function isAlphaAndNumeric(str) {
	var exp = new RegExp("[^A-Za-z0-9]");
	return !exp.test(str);
}

function trimSpaces(str) {
	return str.replace(/\s+/g, "");
}

function trimOutsideSpaces(str) {
	return str.replace(/^\s+|\s+$/g, "");
}

function arrayContainsElement(array, elem) {
	for (var i=0; i<array.length; i++) {
		if(array[i] == elem) return true;
	}
	return false;
}
function isValidSequence(str, validSequence) {
	// is this correct - need to test
	var exp = new RegExp("[^" + validSequence + "]");
	return !exp.test(str);
}

function isValidSequenceAndAlpha(str, validSequence) {
	var exp = new RegExp("[^" + validSequence + "]");
	return (!exp.test(str) && isAlpha(str));
}

function isEmail(str) {
	
	str = str.toLowerCase();
	var validEmail = true;
	var invalidChars = '\/\'\\ ",;:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
   		if (str.indexOf(invalidChars.charAt(i),0) > -1) {
			validEmail=false;
		}
	}
	
	if (validEmail) {
		for (i=0; i<str.length; i++) {
		    if (str.charCodeAt(i)>127) {
	      		validEmail=false;
		    }
		}
	}
	
	var atPos = str.indexOf('@',0);
	
	if (validEmail) {
		if (atPos == -1) {
   			validEmail=false;
		}
	}
	
	if (validEmail) {
		if (atPos == 0) {
   			validEmail=false;
		}
	}
	
	if (validEmail) {
		if (str.indexOf('@', atPos + 1) > - 1) {
   			validEmail=false;
		}
	}
	
	if (validEmail) {
		if (str.indexOf('.', atPos) == -1) {
   			validEmail=false;
		}
	}
	
	if (validEmail) {
		if (str.indexOf('@.',0) != -1) {
   			validEmail=false;
		}
	}
	
	if (validEmail) {
		if (str.indexOf('.@',0) != -1) {
   			validEmail=false;
		}
	}
	
	if (validEmail) {
		if (str.indexOf('..',0) != -1) {
   			validEmail=false;
		}
	}
	
	if (validEmail) {
		var suffix = str.substring(str.lastIndexOf('.')+1);
		if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' && suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   			validEmail=false;
		}
	}
	return validEmail;
	
}

function isUKPostCode(str) {
	//regular expression for matching UK post codes
	var exp = new RegExp("^([A-Z]\\d\\d? \\d[ABD-HJLNP-UW-Z]{2}|[A-Z]{2}\\d\\d? \\d[ABD-HJLNP-UW-Z]{2}|[A-Z][A-Z]?\\d[A-Z] \\d[ABD-HJLNP-UW-Z]{2}|GIR 0AA)$");
	//convert post code passed in into uppercase
	str = str.toUpperCase();
	if (str.match(exp)) {
		return true;
	} else {
		return false;	
	}
	
}

function isName(str) {
	
	//ony letters, apostrophes or minus sign (-) allowed.
	var exp = new RegExp("^([ a-zA-Z'-]+)$");
	
	if (str.match(exp)) {
		return true;
	} else {
		return false;
	}
}

function isValueSelected(field) {
	return (field.options[field.selectedIndex].value!="");
}

function hasItemsSelected(selection) {
var selectionLen = selection.length;	
var checkedItem = false;
	for(var i=0;i<selectionLen;i++) {
	if(selection[i].checked) checkedItem = true;
	}
return checkedItem;
}

function rollBtn(btn) { 
  if (!btn.state) btn.state = 0;
  var newState = (btn.state==0)?1:0;
  btn.src = btn.src.replace("_" + btn.state + ".gif", "_" + newState + ".gif");
  btn.state = newState;
}

function getDays(month, year) {
	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	monthDays[1] = (year % 4 == 0 && year % 100 != 0 || year % 400 ==0)?monthDays[1]+1:monthDays[1];
	return monthDays[month-1];
}

function validateDateOfBirth(day, month, year) {
	var dayStr = trimSpaces(day.value);
	var monthStr = trimSpaces(month.value);
	var yearStr = trimSpaces(year.value);
	var theDate = new Date();
	// check if fields filled
	if (dayStr.length==0||monthStr.length==0||yearStr.length==0) return fieldError(day, "Please complete your full date of birth.");
	// check if they are all individually valid
	if (!(isNumeric(yearStr)&&inRange(parseInt(yearStr), 1849, theDate.getFullYear()))) return fieldError(year, "Please give a valid year.  It may not be before 1849 or after the present year.");
	if (!(isNumeric(monthStr)&&inRange(parseInt(monthStr), 1, 12))) return fieldError(month, "Please give a valid month (1 - 12).");
	var daysInMonth = getDays(parseInt(monthStr), parseInt(yearStr));
	if (!(isNumeric(dayStr)&&inRange(parseInt(dayStr), 1, daysInMonth))) return fieldError(day, "Please give a valid day.");
	// check its not in the future
	var DOB = new Date(parseInt(yearStr), parseInt(monthStr) - 1, parseInt(dayStr));
	if (DOB>=theDate) return fieldError(day, "Please give a date of birth that is not in the future.");
	return true;
}

//Email validation
function validateEmail(fieldRef) {
sendForm = true;
// Check for valid email address format
	if(fieldRef.value == "") {
	alert("Please enter your email address.");
	highlightField(fieldRef);
	sendForm=false;
	}
	else
	if(!isEmail(fieldRef.value)) {
	alert("Please enter a valid email address");
	highlightField(fieldRef); 
	sendForm = false;
	}
}

//Multiple email validation
function validateMultipleEmails(fieldRef) {

	sendForm = true;
	//Check for a value in the email addresses field
	if (trim(fieldRef.value) == "") {
		
		alert("Please enter at least one email address");
		highlightField(fieldRef);
		sendForm=false;
		
	} else {
		
		var emails = seperateEmailAddresses(fieldRef.value);
		for (var i=0; i<emails.length; i++) {
		
			if (!isEmail(emails[i])) {
				alert("Please enter a valid email address");
				highlightField(fieldRef); 
				sendForm = false;
			}
			
		}
	}
}

//seperate out email addresses
function seperateEmailAddresses(inString) {

	var emails = inString.split(",");
	//trim all email addresses
	for (var i=0; i<emails.length; i++) {
	
		emails[i] = trim(emails[i]);
		
	}
	
	return emails
}
// Login Validation
function validateLogin(fieldRef) {
sendForm = true;
// Check for valid email address format
	if(fieldRef.value == "") {
	alert("Please enter your login name.");
	highlightField(fieldRef);
	sendForm=false;
	}
	else
	if(!isEmail(fieldRef.value)) {
	alert("Please enter a valid login name.\n(email address)");
	highlightField(fieldRef); 
	sendForm = false;
	}
}

function validatePassword(field,login,isRegistrationPage) {
// This function checks that a password has been entered when creating an
// account and it checks the password is the correct length and is in
// the correct format.  It also ensures that the login id is not used.

/*
6 characters minimum
20 chars max
at least one number
not more than 4 occurances of any character
the same character can not be repeated 3 times consequetively
should not contain user ID or spaces
*/

sendForm=true;
var passwordStr = trimOutsideSpaces(""+field.value);
var Nums = 0;
var Chars = 0;
var repeatChars = false;
//Count no of alpha and numeric chars
for(var i=0;i<passwordStr.length;i++) {
//find repeat chars
	if(i<=(passwordStr.length-3)) {	
		if(passwordStr.charAt(i) == passwordStr.charAt(i+1) && passwordStr.charAt(i) == passwordStr.charAt(i+2)) {
		repeatChars = true;
		}
	}	

if(isAlpha(passwordStr.charAt(i))) {
	Chars++;
	}
	else {
	Nums++;
	}
}

	if(!isRegistrationPage && passwordStr == "") {
	alert("Forgotten your password? Please use the \"Forgot your password?\" link");
	highlightField(field);
	sendForm=false;
	}
	else
	if(isRegistrationPage && passwordStr == "") {
	alert("Please enter a password.");
	highlightField(field);
	sendForm=false;
	}
	else
	if(passwordStr.indexOf(login.value)!=-1) {
	alert("Your password contains your Logon ID. Please ensure that your password does not contain your Logon ID");
	highlightField(field);
	sendForm=false;
	}
	else
	if(passwordStr.indexOf(" ")!=-1) {
	alert("Please ensure you do not have spaces in your password");
	highlightField(field);
	sendForm=false;
	}
	else
	if((Nums < 1 || Chars < 2) && passwordStr!= "") {
	alert("Password - Must be a minimum of 6 characters including 1 number");
	highlightField(field);
	sendForm=false;
	}
	else
	if (passwordStr.length < 6 && passwordStr.length != 0) {
	alert("Password - Must be a minimum of 6 characters including 1 number");
	highlightField(field);
	sendForm=false;
	}
	else
	if (passwordStr.length > 20) {
	alert("Password can not be greater than 20 characters");
	highlightField(field);
	sendForm=false;
	}
	else
	if (repeatChars) {
	alert("Please do not use 3 letters or numbers in a row in your password");
	highlightField(field);
	sendForm=false;
	}
}

function validateVerifyPassword(password,verify) {
//Verify entered password by comparing value entered in password field
sendForm=true;
if(password.value != verify.value) {
	alert("Please repeat your exact password.");
	highlightField(verify);
	sendForm=false;
	}
}

function validateName(field) {
//Verify name is not empty, is Alpha, can contain apostrophes and < 40 chars
sendForm=true;
if(field.value == "") {
	alert("Please enter your name.");
	highlightField(field);
	sendForm=false;
	}
	else
if(!isName(field.value)) {
	alert("Please use only letters or apostrophes in your name");
	highlightField(field);
	sendForm=false;
	}
	else
if(field.value.length > 40) {
	alert("Please use no more than 40 characters.");
	highlightField(field);
	sendForm=false;
	}
}

function validateOrderNumber(field) {
//Verify order number is not empty, >5 numbers and is numeric only
sendForm=true;
if(field.value == "") {
	alert("Please enter your order number.");
	highlightField(field);
	sendForm=false;
	}
	else
if(field.value.length < 6) {
	alert("Please enter a valid order number.");
	highlightField(field);
	sendForm=false;
	}
	else
if(isNotNumeric(field.value)) {
	alert("Please use only numbers.");
	highlightField(field);
	sendForm=false;
	}
}

function validatePostcode(str,field) {
//Verify postcode is not empty and is in a valid format
sendForm=true;

if ( str != null ) {
	if (document.getElementById(str) != null &&	document.getElementById(str).value == "United Kingdom" ){
		if(field.value == "") {
			alert("Please enter your postcode/ZIP code.");
			highlightField(field);
			sendForm=false;
			}else {
				if(!isUKPostCode(field.value)) {
					alert("Please enter a valid postcode.");
					highlightField(field);
					sendForm=false;
				}
			}
		}else{
		if(field.value == "") {
			alert("Please enter your postcode/ZIP code.");
			highlightField(field);
			sendForm=false;
			}
		}
	}else{
		if (document.getElementById("addressform") != null &&	document.getElementById("addressform").action == "QASAddress" ){
			if(field.value == "") {
				alert("Please enter your postcode/ZIP code.");
				highlightField(field);
				sendForm=false;
			}else {
				if(!isUKPostCode(field.value)) {
					alert("Please enter a valid postcode.");
					highlightField(field);
					sendForm=false;
				}
			}
		}else{
			if(field.value == "") {
				alert("Please enter your postcode/ZIP code.");
				highlightField(field);
				sendForm=false;
			}else {
				if(document.getElementById("country") != null && document.getElementById("country").value.indexOf("United Kingdom") != -1 && !isUKPostCode(field.value)) {
					alert("Please enter a valid postcode.");
					highlightField(field);
					sendForm=false;
				}
			}
		}
	}
}



function validateStreetAddress(field) {
//Verify street address in not empty
sendForm=true;
if(field.value == "") {
	alert("Please enter your street address.");
	highlightField(field);
	sendForm=false;
	}
	
//Change starts for CPMA# 42125596 by Rohit Kumar

if(field.value.length > 50)
{
	alert("Please break the address in the Address2 line.");
	highlightField(field);
	sendForm=false;
}
//Change ends for CPMA# 42125596 by Rohit Kumar

/* Shailendra :R1.18 CPMA:45276595 Starts */
	if(!isSpecialCharacter(field.value))
		{
			alert ("Your Street Address has special characters. \nThese are not allowed.\n Please remove them and try again.");
			highlightField(field);
			sendForm=false;
		}
/* Shailendra :R1.18 CPMA:45276595 Ends */	

}


function validateStreetAddress1(field) {
//Verify street address in not empty
sendForm=true;
if(field.value == "") {
	alert("Please enter your street.");
	highlightField(field);
	sendForm=false;
	}
}


function validateStreetAddress2(field) {
//Verify street address in not empty
sendForm=true;

/* Shailendra :R1.18 CPMA:45276595 Starts */
	if(field.value != "" && (!isSpecialCharacter(field.value)))
		{
			alert ("Your Address 2 has special characters. \nThese are not allowed.\n Please remove them and try again.");
			highlightField(field);
			sendForm=false;
		}
/* Shailendra :R1.18 CPMA:45276595 Ends */	

//Change starts for CPMA# 42125596 by Rohit Kumar

/*if(field.value == "") {
	alert("Please enter your Address 2.");
	highlightField(field);
	sendForm=false;
	}
*/
if(field.value.length > 50)
{
	alert("Please break the Address2 in the above line.");
	highlightField(field);
	sendForm=false;
}
//Change ends for CPMA# 42125596 by Rohit Kumar
}

function validateCity(field) {
//Verify city in not empty
sendForm=true;
if(field.value == "") {
	alert("Please enter your town.");
	highlightField(field);
	sendForm=false;
	}
}

function validateCounty(field) {
//Verify county in not empty

	sendForm=true;
	if(field.value == "") {
		alert("Please enter your county.");
		highlightField(field);
		sendForm=false;
	}
}

function validateDeliveryMethod(field) {
//Verify at least one item is selected
sendForm=true;
if(!hasItemsSelected(field)) {
	alert("Please choose a delivery method.");
	sendForm=false;
	}
}

function validateCardNumber(field) {
//Verify card number is not empty
sendForm=true;
if(field.value == "") {
	alert("Please enter your card number.");
	highlightField(field);
	sendForm=false;
	}
}

function validateExpiryDate(field1, field2) {
//Verify expiry month and year are not in the future
var theDate = new Date();
var expiryMonth = field1.options[field1.options.selectedIndex].value;
var expiryYear = field2.options[field2.options.selectedIndex].value;
//add 1 for correct month
var currentMonth = ""+parseInt(theDate.getMonth()+1);
//add leading 0
if (currentMonth.length < 2) currentMonth = "0"+currentMonth;
var currentYear = theDate.getFullYear();

sendForm=true;
if(field1.options.selectedIndex == 0) {
	alert("Please select your expiry month.");
	sendForm=false;
	}
	else if(field2.options.selectedIndex == 0) {
	alert("Please select you expiry year.");
	sendForm=false;
	}
if(parseInt(expiryYear+expiryMonth) <=  parseInt(currentYear+currentMonth) ) {
	alert("Please select a valid expiry date.");
	sendForm=false;
	}	
}

function validatePersonTitle(field) {
//Verify person's title is not empty
sendForm=true;
if(field.options.selectedIndex == 0) {
	alert("Please enter your title.");
	highlightField(field);
	sendForm=false;
	}
}

function validateContactReason(field) {
//Verify contact reason is not empty
sendForm=true;
if(field.options.selectedIndex == 0) {
	alert("Please enter a contact reason.");
	highlightField(field);
	sendForm=false;
	}
}

function validateComments(field) {
//Verify card number is not empty
sendForm=true;
	if(field.value == "") {
		alert("Please enter your comments.");
		highlightField(field);
		sendForm=false;
	}
}


function validateFirstName(field) {
//Verify name is not empty, is Alpha, can contain apostrophes and < 40 chars
sendForm=true;
if(trim(field.value) == "") {
	alert("Please enter first name.");
	highlightField(field);
	sendForm=false;
	}
	else
if(!isName(field.value)) {
	alert("Please use only letters or apostrophes in your first name");
	highlightField(field);
	sendForm=false;
	}
	else
if(field.value.length > 40) {
	alert("First names can not be more than 40 characters long.");
	highlightField(field);
	sendForm=false;
	}
}

function validateLastName(field) {
//Verify name is not empty, is Alpha, can contain apostrophes and < 40 chars
sendForm=true;
if(field.value == "") {
	alert("Please enter last name.");
	highlightField(field);
	sendForm=false;
	}
	else
if(!isName(field.value)) {
	alert("Please use only letters or apostrophes in your last name");
	highlightField(field);
	sendForm=false;
	}
	else
if(field.value.length > 40) {
	alert("Last names can not be more than 40 characters long.");
	highlightField(field);
	sendForm=false;
	}
}
function validatePhoneNumber(field) {
        var trimmedValue = trim(field.value);
        var fieldName = field.name;
        sendForm = true;
        //phone1 Compulsory, if phone1 is empty
/*     if ( trimmedValue.length <= 0 &&  fieldName == "phone1" && !hasNumbers(trimmedValue)){
                alert("Please enter your phone number without any spaces or characters e.g. 01234567890");
                highlightField(field);
                sendForm=false;
                return;
     }
     */
         /* if phone1 is not empty then
         * if (action = QASAddress or country is UK )
         * { check UK phone format like number should start with 0}
         * else{ for non-uk just check number format
         * }
         */
if (document.getElementById("addressform") != null &&
         ("QASAddress" == document.getElementById("addressform").action ||
         (document.getElementById("country") != null &&
         trim(document.getElementById("country").value)== "United Kingdom"))){

            if ( trimmedValue.length <= 0 &&  fieldName == "phone1" && !hasNumbers(trimmedValue)){
alert("Please enter your phone number without any spaces or characters e.g. 01234567890");
highlightField(field);
                sendForm=false;
                return;
     }


                if ( "" != trimmedValue && "phone1" == fieldName) {
                
                      if(! (/^[+]?[0-9]+[+]?[0-9]?$/.test(trimmedValue.replace(/[\+\-\s]/g, "")))){
                       alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                       highlightField(field);
                        sendForm=false;
                      }
                      else if (trimmedValue.replace(/[\s]/g, "").charAt(0) != '0' && trimmedValue.replace(/[\s]/g, "").charAt(0) != '+' ) {
                                alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }
                        else if (trimmedValue.replace(/[\s]/g, "").charAt(0) == '+' && trimmedValue.replace(/[\s]/g, "").charAt(1) != '0' ) {
                                alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }
                        else if (trimmedValue.replace(/[\s]/g, "").indexOf("+") != -1 && trimmedValue.replace(/[\s]/g, "").lastIndexOf("+") != 0) {
                                alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }
                     /*   else if (!isPhoneNumber(trimmedValue)) {
                                 alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }*/
                        else if (trimmedValue.replace(/[\+\-\s]/g, "").length < 10 || trimmedValue.replace(/[\+\-\s]/g, "").length > 11) {
                               alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }
        }
        if( trimmedValue != "" && fieldName == "phone2") {
		     if(! (/^[+]?[0-9]+[+]?[0-9]?$/.test(trimmedValue.replace(/[\+\-\s]/g, "")))){
                       alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                       highlightField(field);
                        sendForm=false;
                      }
                      else if (trimmedValue.replace(/[\s]/g, "").charAt(0) != '0' && trimmedValue.replace(/[\s]/g, "").charAt(0) != '+' ) {
                                alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }
                        else if (trimmedValue.replace(/[\s]/g, "").charAt(0) == '+' && trimmedValue.replace(/[\s]/g, "").charAt(1) != '0' ) {
                                alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }
                        else if (trimmedValue.replace(/[\s]/g, "").indexOf("+") != -1 && trimmedValue.replace(/[\s]/g, "").lastIndexOf("+") != 0) {
                                alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }
                     /*   else if (!isPhoneNumber(trimmedValue)) {
                                 alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }*/
                        else if (trimmedValue.replace(/[\+\-\s]/g, "").length < 10 || trimmedValue.replace(/[\+\-\s]/g, "").length > 11) {
                               alert("Please ensure that your Contact number begins with a zero and has 10 or more digits.");
                                highlightField(field);
                                sendForm=false;
                        }
        }
        }else {
        //modified by anju for R1.17
           if ( trimmedValue.length <= 0 &&  fieldName == "phone1" && !hasNumbers(trimmedValue)){
                alert("Please enter your phone number without any characters");
                highlightField(field);
                sendForm=false;
                return;
     }
        if ( "" != trimmedValue && "phone1" == fieldName) {
                        var str = trimmedValue;
//                      str = str.replace(/[^\d]/g, "");
                        str = str.replace(/[\+\-\s]/g, "");
                if(! (/^[-+]?[0-9]+[-+]?[0-9]?$/.test(str))){
                 alert("Please enter your phone number without any characters eg. +123456789,123 456789");
                 highlightField(field);
                         sendForm=false;
                         return;
                 }
                        if(str.replace(/[^\d]/g, "").length < 5 )
                {
                alert("Phone number must contain atleast 5 digits");
                highlightField(field);
                        sendForm=false;
                        return;
                        }


        }
            if ( "" != trimmedValue && "phone2" == fieldName) {
                        var str = trimmedValue;
                        //str = str.replace(/[^\d]/g, "");
                        str = str.replace(/[\+\-\s]/g, "");
                if(! (/^[-+]?[0-9]+[-+]?[0-9]?$/.test(str))){
                 alert("Please enter your phone number without any characters");
                 highlightField(field);
                         sendForm=false;
                         return;
                 }
                        if(str.replace(/[^\d]/g, "").length < 5 )
                {
                alert("Phone number must contain atleast 5 digits");
                highlightField(field);
                        sendForm=false;
                        return;
                        }

        }

        //Changed the following code for CPMA# 04736563

                /*if ( "" != trimmedValue && "phone1" == fieldName) {
                        if (!isPhoneNumber(trimmedValue)) {
                                alert("Please enter your phone number without any spaces or characters e.g. 01234567890");
                                highlightField(field);
                                sendForm=false;
                        }
                }

                if( trimmedValue != "" && fieldName == "phone2") {
                        if (!isPhoneNumber(trimmedValue)) {
                                alert("Please enter your phone number without any spaces or characters e.g. 01234567890");
                                highlightField(field);
                                sendForm=false;
                        }
                }*/

}
}




function validateAddressType(field) {
	//Verify card number is not empty
	sendForm=true;
	if(trim(field.value) == "") {
		alert("Please enter an Address Type.");
		highlightField(field);
		sendForm=false;
	}
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function checkMod10(ccNumb) {  // v2.0
	
	sendForm = true;
	var valid = "0123456789"  // Valid digits in a credit card number
	var len = ccNumb.length;  // The length of the submitted cc number
	var iCCN = parseInt(ccNumb);  // integer of ccNumb
	var sCCN = ccNumb.toString();  // string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
	var iTotal = 0;  // integer total set at zero
	var bNum = true;  // by default assume it is a number
	var bResult = false;  // by default assume it is NOT a valid cc
	var temp;  // temp variable for parsing string
	var calc;  // used for calculation of each digit
	// Determine if the ccNumb is in fact all numbers
	for (var j=0; j<len; j++) {
		temp = "" + sCCN.substring(j, j+1);
	  	if (valid.indexOf(temp) == "-1"){bNum = false;}
	}

	// if it is NOT a number, you can either alert to the fact, or just pass a failure
	if(!bNum){
		bResult = false;
	}

	// Determine if it is the proper length 
	if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
		bResult = false;
	} else {  // ccNumb is a number and the proper length - let's see if it is a valid card number
		if(len >= 15){  // 15 or 16 for Amex or V/MC
	    	for(var i=len;i>0;i--){  // LOOP throught the digits of the card
	      		calc = parseInt(iCCN) % 10;  // right most digit
	      		calc = parseInt(calc);  // assure it is an integer
		      	iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
		      	i--;  // decrement the count - move to the next digit in the card
		      	iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
		      	calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
		      	calc = calc *2;                                 // multiply the digit by two
		      	// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
		      	// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
		      	switch(calc){
		        	case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
		        	case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
		        	case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
		        	case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
		        	case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
		        	default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
		      	}                                               
		    	iCCN = iCCN / 10;  // subtracts right most digit from ccNum
		    	iTotal += calc;  // running total of the card number as we loop
	  		}  // END OF LOOP
	  		if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
	    		bResult = true;  // This IS (or could be) a valid credit card number.
		  	} else {
		    	bResult = false;  // This could NOT be a valid credit card number
			}
		}
	}

	if(!bResult){
  		alert("Please enter a valid credit card number.");
  		sendForm = false;
	}
}