// JavaScript Document

// Global Vars
var inputTxt;
var submitBtn;

window.addEventListener('load', init, false);

/////////////////////// INITIALIZATION ///////////////////////
function init() {

	inputTxt  = document.getElementById("email_input");
	submitBtn = document.getElementById("email_submit"); 
		
	inputTxt.onfocus  = doFocus;
	submitBtn.onclick = validate;
}
//////////////////////////////////////////////////////////////


// FUNCTION doFocus -- handles focusing on email input field
function doFocus() {
	if(this.value == "YOUR EMAIL" || this.value == "INVALID EMAIL") {
		this.value = "";
		inputTxt.style.color = "#b0aeae";
	}
}// END FUNCTION


// FUNCTION validate -- validates email before sending it off
function validate() {
	var regExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var email  = inputTxt.value;
	
	// If email is invalid, then display msg
	if( !regExp.test(email) ) {
		inputTxt.value = "INVALID EMAIL";	
		inputTxt.style.color = "#FF0000";
		return false;
	} else {
		this.submit();	
	}// endif
	
	return false;
}// END FUNCTION
