var address;
var subject;
var message;
var submitButton;
var mailForm;
var error;
var img_spinner = new Image(); img_spinner.src = "images/spinner.gif";
var img_navbar_thispage = new Image(); img_navbar_thispage.src = "/images/navbar_bg_current.png";
var img_navbar_hover = new Image(); img_navbar_thispage.src = "/images/navbar_bg_on.png";

window.onload = function() {
	// set up list of elements to attach events to
	firstname = document.getElementById('firstname');
	lastname = document.getElementById('lastname');
	address = document.getElementById('mail_address');
	phone = document.getElementById('phone');
	besttime = document.getElementById('best_time');
	interested1 = document.getElementById('interested_1');
	interested2 = document.getElementById('interested_2');
	interested3 = document.getElementById('interested_3');
	interested4 = document.getElementById('interested_4');
	interested5 = document.getElementById('interested_5');
	interested6 = document.getElementById('interested_6');
	interestedother = document.getElementById('interested_other');
	servicesfor = document.getElementById('services_for');
	servicesfor2 = document.getElementById('services_for2');
	domainname = document.getElementById('domain_name');
	subject = document.getElementById('mail_subject');
	message = document.getElementById('mail_message');
	captcha = document.getElementById('captcha');
	submitButton = document.getElementById('submit_button');
	mailForm = document.getElementById('mail');
	error = document.getElementById('error');
	error2 = document.getElementById('error2');
	error3 = document.getElementById('error3');
	
	// highlight name input box when clicked
	firstname.onfocus = function() {
		firstname.style.backgroundColor = '#ffc';
	};
	firstname.onblur = function() {
		firstname.style.backgroundColor = '#fff';
	};
	lastname.onfocus = function() {
		lastname.style.backgroundColor = '#ffc';
	};
	lastname.onblur = function() {
		lastname.style.backgroundColor = '#fff';
	};


	// highlight email address input box when clicked
	address.onfocus = function() {
		address.style.backgroundColor = '#ffc';
	};
	address.onblur = function() {
		address.style.backgroundColor = '#fff';
	};

	// highlight email address input box when clicked
	phone.onfocus = function() {
		phone.style.backgroundColor = '#ffc';
	};
	phone.onblur = function() {
		phone.style.backgroundColor = '#fff';
	};
	// highlight interested_other input box when clicked
	interestedother.onfocus = function() {
		interestedother.style.backgroundColor = '#ffc';
	};
	interestedother.onblur = function() {
		interestedother.style.backgroundColor = '#fff';
	};
	// highlight domain_name input box when clicked
	domainname.onfocus = function() {
		domainname.style.backgroundColor = '#ffc';
	};
	domainname.onblur = function() {
		domainname.style.backgroundColor = '#fff';
	};
	
	// highlight subject input box when clicked
	subject.onfocus = function() {
		subject.style.backgroundColor = '#ffc';
	};
	subject.onblur = function() {
		subject.style.backgroundColor = '#fff';
	};
	
	// highlight message textarea when clicked
	message.onfocus = function() {
		message.style.backgroundColor = '#ffc';
	};
	message.onblur = function() {
		message.style.backgroundColor = '#fff';
	};
	// highlight captcha input when clicked
	captcha.onfocus = function() {
		captcha.style.backgroundColor = '#ffc';
	};
	captcha.onblur = function() {
		captcha.style.backgroundColor = '#fff';
	};
}

// make sure appropriate values are in the form fields
function validateMailForm() {
	var count = 0;
	if(firstname.value == "") {
		firstname.style.backgroundColor = "#f99";
		count++;
	}
	if(lastname.value == "") {
		lastname.style.backgroundColor = "#f99";
		count++;
	}
	if(address.value == "" || address.value.indexOf("@")==-1) {
		address.style.backgroundColor = "#f99";
		count++;
	}
	if(subject.value == "") {
		subject.style.backgroundColor = "#f99";
		count++;
	}
	if(message.value == "") {
		message.style.backgroundColor = "#f99";
		count++;
	}
	if(captcha.value != "web") {
		captcha.style.backgroundColor = "#f99";
		count++;
	}
	if(count > 0) {
		error.style.visibility = "visible";
		return false;
	}
	else {
		submitButton.disabled = true;
		error.style.visibility = "hidden";
		error2.style.visibility = "hidden";
		error3.style.visibility = "hidden";
		document.getElementById('spinner').src = "images/spinner.gif";
		return true;
	}
}
