
var fadeToColor = "#bf645d";
var fadeBackColor = "#CCCCCC";
var fadeTime = 200;

function validateComment( form ) {
    var err_mess = "";
	

	// checks a text field (text,textarea) for: empty string
	// ( class name, form value , err message for empty string , min numbers of chars (0 for no minimum) , err message for too few chars)
	err_mess += isEmpty("", form.input_Comment.value , "Please enter a comment." , 5 , "Please enter a comment.");




// ************************************ DO NOT DELETE ANYTHING BELOW THIS LINE ************************************

if (err_mess != "") {
       alert(err_mess);
       return false;
    }
	return true;
}



// ------------------------------------------------------------------------------------------------------ //
// --------------------------------------- check an email address --------------------------------------- //
// ------------------------------------------------------------------------------------------------------ //

	function checkEmail(strClassName, strEmail) {
		var error = "";
		// check the empty string
		if (strEmail == "") {
			error = "Please enter an email address.\n";
			if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
			return error;
		}
		// check the syntax "*@*.ab" or "*@*.abc"
		var filter=/^.+@.+\..{2,3}$/;
		if (!(filter.test(strEmail))) { 
		   error = "Please enter a valid email address.\n";
			if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
		   return error;
		}
		// check for invald characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (strEmail.match(illegalChars)) {
		   error = "The email address contains illegal characters.\n";
			if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
		   return error;
		}
		//return error;  
		
		 if (strClassName != "") { $(strClassName).animate( { color: fadeBackColor }, fadeTime ); }
		else { return error; }
	}



// ------------------------------------------------------------------------------------------------------ //
// ----------------------------- check a text element for an empty string ------------------------------- //
// ------------------------------------------------------------------------------------------------------ //

	function isEmpty(strClassName, strText , strMessage , intMinChars , strMinMessage) {
		var error = "";
		// check for the empty string
		if (strText == "") {
			error = strMessage.concat("\n");
			if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
			return error;
		}
		// check for minimum number of characters
		if (intMinChars != 0) {
			if (strText.length < intMinChars) {
				error = strMinMessage.concat("\n");
				if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
				return error;
			}
		}
		 if (strClassName != "") { $(strClassName).animate( { color: fadeBackColor }, fadeTime ); }
		else { return error; }
	}
	
	

// ------------------------------------------------------------------------------------------------------ //
// --------------------------------- check a password and it's retype ----------------------------------- //
// ------------------------------------------------------------------------------------------------------ //

	function checkPasswords(strClassName, intPassNum , strPassword1 , strPassword2 , intMinChars) {
		var error = "";
		// if there are two occurrences of the password, check for the empty strings
		if (intPassNum == 2) {
			if ((strPassword1 == "") && (strPassword2 == "")) {
				error = "Please enter a password and then retype it.\n";
				if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
				return error;
			}
		}
		// check for the empty string
		if (strPassword1 == "") {
			error = "Please enter a password.\n";
			if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
			return error;
		}
		// check for the minimum number of characters
		if (strPassword1.length < intMinChars) {
		   error = "The password is too short.\n";
			if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
		   return error;
		}
		// if there are two occurrences of the password, check for the 2nd empty dtring
		if (intPassNum == 2) {
			if (strPassword2 == "") {
				error = "Please retype the password.\n";
				if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
				return error;
			}
		}
		// if there are two occurrences of the password,
		if (intPassNum == 2) {
			if (strPassword1 != strPassword2) {
				error = "The passwords don't match.\n";
				if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
				return error;
			}
		}
		 if (strClassName != "") { $(strClassName).animate( { color: fadeBackColor }, fadeTime ); }
		else { return error; }
	}   




// ------------------------------------------------------------------------------------------------------ //
// -------------------------------------- check an phone number ----------------------------------------- //
// ------------------------------------------------------------------------------------------------------ //

function checkPhone(strClassName, strPhone) {
	var error = "";
	// check for the empty string
	if (strPhone == "") {
   		error = "Please enter a phone number.\n";
		if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
		return error;
	}
	// check for all numbers after stripping string
	var stripped = strPhone.replace(/[\(\)\.\-\ ]/g, ''); 
    if (isNaN(parseInt(stripped))) {
       error = "Please enter a valid phone number.\n";
	   if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
	   return error;
    }
	// check for the proper length of 10 or 11 digits
    if (!(stripped.length == 10 || stripped.length == 11)) {
		error = "The phone number is the wrong length. Please include the area code.\n";
		if (strClassName != "") { $(strClassName).animate( { color: fadeToColor }, fadeTime ); }
		return error;
    } 
	if (strClassName != "") { $(strClassName).animate( { color: fadeBackColor }, fadeTime ); }
	else { return error; }
}
// ----------------------------- check an phone number ----------------------------- //






// ----------------------------- check a time ----------------------------- //
function checkTime(strTime) {
	var error = "";
	//check for the empty string
	if (strTime == "") {
   		error = "Please enter a time.\n";
		return error;
	}
	// check for all numbers after stripping string
	var stripped = strTime.replace(/[\:\(\)\.\-\ ]/g, ''); 
    if (isNaN(parseInt(stripped))) {
       error = "Please enter a valid time.\n";
	   return error;
    }
	// check for a ":"
	if (strTime.search(/:/) == -1) {
		error = "Please enter a valid time.\n";
		return error;
	}
	// check for "1-12" : "00-59" and that the minute is in a double character format (00-59)
	var hour;
	var minute;
	hour = strTime.substr(0,strTime.search(/:/));
	minute = strTime.substr(strTime.search(/:/)+1,2);
	if ( parseInt(hour) > 12 || parseInt(hour) < 1 || parseInt(minute) > 59 || parseInt(minute) < 0 || minute.length != 2) {		
		error = "Please enter a valid time.\n";
		return error;
    } 
	return error;
}
// ----------------------------- check a time ----------------------------- //







// ----------------------------- check a zipcode ----------------------------- //
function checkZipcode(strZipcode) {
	var error = "";
	var valid = "0123456789-";
	var hyphencount = 0;
	//check for the empty string
	if (strZipcode == "") {
   		error = "Please enter a zip code.\n";
		return error;
	}
	if (strZipcode.length!=5 && strZipcode.length!=10) {
		error = "Please enter a 5 digit or 5 digit+4 zip code.\n";
		return error;
	}
	for (var i=0; i < strZipcode.length; i++) {
		temp = "" + strZipcode.substring(i, i+1);
		if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") {
				error = "The zip code contains illegal characters.\n";
				return error;
			}
			if ((hyphencount > 1) || ((strZipcode.length==10) && ""+strZipcode.charAt(5)!="-")) {
				error = "Please enter a 5 digit or 5 digit+4 zip code.\n";
				return error;
   			}
		}
	return error;
}
// ----------------------------- check a zipcode ----------------------------- //





// ----------------------------- check a radio button or group of ----------------------------- //
function checkRadioORCheckbox(intRadio , strMessage) {
	var error = "";
	// check for a null value
   	if (!(intRadio)) {
       error = strMessage.concat("\n");
    }
	return error;
}
// ----------------------------- check a radio button or group of ----------------------------- //




// ----------------------------- check a drop down list ----------------------------- //
function checkDropdown(intDropdown , strMessage) {
	var error = "";
	// check for a null value
    if (intDropdown == 0) {
    	error = strMessage.concat("\n");
    }    
	return error;
}
// ----------------------------- check a drop down list ----------------------------- //



