window.onload = emailSignupInit;

function emailSignupInit() {
	var userEmail = "Email Address";
	var userName = "";
	
	if (document.cookie != "") {
	var thisCookie = document.cookie.split("; ");
	
		for (var i=0; i<thisCookie.length; i++) {
			if ("ckname" == thisCookie[i].split("=")[0]) {
			userName = thisCookie[i].split("=")[0];
			userEmail = thisCookie[i].split("=")[1];
			}
		}
		
	}

	document.getElementById("cons_email").value = userEmail;
	document.getElementById("cons_email").onblur = setCookie;
	document.getElementById("testcookie").innerHTML = "this is the cookie name: " + userName + " this is the cookie value: " + userEmail;
}

function setCookie() {
	var userEmail = document.getElementById("cons_email").value;
	document.cookie = "ckname=" + userEmail + ";path=/";
}


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid email address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid email address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid email address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid email address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid email address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid email address.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid email address.")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.signupForm.cons_email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your email address.")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }