function toggleAllDayEvent(isAllDay){
	if(isAllDay){
		document.getElementById('start_time_req').style.display="none";
		document.getElementById('start_time').value="";
		document.getElementById('start_time').disabled=true;
		document.getElementById('end_time').value="";
		document.getElementById('end_time').disabled=true;
	}else{
		document.getElementById('start_time_req').style.display="";
		document.getElementById('start_time').disabled=false;
		document.getElementById('end_time').disabled=false;
	}
}

var occurrences=1;
var nextId=2;
var topId=1;
var idList="1";

function addOccurrence(){
	var theTable=document.getElementById('event_date_table');
	var theRow=theTable.insertRow(-1);
	theRow.id="dateRow"+nextId;
	var cell1=	theRow.insertCell(-1);
	cell1.className="dateCell";
	var theCell='<input type="text" name="Date '+nextId+'" id="date'+nextId+'" style="width:74px;height:22px;">'
	cell1.innerHTML=theCell;
	var cell2=	theRow.insertCell(-1);
	cell2.className="dateCell";
	cell2.id="startCell_"+nextId;
	cell2.innerHTML='<img src="../../includes/site_images/spacers/spacer.gif" width="5" height="5" alt="" border="0">';
	var cell3=	theRow.insertCell(-1);
	cell3.className="dateCell";
	cell3.id="endCell_"+nextId;
	cell3.innerHTML='<img src="../../includes/site_images/spacers/spacer.gif" width="5" height="5" alt="" border="0">';
	var cell4=theRow.insertCell(-1);
	cell4.id="remove_"+nextId;
	theCell='<a href="javascript:removeOccurrence(\''+nextId+'\')" onMouseOver="MM_swapImage(\'occur'+nextId+'\',\'\',\'../../includes/site_images/misc/rem_1.gif\',0)" onMouseOut="MM_swapImgRestore()"><img src="../../includes/site_images/misc/rem_0.gif" width="12" height="12" border="0" alt="Remove this Occurrence" name="occur'+nextId+'" id="occur'+nextId+'"></a>';
	cell4.innerHTML=theCell;
	if(occurrences==1){
		var theId="remove_"+topId;
		var theButton='<a href="javascript:removeOccurrence(\''+topId+'\')" onMouseOver="MM_swapImage(\'occur'+topId+'\',\'\',\'../../includes/site_images/misc/rem_1.gif\',0)" onMouseOut="MM_swapImgRestore()"><img src="../../includes/site_images/misc/rem_0.gif" width="12" height="12" border="0" alt="Remove this Occurrence" name="occur'+topId+'" id="occur'+topId+'"></a>'
		document.getElementById(theId).innerHTML=theButton;
	}
	idList=idList+","+nextId;
	occurrences++;
	nextId++;
}

function removeOccurrence(occurID){
	if(occurID==topId&&occurrences>1){
		var listSplit=idList.split(",");
		var start='<input type="text" name="Start Time" id="start_time" style="width:68px;height:22px;">';
		var end='<input type="text" name="End Time" id="end_time" style="width:68px;height:22px;">';
		var startTime="";
		var endTime="";
		startTime=document.getElementById('start_time').value;
		endTime=document.getElementById('end_time').value;
		var theId="dateRow"+occurID;
		var theRow=document.getElementById(theId);
		theRow.parentNode.removeChild(theRow);
		theId="startCell_"+listSplit[1];
		document.getElementById(theId).innerHTML=start;
		document.getElementById('start_time').value=startTime;
		theId="endCell_"+listSplit[1];
		document.getElementById(theId).innerHTML=end;
		document.getElementById('end_time').value=endTime;
		if(document.getElementById('all_day').checked){
			document.getElementById('start_time').disabled=true;
			document.getElementById('end_time').disabled=true;
		}
		topId=parseInt(listSplit[1]);
		idList="";
		for(var i=1;i<listSplit.length;i++){
			idList=idList+listSplit[i];
			if(i+1<listSplit.length){
				idList=idList+",";
			}
		}
		occurrences--;
	}else{
		var theId="dateRow"+occurID;
		var theRow=document.getElementById(theId);
		theRow.parentNode.removeChild(theRow);
		var listSplit=idList.split(",");
		idList="";
		for(var i=0;i<listSplit.length;i++){
			if(parseInt(occurID)!=parseInt(listSplit[i])){
				idList=idList+listSplit[i];
				if(i+1<listSplit.length){
					idList=idList+",";
				}
			}
		}
		occurrences--;
	}
}

function validateForm() {
	var errorsMessage="";
	var eventMessage = "";
	var locationMessage="";
	var contactMessage = "";
	if(document.getElementById("event_name").value.length==0){
		eventMessage+="Event Name is a required field.<br>"
	}
	if(!(document.getElementById("arts").checked||document.getElementById("financial").checked||document.getElementById("planning").checked||document.getElementById("youth").checked||document.getElementById("other").checked)){
		eventMessage+="Event Category is a required field.<br>"
	}
	var listSplit=idList.split(",");
	var errors=false;
	var format=false;
	for(var i=0;i<listSplit.length;i++){
		var theId="date"+parseInt(listSplit[i]);
		if(document.getElementById(theId).value.length==0){
			errors=true;
		}else{
			if(document.getElementById(theId).value.match(/\d{1,2}.\d{1,2}.(\d{4}|\d{2})/gi) == null){
				format=true;
			}
		}
	}
	if(errors){
		eventMessage+="Date is a required field for each occurrence.<br>"
	}
	if(format){
		eventMessage+="Please make sure the Event Dates are in the proper format. (01/01/2009)<br>"
	}
	if(!document.getElementById("all_day").checked&&document.getElementById("start_time").value.length==0){
		eventMessage+="Start Time is a required field.<br>"
	}else{
		if(!document.getElementById("all_day").checked&&(document.getElementById("start_time").value.match(/\d{1,2}:\d{2}(\s+)?((a|pm)|(A|PM))/gi) == null||document.getElementById("end_time").value.match(/\d{1,2}:\d{2}(\s+)?((a|pm)|(A|PM))/gi) == null)){
			eventMessage+="Please make sure the Start and End Times are in the proper format. (01:05 pm)<br>"
		}
	}
	if(eventMessage.length>0){
		errorsMessage="<b>Errors:</b><br><br><i>Event Information:</i><br>"+eventMessage;
	}
	if(document.getElementById("loc_name").value.length==0){
		locationMessage+="Name of Location is a required field.<br>"
	}
	if(document.getElementById("phone").value.length==0){
		locationMessage+="Phone Number is a required field.<br>"
	}else{
		if(document.getElementById("phone").value.match(/^((\d{3}-?){2}\d{4})($|(\D+\d+))/gi) == null){
			locationMessage+="Please make sure the Phone Number is in the proper format. (123-456-7890)<br>"
		}
	}
	if(document.getElementById("address").value.length==0){
		locationMessage+="Street Address is a required field.<br>"
	}
	if(document.getElementById("state").selectedIndex==0){
		locationMessage+="State is a required field.<br>"
	}
	if(document.getElementById("zip_code").value.length==0){
		locationMessage+="ZIP Code is a required field.<br>"
	}else{
		if(document.getElementById("zip_code").value.match(/^\d{5}(\D+\d{4})?/gi) == null){
			locationMessage+="Please make sure the ZIP Code is in the proper format. (12345 or 12345-6789)<br>"
		}
	}
	if(locationMessage.length>0){
		if(errorsMessage.length==0){
			errorsMessage="<b>Errors:</b><br>";
		}
		errorsMessage=errorsMessage+"<br><i>Event Location:</i><br>"+locationMessage;
	}
	if(document.getElementById("contact_name").value.length==0){
		contactMessage+="Contact Name is a required field.<br>"
	}
	if(document.getElementById("contact_org").value.length==0){
		contactMessage+="Organization is a required field.<br>"
	}
	if(document.getElementById("contact_phone").value.length==0){
		contactMessage+="Contact Phone Number is a required field.<br>"
	}else{
		if(document.getElementById("contact_phone").value.match(/^((\d{3}-?){2}\d{4})($|(\D+\d+))/gi) == null){
			contactMessage+="Please make sure the Contact Phone Number is in the proper format. (123-456-7890)<br>"
		}
	}
	if(document.getElementById("address").value.length==0){
		contactMessage+="Contact Street Address is a required field.<br>"
	}
	if(document.getElementById("state").selectedIndex==0){
		contactMessage+="Contact State is a required field.<br>"
	}
	if(document.getElementById("contact_zip_code").value.length==0){
		contactMessage+="Contact ZIP Code is a required field.<br>"
	}else{
		if(document.getElementById("contact_zip_code").value.match(/^\d{5}(\D+\d{4})?/gi) == null){
			contactMessage+="Please make sure the Contact ZIP Code is in the proper format. (12345 or 12345-6789)<br>"
		}
	}
	if(document.getElementById("contact_email").value.length==0){
		contactMessage+="Contact Email is a required field.<br>"
	}else{
		if(document.getElementById("contact_email").value.match(/^(\w|\.)+@\w+\.\w+/gi) == null){
			contactMessage+="Please make sure the Email is in the proper format. (user@nyc.gov)<br>"
		}
	}
	if(document.getElementById("contact_web").value.length>0&&document.getElementById("contact_web").value.match(/(https?:\/\/.+)|(www\..+)/gi) == null){
		contactMessage+="Please enter a valid URL for the Web Site. (www.yourwebsite.com)<br>"
	}
	if(document.getElementById("event_description").value.length==0){
		contactMessage+="Event Description is a required field.<br>"
	}
	if(contactMessage.length>0){
		if(errorsMessage.length==0){
			errorsMessage="<b>Errors:</b><br>";
		}
		errorsMessage=errorsMessage+"<br><i>Contact Information:</i><br>"+contactMessage;
	}
	if(errorsMessage.length>0){
		document.getElementById("errors").innerHTML=errorsMessage;
		window.scrollTo(0,0);
		return(false);
	}
}

