// Form Code
var good = true;
var bgBad = "#FF6666";
var bgGood = "#ededed";

function setColor(elname, bg) {
	el = document.getElementById(elname + "id");
	if(el) el.style.backgroundColor = bg;
}

function checkEmailAddress(field){

	// the following expression must be all on one line...
	var good = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi);

	return good;

}

function checkPhone(field){

	// the following expression must be all on one line...
	var good = field.value.match(/^(\([1-9]\d{2}\))|\d{3}\-\s?\d{3}\-\d{4}$/);

return good;
}


function checkState(field){

	// the following expression must be all on one line...
	// 
	var good = field.value.match(/^[a-zA-Z]{2}$/);

return good;
}

function checkZip(field){

	// the following expression must be all on one line...
	var good = field.value.match(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

return good;
}


function emptyfield(ffield){

	alert(ffield);

}

function validfield(ffield){

	alert("\n" + ffield + " ...\t\t\t\n");

}


// code for checking form input
function checkform(theform){
	var fieldfocus = '';
	var empty = '';
	var valid = '';

	setColor('Email', bgGood);
	setColor('Name', bgGood);
	setColor('Comment', bgGood);
			
	if(theform.Name.value==''){

		empty = empty + "Name\n";

		setColor('Name', bgBad);

		fieldfocus = theform.Name;

	}else{

		setColor('Name', bgGood)

	}
	
	if(theform.Email.value==''){

		empty = empty + "Email\n";

		setColor('Email', bgBad);

		if(fieldfocus == ''){
			fieldfocus = theform.Email;
		}
	}else{

		if(checkEmailAddress(theform.Email)){
		
			setColor('Email', bgGood);
		
		}else{
			
			setColor('Email', bgBad);
		
			if(fieldfocus == ''){
				fieldfocus = theform.Email;
			}
			
			valid = valid + "Email: Please enter a valid e-mail address\n";
			
		}

	}
		
		if(empty != '' || valid != ''){
			
			if(empty != ''){
				
				empty = "Please enter:\n" + empty + " ...\t\t\t\n";

			}
	
			if(valid != ''){
				
				empty = empty + "\nInvalid Format:\n" + valid + " ...\t\t\t\n";

			}

		emptyfield(empty);

		fieldfocus.focus();

		return false;

	}

}

	var messtimer;

	String.prototype.trim = function() {

		a = this.replace(/^\s+/, '');
		return a.replace(/\s+$/, '');

	}
	

	function stopTimer(){

		clearTimeout(messtimer);

	}

	function startTimer(duration, idtemp){

		id = idtemp;

  		messtimer = setTimeout("hidemessage(id)",duration);

		
 	}
	
	function hidemessage(id){
	
		document.getElementById(id).style.display  = 'none';
		
	}
	
