function ChkForm(frm) {
	if (frm.name.value == "") {
		alert("Please enter the contact name!")
		frm.name.focus()
		return false
	}
	if (frm.email.value == "") {
		alert("Please enter the a e-mail address!")
		frm.email.focus()
		return false
	}
	if (frm.email.value != "") {
		if (!validEmail(frm.email.value)) {
			alert("The Email address you entered is invalid. Please enter a valid Email address!")
			frm.email.focus()
			return false
		}
	}
	if (frm.contact.value == "") {
	  alert("Please enter a valid contact number!")
	  frm.contact.focus()
      return false		
	}	
    if (!IsNumeric(frm.contact.value)) {
	  alert("Please enter a valid contact number!")
	  frm.contact.focus()
      return false
	}	
    if (frm.venue.value == "") {
		alert("Please enter the venue / festival / event name!")
		frm.venue.focus()
		return false
	}	
    if (frm.location.value == "") {
		alert("Please enter the location!")
		frm.location.focus()
		return false
	}
	if (frm.capacity.value == "") {
		alert("Please enter the venue capacity!")
		frm.capacity.focus()
		return false
	}
    if (!IsNumeric(frm.capacity.value)) {
	  alert("Please enter a valid venue capacity!")
	  frm.capacity.focus()
      return false
	}	
	if (!computeJD(frm.year.value,frm.month.value,frm.day.value)) {
		alert("Please select a date in the future!")
		frm.day.focus()
		return false
	}
}

function validEmail(email) {
	invalidChars = " /:,;"
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@", 1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@", atPos + 1) > -1) {
		return false
	}
	periodPos = email.indexOf(".", atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length) {
		return false
	}
	return true
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789/?.>,<';:]}[{\|=+-_)(*&^%$#@!~` ";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
function IsAlpha(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
function computeJD(theY,theM,theD) {
    MM=eval(theM)
    DD=eval(theD)
    YY=eval(theY)
    with (Math) {  
      GGG = 1;
      if (YY <= 1585) GGG = 0;
      JD = -1 * floor(7 * (floor((MM + 9) / 12) + YY) / 4);
      S = 1;
      if ((MM - 9)<0) S=-1;
      A = abs(MM - 9);
      J1 = floor(YY + S * floor(A / 7));
      J1 = -1 * floor((floor(J1 / 100) + 1) * 3 / 4);
      JD = JD + floor(275 * MM / 9) + DD + (GGG * J1);
      JD = JD + 1721027 + 2 * GGG + 367 * YY;
    }
	var jdenter = JD
	var jdtoday = todayJD();
	
    if (jdenter < jdtoday) {
      return false
    } else {
	  return true
    }
}

function todayJD() {
  var today = new Date()
  var month = today.getMonth()
  var year = today.getYear()
  var day = today.getDate()
  if(day<10) day = "0" + day
  if(month<10) month= "0" + month 
  if(year<1000) year+=1900

    MM=eval(month)
    DD=eval(day)
    YY=eval(year)
    with (Math) {  
      GGG = 1;
      if (YY <= 1585) GGG = 0;
      JD = -1 * floor(7 * (floor((MM + 9) / 12) + YY) / 4);
      S = 1;
      if ((MM - 9)<0) S=-1;
      A = abs(MM - 9);
      J1 = floor(YY + S * floor(A / 7));
      J1 = -1 * floor((floor(J1 / 100) + 1) * 3 / 4);
      JD = JD + floor(275 * MM / 9) + DD + (GGG * J1);
      JD = JD + 1721027 + 2 * GGG + 367 * YY;
    }
 
  return JD
}