// JavaScript Document

var correct = 0;
var errortext = "";
var temp1 = "";
var temp2 = "";
var temp3 = "";
var temp4 = "";
var error1 = ""; /* email address */
var error2 = ""; /* first name */
var error3 = ""; /* surname */
var error4 = ""; /* phone number */
var error5 = ""; /* postcode */
var error6 = ""; /* organisation */
var error7 = ""; /* address1 */

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";
}
if( error5 !== ""){
errortext = errortext + error5;
//document.sustain.postcode.style.borderColor="red";
//document.sustain.postcode.style.backgroundColor="yellow";
} else{
error5 ="";
//document.sustain.postcode.style.borderColor="#30f017";
//document.sustain.postcode.style.backgroundColor="#b5f8ac";
}
if( error6 !== ""){
errortext = errortext + error6;
//document.sustain.organ.style.borderColor="red";
//document.sustain.organ.style.backgroundColor="yellow";
} else{
error6 ="";
//document.sustain.organisation.style.borderColor="#30f017";
//document.sustain.organisation.style.backgroundColor="#b5f8ac";
}
if( error7 !== ""){
errortext = errortext + error7;
//document.sustain.address1.style.borderColor="red";
//document.sustain.address1.style.backgroundColor="yellow";
} else{
error7 ="";
//document.sustain.address1.style.borderColor="#30f017";
//document.sustain.address1.style.backgroundColor="#b5f8ac";
}
window.alert(errortext);
correct = 0;
errortext = "";
temp1 = "";
temp2 = "";
temp3 = "";
temp4 = "";
temp5 = "";
temp6 = "";
error1 = ""; /* email address */
error2 = ""; /* first name */
error3 = ""; /* surname */
error4 = ""; /* phone number */
error5 = ""; /* postcode */
error6 = ""; /* postcode */
error7 = ""; /* postcode */
return false
}
//document.sustain.firstname.style.borderColor="#7bc7e4";
//document.sustain.surname.style.borderColor="#7bc7e4";
//document.sustain.phone.style.borderColor="#7bc7e4";
//document.sustain.postcode.style.borderColor="#7bc7e4";
//document.sustain.company.style.borderColor="#7bc7e4";
//document.sustain.address1.style.borderColor="#7bc7e4";
document.sustain.action="process.php";

document.sustain.submit();
return true
}

function checktext(){

temp1 = document.sustain.forename.value;
temp2 = document.sustain.surnamea.value;
temp3 = document.sustain.telephonea.value;
temp4 = document.sustain.company.value;
temp5 = document.sustain.comment.value;
temp6 = document.sustain.interest.value;
if (temp1 =="Forename >"){
correct++;
error2 = " - no first name entered\n"; /* firstname */
}
if (temp2 == "Surname >"){
correct++;
error3 = " - no surname entered\n"; /* surname */
}
if (temp3 == "Contact telephone number >"){
correct++;
error4 = " - no phone number entered\n"; /* phone number */
}
if (temp4 == "Company Name >"){
correct++;
error5 = " - no company name entered\n"; /* company name*/
}
if (temp5 == "Nature of enquiry > no more than 500 characters"){
correct++;
error6 = " - no comment entered\n"; /* comment */
}
if (temp6 == "Category of interest >"){
correct++;
error7 = " - no category of interest entered\n"; /* interest */
}
errorcheck();
}

function checkemail(){

correct = 0;
apos=document.sustain.emaila.value.indexOf("@")
dotpos=document.sustain.emaila.value.lastIndexOf(".")
if (document.sustain.emaila.value == "" || document.sustain.emaila.value == "Email address >" || apos<1 || dotpos-apos<2)
{
correct++;
error1 = " - incorrect email address\n"; /* email address */

}
checktext();
} 