// Arthur Wang  06/04/11 /police/js/communications.js for /police/about/dispatcher/contact.shtml 

function validate(frm) {
var themessage = "You are required to complete the following fields: ";

if (frm.date_of_event.value=="" || frm.date_of_event.value=="MM-DD-YYYY") {
themessage = themessage + " - Date of Event";
}
if (frm.time_of_event.value=="") {
themessage = themessage + " -  Time ";
}
if (frm.contact_name.value=="") {
themessage = themessage + " -  Contact Name ";
}
if (frm.contact_phone.value=="") {
themessage = themessage + " -  Contact Phone ";
}
if (frm.contact_email.value=="") {
themessage = themessage + " -  Contact Email ";
}
if (frm.age.value < 5) {
 themessage = themessage + " - Age of Audience must be at least 5 years old ";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
frm.submit();
}
else {
alert(themessage);
return false;
   }
}

function checkdate(objName){
var datefield = objName;
if (chkdate(objName) == false) {
datefield.select();
alert("The Date of Event is invalid because it is less than three weeks from Today's Date.  Please try again.");
datefield.focus();
return false;
}
else {
return true;
   }
}


function chkdate(e) {
var fieldName = e;
var enterDate = fieldName.value.toString();
var theEnter = Date.parse(enterDate);

var d = new Date();
d.setDate(d.getDate()+21);
var advance = Date.parse(d);


if (theEnter == NaN || theEnter < 1){
return false;
} else if (theEnter < advance){
return false;
}
else
return true;
}


function getCurrentTime(){
var currentTime = new Date();
var m = String(currentTime.getMonth()+1);
var month = m.length == 1 ? "0"+m : m;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.write(month + "/" + day + "/" + year);
}

