//  estescreative.com | design. build. host

var email; //global var holds email
var valid1 = new Boolean(false);
var valid2 = new Boolean(false);

/* colors:
#f9f9f9 - off-white, for blank fields
#FFE3E3 - pink, for empty name and incorrect email
#f9f9f9 - off-white, for correct names
*/

function emailCheck(x) {
  if(!email) {
    var y=document.getElementById(x).value;
    if(y.length>=1) {
      emailTest(y,x);
    } else {
      document.getElementById(x).style.backgroundColor = '#f9f9f9'; } //off-white, for blank fields
  }
  else if(x==email){
    emailTest(y,x);
  }
}

function emailCheck2(x) {
  var y=document.getElementById(x).value;
  if(email && x!=email) {
    emailTest(y,x);
  } else {
    document.getElementById(x).style.backgroundColor = '#f9f9f9'; }
}

function emailTest(y,x) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(y)) {
    document.getElementById(x).style.backgroundColor = '#f9f9f9';
    document.getElementById("erroremail").innerHTML = "&nbsp;";    
    email = y;
    valid1 = true;
	}
  else {
    document.getElementById(x).style.backgroundColor = '#FFE3E3';
    document.getElementById("erroremail").innerHTML = "!";
    valid1 = false;
	}
}

function checkName(x) {
  var y=document.getElementById(x).value;
  if(y.length<1) {
    document.getElementById(x).style.backgroundColor = '#FFE3E3';
    document.getElementById("errorname").innerHTML = "!";
    valid2 = false;    
  }
}

function checkName2(x) {
  var y=document.getElementById(x).value;
  if(y.length>=1) {
    document.getElementById(x).style.backgroundColor = '#f9f9f9';
    document.getElementById("errorname").innerHTML = "&nbsp;";
    valid2 = true;
  }
}

function checkValid() {
  if(valid1 == false || valid2 == false) {
    document.getElementById("submiterror").innerHTML = "Please correct errors above.";
    return false
  }
  else if(valid1 == true && valid2 == true) {
    document.getElementById("submiterror").innerHTML = "&nbsp;";
    return true;
  }
  else return false;
}