// util.js: A generic javascript file defining commonly used functions for
// the lopeds web site.

// get_element: Use insted of document.all or document.getElementById
// to increase cross browser compatibility.
function getElement(obj) {
	var retObj;
	if(document.all) {
		retObj = document.all[obj];
	} else {
		retObj = document.getElementById(obj);
		if(!retObj)
			retObj = document.getElementsByName(obj);
	}
	return retObj;
}

// checkRealDate: Check to see if the given date exists and is a valid date.
function checkRealDate(date) {
	var mdy = date.split("/");
	var day = mdy[1];
	var month = mdy[0];
	var year = mdy[2];
	d = new Date(year, month - 1, day);
	if((d.getMonth() == month - 1) && d.getFullYear() == year)
		return true;
	else {
		alert("The given date " + date + " does not exits and is not a valid date. Please enter a vaild date.");
		return false;
	}
}

// onlyNumbers: Returns true if this string only contains numbers and is
// not empty.
function onlyNumbers(string) {
	var regexp = /^[0-9]+$/;
	if(regexp.test(string))
		return true;
	return false;
}

// validEmail: Returns true if this string is in the form of a valid email
// address.
function validEmail(string) {
	var regexp = /.+@.+\..+/;
	if(regexp.test(string))
		return true;
	return false;
}

