function validate() {

	if (document.eventform.event_name.value=="") {alert("Please enter an event name");return false;}
	if (document.eventform.event_location.value=="") {alert("Please enter an event location");return false;}
	if (document.eventform.event_entered_by.value=="") {alert("Please enter your name in the 'Entered By' field");return false;}
	if (document.eventform.event_contact1_email.value=="") {alert("Please enter contact 1 email");return false;}
	if (document.eventform.event_contact1_email.value != "" && document.eventform.event_contact1_name.value=="") {alert("Please enter a contact 1 name");return false;}
	if (document.eventform.event_contact2_email.value != "" && document.eventform.event_contact2_name.value=="") {alert("Please enter a contact 2 name");return false;}
	if (!document.eventform.event_date_tba.checked && document.eventform.event_time.value=="") {alert("Please enter an event time");return false;}
	if (document.eventform.event_date_tba.checked) {document.eventform.check_box_state.value="1";  return true ;}

	data = document.eventform.event_date.value;
	error = 0;

	if ((data.charAt(2)!="/" && data.charAt(5)!="/") || data.length!=10) {
		error = 1;
	} else if (isNaN(data.charAt(0))||isNaN(data.charAt(1))||isNaN(data.charAt(3))||isNaN(data.charAt(4))||isNaN(data.charAt(6))||isNaN(data.charAt(7))||isNaN(data.charAt(8))||isNaN(data.charAt(9))) {
		error = 1;
	} else {
		day = eval(data.charAt(3)+data.charAt(4));
		day = parseInt(day);
		mnth = eval(data.charAt(0)+data.charAt(1));
		mnth = parseInt(mnth);
		//yr = eval("20"+data.charAt(6)+data.charAt(7));
		yr = eval(data.charAt(6)+data.charAt(7)+data.charAt(8)+data.charAt(9));
		yr = parseInt(yr);

		if(mnth>12 || mnth<1) {
			error = 2;
		}

		    // mnthArray[0] is january, mnthArray[11] is december
		mnthArray = new Array(31,29,31,30,31,30,31,31,30,31,30,31);

		// netscape/IE number months starting with january = 0
		mnth = mnth-1;
		mydate = new Date(yr,mnth,day);
		//if(mydate.getDay() != 5) // sunday==0 , saturday==6 we're checking for friday
		//error = 4;

		if(day > parseInt(mnthArray[parseInt(mnth)])) {
			error = 3;
		}
	}

	switch(error) {
	case 1:
		alert("Date must be in mm/dd/yyyy format");
		return false;
		break;
	case 2:
		alert("The month you entered is invalid.");
		return false;
		break;
	case 3:
		alert("The day you entered is invalid for the month.");
		return false;
		break;
	//case 4: alert("The date you entered does not occur on a Friday.");
	//	return false;
	//	break;
	default:
		return true;
	}
}

function newWindow(url){
	window.open(url,'','toolbar=no,statusbar=no,locationbar=no,scrollbars=yes,fullscreen=no,width=640,innerWidth=640,outerWidth=640')
}


function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

function isDigit (c){
	return ((c >= "0") && (c <= "9"))
}


// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag){
	var i;
   	var returnString = "";

	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.

	for (i = 0; i < s.length; i++){
	    // Check that current character isn't whitespace.
	    var c = s.charAt(i);
	    if (bag.indexOf(c) == -1) returnString += c;
	}

	return returnString;
}

function checkZIPCode (theField, emptyOK){
	if (checkZIPCode.arguments.length == 1) {
		emptyOK = false;
	}
	if ((emptyOK == true) && (isEmpty(theField.value))) {
		return true;
	} else {
		var normalizedZIP = stripCharsInBag(theField.value, "-") ;
		if (!isZIPCode(normalizedZIP)) {
			return false ;
		}
		return true;
	}
}

function isZIPCode (s) {
	return (isInteger(s) &&
	        ((s.length == 5) || (s.length == 9)))
}


function isInteger (s) {
	var i;
	if (isEmpty(s)) return false;
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}

