function isValidEmail( emailfield, message ) {
      if ( !emailfield ) {
      	  alert("Email Field not found");
          return false;
      }
      atpos=emailfield.value.indexOf("@");
      dotpos=emailfield.value.lastIndexOf(".");
      spacepos=emailfield.value.lastIndexOf(" ");
      if ( spacepos != -1 || atpos == -1 || dotpos == -1 || dotpos == emailfield.value.length-1 || dotpos <= atpos+1 ) {
		alert(message);
		emailfield.focus();
		return false;
      }
      return true;
}


// String.prototype.LTrim=new Function("return this.replace(/^\\s+/,'')")
// String.prototype.RTrim=new Function("return this.replace(/\\s+$/,'')")
// String.prototype.Trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')")
function isNotEmpty1(field,message,noCheck) {
      if ( !field ) {
      	  alert("thedebuggers Message  Field not found");
          return false;
      }
	 field.value=Trim(field.value);
      if ( field.value >noCheck ) {
		alert("Invalid bet number.","",true);
		field.focus();
		return false;
      }
      if ( field.value =="" ) {
		field.focus();
		alert("Please insert bet number.","",true)
		return false;
	  }
      return true;
}

function isNotEmpty2(field,message,noCheck) {
      if ( !field ) {
      	  alert("thedebuggers Message  Field not found");
          return false;
      }
	 field.value=Trim(field.value);
      if ( field.value >noCheck ) {
		alert("Invalid Time","",true);
		field.focus();
		return false;
      }
      if ( field.value =="" ) {
		field.focus();
		alert("Please insert Time.","",true)
		return false;
	  }
      return true;
}

function isNotEmpty(field,message) {
      if ( !field ) {
      	  alert("thedebuggers Message  Field not found");
          return false;
      }
	 field.value=Trim(field.value);
      if ( field.value == "" ) {
		alert(message,"",true);
		field.focus();
		return false;
      }
return true;
}

// function LTrim(str) {
//  for (var i=0; str.charAt(i)<=" "; i++);
//  return str.substring(i,str.length);
// }
// function RTrim(str) {
//  for (var i=str.length-1; str.charAt(i)<=" "; i--);
//  return str.substring(0,i+1);
// }
 function Trim(str) {
  return str.replace(/^\\s+/,'')
 }

 
 
//Valid date function
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

//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;
}
month = matchArray[3]; // parse date into variables
day = matchArray[1];
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;
   }
}

// User should be about 18
a = new Date()
yy = a.getYear()
if ((yy - year) < 18 ){
	alert("You need to be above 18 years old to register.")
	return false;
	}
return true;  // date is valid
}