// ----------------------------------------------------------------------
// EBC - eAlert OptOut Javascript form validation routines.


function isEmail(e) 
{
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < e.length ;i++){
	if(ok.indexOf(e.charAt(i))<0){ 
	return (false);
	}	
	} 

	if (document.images) {
	re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
	re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (!e.match(re) && e.match(re_two)) {
	return (-1);		
	} 
	}
}


function chkvals(f,nm) 
{
	var df = f.document.forms[nm];
//  if (!compFields(nm)) { return false; }
    if (f.email1.value == "") {
    alert("Must have an email address in 'Email' field");
    f.email1.focus();
    return false;
  	}

/*  if (!isEmail(f.email1.value)) {
	  alert(isemail);
    f.email1.focus();
    return false;
  }*/
  
	if(!isEmail(f.email1.value)){
	alert("Invalid email detected.");
	f.email1.focus(); 
	// if the browser is Netscape 6 or IE
	if(document.all || document.getElementByID){
	// change the color of text field
	f.email1.style.background = "white";
	}
	// make sure the form is not submitted
	return false;
	}  


	if (f.email2.value == "") {
    alert("Must have an email address in 'Retype Email' field");
    f.email2.focus();
    return false;
  	}
  
	if(!isEmail(f.email2.value)){
	alert("Invalid email detected.");
	f.email2.focus(); 
	// if the browser is Netscape 6 or IE
	if(document.all || document.getElementByID){
	// change the color of text field
	f.email2.style.background = "white";
	}
	// make sure the form is not submitted
	return false;
	}  

 
  
	if (f.email1.value != f.email2.value) { 
      alert ('The email addresses do not match. Please re-enter.'); 
	   f.email2.focus();
	return false; 
   	}
  	return true;
}


 /* function isEmail(string) {
  var regex1 = /^[\w\.\-]*[\w\.\-]+\@([a-z0-9]+[\.\-])*[a-z0-9]+\.[a-z]{2,}$/i
  var regex2 = /^[\w\.\-]*[\w\.\-]+\@\[\d{1,3}\.\d{1,3}\.\d{1.3}\.\d{1,3}\]$/i

  if (regex1.test(string)) { return true; }
  else { 
    if (regex2.test(string)) { return true; }
    else { 
      alert("Email address is not valid")
    f.email1.focus();
    }
  }
}*/

/*function compFields(nm) {
  var df = document.forms[nm];
  var aa,bb;
  aa = df.email1.value;
  bb = df.email2.value;
  alert(aa);
  if ((aa=="") || (bb=="")) { return true; }
  if (aa!=bb) {
    alert("Email and check fields should match");
    df.email1.focus();
    return false;
  }
  return true;
}

*/
