/* Publicity Form Validation */
var maxRows=10;
var rowCount=1;
var rows = new Array();

/* On Startup, 'hide' all rows for the multi-date event listing (they appear when you click the button to say "Add New Date") */
function hideRows()
{
for(i=0;i<maxRows;i++) 
  {
	  rows[i] =  document.getElementById("row_"+i);
	  if(i>0) rows[i].style.display="none"; 
  }
}

/* Removes event information when switching between tabs for "Single Day Event" and "Multi Day Event" to prevent confusion with the date/time data */
function removeEventInfo(which)
{

	if(which=="single")
	{
		  document.getElementById("time").value="";
		  document.getElementById("start_date").value="";
          document.getElementById("start_date_span").innerHTML="";
		  document.getElementById("event_length").value="multi";
	}
	else
	{
		for(i=0;i<maxRows;i++) removeDateRow(i);
		rows[0].style.display="";
		
		 document.getElementById("event_length").value="single";
	}
	
	
}


/* Validations the publicity form when the user hits the Submit Buttons */
function validatePubForm(form)
{
	
	var i,j;
	var errors=0;
	var message = "";
			  

    for (i=0;i<form.elements.length;i++)
	{
		j = form.elements[i];
		
		//Non-Required Fields
		if(!j.title) continue;
		
		if((j.id=="start_date_0" || j.id=="time_0") && document.getElementById("event_length").value=="single") continue;
		if((j.id=="start_date" || j.id=="time") && document.getElementById("event_length").value=="multi") continue;


		if (!j.value)
		{
			message += " - " + j.title + " is empty \n";
			errors++;
		}
			
	}
	
	if(errors==0) return true;
	
	
	message = "-------------------------------------------------\nPlease correct the following " + errors + " errors:\n-------------------------------------------------\n\n" + message;
	alert(message);
	return false;
	

	
}

//show a date row if we have clicked the buttom that says "Add new Date"
//find the next available date row that is hidden from the screen.
function writeDateRow()
         {
			
			 for(i=rowCount; i<maxRows;i++)
			 {
				if(rows[i].style.display!="none") { continue; }
				else
				{
					rows[i].style.display="";
					return;
				} 
			
			 }
			 
		 }
			 

		   
//hide a date row if we have clicked the buttom that says " X " next to the row.
//reset some variables such as time, date, etc.	
			function removeDateRow(num)
            {
								
				var testnum = parseInt(num);
				if (isNaN (testnum)) return;
				
				
    		    document.getElementById("time_"+num).value="";
		        document.getElementById("start_date_"+num).value="";
                document.getElementById("start_date_span_"+num).innerHTML="";

		        rows[num].style.display="none";
           } 