function validate_rsvp()
{
  	msg = '';  
		valid = true;
		if (document.theForm.email.value)
		{
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.theForm.email.value)))
			{
				msg += "Invalid E-mail Address! Please re-enter.";
				valid = false;
			}
		}
		
		if (document.theForm.response[0].checked)
		{
	    	if ( document.theForm.spaces.value < 1)
	    	{
	       		msg +=  "Please select the number of guests attending." ;
	        	valid = false;
	    	}
		}
		
		if (document.theForm.numGuests.selectedIndex >=1 && document.theForm.eventCost.value > 0)
		{
			if(!(document.theForm.cc_name.value))
			{
				msg += "Please enter the name on the credit card.\n" ;
	      valid = false;
			}
			
			if(!(document.theForm.cc_address.value))
			{
				msg += "Please enter your credit card billing address.\n" ;
	      valid = false;
			}
			
			if(!(document.theForm.cc_zipcode.value))
			{
				msg += "Please enter your billing address zipcode.\n" ;
	      valid = false;
			}

			if(!(document.theForm.cc_number.value))
			{
				msg += "Please enter your credit card number.\n" ;
	      valid = false;
			}
			
			if(!(document.theForm.cc_exp.value))
			{
				msg += "Please enter your credit card expiration date.\n" ;
	      valid = false;
			}
			
			if(!(document.theForm.cc_cvv.value))
			{
				msg += "Please enter the three digit number from the back of your credit card.\n" ;
	      valid = false;
			}
			
		}
		
		//if msg alert
		if (msg)
		{
			alert (msg);
		}
		
    return valid;
}

function validate_event()
{
    msg = '';
		valid = true;
		
		//make day 2 digits
		day = document.theForm.day.value;
		if( day.length < 2)
		{
			formatDay = '0'+day;
		}
		else
		{
			formatDay = day;
		}
		
		endDay = document.theForm.endday.value;
		if( endDay.length < 2)
		{
			formatEndDay = '0'+endDay;
		}
		else
		{
			formatEndDay = endDay;
		}
		
		rsvpDay = document.theForm.rsvp_day.value;
		if( endDay.length < 2)
		{
			formatRsvpDay = '0'+rsvpDay;
		}
		else
		{
			formatRsvpDay = rsvpDay;
		}

		startDate = document.theForm.year.value + document.theForm.month.value + formatDay;
		endDate = document.theForm.endyear.value + document.theForm.endmonth.value + formatEndDay;
		rsvpDate = document.theForm.rsvp_year.value + document.theForm.rsvp_month.value + formatRsvpDay;
		
		//set time to 24 hour

		if (document.theForm.pm.selectedIndex == 1 && parseInt(document.theForm.hour.value) < 12)
		{
			startHour = (parseInt(document.theForm.hour.value) + 12);
		}
		else
		{
			startHour = document.theForm.hour.value;
		}
		
		if (document.theForm.end_pm.selectedIndex == 1)
		{
			endHour = (parseInt(document.theForm.end_hour.value) + 12);
		}
		else
		{
			endHour = document.theForm.end_hour.value ;
		}
		

		//make minute 2 digits
		StartMinute = document.theForm.minute.value;
		if( StartMinute.length < 2)
		{
			formatMinute = '0'+StartMinute;
		}
		else
		{
			formatMinute = StartMinute;
		}
		
		endMinute = document.theForm.end_minute.value;
		if( endMinute.length < 2)
		{
			formatEndMinute = '0'+endMinute;
		}
		else
		{
			formatEndMinute = endMinute;
		}
		
		startTime = startHour + formatMinute;
		endTime = endHour + formatEndMinute;
		
		//check start date before or equal to end date
		if (parseInt(startDate) > parseInt(endDate))
		{
				msg += "End Date cannot be before the Start Date.\n" ;
	      valid = false;
		}
		
		//Check start time before end time
		if (parseInt(startTime) > parseInt(endTime))
		{
				msg += "End Time cannot be before the Start Time.\n" ;
	      valid = false;
		}
		
		//check event title
		if (!(document.theForm.subject.value))
		{
	        msg += "Please enter an event Title.\n" ;
	        valid = false;
	   }
	   
		//check event description
		if (!(document.theForm.description.value))
		{
	        msg += "Please enter an event description.\n" ;
	        valid = false;
	   }
		
		//if RSVP, check deadline before or equal  to event date
		if (document.getElementById('_rsvp').checked)
		{
			if (parseInt(rsvpDate) > parseInt(startDate))
			{
					msg += "RSVP Deadline cannot be after the Start Date.\n" ;
		      valid = false;
			}
			
			if (!(document.theForm.rsvp_contact.value))
			{
					msg += "Please enter an RSVP contact email.\n" ;
		      valid = false;
			}
		}

		if (document.theForm.addupcoming.checked)
		{ 
			var deleted = '';
			var currentCount = document.getElementById('_upcoming_count').value
			
			if ( parseInt(currentCount) == 10)
			{
				
					if (!document.theForm.upcoming1.checked)
					{
						deleted = 1;
					}
				
					if (!document.theForm.upcoming2.checked)
					{
						deleted = 1;
					}
					
					if (!document.theForm.upcoming3.checked)
					{
						deleted = 1;
					}
					
					if (!document.theForm.upcoming4.checked)
					{
						deleted = 1;
					}
					
					if (!document.theForm.upcoming5.checked)
					{
						deleted = 1;
					}
					
					if (!document.theForm.upcoming6.checked)
					{
						deleted = 1;
					}
					
					if (!document.theForm.upcoming7.checked)
					{
						deleted = 1;
					}
					
					if (!document.theForm.upcoming8.checked)
					{
						deleted = 1;
					}
					
					if (!document.theForm.upcoming9.checked)
					{
						deleted = 1;
					}
					
					if (!document.theForm.upcoming10.checked)
					{
						deleted = 1;
					}
					
				if (deleted!=1)
				{
					msg += "Please uncheck on of the current upcoming events.\n" ;
			    valid = false;
				}
			}
			
			
			
		}
		//if msg alert
		if (msg)
		{
			alert (msg);
		}
		
    return valid;
}

function validate_category()
{
		valid = true;
		if (!(document.theForm.category_title.value))
		{
	        alert ( "Please enter a category title." );
	        valid = false;
	   }
		
    return valid;
}


