function echeck(str){
	at="@"
	mydot="."
	lat=str.indexOf(at)
	lstr=str.length
	ldot=str.indexOf(mydot)
	if (str.indexOf(at)==-1){
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(mydot)==-1 || str.indexOf(mydot)==0 || str.indexOf(mydot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==mydot || str.substring(lat+1,lat+2)==mydot){
		return false
	}
	if (str.indexOf(mydot,(lat+2))==-1){
		return false
	}
	if (str.indexOf(" ")!=-1){
		return false
	}
	return true					
}

function validate_comments(thisForm)
//Check that the user has filled out both fields before
//letting them move on
{
	if (thisForm.cm_name.value == '')
		{
		alert("Please enter Your Name")
		thisForm.cm_name.focus();
			return false;
		}
	if (thisForm.cm_email.value == '')
		{
		alert("Please enter Your Email address")
		thisForm.cm_email.focus();
			return false;
		}
	if (echeck(thisForm.cm_email.value)==false)
		{
		alert("Please check your Email address, it doesnt appear to be in an acceptable format")
		thisForm.cm_email.focus();
		return false
		}
	if (thisForm.cm_text.value == '')
		{
		alert("Please enter your Comment")
		thisForm.cm_text.focus();
			return false;
		}
	return true
}

function textCounter(field,cntfield,maxlimit) 
{
		if (field.value.length > maxlimit) // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
			// otherwise, update 'characters left' counter
		else
			cntfield.value = maxlimit - field.value.length;
}


//Date validation
function isValidDate(dateStr) {
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
	//alert("Date is not in a valid format.")
	return false;
}
	day = matchArray[1]; // parse date into variables
	month = matchArray[3];
	year = matchArray[4];

if (month < 1 || month > 12) { // check month range
	//alert("Month must be between 1 and 12.");
	return false;
}

if (day < 1 || day > 31) {
	//alert("Day must be between 1 and 31.");
	return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	//alert("Month "+month+" doesn't have 31 days!")
	return false
}

if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
	//alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}
