<!--

// Trims the leading and trailing blanks from a given string:
function Trim(strToTrim) {
	while(strToTrim.charAt(0)==' '){strToTrim = strToTrim.substring(1,strToTrim.length);}
	while(strToTrim.charAt(strToTrim.length-1)==' '){strToTrim = strToTrim.substring(0,strToTrim.length-1);}
	return strToTrim;
}

// Validate an e-mail address:
function ValidateEmail(str){
	if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
	else return false; 
}

// Validate date in "mm/dd/yyyy", "m/d/yyyy" format:
function ValidateUSDate(str){
	if (str.search(/((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(11|0?[469])([/])(30|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(2[0-8]|1[0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(29)([/])([2468][048]00)$)|(^(0?2)([/])(29)([/])([3579][26]00)$)|(^(0?2)([/])(29)([/])([1][89][0][48])$)|(^(0?2)([/])(29)([/])([2-9][0-9][0][48])$)|(^(0?2)([/])(29)([/])([1][89][2468][048])$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048])$)|(^(0?2)([/])(29)([/])([1][89][13579][26])$)|(^(0?2)([/])(29)([/])([2-9][0-9][13579][26])$))/) != -1) return true;
	else return false; 
}

// Allows only letters, numbers and underscore:
function ChkIllegalChars(str){
	var illegalChars = /\W/;
	if (illegalChars.test(str)) return false;
	else return true;
}


// ############ EXAMPLES FOR FORMS VALIDATION. ############
// YOU'LL HAVE TO CHANGE THESE FUNCTIONS, THEY ARE ONLY EXAMPLES.

// Validates a form.
function ValidateFormExample(frm) {
	if (Trim(frm.txtName.value)=="") {alert("Please enter First Name.");frm.txtName.focus();return false;}
	else if (Trim(frm.txtEmail.value)=="") {alert("Please enter the Email Address.");frm.txtEmail.focus();return false;}
	else if (!ValidateEmail(Trim(frm.txtEmail.value))) {alert("Please enter a valid Email Address.");frm.txtEmail.focus();return false;}
	else if (frm.selOptions.selectedIndex==0) {alert("Please select an option.");frm.selOptions.focus();return false;}
	else if ((new String(Trim(frm.txtComment.value))).length>1000) {alert("Comment text is too long. Maximum 1000 characters allowed.");frm.txtComment.focus();return false;}
	else if (!ValidateCheckboxes(frm.chkOpt)) {alert("Please select an option.");return false;}
	else return true;
}

// Checking if at least one checkbox was selected.
function ValidateCheckboxes(obj) {
	var found=0;
	if (typeof(obj.length)=="undefined") {
		//for only one checkbox:
		if (obj.checked) found=1;
	} else {
		//for more checkboxes:
		for (var i=0; i<obj.length; i++) {if (obj[i].checked) {found=1;break;}}
	}
	if (found==1) return true;
	else return false;
}

function ValidateRadioButton(obj)
{
	myOption = -1;
	for (i=obj.length-1; i > -1; i--)
	{
		if (obj[i].checked)
		{
			myOption = i;
			i = -1;
		}
	}
	
	if (myOption == -1) return false;
	else return true;
}

// ############ END EXAMPLES FOR FORMS VALIDATION. ############

//-->