// OPTIONS
var InActiveColor = '#43311d';
var ActiveColor = '#1c120c';
var RequiredColor = '#d98d00';
var FormName = "contactform";

////////////////////////////////// FORM FUNCTION
var CheckRequiredInputs = Array();
function CheckInput() {
	document[FormName].onsubmit = function () { return CheckForm(); };
	// INPUTS
	var Inputs = document[FormName].getElementsByTagName('input');
	for (var i = 0; i < Inputs.length; i++) {	
			Inputs[i].style.color = InActiveColor;
			Inputs[i].onfocus = new Function('if(this.value=="'+Inputs[i].value+'" || this.value=="Required '+Inputs[i].value+'") { this.value=""; this.style.color="'+ActiveColor+'" }');
			Inputs[i].onblur = new Function('if(this.value=="") { this.value="'+Inputs[i].value+'"; this.style.color="'+InActiveColor+'"}'); 
			CheckRequiredInputs[Inputs[i].name] = Inputs[i].value;
	}
	// TEXTAREA
	var Inputs = document[FormName].getElementsByTagName('textarea');
	for (var i = 0; i < Inputs.length; i++) {	
			Inputs[i].style.color = InActiveColor;	
			Inputs[i].onfocus = new Function('if(this.value=="'+Inputs[i].value+'" || this.value=="Required '+Inputs[i].value+'") { this.value=""; this.style.color="'+ActiveColor+'" }');
			Inputs[i].onblur = new Function('if(this.value=="") { this.value="'+Inputs[i].value+'"; this.style.color="'+InActiveColor+'"}'); 
			CheckRequiredInputs[Inputs[i].name] = Inputs[i].value;
	}			
}

function CheckForm() {
var Valid = true;	
	// INPUTS
	var Inputs = document[FormName].getElementsByTagName('input');
	for (var i = 0; i < Inputs.length; i++) {
	if (Inputs[i].name != 'submit' && Inputs[i].name != 'Submit') {
		if (Inputs[i].value == CheckRequiredInputs[Inputs[i].name] || Inputs[i].value == "") {		
		Inputs[i].value = 'Required '+CheckRequiredInputs[Inputs[i].name];
		Inputs[i].style.color = RequiredColor;
		Valid = false;
		} else if (Inputs[i].name.match(/email/i)) {
		var CheckEmail = Inputs[i].value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
			if (!CheckEmail) {
			Inputs[i].value = 'Required '+CheckRequiredInputs[Inputs[i].name];
			Inputs[i].style.color = RequiredColor;
			Valid = false;
			} 
		}	
	}		
	}	
	// TEXTAREA
	var Inputs = document[FormName].getElementsByTagName('textarea');
	for (var i = 0; i < Inputs.length; i++) {
		if (Inputs[i].value == CheckRequiredInputs[Inputs[i].name] || Inputs[i].value == "") {		
		Inputs[i].value = 'Required '+CheckRequiredInputs[Inputs[i].name];
		Inputs[i].style.color = RequiredColor;	
		Valid = false;
		}	
	}
	
if (document[FormName].answer.value != '7') { Valid = false; }	
return Valid;
}
window.onload = CheckInput;
////////////////////////////////// FORM FUNCTION