function validateOnSubmit(form) {
    var err='';
    for(i=0;i<els.length;i++){
        for(j=0;j<form.length;j++){
            if(form.elements[j].name==els[i]){
                if(form.elements[j].value==''){
                    err += els[i]+"\n";
                }
            }
			if (form.elements[j].name=='foobar'){
					if(form.elements[j].value!==''){
					err += "foobar filled\n";
					return false
					}
			}
        }
    }
    if (err!==''){
        alert("There are fields which need to be filled out before sending!\n"+err);
        return false;
    }
    else{
        return true;
    }
};


function isNumeric(x) {
    // I use this function like this: if (isNumeric(myVar)) { }
    if(x=='') return true;
    // regular expression that validates a value is numeric
    var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452.
    // compare the argument to the RegEx
    // the 'match' function returns 0 if the value didn't match
    var result = x.match(RegExp);
    return result;
}
function testNumeric(obj){
    if(!isNumeric(obj.value)){
        alert("Please enter a number");
        obj.focus();
        return false;
    }
}
function isDateStr(x){
    if(x=='') return true;
    var RegExp = /\d{1,2}\/\d{1,2}\/\d{2,4}/;
    var result = x.match(RegExp);
    return result;
}
function testDateStr(obj){
    if(!isDateStr(obj.value)){
        alert("Please enter a date in the format mm/dd/yyyy");
        obj.focus();
        return false;
    }
}
