if(window.addEventListener) {
window.addEventListener("load", loadactions, true);
}
else if(window.attachEvent) {
window.attachEvent("onload", loadactions);
}

function loadactions() {
document.getElementById('contact').onsubmit = validate;
var items = Array('name','email','phone','subject','message');
	for(var i = 0;i < items.length;i++) {
	document.getElementById('c' + items[i]).onfocus = focusActions;
	document.getElementById('c' + items[i]).onblur = blurActions;
	}
}

function focusActions() {
	if(document.all) {
	this.style.borderWidth = "2px";
	this.style.padding = "1px";
	}
	document.getElementById('l' + this.id.substring(1)).style.textDecoration = "underline";
}

function blurActions() {
	if(document.all) {
	this.style.borderWidth = "1px";
	this.style.padding = "2px";
	}
	document.getElementById('l' + this.id.substring(1)).style.textDecoration = "none";
}

function validate() {
var emailim = document.getElementById('cemail').value;
var messageim = document.getElementById('cmessage').value;

var emailcheck = true;
var messagecheck = true;

if(messageim.length == 0 || messageim.search(/^[\s]+$/) !== -1) {
messagecheck = false;	
}

if(emailim.length == 0 || emailim.search(/^[\s]+$/) !== -1) {
emailcheck = false;	
}
else {
lastdot = emailim.lastIndexOf('.');
atsign = emailim.indexOf('@');
	if(emailim.length < 6 || lastdot < 3 || atsign < 1 || lastdot < atsign) {
	emailcheck = false;	
	}
}

	if(!emailcheck && !messagecheck) {
	alert('Please enter a message and a valid email address.');
	document.getElementById('cmessage').style.backgroundColor = '#FFDCD5';
	document.getElementById('cemail').style.backgroundColor = '#FFDCD5';
	return false;
	}
	else if(!messagecheck) {
	alert('Please enter a message.');
	document.getElementById('cmessage').style.backgroundColor = '#FFDCD5';
	document.getElementById('cemail').style.backgroundColor = '#ffffff';	
	return false;
	}
	else if(!emailcheck) {
	alert('Please enter a valid email address.');
	document.getElementById('cmessage').style.backgroundColor = '#ffffff';
	document.getElementById('cemail').style.backgroundColor = '#FFDCD5';
	return false;
	}
return true;
}