
function Validate()
{
	var answerinquiry=true
	
	var CALLER_EMAIL=document.inquiry.CALLER_EMAIL.value
	var CALLER_STATE=document.inquiry.CALLER_STATE.value
	var CALLER_FNAME=document.inquiry.CALLER_FNAME.value
	var CALL_NOTE=document.inquiry.CALL_NOTE.value
	var RESPONDING_OFFICER=document.inquiry.RESPONDING_OFFICER.value
	var CLUSTER=document.inquiry.CLUSTER.value
	var CALL_RESPONSE=document.inquiry.CALL_RESPONSE.value
	var CALLER_CITY=document.inquiry.CALLER_CITY.value
	var CALLER_FAX=document.inquiry.CALLER_FAX.value
	var CALLER_FNAME=document.inquiry.CALLER_LNAME.value
	var REFERED_TO=document.inquiry.REFERED_TO.value
	var CALLER_ZIP=document.inquiry.CALLER_ZIP.value
	var CALLER_EMAIL=document.inquiry.CALLER_EMAIL.value
	var CALLER_PHONE=document.inquiry.CALLER_PHONE.value
	var CALL_TOPIC=document.inquiry.CALL_TOPIC.value
	var CALLER_STREET=document.inquiry.CALLER_STREET.value
	var CALLER_ID=document.inquiry.CALLER_ID.value
	var INQUIRY_SOURCE=document.inquiry.INQUIRY_SOURCE.value
	var CALLER_ORG=document.inquiry.CALLER_ORG.value

//Checks to see how CSPI should respond
	{
		for (i=0;  i<document.inquiry.REPLY.length; i++)
			{
				if (document.inquiry.REPLY[i].checked)
					{
						//user requests a response
						//now see what type of response is needed
						if(document.inquiry.REPLY[i].value=="EMAIL")
			   	 			{answerinquiry=true;
					   	 	var REQUEST_RESPONSE="Y";
					   	 	var CALLER_SUBMITS="EMAIL";
							}   	 	
					  	 if(document.inquiry.REPLY[i].value=="PHONE")
							{answerinquiry=true;
					   	 	var REQUEST_RESPONSE="Y";
					   	 	var CALLER_SUBMITS="PHONE";
							}   	 	
						if(document.inquiry.REPLY[i].value=="FAX")
					   	 	{answerinquiry=true;
					   	 	var REQUEST_RESPONSE="Y";
					   	 	var CALLER_SUBMITS="FAX";
							}   	 	
					   	 if(document.inquiry.REPLY[i].value=="POSTAL_SERVICE")
					   	 	{answerinquiry=true;
					   	 	var REQUEST_RESPONSE="Y";
					   	 	var CALLER_SUBMITS="POSTAL";
							} 	
					   }
			}
	}


//Checks COMMENT field.
	     // if comment field is blank, prompt user to make an entry.
		   	if ( (document.inquiry.CALL_NOTE.value == "") )
		      	{alert ("You cannot submit a blank entry.  Enter your inquiry in the comments field and submit again!")
		     		document.inquiry.CALL_NOTE.focus();		      
				 return false;
				 }
	   			// If length of entry is < 5 characters, assume entry is invalid.  	     
	 			  if (document.inquiry.CALL_NOTE.value.length<5)
		   		   {alert ("Your inquiry appears to be to short.   Please provide us with additional information so that we can provide a better service to you.")
				   document.inquiry.CALL_NOTE.focus();		      
           	               return false;
           			   }
           	    else
           	    {
           	    	//User has submitted a valid inquiry
           	    }


//Validates that user has supplied correct information per how they want Alcohol Policies Project to reply	
	   if (REQUEST_RESPONSE=="Y")
		{
			 if (CALLER_SUBMITS=="EMAIL")		//user wants email response
				{
				if( !(isEmail()))		//validate email entry
					{
					return false;		//test failed
					}
				else
					{
					//email passes validation
					//proceed with program execution
					return true;		
					}
				}	
			 else
				{
		 		 if (CALLER_SUBMITS=="PHONE")		//user wants phone response
					{
					if( !(isPhoneNumber()))		//validate phone entry
						{
						return false;				//test failed
						}
					else
						{
						//phone passes validation
						//proceed with program execution
						return true;
						}									
					}
				 else
				 	{
 		 			 if (CALLER_SUBMITS=="FAX")		//user wants fax response
						{
						if( !(isFax()))			//validate fax entry
							{
							return false;		//test failed
							}
						else
							{
							//fax passes validation
							//proceed with program execution
							return true;
							}						
						}
					 else
						{
		 				 if (CALLER_SUBMITS=="POSTAL")		//user wants a reply via the postal service
							{
							//validate CALLER_FNAME, CALLER_LNAME, CALLER_STREET, CALLER_CITY, CALLER_STATE, CALLER_ZIP, CALLER_COUNTRY
							if( !(isFirstName() && isLastName() && isStreetAddress() && isCity() && isState()  && isZip() ))
								{
								return false;			//test failed
								}
							else
						 		{
								//entries have passed tests
								//proceed with program execution
								return true;
						 		}
							 }
						 }
					 }
			 	}
			}
		   if (REQUEST_RESPONSE=="N")     		//user indicates they do not want a response
			{
			//confirm that users doesn't want a response.
			if (confirm("\nClick OK if your are sure that you DO NOT want a response to your inquiry.\n\Otherwise, click CANCEL."))
				{
				//user does not want a response
				//continue with program execution
				return true;		
				}
	 		else
		 		{
		 		return false;
				}
		 	}


// Checks the E-MAIL field.
function isEmail()
   {
   	// Return false if e-mail field is blank.
 	  if ( (document.inquiry.CALLER_EMAIL.value == "") || (document.inquiry.CALLER_EMAIL.value == " ") )
 	     {
 	     alert("\nThe E-MAIL field cannot be blank since you have indicated that a reply to your inquiry be sent via email.\n\nPlease enter your correct email address.")
 	     document.inquiry.CALLER_EMAIL.focus();
 	     return false; 
 	     }
 	  // Return false if e-mail field does not contain a '@' and '.' or its length is < 5 characters or > 60 characters.
	   if (document.inquiry.CALLER_EMAIL.value.indexOf ('@',0) == -1 || document.inquiry.CALLER_EMAIL.value.indexOf ('.',0) == -1 || document.inquiry.CALLER_EMAIL.value.length<5 || document.inquiry.CALLER_EMAIL.value.length>60)
	      {
     		alert("\nThe E-MAIL field requires a \"@\" and a \".\" be used and must be between 5 and 60 characters.\n\nPlease re-enter your e-mail address.")
   	      document.inquiry.CALLER_EMAIL.select();
   	      document.inquiry.CALLER_EMAIL.focus();
  	      return false;
  	      }
	// Return true if e-mail entry passes validation to continue program execution.
	return true;  	      
   }


// Checks the CALLER_PHONE field.
function isPhoneNumber()
	{
		 //Return false if phone number is empty
		  if ( (document.inquiry.CALLER_PHONE.value == "") )
			{
			alert("The PHONE NUMBER field cannot be blank since you have indicated that a reply to your inquiry be sent via phone.\n\nPlease enter your correct phone number.")
   	      	document.inquiry.CALLER_PHONE.select();
			document.inquiry.CALLER_PHONE.focus();
			return false;
			}
		//return false is length < 12 or > 24
		 if ( (document.inquiry.CALLER_PHONE.value.length < 12) || (document.inquiry.CALLER_PHONE.value.length > 24) )
			{
			alert("The length of the PHONE NUMBER entry is invalid.  Please enter between 12 and 24 characters, including dashes.")
			document.inquiry.CALLER_PHONE.select();
			document.inquiry.CALLER_PHONE.focus();
			return false;
			}
		//Return false if phone number is not digits 0 through 9 or a "-" (dash).
		for (i=0; i<document.inquiry.CALLER_PHONE.value.length; i++)
			{   
				if ( (document.inquiry.CALLER_PHONE.value.charAt(i) < "0") || (document.inquiry.CALLER_PHONE.value.charAt(i) > "9") ) 
					{
					if (document.inquiry.CALLER_PHONE.value.charAt(i) != "-")
						{
						alert("\nThe PHONE NUMBER field must consist of only the digiits 0-9 and dashes (-).\n\nPlease enter your correct phone number.")
						document.inquiry.CALLER_PHONE.select();
					      document.inquiry.CALLER_PHONE.focus();				
						return false;
						}
					}
			}
	// Return true if phone entry passes validation to continue program execution.
	return true;
	}

// Checks the CALLER_FAX field.
function isFax()
	{
		 //Return false if fax number is empty
		  if ( (document.inquiry.CALLER_FAX.value == "") )
			{
			alert("The FAX NUMBER field cannot be blank since you have indicated that a reply to your inquiry be sent via fax.\n\nPlease enter your correct fax number.")
			document.inquiry.CALLER_FAX.select();
			document.inquiry.CALLER_FAX.focus();
			return false;
			}
		//return false is length < 12  or > 24
		 if ( (document.inquiry.CALLER_FAX.value.length < 12) || (document.inquiry.CALLER_FAX.value.length > 24) )
			{
			alert("\nThe length of the FAX NUMBER entry is invalid.  Please enter between 12 and 24 characters, including dashes.")
			document.inquiry.CALLER_FAX.select();
			document.inquiry.CALLER_FAX.focus();
			return false;
			}
		//Return false if fax number is not digits 0 through 9 or a "-" (dash).
		for (i=0; i<document.inquiry.CALLER_FAX.value.length; i++)
			{   
				if ( (document.inquiry.CALLER_FAX.value.charAt(i) < "0") || (document.inquiry.CALLER_FAX.value.charAt(i) > "9") ) 
					{
					if (document.inquiry.CALLER_FAX.value.charAt(i) != "-")
						{
						alert("\nThe FAX NUMBER field must consist of only the digiits 0-9 and dashes (-).\n\nPlease enter your correct fax number.")
						document.inquiry.CALLER_FAX.select();
					      document.inquiry.CALLER_FAX.focus();				
						return false;
						}
					}
			}
	// Return true if fax entry passes validation to continue program execution.
	return true;			
	}


// Checks the CALLER_FNAME field.
function isFirstName()
	{
		 //Return false if first name field is empty
		  if ( (document.inquiry.CALLER_FNAME.value == "") )
			{
			alert("The FIRST NAME field cannot be blank since you have indicated that a reply to your inquiry be sent via postal service.\n\nPlease enter your correct first name.")
			document.inquiry.CALLER_FNAME.select();
			document.inquiry.CALLER_FNAME.focus();
			return false;
			}
		//return false if length < 3 or > 15
		 if ( (document.inquiry.CALLER_FNAME.value.length < 3) || (document.inquiry.CALLER_FNAME.value.length > 15) )
			{
			alert("\nThe length of the FIRST NAME entry is invalid.\nPlease enter between 3 and 15 characters.")
			document.inquiry.CALLER_FNAME.select();
			document.inquiry.CALLER_FNAME.focus();
			return false;
			}
		//Return false if first name is not a character "a-z" or "A-Z".
		for (i=0; i<document.inquiry.CALLER_FNAME.value.length; i++)
			{   
				if ( !( ((document.inquiry.CALLER_FNAME.value.charAt(i) >= "a") && (document.inquiry.CALLER_FNAME.value.charAt(i) <= "z"))  || ((document.inquiry.CALLER_FNAME.value.charAt(i) >= "A") && (document.inquiry.CALLER_FNAME.value.charAt(i) <= "Z"))  ) ) 
					{
					//Allow user to enter periods "."  Otherwise return false for other characters .
					if (document.inquiry.CALLER_FNAME.value.charAt(i) != ".")
						{
						alert("\nThe FIRST NAME field must consist of only upper and lowercase characters A-Z and periods (.).\n\nPlease enter your correct first name.")
					      document.inquiry.CALLER_FNAME.select();
					      document.inquiry.CALLER_FNAME.focus();				
						return false;
						}
					}
			}
	// Return true if CALLER_FNAME entry passes validation to continue program execution.
	return true;
	}

// Checks the CALLER_LNAME field.
function isLastName()
	{
		 //Return false if last name field is empty
		  if ( (document.inquiry.CALLER_LNAME.value == "") )
			{
			alert("The LAST NAME field cannot be blank since you have indicated that a reply to your inquiry be sent via postal service.\n\nPlease enter your correct last name.")
			document.inquiry.CALLER_LNAME.select();
			document.inquiry.CALLER_LNAME.focus();
			return false;
			}
		//return false if length < 3 or > 15
		 if ( (document.inquiry.CALLER_LNAME.value.length < 3) || (document.inquiry.CALLER_LNAME.value.length > 15) )
			{
			alert("\nThe length of the LAST NAME entry is invalid.\nPlease enter between 3 and 15 characters.")
			document.inquiry.CALLER_LNAME.select();
			document.inquiry.CALLER_LNAME.focus();
			return false;
			}
		//Return false if last name is not a character "a-z" or "A-Z".
		for (i=0; i<document.inquiry.CALLER_LNAME.value.length; i++)
			{   
				if ( !( ((document.inquiry.CALLER_LNAME.value.charAt(i) >= "a") && (document.inquiry.CALLER_LNAME.value.charAt(i) <= "z"))  || ((document.inquiry.CALLER_LNAME.value.charAt(i) >= "A") && (document.inquiry.CALLER_LNAME.value.charAt(i) <= "Z"))  ) ) 
					{
					//Allow user to enter periods "."  Otherwise return false for other characters .
					if (document.inquiry.CALLER_LNAME.value.charAt(i) != ".")
						{
						alert("\nThe LAST NAME field must consist of only upper and lowercase characters A-Z and periods (.).\n\nPlease enter your correct last name.")
						document.inquiry.CALLER_LNAME.select();
					      document.inquiry.CALLER_LNAME.focus();				
						return false;
						}
					}
			}

	// Return true if CALLER_LNAME entry passes validation to continue program execution.
	return true;
	}

function isStreetAddress()
	{
		 //Return false if street address field is empty
		  if ( (document.inquiry.CALLER_STREET.value == "") )
			{
			alert("The STREET ADDRESS field cannot be blank since you have indicated that a reply to your inquiry be sent via postal service.\n\nPlease enter your correct street address.")
			document.inquiry.CALLER_STREET.select();
			document.inquiry.CALLER_STREET.focus();
			return false;
			}
		//return false if length <= 5 or > 50
		 if ( (document.inquiry.CALLER_STREET.value.length <= 5) || (document.inquiry.CALLER_STREET.value.length > 50) )
			{
			alert("\nThe length of the STREET ADDRESS entry is invalid.\nPlease enter between 5 and 50 characters.")
			document.inquiry.CALLER_STREET.select();
			document.inquiry.CALLER_STREET.focus();
			return false;
			}
	// Return true if CALLER_STREET entry passes validation to continue program execution.
	return true;
	}

function isCity()
	{
		 //Return false if city field is empty
		  if ( (document.inquiry.CALLER_CITY.value == "") )
			{
			alert("The CITY field cannot be blank since you have indicated that a reply to your inquiry be sent via postal service.\n\nPlease enter your correct city.")
			document.inquiry.CALLER_CITY.select();
			document.inquiry.CALLER_CITY.focus();
			return false;
			}
		//return false if length < 3 or > 30
		 if ( (document.inquiry.CALLER_CITY.value.length < 3) || (document.inquiry.CALLER_CITY.value.length > 30) )
			{
			alert("\nThe length of the CITY entry is invalid.\nPlease enter between 3 and 30 characters.")
			document.inquiry.CALLER_CITY.select();
			document.inquiry.CALLER_CITY.focus();
			return false;
			}
	// Return true if CALLER_CITY entry passes validation to continue program execution.
	return true;
	}

function isState()
	{
		//Return false if state field is empty
		//Note that the entry for this field comes from a drop-down list.
		 if ( (document.inquiry.CALLER_STATE.value == "") || (document.inquiry.CALLER_STATE.value == " ") )
			{
			alert("The STATE field cannot be blank since you have indicated that a reply to your inquiry be sent via postal service.\n\nPlease enter your correct state.")
			document.inquiry.CALLER_STATE.focus();
			return false;
			}
		 if ( (document.inquiry.CALLER_STATE.value.length < 2) || (document.inquiry.CALLER_STATE.value.length > 20) )
			{
			alert("\nThe STATE field entry must be between 2 and 20 characters.")
			document.inquiry.CALLER_STATE.focus();
			return false;
			}			

	// Return true if CALLER_STATE entry passes validation to continue program execution.
	return true;
	}


function isCountry()
	{
		//Return false if country field is empty
		//Note that the entry for this field comes from a drop-down list.
		 if ( (document.inquiry.CALLER_COUNTRY.value == "") || (document.inquiry.CALLER_COUNTRY.value == " ") )
			{
			alert("The COUNTRY field cannot be blank since you have indicated that a reply to your inquiry be sent via postal service.\n\nPlease enter your correct country.")
			document.inquiry.CALLER_COUNTRY.focus();
			return false;
			}
		 if ( (document.inquiry.CALLER_COUNTRY.value.length < 3) || (document.inquiry.CALLER_COUNTRY.value.length > 50) )
			{
			alert("\nThe COUNTRY field entry must be between 3 and 50 characters.")
			document.inquiry.CALLER_COUNTRY.focus();
			return false;
			}
	// Return true if CALLER_COUNTRY entry passes validation to continue program execution.
	return true;
	}

function isZip()
	{
		//Return false if zip field is empty
		 if ( (document.inquiry.CALLER_ZIP.value == "") )
			{
			alert("The ZIP CODE field cannot be blank since you have indicated that a reply to your inquiry be sent via postal service.\n\nPlease enter your correct zip.")
			document.inquiry.CALLER_ZIP.select();
			document.inquiry.CALLER_ZIP.focus();
			return false;
			}
		 if ( (document.inquiry.CALLER_ZIP.value.length < 5) || (document.inquiry.CALLER_ZIP.value.length > 10) )
			{
			alert("\nThe ZIP CODE field entry must contain between 5 and 20 characters.")
			document.inquiry.CALLER_ZIP.select();
			document.inquiry.CALLER_ZIP.focus();
			return false;
			}			

	// Return true if CALLER_ZIP entry passes validation to continue program execution.
	return true;
	}

function isEmpty()
	{
		//If users doesnt select any of the options from our drop-down lists, a blank space will be stored
		//in the SQL table.  THIS IS INCONSISTENT with the other fields.  Instead, remove this space so
		//that NULL will be store in the field
		
	}
//somehow user made it through the page without making an entry  (this scerino cannot happen)
//but to keep netscape from returning errors, we have to trick it!
return false;
}	

