﻿var i=0;

function incrementi()
{
	i++;
}

function dontPaste(obj){
   if(obj.value.length>i){
      alert('Please do not copy/paste. Type your confirmation email address!')
      obj.value='';i=0;
      obj.focus();obj.select();
      return false;
   }
   else
   {
   	   return check();
   	}
}
//helpers
function trim(str) {
  var s = new String(str);
  while (s.length > 1 && s.charAt(0) == ' ')  s = s.substring(1, s.length);
  while (s.length > 1 && s.charAt(s.length - 1) == ' ') s = s.substring(0, s.length - 1);
  if (s.length == 1 && s.charAt(0) == ' ') s = "";
  return s;
} //trim()
function compare(arg){
        return (this.toString()==arg.toString());
}
function check(){
        var errors = new Array();
        var erm = "Please fix the following errors so that you can signup:\n\n";

        errors[1] = "Email address cannot be empty";
        errors[2] = "The supplied confirmation email does not match the email address";     
        errors[3] = "Your email address appears incorrect. Please re-enter.";
        errors[4] = "Invalid email format. Address required.";
        errors[5] = "Invalid email format.Domain required.";
        errors[6] = "Invalid email format. Domain appears incorrect.";
        errors[7] = "The email address contains invalid characters.";
        var er = "";
        var err = '';   
        var  balert=false;


        var tmpEm = trim(document._store.email.value);  
        if (tmpEm.length == 0) err += '1|';
        var tmpCm = trim(document._store.cmail.value);
        if (tmpCm.length == 0 ||  tmpEm.toString() != tmpCm.toString() ) err += '2|';

//      er = err.split("|")
        em = trim(document._store.email.value);
        err += split(em,'@','.');
        er = err.split("|")

        if(er.length > 0){
                for (i=0; i < er.length; i++){
                        if ( er[i] ){ balert=true; erm += errors[er[i]] + "\n" }
                }               
        }
        if(balert)
        {
                alert(erm);
                return false;
        }
        return true;
}
function split(sx,a,d){
  var err = '';
  var s = new String();
  var q = new String();
  if((sx.indexOf(a)==-1)){ err += '3|';}
  q=sx.substring(0,sx.search(a));
  if(q==''){err += '4|';}
  err += cc(q);
  s=sx.substring(sx.length+1,sx.search(a)+1);
  err += cc(s);
  if(s.indexOf(d)==-1){err += '5|';}
  if(s.lastIndexOf(d)==s.length-1){err +='6|';}
  return err;
}       //split(sx,c,d)
function cc(sc){
  var s = new String(sc);
  var err = '';
  for (i=0; i < sc.length; i++){
    if(sc.charAt(i)==' '||sc.charAt(i)=='"'||sc.charAt(i)=='@'||sc.charAt(i)=='%') err +='7|';
  }
  return err;
}

