
//this function is used to validate all of the forms
function checkForms(formname){
	var date = "";
	var radioCheckName="";
	var radioCheckChecked=false;
	for (var i=0; i<eval("document."+formname+".elements.length"); i++){
		//this function checks to see if the field is null and required, and then returns an error message
    var formElement=eval("document."+formname+".elements[i]");
    var FieldName = getFieldName(formElement.name);
    var CheckReqs = getCheckReqs(formElement.name);
    if((formElement.type=='text')||(formElement.type=='textarea')){
	  if((formElement.value=="" || formElement.value==null) && 	
			CheckReqs.substring(0, 8)=="required")
		  {
				validatePrompt(formElement, errInval(FieldName));
				return false;	
		  }//closes if
		}
		if(CheckReqs.substring(CheckReqs.length-4 , CheckReqs.length)=="_let")
		{	
			if(!vali_name(formElement, errInval(FieldName))){
			  return false;
			}
		}
		
		if(CheckReqs.substring(CheckReqs.length-4 , CheckReqs.length)=="_num")
		{	
			if(!vali_number(formElement, errInval(FieldName))){
				return false;
			}
		}
		
		if(CheckReqs.substring(CheckReqs.length-4 , CheckReqs.length)=="_ema")
		{	
			if(!vali_email(formElement, errInval(FieldName))){
				return false;
			}
		}
		
		if(CheckReqs.substring(CheckReqs.length-4 , CheckReqs.length)=="_sta")
		{	
			if(!vali_state(formElement, errInval(FieldName))){
				return false;
			}
		}

		if(CheckReqs.substring(CheckReqs.length-4 , CheckReqs.length)=="_zip")
		{	
			if(!vali_zip(formElement, errInval(FieldName))){
				return false;
			}
		}
		
		if(CheckReqs.substring(CheckReqs.length-4 , CheckReqs.length)=="_crd")
		{	
				if(!vali_card(eval("document."+formname), 'required_card_type', 'card_type', 'required_crd_card_number', formname)){
					return false;
				}
		}

	
		if((FieldName.search("_date_")!=-1 || FieldName.search("_date1_")!=-1 ||
			FieldName.search("_date2_")!=-1 || FieldName.search("_date3_")!=-1)
			&& FieldName.search("_day")!=-1)
			{
				var monthName=formElement.name.substring(0, formElement.name.lastIndexOf("_"))+"_month";
				var dateName=formElement.name.substring(0, formElement.name.lastIndexOf("_"))+"_day";
				var yearName=formElement.name.substring(0, formElement.name.lastIndexOf("_"))+"_year";
				
				var monthValue=eval("document."+formname+"."+monthName+".value");
				var dateValue=eval("document."+formname+"."+dateName+".value");
				var yearValue=eval("document."+formname+"."+yearName+".value");

				if(monthValue.length==1) monthValue="0"+monthValue;
				if(dateValue.length==1) dateValue="0"+dateValue;
				date=monthValue+"/"+dateValue+"/"+yearValue;

				if(date!="//"){
					if(!vali_checkdate(date, formname, monthName, dateName, yearName, errInval(FieldName))){
						date="";
						return false;
					}
				}
				date="";
			} 
		
		//this validates the hour
		
		if((FieldName.substring(FieldName.length-5 , FieldName.length)=="_hour"))
			{	if(((formElement.value>12)||(formElement.value<1))&&(formElement.value.length!=0)){
				validatePrompt(formElement,errInval(FieldName));
				return false;
				}	
				else if(!vali_number(formElement, errInval(FieldName))){
					return false;
				}
			}
		//this validates minute
				
		if((FieldName.substring(FieldName.length-7 , FieldName.length)=="_minute"))
			{	if((formElement.value>59)&&(formElement.value.length!=0)){
				validatePrompt(formElement,errInval(FieldName));
				return false;
				}	
				else if(!vali_number(formElement, errInval(FieldName))){
					return false;
				}
			}
		//this validates the expiration date month

		if((FieldName.substring(FieldName.length-9 , FieldName.length)=="exp_month"))
			{	if(((formElement.value>12)||(formElement.value<1))&&(formElement.value.length!=0)){
				validatePrompt(formElement,errInval(FieldName));
				return false;
				}	
				else if(!vali_number(formElement, errInval(FieldName))){
					return false;
				}
			}		
		//this validates the expiration year
		if((FieldName.substring(FieldName.length-8 , FieldName.length)=="exp_year"))
			{	if(formElement.value.length!=2){
				validatePrompt(formElement,errInval(FieldName));
				return false;
				}	
				else if(!vali_number(formElement, errInval(FieldName))){
					return false;
				}
			}

			
		if((FieldName.substring(FieldName.length-5 , FieldName.length)=="_area") ||
			(FieldName.substring(FieldName.length-7 , FieldName.length)=="_prefix"))
			{	if((formElement.value.length!=3)&&(formElement.value.length!=0)){
				validatePrompt(formElement,errInval(FieldName));
				return false;
				}	
				else if(!vali_number(formElement, errInval(FieldName))){
					return false;
				}
			}
		if((FieldName.substring(FieldName.length-7 , FieldName.length)=="_suffix"))
			{	if((formElement.value.length!=4)&&(formElement.value.length!=0)){
				validatePrompt(formElement,errInval(FieldName));
				return false;
				}	
				else if(!vali_number(formElement, errInval(FieldName))){
					return false;
				}
			}

		
		
		if(((formElement.type=="radio")||(formElement.type=="checkbox")) && (CheckReqs=="required")){
		  if(radioCheckName==""){
		  	radioCheckName=FieldName;
			}
			else if (radioCheckName!=FieldName){
				if(radioCheckChecked==false){
					alert(errInval(radioCheckName));
					setRadioCheckFocus(formname, radioCheckName);
					return false;
				}
				radioCheckName=FieldName;
				radioCheckChecked=false;
			}//closes else if
			
			if(formElement.checked){
			radioCheckChecked=true;
			}//closes checked if
		
		 } 
	 }	
		if(radioCheckName!=""){
			if(radioCheckChecked==false){
				alert(errInval(radioCheckName));
				setRadioCheckFocus(formname, radioCheckName);
				return false;
			}
		
		}
	
		// cross field validate
		return crossFieldValidate(formname);
}//closes function		

function setRadioCheckFocus(formname, radioCheckName){
  var theForm=eval("document."+formname);
  var pos=0;
  for(i=0; i<theForm.elements.length; i++){
  	if(theForm.elements[i].name.search(radioCheckName)!=-1){
  		pos=i;
  		break;
  	}
  }
  theForm.elements[pos].focus();
}

//my library

//function used to parse out field name
function getFieldName (OldString)
	{
		var FieldName;
		if (OldString.substring(0, 8)=="required")
			{
				if (OldString.substring(8,12)=="_let" || OldString.substring(8,12)=="_num" || OldString.substring(8,12)=="_ema" || OldString.substring(8,12)=="_sta" || OldString.substring(8,12)=="_zip" || OldString.substring(8,12)=="_crd")
					{
						FieldName=OldString.substring(13,OldString.length);
					}
				else
					{
						FieldName=OldString.substring(9,OldString.length);
					}
			}
		else
			{
				if (OldString.charAt(0)=="_")
					{
						FieldName=OldString.substring(5,OldString.length);
					}
				else
					{
						FieldName=OldString;
					}
			}
		return(FieldName);	
	}

//function used to parse out FieldReqs	
function getCheckReqs (OldString)
	{
		var CheckReqs;
		if (OldString.substring(0, 8)=="required")
			{
				if (OldString.substring(8,12)=="_let" || OldString.substring(8,12)=="_num" || OldString.substring(8,12)=="_ema" || OldString.substring(8,12)=="_sta" || OldString.substring(8,12)=="_zip" || OldString.substring(8,12)=="_crd")
					{
						CheckReqs=OldString.substring(0,12);
					}
				else
					{
						CheckReqs=OldString.substring(0,8);
					}
			}
		else
			{
				if (OldString.charAt(0)=="_")
					{
						CheckReqs=OldString.substring(0,4);
					}
				else
					{
						CheckReqs="";					
					}
			}
		return(CheckReqs);
			
	}

//function used to display the errors

function validatePrompt (Ctrl, PromptStr)
	{
		alert (PromptStr);
		Ctrl.focus();
	}


//checks if a valid credit card number has been entered
function vali_card (formobj, type, typename, no, formname)
{

	for(i = 0; i < formobj.elements[type].length; i++)
	{
		var cctype="";
		if(formobj.elements[type][i].checked)
		{
			cctype = formobj.elements[type][i].value;
			break;
		}
	}

	if(cctype=="")
	{
		alert(errInval(typename));
		setRadioCheckFocus (formname, type);
		return false;
	}

	var ccnofield=formobj.elements[no];
	var ccno=formobj.elements[no].value;

	//check number of digits
	if(
	  !(
		  (cctype == 'mastercard' && ccno.length == 16)	||
		  (cctype == 'visa' && (ccno.length == 13 || ccno.length == 16)) ||
		  (cctype == 'american_express' && ccno.length == 15)
	   )
	  )
	{
		validatePrompt (ccnofield, "Invalid credit card number length!");
		return false;
	}
	var sum = 0;
  for (i = 0; i < ccno.length; i++)
	{
		var intval = parseInt(ccno.charAt(ccno.length-i-1),10);
		if(isNaN(intval))
		{
			validatePrompt (ccnofield, "Invalid credit card number!");
			return false;
		}
		if ((i%2) != 0) intval = intval*2;
		sum = sum + intval%10;
		if (intval > 9) sum = sum + 1;
	}
	var modno = sum%10;
	if (modno != 0)
	{
		validatePrompt (ccnofield, "Invalid credit card number!");
		return false;
	}
	else
		return true;
}


// This Function returns true if value is a date format and is equal to or greater than 
	// today's date or is NULL otherwise returns false.  Default or custom error message is
	// displayed.	
	function vali_checkdate(date, formName, monthName, dateName, yearName, PrmtStr)
	{
		var dateString = date;
		var validchar = "01234567890";
		var found;
		monthCtrl=eval("document."+formName+"."+monthName);
		dateCtrl=eval("document."+formName+"."+dateName);
		yearCtrl=eval("document."+formName+"."+yearName);
		
		// set error message
		if (PrmtStr == "")
			PrmtStr = "Invalid date!  Dates should be in format mm/dd/yyyy.";		
		
		

		for (var i=0; i<10; i++)
		{
			found = false;
			for (var j=0; j<10; j++){
				if (dateString.substring(i, i+1) == validchar.substring(j, j+1) )
					found = true;
			}
			if ( (found == false) && (i !=2) && (i!=5) )
			{
				if(i<2)	validatePrompt(monthCtrl, PrmtStr);
				if(i>2 && i<5)	validatePrompt(dateCtrl, PrmtStr);
				if(i>5)	validatePrompt(yearCtrl, PrmtStr);
				return (false);
			}
		}
			
		var mon = parseInt(dateString.substring(0,2),10);
		var day = parseInt(dateString.substring(3,5),10);
		var year = parseInt(dateString.substring(6,10),10);

		// check for valid month
		if ( (mon <1) || (mon >12) )
		{
			validatePrompt(monthCtrl, PrmtStr);
			return(false);
		} 

		//check for valid day
		if ( (day < 1) || (day > 31) )
		{
			validatePrompt(dateCtrl, PrmtStr);
			return(false);
		} 
		//check for valid year
		if ( (year < 1900))
		{
			validatePrompt(yearCtrl, PrmtStr);
			return(false);
		} 
		//check for invalid day
		if ( ( (mon==4) || (mon==6) || (mon==9) || (mon==11) ) && (day == 31) )
		{
			validatePrompt(dateCtrl, PrmtStr);
			return(false);
		} 

		if  (mon == 2)
		{
			// februrary
			if (day > 29)
			{
				validatePrompt(dateCtrl, PrmtStr);
				return(false);
			} 
			// leap year
			if ( ( ( (year-2000)%4) != 0) && (day == 29) )
			{
				validatePrompt(dateCtrl, PrmtStr);
				return(false);
			}
		}
		return(true);  //passed all tests	 
	}	
	
	//This checks that the date entered is less or equal to the current date.
	function vali_checkpastdate(Ctrl) 
		{
			var today = new Date();
			var err = 0;
			var string = Ctrl.value;
			var valid = "0123456789/";
			var ok = "yes";
			var temp;
			var compare;
			
			//for loop to break up the today var.
			for (var i=0; i< today.length; i++)
			{
				compare = "" + today.substring(i, i+1); //compare variable to hold the values
			}
			
			if (Ctrl.value.length!=0)
			{
				for (var i=0; i< string.length; i++)
				{
					temp = "" + string.substring(i, i+1);
					if (valid.indexOf(temp) == "-1") err = 1;
				}
				if (string.length != 10)
				{
					err=1
				}
				
				var b = string.substring(0, 2) // entered month
				var c = string.substring(2, 3)// entered '/'
				var d = string.substring(3, 5) // entered day
				var e = string.substring(5, 6)// entered '/'
				var f = string.substring(6, 10) // entered year
				
				var h = today.substring(0, 2) // today's month
				var i = today.substring(2, 3)// today's '/'
				var j = today.substring(3, 5) // today's day
				var k = today.substring(5, 6)// today's '/'
				var l = today.substring(6, 10) // today's year
				
				//check to see if the date entered is of correct format.
				if (b<1 || b>12)
				{
					err = 1;
				}
				if (c != '/')
				{
					err = 1;
				}
				if (d<1 || d>31)
				{
					err = 1;
				}
				if (e != '/')
				{
					err = 1;
				}
								
				if (b==4 || b==6 || b==9 || b==11)
				{
					if (d==31)
					{
						err=1;
					}
				}
				if (b==2)
				{
					var g = parseInt(f/4,10)
					if (isNaN(g))
					{
						err=1;
					}
					if (d>29)
					{
						err=1;
					}
					if (d==29 && ((f/4)!=parseInt(f/4,10)))
					{
						err=1;
					}
				}
				
				//compare the date entered to today's date
				if (f > l)//compare the year
				{
					err = 2;
				}
				else if (b > h && f == l)//compare the months
				{
					err = 2;
				}
				else if (d > j && f == l && b ==h)//compare the days
				{
					err = 2;
				}
				if (err==1)
				{
					validatePrompt (Ctrl, "Invalid  entry!  Please enter the date in the MM/DD/YYYY format");
					return(false);
				}
							
				if (err==2)
				{
					validatePrompt (Ctrl, "Please enter a past or present date.  Future dates are not valid!");
					return(false);
				}
			}
			return(true);	
		}

//this function checks for only integers
function vali_integer(Ctrl, PrmtStr)
	{
		var validchar = "1234567890";
		var ok = true;
		if (!(Ctrl.value.length==0))
		{
			for (var i=0; i<Ctrl.value.length; i++)
			{
				if (validchar.indexOf(Ctrl.value.charAt(i))==-1)
				{
					ok = false;
				} 
			}
		}
		if (!ok)
		{
			if (PrmtStr == "")
				validatePrompt (Ctrl, "Invalid entry!  Only integers are accepted!");
			else
				validatePrompt (Ctrl, PrmtStr);
		}
		return(ok);
	} 
	
	//checks if a valid state has been entered
	function vali_state (Ctrl, PrmtStr) {
		if(Ctrl.value.length!=2){
			validatePrompt(Ctrl, PrmtStr);
			return false;
		}
		else if(!vali_char(Ctrl, PrmtStr)){
			validatePrompt(Ctrl, PrmtStr);
			return false;
		}
		else {
			return true;
		}
	}

	//this checks for letters
	function vali_char(Ctrl, PrmtStr)
	{
		var validchar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var ok = true;
		if (!(Ctrl.value.length==0))
		{

			for (var i=0; i<Ctrl.value.length; i++)
			{
				if (validchar.indexOf(Ctrl.value.charAt(i))==-1)
				{
					ok = false;
				} 
			}
		}
		return(ok);
	}		

	//this checks for letters and symbols
	function vali_name(Ctrl, PrmtStr)
	{
		var validchar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,'() ";
		var ok = true;
		if (!(Ctrl.value.length==0))
		{

			for (var i=0; i<Ctrl.value.length; i++)
			{
				if (validchar.indexOf(Ctrl.value.charAt(i))==-1)
				{
					ok = false;
				} 
			}
		}
		
		if (!ok)
		{
			if (PrmtStr == "")
				validatePrompt (Ctrl, "Invalid entry!  Only characters are accepted!");
			else
				validatePrompt (Ctrl, PrmtStr);
		}
		return(ok);
	}                 
//this function validates email
function vali_email(Ctrl, PrmtStr)
	{
		if (!(Ctrl.value==""))
		{
        	if (Ctrl.value.indexOf ('@', 0) == -1)
			{
				if (PrmtStr == "")
	                validatePrompt (Ctrl, "Invalid entry!  Please enter a valid email address");
      				else
					validatePrompt (Ctrl, PrmtStr);
		        return (false);
        	} 
			else if (Ctrl.value.indexOf ('.', 0) == -1)
			{
				if (PrmtStr == "")
	                validatePrompt (Ctrl, "Invalid entry!  Please enter a valid email address");
      				else
					validatePrompt (Ctrl, PrmtStr);
		        return (false);
        	}
			else
			{
                return (true);
			}
		} 
		else return (true);
	}
		
	
	// This function validates that the value entered was a number only. The PrmtStr or
	// generic message is displayed in case of error.
	function vali_number(Ctrl, PrmtStr)
		{
			var validchar = "1234567890.";
			var ok = true;
			if (!(Ctrl.value.length==0))
			{
				for (var i=0; i<Ctrl.value.length; i++)
				{
					if (validchar.indexOf(Ctrl.value.charAt(i))==-1)
					{
						ok = false;

					} else if (Ctrl.value.charAt(i)=='.') {

						validchar = validchar.substring(0,validchar.length-1);
					}
				}
			}
			if (!ok)
			{
				if (PrmtStr == "")
	        		validatePrompt (Ctrl, "Invalid entry!  Only numbers are accepted!");
				else
					validatePrompt (Ctrl, PrmtStr);
            	return (false);
			}
			return(ok);
		}                
		//this function validates zip codes.
		function vali_zip(Ctrl, PrmtStr) 
	{
		var valid = "0123456789";
		if (Ctrl.value.length!=0)
		{
			// ZIP can be six if 5 digits and - e.g. 12345-
			if (Ctrl.value.length!=5 && Ctrl.value.length!=10 && Ctrl.value.length!=6)
			{
				if (PrmtStr == "")
					validatePrompt (Ctrl, "Invalid entry!  Please enter your 5 digit or 5 digit - 4 zip code:");
				else
					validatePrompt (Ctrl, PrmtStr);
				return (false);
			} else
			{
				var ok = true;
				for (var i=0; i<5; i++)
				{
					if (valid.indexOf(Ctrl.value.charAt(i))==-1)
					{
						ok = false;
					} 
				}
				if (!ok)
				{
					if (PrmtStr == "")
						validatePrompt (Ctrl, "Invalid entry!  You have entered invalid characters!");
					else
						validatePrompt (Ctrl, PrmtStr);
					return false;
				}
				if (Ctrl.value.length>5)
				{
					if (Ctrl.value.charAt(5)!="-")
					{
						if (PrmtStr == "")
							validatePrompt (Ctrl, "Invalid entry! You have entered an invalid zip code!");
						else
							validatePrompt (Ctrl, PrmtStr);
						return false;
					} 
					else
					{
						if (Ctrl.value.length==10)
						{
							for (var i=6; i<11; i++)
							{
								if (valid.indexOf(Ctrl.value.charAt(i))==-1)
								{
									ok=false;
								}
							}
							if (!ok)
							{
								if (PrmtStr == "")
									validatePrompt (Ctrl, "Invalid entry! You have entered an invalid zip code!");
								else
									validatePrompt (Ctrl, PrmtStr);
								return false;
							}
						}
					}
				}
			}
		}
		return (true);
	}


//error messages for when fields are left blank

function errInval(name)
{//request a tree
	var value="There is an unknown error in processing your request.  Please make sure all fields are filled in properly.";

	if (name=="firstname")
		{
			value= "Please fill in a valid first name!";
		}

	else if (name=="lastname")
		{
   			value= "Please fill in a valid last name!";
		}
	else if (name=="middleinitial")
		{
   			value= "Please fill in a valid middle initial!";
		}
		else if (name=="address1")
		{
   			value= "Please fill in your address!";
		}
	else if (name=="email")
		{
   			value= "Please fill in a valid email address!";
		}
	else if(name=="city")
		{
			value= "Please fill in valid city information!";	
		}
	else if(name=="state")
		{
			value= "Please fill in valid state information!";	
		}
 	else if(name=="zip")
		{
			value= "Please fill in a valid zip code!";	
		}
	else if(name=="phone_area")
		{
			value= "Please fill in a valid phone number!";	
		}
	else if(name=="phone_prefix")
		{
			value= "Please fill in a valid phone number!";	
		}
	else if(name=="phone_suffix")
		{
			value= "Please fill in a valid phone number!";	
		}
	else if(name=="tree_street_address")
		{
			value= "Please enter address of the tree!";	
		}
	else if(name=="tree_cross_street1")
		{
			value= "Please enter the cross streets!";	
		}
	else if(name=="tree_cross_street2")
		{
			value= "Please enter the cross streets!";	
		}
		else if(name=="borough")
		{
			value= "Please select the borough.";	
		}
	else if(name=="exist_tree_pit")
		{
			value= "Please specify whether or not there is an existing tree pit in the location of the tree to be planted.";	
		}
	else if(name=="exist_stump")
		{
			value= "Please specify whether or not there is an existing stump in the existing tree pit.";	
		}
	else if(name=="has_dead_tree")
		{
			value= "Please specify whether or not there is a dead tree in the existing tree pit.";	
		}
	else if(name=="exist_vault")
		{
			value= "Please specify whether or not there is a vault beneath the sidewalk.";	
		}
	else if(name=="owner_aware")
		{
			value= "Please specify whether or not you have notified the property owner of your request for a street tree.";	
		}
	else if(name=="board_aware")
		{
			value= "Please specify whether or not you have notified your community board of your request for a street tree.";
		}
	else if(name=="stump_no_dead_tree")
		{
			value= "Please answer 'Yes' to either has a dead tree or has a tree stump question, but not both.";
		}
	else if(name=="existing_tree_pit")
		{
			value= "Because there is no existing tree pit, there should be no stump nor a dead tree in it.";
		}
	else if(name=="agreebox")
		{
			value= "Please check the checkbox to acknowledge the form submission agreement.";
		}
		//closes request a tree

//deadtree
	else if(name=="two_year_tree")
		{
			value= "Please specify whether or not the tree was planted within the last two years!";	
		}//closes dead tree
	
//lifeguard
	else if(name=="advertise")
		{
			value= "Please specify where you heard about NYC lifeguard employment opportunities!";	
		}
		
	//closes lifeguard
//tennis-none

//special events
//event park name and event type are not validated because they could include numbers, correct? 

	else if(name=="contact1_name")
		{
			value= "Please enter a valid name of a first alternate contact!";	
		}
	else if(name=="contact1_phone_area")
		{
			value= "Please enter a valid telephone number for the first alternate contact!";	
		}
	else if(name=="contact1_phone_prefix")
		{
			value= "Please enter a valid telephone number for the first alternate contact!";	
		}
	else if(name=="contact1_phone_suffix")
		{
			value= "Please enter a valid telephone number for the first alternate contact!";	
		}
	else if(name=="fax_area")
		{
			value= "Please enter a valid fax number!";	
		}
	else if(name=="fax_prefix")
		{
			value= "Please enter a valid fax number!";	
		}
	else if(name=="fax_suffix")
		{
			value= "Please enter a valid fax number!";	
		}
	else if(name=="contact2_name")
		{
			value= "Please enter a valid name of a second alternate contact!";	
		}
	else if(name=="contact2_phone_area")
		{
			value= "Please enter a valid telephone number for the second alternate contact!";	
		}
	else if(name=="contact2_phone_prefix")
		{
			value= "Please enter a valid telephone number for the second alternate contact!";	
		}
	else if(name=="contact2_phone_suffix")
		{
			value= "Please enter a valid telephone number for the second alternate contact!";	
		}
	//should we validate organization name?
	else if(name=="org_phone_area")
		{
			value= "Please enter a valid telephone number for the organization!";	
		}
	else if(name=="org_phone_prefix")
		{
			value= "Please enter a valid telephone number for the organization!";	
		}
	else if(name=="org_phone_suffix")
		{
			value= "Please enter a valid telephone number for the organization!";	
		}
	else if(name=="event_type")
		{
			value= "Please enter the type of event!";	
		}
	else if(name=="event_borough")
		{
			value= "Please select the borough.";	
		}

	else if(name=="event_park_name")
		{
			value= "Please enter a park!";	
		}
	
	else if(name=="event1_date_day")
		{
			value= "Please enter a valid date!";	
		}
	else if(name=="event1_date_month")
		{
			value= "Please enter a valid date!";	
		}
	else if(name=="event1_date_year")
		{
			value= "Please enter a valid date!";	
		}
	else if(name=="event2_date_day")
		{
			value= "Please enter a valid date!";	
		}
	else if(name=="event2_date_month")
		{
			value= "Please enter a valid date!";	
		}
	else if(name=="event2_date_year")
		{
			value= "Please enter a valid date!";	
		}
	else if(name=="event3_date_day")
		{
			value= "Please enter a valid date!";	
		}
	else if(name=="event3_date_month")
		{
			value= "Please enter a valid date!";	
		}
	else if(name=="event3_date_year")
		{
			value= "Please enter a valid date!";	
		}
	//should we validate previous event parks and events?
//closes special events one
//should we validate event type, park, etc on special events two?
	else if(name=="activity_detail")
		{
			value= "Please describe the planned activities in detail!";	
		}
	else if(name=="event_date_month")
		{
			value= "Please enter a valid event date!";	
		}
	else if(name=="event_date_day")
		{
			value= "Please enter a valid event date!";	
		}
	else if(name=="event_date_year")
		{
			value= "Please enter a valid event date!";	
		}
   /*
	else if(name=="rain_date_month")
		{
			value= "Please enter a valid rain date!";	
		}
	else if(name=="rain_date_day")
		{
			value= "Please enter a valid rain date!";	
		}
	else if(name=="rain_date_year")
		{
			value= "Please enter a valid rain date!";	
		}
     */
       else if(name== "event_park_location")
		{
			value= "Please enter a location in Park!";
		}
	else if(name=="attend_people_num")
		{
			value= "Please enter a valid number of people expected to attend the event!";	
		}
	else if(name=="event_start_time_hour")
		{
			value= "Please enter a valid event start time!";	
		}
	else if(name=="event_start_time_minute")
		{
			value= "Please enter a valid event start time!";	
		}
	else if(name=="event_start_time_am_pm")
		{
			value= "Please select A.M. or P.M for the event start time!";	
		}
	
	else if(name=="event_end_time_hour")
		{
			value= "Please enter a valid event end time!";	
		}
	else if(name=="event_end_time_minute")
		{
			value= "Please enter a valid event end time!";	
		}
	else if(name=="event_end_time_am_pm")
		{
			value= "Please select A.M. or P.M for the event end time!";	
		}
	else if(name=="setup_start_time_hour")
		{
			value= "Please enter a valid set-up start time!";	
		}
	else if(name=="setup_start_time_minute")
		{
			value= "Please enter a valid set-up start time!";	
		}
	else if(name=="setup_start_time_am_pm")
		{
			value= "Please select A.M. or P.M for the setup start time!";	
		}
	else if(name=="clean_end_time_hour")
		{
			value= "Please enter a valid clean up end time!";	
		}
	else if(name=="clean_end_time_minute")
		{
			value= "Please enter a valid clean up end time!";	
		}
	
	else if(name=="clean_end_time_am_pm")
		{
			value= "Please select A.M. or P.M for the clean up end time!";	
		}
	else if(name=="activity_detail")
		{
			value= "Please describe the planned activities in detail!";	
		}
		//closes special event two
	else if(name=="is_participate_charged")
		{
			value= "Please select whether or not the participants will be charged!";	
		}
	else if(name=="is_food_sale")
		{
			value= "Please select whether or not there will be food for sale!";	
		}
	else if(name=="is_merchandise_sale")
		{
			value= "Please select whether or not there will be merchandise for sale!";	
		}
	else if(name=="is_vendor_fee")
		{
			value= "Please select whether or not there will be a vendor participation fee!";	
		}
	else if(name=="is_insured")
		{
			value= "Please select whether or not you have insurance!";	
		}
	else if(name=="is_free_items_distributed")
		{
			value= "Please select whether or not there will be any free items distributed!";	
		}
	else if(name=="is_event_advertised")
		{
			value= "Please select whether or not the event will be advertised!";	
		}
	else if(name=="is_security_provided")
		{
			value= "Please select whether or not you have made any provision for on-site security!";	
		}
	else if(name=="is_medical_service_provided")
		{
			value= "Please select whether or not you have made any provision for on-site medical services!";	
		}
	else if(name=="is_extra_equipment_needed")
		{
			value= "Please select whether or not you plan to bring any extra equipment into the park!";	
		}
	else if(name=="is_vehicle_driven")
		{
			value= "Please select whether or not you plan to drive vehicles onto parkland!";	
		}
	else if(name=="is_amplifier_used")
		{
			value= "Please select whether or not you plan to have amplified sound at your event!";	
		}
		else if(name=="agreement")
		{
			value= "Please select whether or not you agree to the terms!";	
		}
		else if(name=="past_date")
		{
			value= "The date you enter should be a past date.";	
		}
		else if(name=="future_date")
		{
			value= "The date you enter should be a future date.";	
		}
		else if(name=="setup_time_err")
		{
			value= "The setup time should be earlier than the event start time.";
		}
		else if(name=="cleanup_time_err")
		{
			value= "The clean up time should be later than the event end time.";
		}
		else if(name=="future_21_day_err")
		{
			value= "All event applications must be submitted at least 21 days prior to the requested date.  For more information call your borough special events office.";
		}
		//ends special event 3

	
	
//guidelines
	else if(name=="is_guidelines")
		{
			value= "You must agree to the guidelines above to continue!";	
		}
//sportschoose
	else if(name=="permit_type")
		{
			value= "You must select the type of permit you are applying for to continue!";	
		}//ends sportschoose
	
//sportsleague
//name of court/field choices are not validated because they could include numbers and letters, correct? 
	else if(name=="sport")
		{
			value= "Please select sport!";	
		}
	else if(name=="eighteen")
		{
			value= "Please indicate whether or not any of the players are over the age of 18!";
		}	
	else if(name=="players_number")
		{
			value= "Please fill in a valid number of players per team!";	
		}
	else if(name=="team_number")
		{
			value= "Please fill in a valid number of teams in the league!";	
		}
	else if(name=="court_choice1")
		{
			value= "Please fill in first choice of court/field!";	
		}	
	else if(name=="start_date1_month")
		{
			value= "Please fill in a valid start date!";	
		}
	else if(name=="start_date1_day")
		{
			value= "Please fill in a valid start date!";	
		}
	else if(name=="start_date1_year")
		{
			value= "Please fill in a valid start date!";	
		}
	else if(name=="end_date1_month")
		{
			value= "Please fill in a valid end date!";	
		}
	else if(name=="end_date1_day")
		{
			value= "Please fill in a valid end date!";	
		}
	else if(name=="end_date1_year")
		{
			value= "Please fill in a valid end date!";	
		}
	else if(name=="start_time1_hour")
		{
			value= "Please fill in a valid start time!";	
		}
	else if(name=="start_time1_minute")
		{
			value= "Please fill in a valid start time!";	
		}
	else if(name=="start_time1_am_pm")
		{
			value= "Please indicate start time A.M. or P.M.!";	
		}
	
	else if(name=="end_time1_hour")
		{
			value= "Please fill in a valid end time!";	
		}
	else if(name=="end_time1_minute")
		{
			value= "Please fill in a valid end time!";	
		}
	else if(name=="end_time1_am_pm")
		{
			value= "Please indicate end time A.M. or P.M.!";	
		}
	else if(name=="start_date2_month")
		{
			value= "Please fill in a valid start date!";	
		}
	else if(name=="start_date2_day")
		{
			value= "Please fill in a valid start date!";	
		}
		else if(name=="start_date2_year")
		{
			value= "Please fill in a valid start date!";	
		}
	else if(name=="end_date2_month")
		{
			value= "Please fill in a valid end date!";	
		}
	else if(name=="end_date2_day")
		{
			value= "Please fill in a valid end date!";	
		}
	else if(name=="end_date2_year")
		{
			value= "Please fill in a valid end date!";	
		}
	else if(name=="start_time2_hour")
		{
			value= "Please fill in a valid start time!";	
		}
	else if(name=="start_time2_minute")
		{
			value= "Please fill in a valid start time!";	
		}
	
	else if(name=="end_time2_hour")
		{
			value= "Please fill in a valid end time!";	
		}
	else if(name=="end_time2_minute")
		{
			value= "Please fill in a valid end time!";	
		}
	else if(name=="start_date3_month")
		{
			value= "Please fill in a valid start date";	
		}
	else if(name=="start_date3_day")
		{
			value= "Please fill in a valid start date";	
		}
	else if(name=="start_date3_year")
		{
			value= "Please fill in a valid start date";	
		}
	else if(name=="end_date3_month")
		{
			value= "Please fill in a valid end date";	
		}
	else if(name=="end_date3_day")
		{
			value= "Please fill in a valid end date";	
		}
	else if(name=="end_date3_year")
		{
			value= "Please fill in a valid end date";	
		}
	else if(name=="start_time3_hour")
		{
			value= "Please fill in a valid start time!";	
		}
	else if(name=="start_time3_minute")
		{
			value= "Please fill in a valid start time!";	
		}
	
	else if(name=="end_time3_hour")
		{
			value= "Please fill in a valid  end time!";	
		}
	else if(name=="end_time3_minute")
		{
			value= "Please fill in a valid  end time!";	
		}
	else if(name=="day_choice1")
		{
			value= "Please indicate the day(s) of the week for which you would like to request a permit!";		
		}
		//league additional
	else if(name=="league_type")
		{
			value= "Please select type of league!";	
		}
	else if(name=="league_name")
		{
			value= "Please fill in the name of the league!";	
		}
	else if(name=="permit_years")
		{
			value= "Please indicate how many consecutive years the league has received permits!";	
		}
	else if(name=="membership_fee")
		{
			value= "Please indicate whether or not teams pay membership to the league!";	
		}
	else if(name=="official_compensated")
		{
			value= "Please indicate whether or not league officials are compensated!";	
		}
	else if(name=="permit_years")
		{
			value= "Please fill in a valid number of consecutive years the league has received permits!";	
		}
	
	else if(name=="old_permit_number")
		{
			value= "Please fill in a valid permit number from last year!";	
		}
	else if(name=="league_membership_fee")
		{
			value= "Please fill in a valid membership fee!";	
		}
	
		//ends league additional
//sports school
	else if(name=="school_name")
		{
			value= "Please fill in school name!";	
		}
	else if(name=="school_league")
		{
			value= "Please fill in the name of the league!";	
		}
	else if(name=="school_level")
		{
			value= "Please select type of school!";	
		}
	else if(name=="competition_level")
		{
			value= "Please select level of competition!";	
		}//ends school
	
//other
	else if(name=="is_team_in_league")
		{
			value= "Please indicate whether or not the teams are part of a league!";	
		}//ends other
	
//details
	else if(name=="spectators_number")
		{
			value= "Please fill in a valid number of spectators!";	
		}
//can we validate money values-how much spectators are charged, insurance rate?
	else if(name=="spectator_charge")
		{
			value= "Please indicate how much spectators will be charged!";	
		}
	
//What do we do about insurance rate being that it is only required given that the insurance rate=yes?
	else if(name=="insurance_rate")
		{
			value= "Please fill in a valid insurance rate!";	
		}
	else if(name=="sponsorship_exist")
		{
			value= "Please indicate whether or not there will be sponsorship signage at the event!";	
		}
	else if(name=="vendors_exist")
		{
			value= "Please indicate whether or not there will be vendors at event!";	
		}
	else if(name=="advertised")
		{
			value= "Please indicate whether or not the event will be advertised!";	
		}
	else if(name=="amplifier_used")
		{
			value= "Please indicate whether or not you will be using amplified sound!";	
		}
	else if(name=="security")
		{
			value= "Please indicate whether or not there will be on-site security services!";	
		}

	else if(name=="medical")
		{
			value= "Please indicate whether or not there will be on-site medical services!";	
		}
	else if(name=="insurance")
		{
			value= "Please indicate whether or not your organization has insurance!";	
		}
	else if(name=="terms")
		{
			value= "You must agree to the terms above in order to submit your request!";	
		}
	else if(name=="start_end_dates")
		{
			value= "Event start date should not be later than the end date";	
		}
	else if(name=="start_end_times")
		{
			value= "Event start time should not be later than the end time";	
		}//ends sports details

//sports all
	else if(name=="one_season_only")
		{
			value= "A single permit cannot span 2 permit seasons.\r\nPlease apply for a single season permit.\r\nThe Spring/Summer Season is Apr. 13 - Sept. 2.\r\nThe Fall Season is Sept. 14 - Dec. 1.";	
		}


//payment
	else if(name=="bill_name")
		{
			value= "Please fill in name exactly as it appears on the credit card!";	
		}
	else if(name=="bill_address1")
		{
			value= "Please fill in your billing address!";	
		}
	
	else if(name=="bill_city")
		{
			value= "Please fill in a valid city for your billing address!";	
		}
	else if(name=="bill_state")
		{
			value= "Please fill in a valid state for your billing address!";	
		}
	else if(name=="bill_zip")
		{
			value= "Please fill in a valid zip code of your billing address!";	
		}
	else if(name=="bill_email")
		{
			value= "Please fill in a valid email address!";	
		}
	else if(name=="card_type")
		{
			value= "Please select type of credit card!";	
		}
	
	else if(name=="card_number")
		{
			value= "Please fill in a valid credit card number!";	
		}
	else if(name=="exp_month")
		{
			value= "Please fill in a valid expiration date for your credit card!";	
		}
	else if(name=="exp_year")
		{
			value= "Please fill in a valid expiration date for your credit card!";	
		}//closes payment
		//closes league one
		
  // all
  else if(name="not_ny_zip"){
  	value= "Please enter a New York zip code";
  }
		
	return value;


}//closes function

// if a different country is selected other than US, state or zip will not be checked.
function countrychange(countryelement, formelement)
{
  var isCurrentlyUS=true;

  for (i=0; i<formelement.elements.length; i++){
     if(formelement.elements[i].name=="state" || formelement.elements[i].name=="zip"){
       isCurrentlyUS=false;
     }
  }
  if(countryelement.options[countryelement.selectedIndex].value != "United States"){
     if(isCurrentlyUS){
	formelement.required_sta_state.name="state";
	formelement.required_zip_zip.name="zip";
     }
  }
  else{
     if(!isCurrentlyUS){
	formelement.state.name="required_sta_state";
	formelement.zip.name="required_zip_zip";
     }
  }
}

function my_win(url)
{
window.open( url,'mywindow','width=700,height=500,toolbar=yes,location=yes,directories=yes,status=yes, menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
}

