// JavaScript Document for validation 

function validateForm(){
	//establish variables
	var nameField, addyField, infoField, typeField, windowField, phoneField, faxField, emailField, testDigit, allow;
	nameField = document.getElementById('name').value;
	addyField = document.getElementById('addy').value;
	infoField = document.getElementById('info').value;
	typeField = document.getElementById('type').value;
	windowField = document.getElementById('windowloc').value;
	phoneField = document.getElementById('phone').value;
	emailField = document.getElementById('email').value;
	
	var errors = new Array(6);
	var emailPattern = /\w+@\w+\.\w{1,3}/;
	var pattern = /[0-9]/; 
	
	if(document.getElementById('successError')){
		document.getElementById('successError').style.display = "none";
	}
	if(document.getElementById('unSuccessError')){
		document.getElementById('unSuccessError').style.display = "none";
	}

	//validate the email field
	if(emailField == ''){
		document.getElementById('emailError').style.display = "block";
		document.theForm.email.style.backgroundColor = "#FFFF99";
		errors[0] = 'yes';
	}else{
		//the field is not empty so time to compare it against the email reg expression
		if(!emailPattern.test(emailField)){
			errors[0] = 'yes';
			document.getElementById('emailError').style.display = "block";
			document.theForm.email.style.backgroundColor = "#FFFF99";
		}else{
			document.getElementById('emailError').style.display = "none";
			document.theForm.email.style.backgroundColor = "#FFFFFF";
			errors[0] = '';
		}
	}
	
	//validate the name field
	if(nameField == ''){
		document.getElementById('nameError').style.display = "block";
		document.theForm.name.style.backgroundColor = "#FFFF99";
		errors[1] = 'yes';
	}else{
		//check to see if a number was entered
		for(j=0; j<nameField.length; j++){
			testDigit = nameField.charAt(j);
			if(pattern.test(testDigit)){
				errors[1] = 'yes';
				break;
			}
		}
		if(errors[1] == 'yes'){
			document.getElementById('nameError').style.display = "block";
     		document.theForm.name.style.backgroundColor = "#FFFF99";
		}else{
			document.getElementById('nameError').style.display = "none";
        	document.theForm.name.style.backgroundColor = "#FFFFFF";
			errors[1] = '';
		}
	}

	//validate the addy field
	if(addyField == ''){
		document.getElementById('addyError').style.display = "block";
    	document.theForm.addy.style.backgroundColor = "#FFFF99";
		errors[2] = 'yes';
	}else{
		document.getElementById('addyError').style.display = "none";
    	document.theForm.addy.style.backgroundColor = "#FFFFFF";
		errors[2] = '';
	}

	//validate the vehicle information field
	if(infoField == ''){
		document.getElementById('infoError').style.display = "block";
    	document.theForm.info.style.backgroundColor = "#FFFF99";
		errors[3] = 'yes';
	}else{
		document.getElementById('infoError').style.display = "none";
    	document.theForm.info.style.backgroundColor = "#FFFFFF";
		errors[3] = '';
	}

	//validate the vehicle type field
	if(typeField == '0'){
		document.getElementById('typeError').style.display = "block";
    	document.theForm.type.style.backgroundColor = "#FFFF99";
		errors[4] = 'yes';
	}else{
		document.getElementById('typeError').style.display = "none";
    	document.theForm.type.style.backgroundColor = "#FFFFFF";
		errors[4] = '';
	}
	
	//validate the window location field
	if(windowField == ''){
		document.getElementById('windowError').style.display = "block";
    	document.theForm.windowloc.style.backgroundColor = "#FFFF99";
		errors[5] = 'yes';
	}else{
		document.getElementById('windowError').style.display = "none";
    	document.theForm.windowloc.style.backgroundColor = "#FFFFFF";
		errors[5] = '';
	}

	//validate the phone field
	if(phoneField == ''){
		document.getElementById('phoneError').style.display = "block";
    	document.theForm.phone.style.backgroundColor = "#FFFF99";
		errors[6] = 'yes';
	}else{
		document.getElementById('phoneError').style.display = "none";
    	document.theForm.phone.style.backgroundColor = "#FFFFFF";
		errors[6] = '';
	}

	//check the errors array
	for(i=0; i<6; i++){
		if(errors[i] == 'yes'){
			allow = 'no';
		}
	}
	
	//check the allow flag. This flag determines whether or not to submit the information
	if(allow == 'no'){
		return false;
	}else{
		return true;
	}
}

function validateForm2(){
	//establish variables
	var nameField, phoneField, commentsField, emailField, testDigit, allow;
	nameField = document.getElementById('name').value;
	phoneField = document.getElementById('phone').value;
	emailField = document.getElementById('email').value;
	commentsField = document.getElementById('comments').value;
	
	var errors = new Array(3);
	var emailPattern = /\w+@\w+\.\w{1,3}/;
	var pattern = /[0-9]/; 
	
	//validate the email field
	if(emailField == ''){
		document.getElementById('emailError').style.display = "block";
		document.theForm.email.style.backgroundColor = "#FFFF99";
		errors[0] = 'yes';
	}else{
		//the field is not empty so time to compare it against the email reg expression
		if(!emailPattern.test(emailField)){
			errors[0] = 'yes';
			document.getElementById('emailError').style.display = "block";
			document.theForm.email.style.backgroundColor = "#FFFF99";
		}else{
			document.getElementById('emailError').style.display = "none";
			document.theForm.email.style.backgroundColor = "#FFFFFF";
			errors[0] = '';
		}
	}

	//validate the comments field
	if(commentsField == ''){
		document.getElementById('commentsError').style.display = "block";
    	document.theForm.comments.style.backgroundColor = "#FFFF99";
		errors[1] = 'yes';
	}else{
		document.getElementById('commentsError').style.display = "none";
    	document.theForm.comments.style.backgroundColor = "#FFFFFF";
		errors[1] = '';
	}
	
	//validate the name field
	if(nameField == ''){
		document.getElementById('nameError').style.display = "block";
		document.theForm.name.style.backgroundColor = "#FFFF99";
		errors[2] = 'yes';
	}else{
		//check to see if a number was entered
		for(j=0; j<nameField.length; j++){
			testDigit = nameField.charAt(j);
			if(pattern.test(testDigit)){
				errors[2] = 'yes';
				break;
			}
		}
		if(errors[2] == 'yes'){
			document.getElementById('nameError').style.display = "block";
     		document.theForm.name.style.backgroundColor = "#FFFF99";
		}else{
			document.getElementById('nameError').style.display = "none";
        	document.theForm.name.style.backgroundColor = "#FFFFFF";
			errors[2] = '';
		}
	}
	
	//check the errors array
	for(i=0; i<3; i++){
		if(errors[i] == 'yes'){
			allow = 'no';
		}
	}
	
	//check the allow flag. This flag determines whether or not to submit the information
	if(allow == 'no'){
		return false;
	}else{
		return true;
	}
}
	
	
	
	
	
	
	
	
	
	
	