<!--
/***************************************************************************************
TRIM function for strings
***************************************************************************************/
function trim ( string ) {
	var i, numFirstChar = -1, numLastChar = -1;
	
	for ( i = 0; i < string.length; i ++ ) {
		if ( string.substring ( i, i + 1 ) != ' ' ) {
			numFirstChar = i;
			break;
		}
	}
	
	if ( numFirstChar == -1 )
		return "";
	
	for ( i = string.length; i >= 0; i -- ) {
		if ( string.substring ( i - 1, i ) != ' ' ) {
			numLastChar = i;
			break;
		}
	}
	
	return string.substring ( numFirstChar, numLastChar );
}
/***************************************************************************************
Verify that NAMEFIRST is not empty
***************************************************************************************/
function validate_nameFirst (obj_form) {
	obj_form.nameFirst.value = trim ( obj_form.nameFirst.value );
	if ( obj_form.nameFirst.value == "" ) {	
		obj_form.nameFirst.focus ();
		alert ( "First name is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that NAMELAST is not empty
***************************************************************************************/
function validate_nameLast (obj_form) {
	obj_form.nameLast.value = trim ( obj_form.nameLast.value );
	if ( obj_form.nameLast.value == "" ) {	
		obj_form.nameLast.focus ();
		alert ( "Last name is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that POSITION is not empty
***************************************************************************************/
function validate_position (obj_form) {
	obj_form.position.value = trim ( obj_form.position.value );
	if ( obj_form.position.value == "" ) {	
		obj_form.position.focus ();
		alert ( "Position is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that FACILITY is not empty
***************************************************************************************/
function validate_facility (obj_form) {
	obj_form.facility.value = trim ( obj_form.facility.value );
	if ( obj_form.facility.value == "" ) {	
		obj_form.facility.focus ();
		alert ( "Facility is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that ADDRESS1 is not empty
***************************************************************************************/
function validate_address1 (obj_form) {
	obj_form.address1.value = trim ( obj_form.address1.value );
	if ( obj_form.address1.value == "" ) {	
		obj_form.address1.focus ();
		alert ( "Street address is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that ADDRESS2 is not empty
***************************************************************************************/
function validate_address2 (obj_form) {
	obj_form.address2.value = trim ( obj_form.address2.value );
	if ( obj_form.address2.value == "" ) {	
		obj_form.address2.focus ();
		alert ( "Second address line is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that CITY is not empty
***************************************************************************************/
function validate_city (obj_form) {
	obj_form.city.value = trim ( obj_form.city.value );
	if ( obj_form.city.value == "" ) {	
		obj_form.city.focus ();
		alert ( "City is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that STATE is not empty
***************************************************************************************/
function validate_state (obj_form) {
	obj_form.state.value = trim ( obj_form.state.value );
	if ( obj_form.state.value == "" ) {	
		obj_form.state.focus ();
		alert ( "State/province is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that POSTALCODE is not empty
***************************************************************************************/
function validate_postalcode (obj_form) {
	obj_form.postalcode.value = trim ( obj_form.postalcode.value );
	if ( obj_form.postalcode.value == "" ) {	
		obj_form.postalcode.focus ();
		alert ( "Postal code is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that COUNTRY is not empty
***************************************************************************************/
function validate_country (obj_form) {
	obj_form.country.value = trim ( obj_form.country.value );
	if ( obj_form.country.value == "" ) {	
		obj_form.country.focus ();
		alert ( "Country is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that TELEPHONE is not empty
***************************************************************************************/
function validate_telephone (obj_form) {
	obj_form.telephone.value = trim ( obj_form.telephone.value );
	if ( obj_form.telephone.value == "" ) {	
		obj_form.telephone.focus ();
		alert ( "Telephone is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that AGE is not empty
***************************************************************************************/
function validate_age (obj_form) {
	for ( var i = 0; i < obj_form.age.length; i ++ ) {
		if ( obj_form.age [ i ].checked ) {
			i = -1;
			break;
		}
	}
	if ( i != -1 ) {
		alert ( "Age is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that E-MAIL is not empty and call isEmail function
***************************************************************************************/
function validate_email (obj_form) {
	obj_form.email.value = trim ( obj_form.email.value );
	if ( obj_form.email.value == "" ) {	
		obj_form.email.focus ();
		alert ( "E-mail is a required field." );
		return false;
	} else {
		if (!isEmail(obj_form.email.value)) {
			obj_form.email.focus ();
			alert ( "A valid e-mail address is required." );
			return false;
		}
	}
	return true;
}
/***************************************************************************************
Verify that PASSWORD is not empty
***************************************************************************************/
function validate_password (obj_form) {
	obj_form.password.value = trim ( obj_form.password.value );
	if ( obj_form.password.value == "" ) {	
		obj_form.password.focus ();
		alert ( "Password is a required field." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that PASSWORD2 is not empty
***************************************************************************************/
function validate_password2 (obj_form) {
	obj_form.password2.value = trim ( obj_form.password2.value );
	if ( obj_form.password2.value == "" ) {	
		obj_form.password2.focus ();
		alert ( "Please confirm your password." );
		return false;
	}
	return true;
}
/***************************************************************************************
Verify that the two entered PASSWORDS are the same
***************************************************************************************/
function validate_passwords (obj_form) {
	if ( obj_form.password.value != obj_form.password2.value ) {	
		obj_form.password.value = "";
		obj_form.password2.value = "";
		obj_form.password.focus ();
		alert ( "Your password confirmation does not match your password.\n\nPlease re-enter your password and password confirmation." );
		return false;
	}
	return true;
}

/***************************************************************************************
Verify that the entered E-MAIL address is valid
***************************************************************************************/
function isEmail(theEmail){
	var s = theEmail;
	var ok = 1;
	
	//Check to make sure it is more than 6 characters in length
	if ((s.length < 7)){
		ok = 0;
	}

	//Check to make sure it is has an @ character and there is at least one character before it
	var at = s.indexOf('@');
	if (at < 1){
		ok = 0;
	}
	
	//Check to make sure it is has only one @ character
	if (at != s.lastIndexOf('@')){
		ok = 0;
	}

	//Check to make sure there is at least one full stop after the @ character and the number of characters from the full stop to the end is between 2-5 characters in length
	if ((s.lastIndexOf('.') < (at+1)) || (s.lastIndexOf('.') > (s.length-3)) || (s.lastIndexOf('.') < (s.length-6))){
		ok = 0;
	}

	//Check to make sure there are no funny characters
	if ((s.indexOf(',') != -1) || 
		(s.indexOf(' ') != -1) || 
		(s.indexOf(';') != -1) || 
		(s.indexOf(':') != -1) || 
		(s.indexOf('?') != -1) || 
		(s.indexOf('/') != -1) || 
		(s.indexOf('"') != -1) || 
		(s.indexOf('\\') != -1) || 
		(s.indexOf("'") != -1) || 
		(s.indexOf('[') != -1) || 
		(s.indexOf(']') != -1)){
		ok = 0;
	}
	
	if (s.length == 0){
		ok = 1
	}
	
	if (ok == 1) {
		return true;
	}
	else
	{
		return false;
	}
}



/******
END
******/
//-->

