
function Form1_Validator2(theForm){

if (theForm.Title.value == ""){
alert("Please enter the event title.");
theForm.Title.focus();
return (false);
}

if (theForm.StartDate.value == ""){
alert("Please enter a start date.");
theForm.StartDate.focus();
return (false);
}

if (theForm.id.value == ""){
if (theForm.frequency.value == "1" && (theForm.StartDate.value == theForm.EndDate.value || theForm.EndDate.value == "")){
alert("You must specify an end date that is sometime in the future if you are adding a repeating event.");
theForm.EndDate.focus();
return (false);
}}


if (theForm.frequency){
if (theForm.frequency.value == "1"){
var checkbox_choices = 0;
var counter = 0;

for (counter = 0; counter < theForm.repeatingdays.length; counter++){
if (theForm.repeatingdays[counter].checked){
checkbox_choices = checkbox_choices + 1;
}}

if (counter > 0 && checkbox_choices == 0){
alert("Please select at least one day the event falls on.");
return (false);
}
}
}



if (theForm.Description.value == ""){
alert("Please enter an event description.");
theForm.Description.focus();
return (false);
}

if (theForm.LocationAddress.value == ""){
alert("Please enter the event's address.");
theForm.LocationAddress.focus();
return (false);
}

if (theForm.LocationCity.value == ""){
alert("Please enter the event's city.");
theForm.LocationCity.focus();
return (false);
}

if (theForm.LocationState.value == ""){
alert("Please enter the event's state.");
theForm.LocationState.focus();
return (false);
}

if (theForm.PublicTrans.value == ""){
alert("Please enter the closest public transportation stop.");
theForm.PublicTrans.focus();
return (false);
}

var checkbox_choices = 0;
var counter = 0;

for (counter = 0; counter < theForm.eventtypes.length; counter++){
if (theForm.eventtypes[counter].checked){
checkbox_choices = checkbox_choices + 1;
}}

if (counter > 0 && checkbox_choices == 0){
alert("Please select at least one event type.");
return (false);
}


return (true);
}



function IsValidTime(timeStr,ampmForm,timeForm) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.
if (timeStr > ""){

if (timeStr.indexOf(":")<0){
timeForm.value = timeForm.value + ":00";
timeStr = timeForm.value + ":00";
}

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);

if (matchArray == null) {
alert("Time is not in a valid format.");
timeForm.value = "";
return false;
}

hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = ampmForm;

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12.");
timeForm.value = "";

return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
timeForm.value = "";

return false;
   }
}
if  (hour > 12 && ampm != null) {
alert("Hour must be between 1 and 12.");
//alert("You can't specify AM or PM for military time.");
timeForm.value = "";

return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
timeForm.value = "";

return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
timeForm.value = "";

return false;
}
return false;
}}


function formatCurrency(formfld) {
num = formfld.value;
if (num > ""){
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
if ((num == 0)&&(cents == 0)) formfld.value = "";
else formfld.value = ((sign)?'':'-') + '$' + num + '.' + cents;
}}

function numTyped(current,next,maxlen){
var len = current.value.length
if (len==maxlen) {
next.focus()
}}



function Form1_Validator3(theForm){

if (theForm.phone1.value == ""){
alert("Please enter your area code.");
theForm.phone1.focus();
return (false);
}

if (theForm.phone1.value.length < 3){
alert("Your area code must be 3 digits.");
theForm.phone1.focus();
return (false);
}

if (theForm.phone2.value == ""){
alert("Please enter your phone number.");
theForm.phone2.focus();
return (false);
}

if (theForm.phone2.value.length < 3){
alert("Your phone number must be 10 digits.");
theForm.phone2.focus();
return (false);
}

if (theForm.phone3.value == ""){
alert("Please enter your phone number.");
theForm.phone3.focus();
return (false);
}

if (theForm.phone3.value.length < 4){
alert("Your phone number must be 10 digits.");
theForm.phone3.focus();
return (false);
}

//if (theForm.carrier.value == "0"){
//alert("Please select your carrier.");
//theForm.carrier.focus();
//return (false);
//}

return (true);
}





function Form1_Validator4(theForm){

// test if valid email address, must have @ and .
  var checkEmail = "@.";
  var checkStr = theForm.email.value;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkEmail.length;  j++)
    {
      if (ch == checkEmail.charAt(j) && ch == "@")
        EmailAt = true;
      if (ch == checkEmail.charAt(j) && ch == ".")
        EmailPeriod = true;
	  if (EmailAt && EmailPeriod)
		break;
	  if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
		EmailValid = true
		break;
	}
  }

if (theForm.email.value == ""){
alert("Please enter your e-mail address.");
theForm.email.focus();
return (false);
}

if (!EmailValid){
alert("The format of your e-mail address is incorrect.");
theForm.email.focus();
return (false);
}

return (true);
}