	extArray = new Array(".gif", ".jpg",".pdf");

function LimitAttach(file) {
	allowSubmit = false;
	fileob = ob(file).value;
	if (!fileob) return;
	while (fileob.indexOf("\\") != -1)
		fileob = fileob.slice(fileob.indexOf("\\") + 1);
		ext = fileob.slice(fileob.indexOf(".")).toLowerCase();
		for (var i = 0; i < extArray.length; i++) {
			if (extArray[i] == ext) { allowSubmit = true; break; }
			}
			if (allowSubmit) return false;
			else
			alert("Only files with ext: " 
			+ (extArray.join(" ")) + "\nPlease, select another file "
			+ ".");
			return true;
		}
function ob(field){
//	return document.getElementById(field);
	d = document;
	if(d.all){
		return d.all(field);
	}else if(d.getElementById){
		return d.getElementById(field);
	}else if(d.layers){
		return d.layers(field);
	}

}

function CheckNonEmpty(field) {
	if (ob(field).value == "") {
		return true;	
	} else {
		return false;
	}
}

function CheckValues(field){
	if (ob(field).value!="1" && ob(field).value!="2" && ob(field).value!="3"){
		return true;
	} else {
		return false;
	}
}
function CheckNonEmptyDropDown(field) {
	if (ob(field).selectedIndex == "") {
		return true;	
	} else {
		return false;
	}
}

function CheckNumeric(field) {
	if (isNaN(ob(field).value)) {
		return true;
	} else {
		return false;
	}
}

function testAlphabetic(field){
//THIS ONE ACTUALLY WORKS!
	string=ob(field).value;
	regex='[^0-9]';
	myRegexp=/[^a-zA-Z]/;
	if(string.search(myRegexp) > -1){
		return true;
	} else {
		return false;
	}
}

function testNumeric(field){
	string=ob(field).value;
	regex=/[^0-9]/;
	if(string.search(regex) > -1){
		return true;
	} else {
		return false;
	}
}

function CheckNonNumeric(field) {
	if (isNaN(ob(field).value)) {
		return false;	
	} else {
		return true;
	}
}

function CheckLength(field, minlength) {
	if (trimString(ob(field).value).length < minlength) {
		return true;	
	} else {
		return false;
	}
}
function CheckLengthEssay(field, minlength) {
	var words=ob(field).value;
	var numberOfWords=words.match(/\b\w+\b/g);
	var l=numberOfWords.length;
	if (l > minlength) {
		return true;	
	} else {
		return false;
	}
}

function CheckIncludeNumbers(field) {
	if(!(ob(field).value.match(/\d/))) {
		return true;	
	} else {
		return false;
	}
}

function CheckValidEmail(field) {
	var emailPattern = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if (!emailPattern.test(ob(field).value)) {
		return true;	
	} else {
		return false;
	}
}

function CompareStrings(field1, field2) {
	if (ob(field1).value != ob(field2).value) {
		return true;
	} else {
		return false;
	}
}

function CheckDate(year, month, day)
{
	var myDate=new Date()
	myDate.setFullYear(ob(year).value,ob(month).value - 1,ob(day).value);

	var today = new Date();

	if (ob(year).value == "" || ob(month).value == "" || ob(day).value == "") {
		return true;
	}
	if (myDate>=today) {
		return true;
	} else {
		return false;
	}
}

function ShowHideError(field, display) {
	ob(field).className = display;
}

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function CheckBoxx(check)
{
	if (ob(check).checked == true){
			return true;}
	else{
		return false;}
}

function grab(field){
//	return document.getElementById(field);
	d = document;
	if(d.all){
		return d.all(field);
	}else if(d.getElementById){
		return d.getElementById(field);
	}else if(d.layers){
		return d.layers(field);
	}
}

function checkAge(requiredAge){
	dd=document.contactform.day.selectedIndex;
	mm=document.contactform.month.selectedIndex;
	yy=document.contactform.year.value;
	realDate=mm+'/'+dd+'/'+yy;
	days = new Date();
	gdate = days.getDate();
	gmonth = days.getMonth();
	gyear = days.getFullYear();
	if (gyear < 2000) gyear += 1900;
	age = gyear - yy;
	if ((mm == (gmonth + 1)) && (dd <= parseInt(gdate))){
		age = age; 
	} else {
		if (mm <= (gmonth)){
			age = age;
		} else {
			age = age - 1; 
   		}
	}
	if (age == 0) age = age;
	if(age < requiredAge){
		return false;
	} else {
		return true;	
	}
}

function validateDate(fld) {
    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 ((fld.match(RegExPattern)) && (fld!='')) {
     		return true;
    } else {
		return false;
    } 
}
