var rxIsName = new Array(/^[a-zA-Z0-9\,\.\-\'\&]+(( &){0,1} [a-zA-Z0-9(\)\\,\.\-\'\&]+)*$/, "characters a-Z, 0-9, apostrophe('), comma(,), hyphen(-), or period(.)");
var rxIsAddress = new Array(/^([a-zA-Z0-9\/\s\.\-\,\(\)#&\']{1,50})$/, "characters a-Z, 0-9, comma(,), hyphen(-), period(.), slash(/), parentheses, and/or the apostrophe(')");
var rxZIPCode = new Array(/^[a-zA-Z0-9]{4,6}\-?[a-zA-Z0-9]{0,4}$/, "12345, A3A3A3, 12345-1234");
var rxPhoneNum = new Array(/^[a-zA-Z0-9\s\(\)\-]{8,29}$/, "form (###) ###-####");
var rxEmail = new Array(/^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "form someone@somewhere.com");
var rxURL = new Array(/^(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?$/, "http://www.somedomainname.com");
var rxIsWord = new Array(/^[a-zA-Z0-9_\-]+$/, "characters a-Z, 0-9, hyphen(-) and/or the underscore(_)");
var rxIsCity = new Array(/^[0-9a-zA-Z\- \.]+$/, "characters a-Z, space, hyphen(-) and/or period(.)");
var rxIsCurr = new Array(/^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{1,3})?|\d{1,3}(\.\d{2})?)$/, "form #,###.##\r\n\r\nThe dollar sign($) is optional");
var rxIsInt = new Array(/^[\d\,]+$/, "form #,###");
var rxIsYear = new Array(/^\d{4}$/, "form ####");
var rxIsPercent = new Array(/^(?:100|\d{0,2}(?:\.?|\.\d{0,5}))%$/, "numbers, the decimal(.) and/or the percent(%)\r\ncharacters (i.e. 100%, 7%, 33.33333% etc..)");
var rxIsAdjust = new Array(/^\+?\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{1,3})?|\d{1,3}(\.\d{2})?)$|^\+?(?:100|\d{0,2}(?:\.?|\.\d{0,5}))%$/, "form #,###.## or ##.##%\r\n\r\nAll values are automatically treated as deductions unless an \"+\" character is\r\nentered into the field");
var rxSSNum = new Array(/^\d{3}-\d{2}-\d{4}$/, "form ###-##-####");
var rxIsNumber = new Array(/^\d{1,}$/, "only numbers");

function validateField(id, rx, label, req) {
	getTopSession().document.form.all[id].value=rTrim(getTopSession().document.form.all[id].value)
	var val = new String(getTopSession().document.form.all[id].value);
	if((val == "" && req == false) || val.match(rx[0])) {
		return true;
	} else {
		alert("Invalid or missing value in " + label + " field. Please use " + rx[1] + ".");
		try { getTopSession().document.form.all[id].focus(); } catch(e){}
		return false;
	}
}

function checkSelect(id, label) {
	var val = new String(getTopSession().document.form.all[id].value);
	if(val == "") {
		alert("You must make a selection from the " + label + " drop-drown list.");
		try { getTopSession().document.form.all[id].focus(); } catch(e){}
		return false;
	} else {
		return true;
	}
}

function checkDependancy(master, masterName, dependant, dependantName) {
	if(getTopSession().document.form.all[dependant].value != ""){
		if(getTopSession().document.form.all[master].value == ""){
			alert("You cannot enter " + dependantName + " without specifying " + masterName + ".");
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}

function checkTimeline(past, pastName, future, futureName, req) {
	if(getTopSession().document.form.all[past].value != "" && getTopSession().document.form.all[future].value != ""){
		var pastArray = getTopSession().document.form.all[past].value.split('/');
		var futureArray = getTopSession().document.form.all[future].value.split('/');
		var pastDate = new Date(pastArray[2], pastArray[0], pastArray[1]);
		var futureDate = new Date(futureArray[2], futureArray[0], futureArray[1]);
		if(pastDate.getTime() <= futureDate.getTime()){
			return true;
		} else {
			alert(futureName + " cannot occur before " + pastName + ".");
			return false;
		}
	} else {
		if(req == true) {
			if (getTopSession().document.form.all[past].value == "") {
				alert('You must select or enter an ' + pastName + ".");
				getTopSession().document.form.all[past].focus();
				return false;
			} else {
				alert('You must select or enter an ' + futureName + ".");
				getTopSession().document.form.all[future].focus();
				return false;
			}			
		} else {
			return true;
		}	
	}
}

function clearAny(id) {
	getTopSession().document.form.all[id].value = '';
}

function rTrim(str) {
	for (var i=str.length-1; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i--);
	return str.substring(0,i+1);
}