// JavaScript Document
	
	function checkWholeRequestForm(theForm) {
		//alert(theForm.name);
		var dayareacode = theForm.intDayAreaCode.value;
		var dayphone1 = theForm.intDayPhone1.value;
	 	var dayphone2 = theForm.intDayPhone2.value;	
		
		if (theForm.intEveAreaCode) {
		var eveareacode = theForm.intEveAreaCode.value;
		var evephone1 = theForm.intEvePhone1.value;
	 	var evephone2 = theForm.intEvePhone2.value;	
		var evephone = eveareacode+evephone1+evephone2;
		//alert('eve phone not zero: '+(evephone.length !== 0));
		//alert('eve phone not null: '+(evephone !== null));
		}
		else { var evephone = 0 };
		
		
  	 	var why = "";
	 	//why = "The request could not be sent:\n";
		why += checkFirstName('firstname','firstNameValid');
		why += checkLastName('lastname','lastNameValid');
		why += checkAddress('address','addressValid');
		why += checkCity('city','cityValid');
		why += checkZip('zip','zipValid');
		why += checkPhone('dayareacode','dayphone1','dayphone2','dayPhoneValid');
		if (evephone !== 0) {
		if(evephone.length !== 0) { 
			why += checkPhone('eveareacode','evephone1','evephone2','evePhoneValid');
		}
		else {
			document.getElementById('eveareacode').className='inputstart';
			document.getElementById('evephone1').className='inputstart';
			document.getElementById('evephone2').className='inputstart';
			removeValid('evePhoneValid');
		}
		}
		why += checkEmail('email','emailValid');
		
		if (why !== "") {
      		//alert(why);
			return false;
		} 
		return true;
	}
	
	function IsRequestFormReady(theForm) {
		//alert('CHECKING!!!');
		if (!checkWholeRequestForm(theForm)) {
			//alert('FALSE!!!');
			alert('The form cannot be sent!\n Please go back and complete the fields in red.');
			//document.write(checkWholeRequestForm(theForm))
			return false;
		}
		return true;
	}
	
	function getPhone(areacode,phone1,phone2) {
		thePhone = areacode+phone1+phone2;
		return thePhone;
	}
	
	function checkFirstName(inputclassname,isvalidclassname) {
		var firstName = document.getElementById(inputclassname);
		var firstNameValid = document.getElementById(isvalidclassname);
		var error="";
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]\~\!\#\$\%\^\&\*\+\=\{\}\|]/;
		
		if (firstName.value == ''){
			//alert(firstName.name + ' is empty');
			error = "Required.";
			firstName.className = 'invalidinput';
			removeValid(isvalidclassname);
			firstNameValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
		}
		
		//test email for illegal characters
		else if (firstName.value.match(illegalChars)) {
        	error = "Illegal characters.";
			firstName.className = 'invalidinput';
			//alert('email chars class: '+email.className);
			removeValid(isvalidclassname);
			firstNameValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
      	}
		
		else {
			//alert(firstName.name + ' is not empty');
			firstName.className = 'validinput';
			removeValid(isvalidclassname);
			firstNameValid.className = 'valid';
			showValid(isvalidclassname,'yes');
		}
		return error;
	}
	
	function checkLastName(inputclassname,isvalidclassname) {
		var lastName = document.getElementById(inputclassname);
		var lastNameValid = document.getElementById(isvalidclassname);
		var error="";
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]\~\!\#\$\%\^\&\*\+\=\{\}\|]/;
		
		if (lastName.value == ''){
			//alert(firstName.name + ' is empty');
			error = "Required.";
			lastName.className = 'invalidinput';
			removeValid(isvalidclassname);
			lastNameValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
		}
		
		else if (lastName.value.match(illegalChars)) {
        	error = "Illegal characters.";
			lastName.className = 'invalidinput';
			//alert('email chars class: '+email.className);
			removeValid(isvalidclassname);
			lastNameValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
      	}
		
		else {
			//alert(firstName.name + ' is not empty');
			lastName.className = 'validinput';
			removeValid(isvalidclassname);
			lastNameValid.className = 'valid';
			showValid(isvalidclassname,'yes');
		}
		return error;
	}
	
	function checkAddress(inputclassname,isvalidclassname) {
		var address = document.getElementById(inputclassname);
		var addressValid = document.getElementById(isvalidclassname);
		var error="";
		var illegalChars= /[\(\)\<\>\;\:\\\"\[\]\~\!\$\%\?\^\*\+\=\{\}\|]/;
		
		if (address.value == ''){
			//alert(firstName.name + ' is empty');
			error = "Required.";
			
			address.className = 'invalidinput';
			removeValid(isvalidclassname);
			addressValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
		}
		
		else if (address.value.match(illegalChars)) {
        	error = "Illegal characters.";
			address.className = 'invalidinput';
			//alert('email chars class: '+email.className);
			removeValid(isvalidclassname);
			addressValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
      	}
		
		else {
			//alert(firstName.name + ' is not empty');
			address.className = 'validinput';
			removeValid(isvalidclassname);
			addressValid.className = 'valid';
			showValid(isvalidclassname,'yes');
		}
		return error;
	}
	
	function checkCity(inputclassname,isvalidclassname) {
		var city = document.getElementById(inputclassname);
		var cityValid = document.getElementById(isvalidclassname);
		var error="";
		var illegalChars= /[\(\)\<\>\;\:\\\"\[\]\~\!\$\%\?\^\*\+\=\{\}\|]/;
		
		if (city.value == ''){
			//alert(firstName.name + ' is empty');
			error = "Required.";
			
			city.className = 'invalidinput';
			removeValid(isvalidclassname);
			cityValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
		}
		
		else if (city.value.match(illegalChars)) {
        	error = "Illegal characters.";
			city.className = 'invalidinput';
			//alert('email chars class: '+email.className);
			removeValid(isvalidclassname);
			cityValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
      	}
		
		else {
			//alert(firstName.name + ' is not empty');
			city.className = 'validinput';
			removeValid(isvalidclassname);
			cityValid.className = 'valid';
			showValid(isvalidclassname,'yes');
		}
		return error;
	}
	
	function checkZip (inputclassname,isvalidclassname) {
 		var zip = document.getElementById(inputclassname);
		var zipValid = document.getElementById(isvalidclassname);
		var error = "";
		var digit;
		///alert(strng.length);
		//alert("phoneln: "+parseInt(strng).toString().length)
		//alert('Zip Code: '+zip.value.length);
		//alert('Is strng null: '+(strng.length == ""));
		if (zip.value == "" || zip.value == null || zip.value.length !== 5 ) {
    		error = "Required, 5-digit.";
			zip.className = 'invalidinput';
			removeValid(isvalidclassname);
			zipValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
			
			//alert('Zip error: '+error);
 		}
		else  {
			for (var count=0; count < 5; count++) {
				//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
				if (isNaN(parseInt(zip.value.charAt(count)))) {
					error = "Must be numeric.";
					zip.className = 'invalidinput';
					removeValid(isvalidclassname);
					zipValid.className = 'invalid';
					showValid(isvalidclassname,'no',error);
					return error;
				}
				else {
					zip.className = 'validinput';
					removeValid(isvalidclassname);
					zipValid.className = 'valid';
					showValid(isvalidclassname,'yes');
				}
			}
			
		}
		return error;
		/*else if (parseInt(strng).toString().length !== 5) {
			error = "Please enter numeric values for the zip code.\n";
		}*/
		//return error;
	}
	
	function checkEmail(inputclassname,isvalidclassname) {
		//alert('checking email');
		var error = "";
		var email = document.getElementById(inputclassname);
		var emailValid = document.getElementById(isvalidclassname);
		
		if (email.value == "" || email.value == null) {
   		error = "Required.";
			email.className = 'invalidinput';
			//alert('email blank class: '+email.className);
			removeValid(isvalidclassname);
			emailValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
		}
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(email.value))) { 
      	error = "Invalid email address.";
			email.className = 'invalidinput';
			//alert('email filter class: '+email.className);
			removeValid(isvalidclassname);
			emailValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
   	}
   		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]\~\!\#\$\%\^\&\*\+\=\{\}\|\s]/
		if (email.value.match(illegalChars)) {
        	error = "Illegal characters.";
			email.className = 'invalidinput';
			//alert('email chars class: '+email.className);
			removeValid(isvalidclassname);
			emailValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
      }
		else {
			email.className = 'validinput';
			//alert('email good class: '+email.className);
			removeValid(isvalidclassname);
			emailValid.className = 'valid';
			showValid(isvalidclassname,'yes');
		}
		return error;
    		 
	}
	
	function checkPhone(area,phone1,phone2,isvalidclassname) {
 		var error = "";
		var digit;
		var thisAreaCode = document.getElementById(area);
		var thisPhone1 = document.getElementById(phone1);
		var thisPhone2 = document.getElementById(phone2);
		var thePhoneNum = getPhone(thisAreaCode.value,thisPhone1.value,thisPhone2.value);
		
		var phoneValid = document.getElementById(isvalidclassname);
		//alert('id: '+isvalidclassname);
		
		///(strng.length);
		//("phoneln: "+parseInt(strng).toString().length)
		if (thePhoneNum.length !== 10) {
			//alert('phone: '+thePhoneNum);
    		error = "Required.";
			thisAreaCode.className = 'invalidinput';
			thisPhone1.className = 'invalidinput';
			thisPhone2.className = 'invalidinput';
			
			//email.className = 'invalidinput';
			//alert('email chars class: '+email.className);
			removeValid(isvalidclassname);
			phoneValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
 		}
		else  {
			for (var count=0; count < 10; count++) {
				//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
				//alert('num: '+thePhoneNum.charAt(count)+ ', not numeric: '+isNaN(parseInt(thePhoneNum.charAt(count))));
				/**/
				if (isNaN(parseInt(thePhoneNum.charAt(count)))) {
					error = "Must be numeric.\n";
					thisAreaCode.className = 'invalidinput';
					thisPhone1.className = 'invalidinput';
					thisPhone2.className = 'invalidinput';
			
					//email.className = 'invalidinput';
					//alert('email chars class: '+email.className);
					removeValid(isvalidclassname);
					phoneValid.className = 'invalid';
					showValid(isvalidclassname,'no',error);
					return error;
				}
				
			}
			thisAreaCode.className = 'validinput';
			thisPhone1.className = 'validinput';
			thisPhone2.className = 'validinput';
			//alert('phone good class: '+thisAreaCode.className);
			removeValid(isvalidclassname);
			phoneValid.className = 'valid';
			showValid(isvalidclassname,'yes');
		}
		return error;
	}
	
	
	function showValid(classname,isvalid,error) {
		if (isvalid == 'no') {
			var descdiv = document.getElementById(classname);
			var desc_node = document.createTextNode(error);
			descdiv.appendChild(desc_node);
			return
			
		}
		/*else {
			var descdiv = document.getElementById(classname);
			var desc_node = document.createTextNode("Good!");
			descdiv.appendChild(desc_node);
		}*/
	
	}
	
	function removeValid(classname) {
		//alert(classname);
		var descdiv = document.getElementById(classname);
		//alert(descdiv.id+', '+descdiv.childNodes.length);
		if (descdiv.childNodes.length > 0) {
			for (link_counter = descdiv.childNodes.length - 1;link_counter >=0;link_counter--) {
				// Get the row element to be deleted
				var remove_node = descdiv.childNodes[link_counter];
				descdiv.removeChild(remove_node);
			}
		}
		//return;y
	}
	
	function resetValid() {
		removeValid('firstNameValid');
		document.getElementById('firstname').className = 'inputStart';
		
		removeValid('lastNameValid');
		document.getElementById('lastname').className = 'inputStart';
		
		removeValid('addressValid');
		document.getElementById('address').className = 'inputStart';
		
		removeValid('cityValid');
		document.getElementById('city').className = 'inputStart';
		
		removeValid('zipValid');
		document.getElementById('zip').className = 'inputStart';
		
		
		document.getElementById('dayareacode').className = 'inputStart';
		
		document.getElementById('dayphone1').className = 'inputStart';
		
		document.getElementById('dayphone2').className = 'inputStart';
		removeValid('dayPhoneValid');
		
		
		
		document.getElementById('eveareacode').className = 'inputStart';
		
		document.getElementById('evephone1').className = 'inputStart';
		
		document.getElementById('evephone2').className = 'inputStart';
		removeValid('evePhoneValid');
	
		//removeValid('email');
		removeValid('emailValid');
		document.getElementById('email').className = 'inputStart';
		
		//removeValid('comments');
		document.getElementById('comments').className = 'inputStart';
		
		
	}