// JavaScript Document

var correct = 0;
var errortext = "";
var temp1 = "";
var temp2 = "";
var temp3 = "";
var error1 = ""; /* email address */
var error2 = ""; /* name*/
var error3 = ""; /* message */
var error4 = ""; /* recipient */

function errorcheck(){
	if (correct !== 0){
		errortext = "Please note the following errors: \n";
		if( error1 !== ""){
			errortext = errortext + error1;
			//document.getElementById('emaila').style.color="red";
		}
		if( error2 !== ""){
			errortext = errortext + error2;
			//document.getElementById('forename').style.color="red";
		} else{
			error2 ="";
			//document.sustain.firstname.style.borderColor="#30f017";
			//document.sustain.firstname.style.backgroundColor="#b5f8ac";
		}
		if( error3 !== ""){
			errortext = errortext + error3;
			//document.sustain.surname.style.borderColor="red";
			//document.sustain.surname.style.backgroundColor="yellow";
		} else{
			error3 ="";
			//document.sustain.surname.style.borderColor="#30f017";
			//document.sustain.surname.style.backgroundColor="#b5f8ac";
		}
		if( error4 !== ""){
			errortext = errortext + error4;
			//document.sustain.phone.style.borderColor="red";
			//document.sustain.phone.style.backgroundColor="yellow";
		} else{
			error4 ="";
			//document.sustain.phone.style.borderColor="#30f017";
			//document.sustain.phone.style.backgroundColor="#b5f8ac";
		}

		window.alert(errortext);
		correct = 0;
		errortext = "";
		temp1 = "";
		temp2 = "";
		temp3 = "";
		error1 = ""; /* email address */
		error2 = ""; /* Name */
		error3 = ""; /* Message */
		error4 = ""; /* Recipient */
		return false
	}

	document.ContactForm.action="GloDerMail.asp";
	document.ContactForm.submit();
	return true
}

function checktext(){

	temp1 = document.ContactForm.home_input1.value;
	temp2 = document.ContactForm.home_input5.value;
	temp3 = document.ContactForm.recipient.value;
	if (temp1 =="Name..."){
		correct++;
		error2 = " - no name entered\n"; /* Name */
	}
	if (temp2 == "Topic..."){
		correct++;
		error3 = " - no topic entered\n"; /* Message */
	}
	if (temp3 == ""){
		correct++;
		error4 = " - no nearest office chosen\n"; /* Message */
	}
		errorcheck();
}

function contactcheck(){
	correct = 0;
	apos=document.ContactForm.home_input4.value.indexOf("@")
	dotpos=document.ContactForm.home_input4.value.lastIndexOf(".")
	if (document.ContactForm.home_input4.value == "" || document.ContactForm.home_input4.value == "Email..." || apos<1 || dotpos-apos<2){
		correct++;
		error1 = " - incorrect email address\n"; /* email address */
	}
	checktext();
} 