
function strtrim() {
    //Match spaces at beginning and end of text and replace
    //with null strings
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.trim = strtrim;

function validateForm(xxx, yyy){
	var errString = "";
	with (xxx) {
       
	   	var requireds_array = yyy;
		
		for (var i = 0; i < (requireds_array.length) / 4; i++){
			thisField = eval(requireds_array[4*i]);
			thisType = requireds_array[4*i+1];
			thisDisplay = requireds_array[4*i+2];
			thisRegex = requireds_array[4*i+3];
			if ((thisType == "text")||(thisType == "textarea")){
				if (thisField.value.trim() == "")
					errString += "\n\t - " + thisDisplay + " cannot be blank";
				//else if (thisRegex != ""){
				//	var regX = eval(thisRegex);
				//	if ( !regX.test(thisField.value) )
				//		errString += "\r\t - " + + " must be in the correct format";
				//}
					
			}
			
			if (thisType == "select"){
				if (thisField[thisField.selectedIndex].value.trim() == "")
					errString += "\n\t - Please select " + thisDisplay;
			}
			if ((thisType == "checkbox")||(thisType == "radio")){
				var j, found = false;
				for(j=0; j< thisField.length; j++)
					if (thisField[j].checked)
						found = true;
		
				if (!found)
					errString += "\r\t - At least one " + thisDisplay + " must be checked";
			}
		}

	}
		
	if (errString != "") {
		alert("The following errors have occurred:\n" + errString);
		return false;
	}
	return true;
}
