// JavaScript Document

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){
       return false
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
      alert("Your email address is invalid.")
       return false
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Your email address is invalid.")
        return false
    }
     if (str.indexOf(at,(lat+1))!=-1){
        alert("Your email address is invalid.")
        return false
     }
     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Your email address is invalid.")
        return false
     }
     if (str.indexOf(dot,(lat+2))==-1){
        alert("Your email address is invalid.")
        return false
     }
     if (str.indexOf(" ")!=-1){
        alert("Your email address is invalid.")
        return false
     }        
  }


function checkSignup() {

  var problem;
  problem = 'No';

  if (document.signup.name.value.length < "1") { problem = 'Yes'; alert ('Please provide your name.'); }
  if (document.signup.email.value.length < "1") { problem = 'Yes'; alert ('We need your email address. You will not be able to access swif.ly without providing it.');  }
  if (document.signup.password.value.length < "1") { problem = 'Yes'; alert ('Please provide a password.'); } 
  if (!document.signup.terms.checked) { problem = 'Yes'; alert ('You have to agree to the Terms and Privacy Policy to join.'); }

  /*
  var re = /^[\w ]+$/; // validation fails if the input doesn't match the regular expression 
  if(!re.test(document.signup.name.value)) { 
    alert("Your name can only contain letters."); 
    document.signup.name.value="";
    document.signup.name.focus();  
    problem = 'Yes';  
  } 
  */

  if (echeck(document.signup.email.value)==false){
    document.signup.email.value=""
    document.signup.email.focus()
    problem = 'Yes';
    return false;
  }

  if (problem == 'No') {
    //document.getElementById('submitholder').innerHTML = '<input type=image name=submit id="checkUser" value=submit src="images/btn_join.png">';
    problem = 'No';
  	return true;
  } else {
    problem = 'No';
  	return false;
  }

}
