// JavaScript Document

function validate(formName)
{
	//Radio Button Name Holder
	var radioName = "";
	var radioOn = 0;

	/*if there is more then one form on a page change forms[formName] to the name of the form needing validation forms[thename]*/
	for(i=0; i<document.forms[formName].length; i++)
	{
		//Get the className
		var classValidate = document.forms[formName].elements[i].className;
		//Variable to hold the split
		var temp = [];
		//Split the className
		temp = classValidate.split('_');
		
		
		
		//If there is no className
		if(temp[0] == "" || temp[0] == null || temp[0] == "null" || temp[0] == false)
		{
			//Do nothing since no validation is needed
		}
		else
		{
			document.forms[formName].elements[i].style.backgroundColor = "#FFFFFF";
			
			//if className has no underscores in it
			if(temp.length == 1)
			{
				//If className is check_radio
				if(temp[0] == "checkRadio" && document.forms[formName].elements[i].name != radioName)
				{
							
					if(document.forms[formName].elements[i].name == radioName)
					{
						//Do nothing because we have already checked for a selection
					}
					else
					{
						radioOn = 0;
						
						radioName = document.forms[formName].elements[i].name;
						
						var cycle = document.getElementsByName(radioName).length;
						
						for(x=1;x<cycle;x++)
						{		
							for(y=i;y<(i+cycle);y++)
							{
								if(document.forms[formName].elements[y].checked == true)
								{
									radioOn = 1;
								}
							}
						}
						
						if(radioOn != 1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Check a Value for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}
					}
				}
				
				//If the className is validate
				else if(temp[0] == "validate")
				{
						
						//If there is nothing entered in the 
						if(document.forms[formName].elements[i].value.search(/./) == -1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Enter a Value for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}

				//End of if className is Validate
				}
				
				//If className is email
				else if(temp[0] == "email")
				{
						
						//If there is nothing entered in the 
						if(document.forms[formName].elements[i].value.search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.[a-zA-Z]{2,3}$/) == -1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Enter a Value for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}

				//End of if className is email
				}
				
								//If className is emailVer
				else if(temp[0] == "emailVer")
				{
						
						//If there is nothing entered in the 
						if(document.forms[formName].elements[i].value.search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.[a-zA-Z]{2,3}$/) == -1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Enter a Value for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}
						if(document.forms[formName].elements[i].value != document.forms[formName].elements[i-1].value)
						{
														//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Your Emails do Not Match");
							//Stop submission
							return false;
						}

				//End of if className is emailVer
				}
				
				//If className is password
				else if(temp[0] == "password")
				{
						
						//If there is nothing entered in the 
						if(document.forms[formName].elements[i].value.search(/^\w{8,}$/) == -1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Enter a Value for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}

				//End of if className is password
				}
				
				//If the validation needed is to be sure something is entered and it is a letter only plus underscores
				else if(temp[0] == "Text" || temp[0] == "text")
				{
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(/^[a-zA-Z_]+$/) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
				else if(temp[0] == "TextSpace" || temp[0] == "textSpace")
				{
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(/^(\s*[a-zA-Z_]+\s*)+$/) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
				//If the validation needed is to be sure something is entered and it is a digit only
				else if(temp[0] == "Digit" || temp[0] == "digit")
				{
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(/^\d$/) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Digit Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
				else if(temp[0] == "DigitSpace" || temp[0] == "digitSpace")
				{
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(/^(\s*\d+\s*)+$/) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
				//If the validation needed is for zip codes
				else if(temp[0] == "Zip" || temp[0] == "zip")
				{
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(/^\d{5}$/) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a 5 Digit Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
				else if(temp[0] == "phone" || temp[0] == "phone")
				{
					var digits = new RegExp("^(\\d+\\s?[-]?){10}$|^(\\d+\\s?[-]?){7}$");
					
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(digits) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
			//End of if statement if temp.length is 1
			}
			
			//If temp.length = 2
			else if(temp.length == 2)
			{
				minLength = temp[1];
				
				//If the className is validate
				if(temp[0] == "validate")
				{
						var newVal = new RegExp("^\.{" + minLength + ",}$");
						
						//If there is nothing entered in the 
						if(document.forms[formName].elements[i].value.search(newVal) == -1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Enter a Value for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}

				//End of if className is Validate
				}			
				//If className is password
				else if(temp[0] == "password")
				{
						var newLe = new RegExp("^\\w{" + minLength + ",}$");
						
						//If there is nothing entered in the 
						if(document.forms[formName].elements[i].value.search(newLe) == -1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Enter a Value for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}

				//End of if className is password
				}
				
				//If the validation needed is to be sure something is entered and it is a letter only plus underscores
				else if(temp[0] == "Text" || temp[0] == "text")
				{
					var texts = new RegExp("^[a-zA-Z_]{" + minLength + ",}$");
					
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(texts) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
				else if(temp[0] == "TextSpace" || temp[0] == "textSpace")
				{
					var texts = new RegExp("^(\\s*[a-zA-Z_]+\\s*){" + minLength + ",}$");
					
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(texts) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
				//If the validation needed is to be sure something is entered and it is a digit only
				else if(temp[0] == "Digit" || temp[0] == "digit")
				{
					var digits = new RegExp("^\\d{" + minLength + ",}$");
					
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(digits) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Digit Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
				
				else if(temp[0] == "DigitSpace" || temp[0] == "digitSpace")
				{
					var digits = new RegExp("^(\\s*\\d+\\s*){" + minLength + ",}$");
					
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(digits) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
		
			//End of if temp.length = 2
			}
			//If length is 3
			else if(temp.length == 3)
			{
				if(temp[0] == "checkBox")
				{
					var numChecked = 0;
					
					var p = 0;
					
					for(p=i;p<(i+parseInt(temp[1]));p++)
					{
						if(document.forms[formName].elements[p].checked == true)
						{
							numChecked++;
						}
					}
					
					if(numChecked != temp[2])
					{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Check "+ temp[2] + " Value(s) for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
					}
					
				}
				else
				{
					minLength = temp[1];
					maxLength = temp[2];
					
					//If the className is validate
					if(temp[0] == "validate")
					{
							var newVal = new RegExp("^\.{" + minLength + ","+maxLength+"}$");
							
							//If there is nothing entered in the 
							if(document.forms[formName].elements[i].value.search(newVal) == -1)
							{
								//Go to the spot in the form
								document.forms[formName].elements[i].focus();
								//Highlight the field	
								document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
								//Alert the user what needs fixing
								alert("Please Enter a Value for " + document.forms[formName].elements[i].name);
								//Stop submission
								return false;
							}
	
					//End of if className is Validate
					}			
					//If className is password
					else if(temp[0] == "password")
					{
							var newLe = new RegExp("^\\w{" + minLength + ","+maxLength+"}$");
							
							//If there is nothing entered in the 
							if(document.forms[formName].elements[i].value.search(newLe) == -1)
							{
								//Go to the spot in the form
								document.forms[formName].elements[i].focus();
								//Highlight the field	
								document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
								//Alert the user what needs fixing
								alert("Please Enter a Value for " + document.forms[formName].elements[i].name);
								//Stop submission
								return false;
							}
	
					//End of if className is password
					}
					
					//If the validation needed is to be sure something is entered and it is a letter only plus underscores
					else if(temp[0] == "Text" || temp[0] == "text")
					{
						var texts = new RegExp("^[a-zA-Z_]{" + minLength + ","+maxLength+"}$");
						
						//If there is nothing entered in the 
						if(document.forms[formName].elements[i].value.search(texts) == -1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}
					}
					
				else if(temp[0] == "TextSpace" || temp[0] == "textSpace")
				{
					var texts = new RegExp("^(\\s*[a-zA-Z_]+\\s*){" + minLength + ","+maxLength+"}$");
					
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(texts) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
					
					//If the validation needed is to be sure something is entered and it is a digit only
					else if(temp[0] == "Digit" || temp[0] == "digit")
					{
						var digits = new RegExp("^\\d{" + minLength + ","+maxLength+"}$");
						
						//If there is nothing entered in the 
						if(document.forms[formName].elements[i].value.search(digits) == -1)
						{
							//Go to the spot in the form
							document.forms[formName].elements[i].focus();
							//Highlight the field	
							document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
							//Alert the user what needs fixing
							alert("Please Enter a Digit Value Only for " + document.forms[formName].elements[i].name);
							//Stop submission
							return false;
						}
					}
					
				else if(temp[0] == "DigitSpace" || temp[0] == "digitSpace")
				{
					var digits = new RegExp("^(\\s*\\d+\\s*){" + minLength + ","+maxLength+"}$");
					
					//If there is nothing entered in the 
					if(document.forms[formName].elements[i].value.search(digits) == -1)
					{
						//Go to the spot in the form
						document.forms[formName].elements[i].focus();
						//Highlight the field	
						document.forms[formName].elements[i].style.backgroundColor = "#FFCCFF";
						//Alert the user what needs fixing
						alert("Please Enter a Text Value Only for " + document.forms[formName].elements[i].name);
						//Stop submission
						return false;
					}
				}
					
				}
				
				
			//End of else if temp.length = 3	
			}
		//End of else statements
		}
	//End of the for loop
	}

return true;
}