<!--

/*######################################### GENERAL FUNCTIONS: ####################################################*/

// 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 ValidateDateMDY(str){
	var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
	if ((str.match(RegExPattern)) && (str!="")) return true;
	else return false;
}

// Validate date in "dd/mm/yyyy", "d/m/yyyy" format:
function ValidateDateDMY(str){
	if (str.search(/^(?:(?:0?[1-9]|1\d|2[0-8])(\/|-)(?:0?[1-9]|1[0-2]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:31(\/|-)(?:0?[13578]|1[02]))|(?:(?:29|30)(\/|-)(?:0?[1,3-9]|1[0-2])))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(29(\/|-)0?2)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[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;
}

// Validates a collection of checkboxes or radio buttons:
function ValidateCheckboxes(obj){
	var found=0;
	if (typeof(obj)!="undefined") {
		if (typeof(obj.length)=="undefined") {
			if (obj.checked) found=1;
		} else {
			for (var i=0; i<obj.length; i++) {
				if (obj[i].checked) {found=1;break;}
			}
		}
	}
	if (found==1) return true;
	else return false;
}

// Returns a string of checkboxes or radio buttons, separated by comma:
function GetSelectedCheckboxes(obj){
	var str="";
	if (typeof(obj)!="undefined") {
		if (typeof(obj.length)=="undefined") {
			if (obj.checked) str+=obj.value+","
		} else {
			for (var i=0; i<obj.length; i++) {
				if (obj[i].checked) {str+=obj[i].value+",";}
			}
		}
	}
	str=str.substr(0,str.length-1);
	return str;
}

// Saving selected checkboxes to a hidden field with name "fieldTo":
function SaveSelectedCheckboxesToHidden(fieldTo,fieldFrom){
	if (typeof(fieldTo)!="undefined") fieldTo.value=GetSelectedCheckboxes(fieldFrom);
}

// Check/Uncheck a collection of checkboxes or radio buttons:
function CheckUncheckAll(obj,mode){
	var str="";
	if (typeof(obj)!="undefined") {
		if (typeof(obj.length)=="undefined") {
			obj.checked=mode;
		} else {
			for (var i=0; i<obj.length; i++) obj[i].checked=mode;
		}
	}
}

// Validates a collection of select options:
function ValidateSelect(obj){
	var found=0;
	if (typeof(obj)!="undefined") {
		for (var i=0; i<obj.options.length; i++) {
			if (obj.options[i].selected) {found=1;break;}
		}
	}
	if (found==1) return true;
	else return false;
}

// Returns a string of select options values, separated by comma:
function GetSelectedOptions(obj){
	var str="";
	if (typeof(obj)!="undefined") {
		for (var i=0; i<obj.options.length; i++) {
			if (obj.options[i].selected) {str+=obj.options[i].value+",";}
		}
	}
	str=str.substr(0,str.length-1);
	return str;
}

// Select/Unselect a collection of select options:
function SelectUnselectAll(obj,mode){
	var str="";
	if (typeof(obj)!="undefined") {
		for (var i=0; i<obj.options.length; i++) obj.options[i].selected=mode;
	}
}

//-->