/*this script is used for ALL request information pages in the SHC website.  There are
2 different functions here because of the 2 different types of request pages.
1.  The requestion-information.html page.
2.  The short form which 
*/	
	
//form validator
//params:  theForm = sending form:  requestType = extended for dropdown form, short for page forms, standard for all other forms.
//NOTE:  case sensitive.  make sure the field names are in all lower case - no exceptions.
function ValidateFields(theForm,RequestType)
{

	var temp = new Array();	
	var allValid = true;  
	var checkStr = "";
	var checkOK ;
	var len;
		
	if (theForm.campus.value == "")
	{
		alert("Please select a preferred location.");//\"enroll\" options.");
		theForm.campus.focus();
		return (false);
	}
	
  temp[0] = theForm.firstname.value;
  temp[1] = theForm.lastname.value;
  for( b = 0; b < 2; b++)
  {  
	 //go through each character to determine if this is an alpha or a hypen.  Numbers are not allowed.		
			  checkStr = temp[b];	
			  //first and last names are required.
			  if(checkStr.length == 0)
			  {
				alert("The First and Last Name fields are required.");
				b == 0 ? theForm.firstname.focus():theForm.lastname.focus();
				return(false);			
			  }
			  for (i = 0;  i < checkStr.length;  i++)
			  {
					//the individual character to be checked.
					ch = checkStr.charAt(i);
					if(!isNaN(ch) || ch == "-") //if this is numeric and not a hyphen - invalid
					{
						alert("Numbers are not allowed in the name fields.");
						b == 0 ? theForm.firstname.focus():theForm.lastname.focus();
						return (false);
					}
			  }
   }
  
  
		checkStr = theForm.phone.value;
		//replace all characters that aren't numeric.
		for (i = 0;  i < checkStr.length;  i++)
		  {
				//the individual character to be checked.
				ch = checkStr.charAt(i);
				if(isNaN(ch)) //strip out all non numeric characters.
				{
					//replace any non numeric value with an X.  then they are all replaced before being sent through.
					checkStr = checkStr.replace( ch, "X" );
				}
					
		  }
		 
		 checkStr = checkStr.replace( /X/g, '' );//replace the X with nothing.
		 theForm.phone.value = checkStr.substring(0,10);
		  //after stripping out all of the characters, the phone number has to be at least 10 numbers.
		  if(checkStr.length < 10)
		  {
			alert("The phone number and area code must contain at least 10 numbers.");
				theForm.phone.focus();
			//don't go any further.
			return (false);			  
		  }	
		  
	if(RequestType != "short" && theForm.cellphone.value.length > 0 )
	{
		  
		checkStr = theForm.cellphone.value;
		//replace all characters that aren't numeric.
		for (i = 0;  i < checkStr.length;  i++)
		  {
				//the individual character to be checked.
				ch = checkStr.charAt(i);
				if(isNaN(ch)) //strip out all non numeric characters.
				{
					//replace any non numeric value with an X.  then they are all replaced before being sent through.
					checkStr = checkStr.replace( ch, "X" );
				}
					
		  }
		checkStr = checkStr.replace( /X/g, "" );
		theForm.cellphone.value = checkStr.substring(0,10);
		  //after stripping out all of the characters, the phone number has to be at least 10 numbers.
		  if(checkStr < 10)
		  {
			alert("The cell phone number and area code must contain at least 10 numbers.");
				theForm.cellphone.focus();
			//don't go any further.
			return (false);			  
		  }	
	}															
	
	//email field is required
	if (theForm.email.value == "")
	 {
	    alert("Please enter a valid email address");
	    theForm.email.focus();
	    return (false);
	  }
  
	  var value = theForm.email.value;
	  apos=value.indexOf("@");
	  dotpos=value.lastIndexOf(".");

	  if (apos<1||dotpos-apos<2)
	  {
	    alert("Please enter valid email addreess");
	    return (false);
	  }

  /*NOTE:  the short form doesn't have address so check the campus and area of interest next.  
	After this, if it's the short form it returns true and goes to mailer code.
	----------------------------------------------------------------------------------------------*/
  if (theForm.campus.value == "")
  {
    alert("Please select a preferred location.");
    theForm.campus.focus();
    return (false);
  }
  if (theForm.program.value == "")
  {
    alert("Please select a program of interest.");
    theForm.program.focus();
    return (false);
  }
    
  //end of validation for the short form.
  if(RequestType == "short")
		return(true);
		
 /*-----------------------------------------------------------------------------------
	LONG FORMS ONLY FROM THIS POINT 
	--------------------------------------------------------------------------------*/		
  //zip code
  	  if (theForm.zip.value == "")
	  {
	    alert("Please enter a value for the zip code.");
	    theForm.zip.focus();
	    return (false);
	  }
	  checkStr = theForm.zip.value;
		//replace all characters that aren't numeric.
		for (i = 0;  i < checkStr.length;  i++)
		  {
				//the individual character to be checked.
				ch = checkStr.charAt(i);
				if(isNaN(ch)) //strip out all non numeric characters.
				{
					//replace any non numeric value with an X.  then they are all replaced before being sent through.
					checkStr = checkStr.replace( ch, "X" );
				}
					
		  }
		checkStr = checkStr.replace( /X/g, "" );
	  if(checkStr.length < 5)
	  {
		alert("The zip code must be at least 5 numbers in length.");
		theForm.zip.focus();
		//don't go any further.
		return (false);			  
	  }	
	//if the code reached this point, then all of the fields passed validation.
	return (true);

}
	
	
//form validator
//params:  theForm = sending form:  requestType = extended for dropdown form, short for page forms, standard for all other forms.
//NOTE:  case sensitive.  make sure the field names are in all lower case - no exceptions.
function ValidateAlumniForm(theForm)
{
	var temp = new Array();	
	var allValid = true;  
	var checkStr = "";
	var checkOK ;
  temp[0] = theForm.firstname.value;
  temp[1] = theForm.lastname.value;
  for( b = 0; b < 2; b++)
  {  
	 //go through each character to determine if this is an alpha or a hypen.  Numbers are not allowed.		
			  checkStr = temp[b];	
			  //first and last names are required.
			  if(checkStr.length == 0)
			  {
				alert("The First and Last Name fields are required.");
				b == 0 ? theForm.firstname.focus():theForm.lastname.focus();
				return(false);			
			  }
			  for (i = 0;  i < checkStr.length;  i++)
			  {
					//the individual character to be checked.
					ch = checkStr.charAt(i);
					if(!isNaN(ch) || ch == "-") //if this is numeric and not a hyphen - invalid
					{
						alert("Numbers are not allowed in the name fields.");
						b == 0 ? theForm.firstname.focus():theForm.lastname.focus();
						return (false);
					}
			  }
   }
  	 checkStr = theForm.phone.value;
		//replace all characters that aren't numeric.
		for (i = 0;  i < checkStr.length;  i++)
		  {
				//the individual character to be checked.
				ch = checkStr.charAt(i);
				if(isNaN(ch)) //strip out all non numeric characters.
				{
					//replace any non numeric value with an X.  then they are all replaced before being sent through.
					checkStr = checkStr.replace( ch, "X" );
				}
					
		  }
		 
		 checkStr = checkStr.replace( /X/g, '' );//replace the X with nothing.
		 theForm.phone.value = checkStr.substring(0,10);
		  //after stripping out all of the characters, the phone number has to be at least 10 numbers.
		  if(checkStr.length < 10)
		  {
			alert("The phone number and area code must contain at least 10 numbers.");
				theForm.phone.focus();
			//don't go any further.
			return (false);			  
		  }	
		  
					
	
	//email field is required
	if (theForm.email.value == "")
	 {
	    alert("Please enter a value for the \"email\" field.");
	    theForm.email.focus();
	    return (false);
	  }
  
	  var value = theForm.email.value;
	  apos=value.indexOf("@");
	  dotpos=value.lastIndexOf(".");

	  if (apos<1||dotpos-apos<2)
	  {
	    alert("Please enter valid email addreess");
	    return (false);
	  }

   //zip code
  	  if (theForm.zip.value == "")
	  {
	    alert("Please enter a value for the zip code.");
	    theForm.zip.focus();
	    return (false);
	  }
	  checkStr = theForm.zip.value;
		//replace all characters that aren't numeric.
		for (i = 0;  i < checkStr.length;  i++)
		  {
				//the individual character to be checked.
				ch = checkStr.charAt(i);
				if(!isNaN(ch)) //strip out all non numeric characters.
					checkStr.substring(i,1).replace(ch,'');						
		  }
	  //after stripping out all of the characters, the phone number has to be at least 10 numbers.
	  if(checkStr.length < 5)
	  {
		alert("The zip code must be at least 5 numbers in length.");
		theForm.zip.focus();
		//don't go any further.
		return (false);			  
	  }	
	//if the code reached this point, then all of the fields passed validation.
	return (true);

}
	
function setIndex()
{
	if(document.getElementById("campus").value == "campus" || document.getElementById("campus").value == "cec")
	{
		document.getElementById("campus").selectedIndex = 0;		
	}
}
function setProgramName(theObject) { 
	document.getElementById("programfullname").value = theObject.getElementsByTagName("option")[theObject.selectedIndex].innerHTML;
} 
/*function setIndex()
{
	if(document.getElementById("campus").value == "campus" || document.getElementById("campus").value == "cec")
	{
		document.getElementById("campus").selectedIndex = 0;		
	}
}*/
