
top.GenericCheck = function GenericCheck() {

  this.successor = null;

  this.check = function(el) {
    if(this.successor != null) {
      this.successor.check(el);
    }
  }

  this.isEmpty = function(v) {
    return (v.search(/\S/) == -1);
  }

  this.isNumber = function(v, l, m) {
    if(!l) var l = (v.length > 0) ? v.length : 1;
    if(!m) var m = l;
    return (v.search(new RegExp("\\d{" + m + "," + l + "}")) > -1) || (this.isEmpty(v));
  }
}
top.GenericCheck.instance = null;
top.GenericCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.GenericCheck();
  }
  return this.instance;
}

top.IsCnpjCheck = function IsCnpjCheck() {

  this.successor = null;
  this.errorMessages = top.IsCnpjErrorMessages;

  this.check = function(e) {
    var error = "";
    switch(e.getAttribute("datatype")) {
      case "cnpj":
        error += this.checkCnpj(e);
        break;
    }

    FormCheck.getInstance().addElementError(error);

    if(this.successor != null) {
      this.successor.check(e);
    }
  }

  this.checkCnpj = function(e) {
    if(this.isEmpty(el.value)) return "";
    var str = "";

    switch(parseInt(e.getAttribute("maxlength"))) {
      case 18:  //one field, format = 99.999.999/9999-99
      if(!this.isCnpj(e.value.replace(/-/g, "").replace(/\./g, "").replace(/\//g, ""))) {
        str += this.errorMessages.invalid;
      }
      if(e.value.search(/\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}/) == -1) {
        str += this.errorMessages.invalidFormat1;
      }
      break;
    }

    return str;
  }

  this.isCnpj = function(v) {
  	var alg1 = 0;
    var ok = false;
    var size = v.length;

    size--;

    alg1 = v.substr(1,1);
    for (i=2; i<size-1; ++i) {
      if (alg1 != v.charAt(i)) {
        ok = true;
        break;
      }
    }
	
    if (!ok) {
      return false;
    }
	
   	if(this.modulus(v.substring(0,v.length - 2)) + "" + this.modulus(v.substring(0,v.length - 1)) != v.substring(v.length - 2,v.length)) {
   		return false;
   	}

   	return true;
  }

  this.modulus = function(str) {
      var sum = 0;
      var ind = 2;

      for(pos=str.length-1;pos>-1;pos=pos-1) 
          {
        sum = sum + (parseInt(str.charAt(pos)) * ind);
        ind++;
        if(str.length>11) 
                  {
          if(ind>9) ind=2;
        }
    }

      rest = sum - (Math.floor(sum / 11) * 11);

      return (rest < 2)?0:(11 - rest);
  }
}
IsCnpjCheck.prototype.extendss("GenericCheck");

//implementation of the singleton design pattern
IsCnpjCheck.instance = 0;              //static "private" variable
IsCnpjCheck.getInstance = function() { //static method
  if(this.instance == 0) {
    this.instance = new IsCnpjCheck();
  }
  return this.instance;
}

top.IsTelephoneCheck = function IsTelephoneCheck() {

  this.successor = null;
  this.errorMessages = top.IsTelephoneErrorMessages;

  this.check = function(e) {
    var error = "";
    if(e.getAttribute("validation").indexOf("telephone") > -1) {
      error += this.checkTelephone(e);
    }

    if(this.successor != null) {
      return error + this.successor.check(e);
    }
    return error;
  }

  this.checkTelephone = function(e) {
    if(this.isEmpty(e.value)) return "";
    var str = "";
    switch(parseInt(e.getAttribute("maxlength"))) {
      case 2:  //two separate fields
        if(!this.isNumber(e.value + "" + e.form.elements[e.index + 1].value, 10)) {
          str += this.errorMessages.invalidFormat1;
        }
        break;
      case 10: //one field with prefix, format = 0099999999
        if(!this.isNumber(e.value, 10)) {
          str += this.errorMessages.invalidFormat2;
        }
        break;
      case 11: //one field, format = 00-99999999
        if(e.value.search(/\d{9}-\d{2}/) == -1) {
          str = this.errorMessages.invalidFormat3;
        }
        break;
      default:  //one field no prefix
        if(!this.isNumber(e.value, 8, 7)) {
          str += this.errorMessages.invalidFormat4;
        }
        break;
    }

    return str;
  }
}
top.IsTelephoneCheck.prototype.extendss("GenericCheck");
top.IsTelephoneCheck.instance = null;
top.IsTelephoneCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsTelephoneCheck();
  }
  return this.instance;
}

top.IsEmailCheck = function IsEmailCheck() {

  this.successor = top.IsCepCheck.getInstance();
  this.errorMessages = top.IsEmailErrorMessages;

  this.check = function(el) {
    var error = "";
    if(el.getAttribute("validation").indexOf("email") > -1) {
      error += this.checkEmail(el.value);
    }
    if(el.getAttribute("validation").indexOf("emailcheck") > -1) {
      error += this.emailMatch(el);
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.checkEmail = function(v) {
    var str = "";
    if(v.search(/^([a-z\d]+[\.]?[\_\-]*)*[a-z\d\_]+@(([a-z\d]+[\_\-]*)*[a-z\d]+\.)+[a-z]{2,3}$/i) == -1 && !this.isEmpty(v)) {
      str += this.errorMessages.invalid;
    }
    return str;
  }

  this.emailMatch = function(el) {
    var str = "";
    if(el.value != eval("el.form." + el.name.replace("check", "")).value && !this.isEmpty(el.value)) {
      str += this.errorMessages.invalidMatch;
    }
    return str;
  }
}
top.IsEmailCheck.prototype.extendss("GenericCheck");
top.IsEmailCheck.instance = null;
top.IsEmailCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsEmailCheck();
  }
  return this.instance;
}

top.IsZipCodeCheck = function IsZipCodeCheck() {

  this.successor = top.IsDateCheck.getInstance();
  this.errorMessages = top.IsCepErrorMessages;

  this.check = function(el) {
    var error = "";
    if(el.getAttribute("validation").indexOf("zipCode") > -1) {
      error += this.checkZipCode(el);
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.checkZipCode = function(el) {
    if(this.isEmpty(el.value)) return "";
    var str = "";

    switch(parseInt(el.getAttribute("maxlength"))) {
      case 5:  //two separate fields
        if(!this.isNumber(el.value, 5) || !this.isNumber(el.form.elements[el.index + 1].value), 4) {
          str += this.errorMessages.invalidFormat1;
        }
        break;
      case 10: //one field, format = 99999-9999
        if(!this.isNumber(el.value.replace("-", ""), 9) || el.value.charAt(5) != "-") {
          str += this.errorMessages.invalidFormat2;
        }
        break
      default:  //one field no format
        if(!this.isNumber(el.value, 9) ) {
          str += this.errorMessages.invalidFormat3;
        }
        break;
    }

    return str;
  }
}
top.IsZipCodeCheck.prototype.extendss("GenericCheck");
top.IsZipCodeCheck.instance = null;
top.IsZipCodeCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsZipCodeCheck();
  }
  return this.instance;
}


top.IsCepCheck = function IsCepCheck() {

  this.successor = top.IsZipCodeCheck.getInstance();
  this.errorMessages = top.IsCepErrorMessages;

  this.check = function(el) {
    var error = "";
    if(el.getAttribute("validation").indexOf("cep") > -1) {
      error += this.checkCep(el);
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.checkCep = function(el) {
    if(this.isEmpty(el.value)) return "";
    var str = "";

    switch(parseInt(el.getAttribute("maxlength"))) {
      case 5:  //two separate fields
        if(!this.isNumber(el.value, 5) || !this.isNumber(el.form.elements[el.index + 1].value), 3) {
          str += this.errorMessages.invalidFormat1;
        }
        break;
      case 9: //one field, format = 99999-999
        if(!this.isNumber(el.value.replace("-", ""), 8) || el.value.charAt(5) != "-") {
          str += this.errorMessages.invalidFormat2;
        }
        break
      default:  //one field no format
        if(!this.isNumber(el.value, 8) ) {
          str += this.errorMessages.invalidFormat3;
        }
        break;
    }

    return str;
  }
}
top.IsCepCheck.prototype.extendss("GenericCheck");
top.IsCepCheck.instance = null;
top.IsCepCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsCepCheck();
  }
  return this.instance;
}

top.IsDateCheck = function IsDateCheck() {

  this.successor = top.IsTelephoneCheck.getInstance();
  this.errorMessages = top.IsDateErrorMessages;

  this.daysInMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  this.MIN_Y = 1900;
  this.MAX_Y = 2030;

  this.check = function(e) {
    var error = "";
    var val = e.getAttribute("validation");
    if(val.indexOf("dateddmmyyyy") > -1) {
      error += this.isDdMmYyyy(e);
    } else if(val.indexOf("datemmddyyyy") > -1) {
      error += this.isMmDdYyyy(e);
    } else if(val.indexOf("yearyyyy") > -1) {
      error += this.isDateYyyyMmDd(e.value, "01", "01");
    }

    if(this.successor != null) {
      return error + this.successor.check(e);
    }
    return error;
  }

  this.isDdMmYyyy = function(e) {
    var d, m, y;
    var str = "";
    if(e.getAttribute("maxlength") == 2) {
        d = e.value;
        m = e.form.elements[e.index + 1].value;
        y = e.form.elements[e.index + 2].value;
    } else {
      if(e.value.search(/\d{2}\/\d{2}\/\d{4}/) == -1 && !this.isEmpty(e.value)) {
        str = this.errorMessages.invalidFormat1;
      }
      d = e.value.substring(0, e.value.indexOf("/"));
      m = e.value.substring(e.value.indexOf("/")+1, e.value.lastIndexOf("/"));
      y = e.value.substring(e.value.lastIndexOf("/")+1, e.value.length);
    }

    str = this.isDateYyyyMmDd(y, m, d) + str;

    return str;
  }

  this.isMmDdYyyy = function(e) {
    var d, m, y;
    var str = "";
    if(e.getAttribute("maxlength") == 2) {
        m = e.value;
        d = e.form.elements[e.index + 1].value;
        y = e.form.elements[e.index + 2].value;
    } else {
      if(e.value.search(/\d{2}\/\d{2}\/\d{4}/) == -1 && !this.isEmpty(e.value)) {
        str = this.errorMessages.invalidFormat2;
      }
      m = e.value.substring(0, e.value.indexOf("/"));
      d = e.value.substring(e.value.indexOf("/")+1, e.value.lastIndexOf("/"));
      y = e.value.substring(e.value.lastIndexOf("/")+1, e.value.length);
    }

    str = this.isDateYyyyMmDd(y, m, d) + str;

    return str;
  }

  this.isDateYyyyMmDd = function(y, m, d) {
    var str = "";

    if(!this.isDayDd(y, m, d) && !this.isEmpty(d)) {
      str += this.errorMessages.invalidDay;
    }
    if(!this.isMonthMm(m) && !this.isEmpty(m)) {
      str += this.errorMessages.invalidMonth;
    }
    if(!this.isYearYyyy(y) && !this.isEmpty(y)) {
      str += this.errorMessages.invalidYearIni + this.MIN_Y + this.errorMessages.invalidYearMid + this.MAX_Y + this.errorMessages.invalidYearEnd;
    }

    return str;
  }

  this.isDayDd = function(y, m, d) {
    return (this.isDay(y, parseInt(m), d) && d.length == 2);
  }

  this.isMonthMm = function(m) {
    return (this.isMonth(m) && m.length == 2);
  }

  this.isYearYyyy = function(y) {
    return (this.isYear(y) && y.length == 4);
  }

  this.isDay = function(y, m, d) {
    if(m == 2) {
      if(((y % 4 == 0) && ((!(y % 100 == 0)) || (y % 400 == 0))) && d <= 29) {
        return true;
      }
    }
    return (d >= 1 && d <= this.daysInMonth[m]);
  }

  this.isMonth = function(m) {
    return (m >= 1 && m <= 12);
  }

  this.isYear = function(y) {
    return (y >= this.MIN_Y && y <= this.MAX_Y);
  }
}
top.IsDateCheck.prototype.extendss("GenericCheck");
top.IsDateCheck.instance = null;
top.IsDateCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsDateCheck();
  }
  return this.instance;
}

top.IsPasswordCheck = function IsPasswordCheck() {

  this.successor = top.IsEmailCheck.getInstance();
  this.errorMessages = top.IsPasswordErrorMessages;

  var MIN = 6;
  var NUMBERS = 1;      // -1 for undefined
  var CHARS = 1;        // -1 for undefined
  var UPPER_CASES = 0;  // Must be lower or equal to CHARS.
                        // -1 for undefined
  var LOWER_CASES = 1;  // Must be lower or equal to CHARS.
                        // -1 for undefined
  this.check = function(el) {
    var error = "";
    if(el.type == "password" || el.getAttribute("validation").indexOf("password") > -1) {
      error += this.isValidPassword(el.value);
    }
    if(el.getAttribute("validation").indexOf("passwordcheck") > -1) {
      error += this.passwordMatch(el);
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.isValidPassword = function(v) {
    if(this.isEmpty(v)) return "";
    var str = "";
    var totalN = 0;
    var totalC = 0;
    var totalU = 0;
    var totalL = 0;
    
    for(var i = 0; i < v.length; i++) {
      if(v.charAt(i).search(/\d/) > -1) {
        totalN++;
      } else {
        totalC++;
        if(v.charAt(i).search(/[A-Z]/) > -1) {
          totalU++;
        } else if(v.charAt(i).search(/[a-z]/) > -1) {
          totalL++;
        }
      }
    }

    if(totalC + totalN < MIN) {
      str += this.errorMessages.invalidMinIni + MIN + this.errorMessages.invalidMinEnd;
    }
    if(totalN < NUMBERS) {
      str += this.errorMessages.invalidMinIni + NUMBERS + this.errorMessages.invalidMinNumbersEnd;
    }
    if(totalC < CHARS) {
      str += this.errorMessages.invalidMinIni + CHARS + this.errorMessages.invalidMinCharsEnd;
    }
    if(totalU < UPPER_CASES) {
      str += this.errorMessages.invalidMinIni + UPPER_CASES + this.errorMessages.invalidMinUpperEnd;
    }
    if(totalL < LOWER_CASES) {
      str += this.errorMessages.invalidMinIni + LOWER_CASES + this.errorMessages.invalidMinLowerEnd;
    }

    return str;
  }

  this.passwordMatch = function(el) {
    var str = "";
    if(el.value != eval("el.form." + el.name.replace("check", "")).value && !this.isEmpty(el.value)) {
      str += this.errorMessages.invalidMatch;
    }
    return str;
  }
}
top.IsPasswordCheck.prototype.extendss("GenericCheck");
top.IsPasswordCheck.instance = null;
top.IsPasswordCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsPasswordCheck();
  }
  return this.instance;
}

top.IsCpfCheck = function IsCpfCheck() {

  this.successor = top.IsPasswordCheck.getInstance();
  this.errorMessages = top.IsCpfErrorMessages;

  this.check = function(el) {
    var error = "";
    if(el.getAttribute("validation").indexOf("cpf") > -1) {
      error += this.checkCpf(el);
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.checkCpf = function(el) {
    if(this.isEmpty(el.value)) return "";
    var str = "";
    var sCpf = "";
    switch(parseInt(el.getAttribute("maxlength"))) {
      default: //one field, no format
        sCpf = el.value;
        break;
    }

    if(!this.isCpf(sCpf)) {
      str = this.errorMessages.invalid
    }

    return str;
  }

  this.isCpf = function(v) {
    var ok = false;
    var alg = 0;
    var soma1 = soma2 = 0;
    var var1 = var2 = var3 = var4 = 0;

    for(var i = 1 ; i < 11 ; i++) {
      if(v.charAt(0) != v.charAt(i)) {
        ok = true;
        break;
      }
    }

    if(!ok) {
      return false;
    }

    for(i = 0 ; i < 9 ; i++){	
      if (v.charAt(i) < '0' || v.charAt(i) > '9'){
        return false;
      }

      alg = parseInt(v.charAt(i));
      soma1 = soma1 + alg;
      soma2 = soma2 + alg * (9 - i);
    }

    var1 = 11 - ((soma1 * 1 + soma2 * 1) % 11);
    var3 = (var1 <= 9) ? var1 : 0;
    var2 = 11 - ((2 * (soma1 + var3) + soma2) % 11);
    var4 = (var2 <= 9) ? var2 : 0;

    dv = v.substring(v.length-2);
    if(dv != var3 * 10 + var4) {
      return false;
    }
    return true;
  }
}
top.IsCpfCheck.prototype.extendss("GenericCheck");
top.IsCpfCheck.instance = null;
top.IsCpfCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsCpfCheck();
  }
  return this.instance;
}

top.IsSocialSecurityCheck = function IsSocialSecurityCheck() {

  this.successor = top.IsCpfCheck.getInstance();
  this.errorMessages = top.IsSocialSecurityErrorMessages;

  this.check = function(el) {
    var error = "";
    if(el.getAttribute("validation").indexOf("socialsecurity") > -1) {
      error += this.checkSocialSecurity(el);
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.checkSocialSecurity = function(el) {
    if(this.isEmpty(el.value)) return "";
    var str = "";
    var sSocialSecurity = "";
    switch(parseInt(el.getAttribute("maxlength"))) {
      default: //one field, no format
        sSocialSecurity = el.value;
        break;
    }

    if(!this.isSocialSecurity(sSocialSecurity)) {
      str = this.errorMessages.invalid
    }

    return str;
  }

  this.isSocialSecurity = function(v) {
    //http://en.wikipedia.org/wiki/Social_Security_number#Valid_SSNs
    var var1 = var2 = var3 = 0;

    if (v.length!=9){ return false; }

    var1 = v.substr(0,3);
    var2 = v.substr(3,2);
    var3 = v.substr(5,4);

    
    if (parseInt(var1,10)==0 || parseInt(var2,10)==0 || parseInt(var3,10)==0){ return false; }
    if (parseInt(var1,10)==666){ return false; }
    if (parseInt(var1,10)==987 && parseInt(var2,10)==65 && (parseInt(var3,10)>=4320 && parseInt(var3,10)<=4329)){ return false; }

    return true;
  }
}
top.IsSocialSecurityCheck.prototype.extendss("GenericCheck");
top.IsSocialSecurityCheck.instance = null;
top.IsSocialSecurityCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsSocialSecurityCheck();
  }
  return this.instance;
}

top.IsNumberCheck = function IsNumberCheck() {

  this.successor = top.IsSocialSecurityCheck.getInstance();
  this.errorMessages = top.IsNumberErrorMessages;

  this.check = function(el) {
    var error = "";
    if(el.getAttribute("validation").indexOf("integer") > -1) {
      error += this.isInteger(el);
    } else if(el.getAttribute("validation").indexOf("float") > -1) {
      error += this.isFloat(el);
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.isInteger = function(el) {
    var str = "";
    if(!this.isNumber(el.value)) {
      str = this.errorMessages.invalidInteger;
    }
    return str;
  }

  this.isFloat = function(el) {
    var str = "";
    if(!this.isNumber(el.value)) {
      str = this.errorMessages.invalidFloat;
    }
    return str;
  }
}
top.IsNumberCheck.prototype.extendss("GenericCheck");
top.IsNumberCheck.instance = null;
top.IsNumberCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsNumberCheck();
  }
  return this.instance;
}

top.IsInLengthCheck = function IsInLengthCheck() {

  this.successor = top.IsNumberCheck.getInstance();
  this.errorMessages = top.IsInLengthErrorMessages;

  this.check = function(el) {
    var error = "";
    max = el.getAttribute("maxlength");
    if(max != null) {
      max = parseInt(max);
      switch(el.type) {
        case "file":
        case "password":
        case "text":
        case "textarea":
          error += this.isInLength(el);
          break;
        case "select-one":
        case "select-multiple":
          error += this.isInLengthSelect(el);
          break;
      }
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.isInLength = function(el) {
    var str = "";
    var quebras = (quebras = el.value.match(/\n/g)) ? quebras.length : 0;
    if((el.value.length + quebras) > max) {
      str += this.errorMessages.invalidIni + " " + (el.value.length + quebras) + " " + this.errorMessages.invalidMid1 + " " + (el.value.length + quebras - parseInt(el.getAttribute("maxlength"))) + " " + this.errorMessages.invalidMid2 + " " + el.getAttribute("maxlength") + " " + this.errorMessages.invalidEnd;
    }
    return str;
  }

  this.isInLengthSelect = function(el) {
    var str = "";
    var selecteds = 0;
    for(var i = 0; i < el.length; i++) {
      if(el[i].selected) {
        selecteds++;
      }
    }

    if(selecteds > max) {
      str += this.errorMessages.invalidSelectIni + " " + selecteds + " " + this.errorMessages.invalidSelectMid1 + " " + (selecteds - max) + " " + this.errorMessages.invalidSelectMid2 + " " + max + " " + this.errorMessages.invalidSelectEnd;
    }
    return str;
  }
}
top.IsInLengthCheck.prototype.extendss("GenericCheck");
top.IsInLengthCheck.instance = null;
top.IsInLengthCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsInLengthCheck();
  }
  return this.instance;
}

top.IsEmptyCheck = function IsEmptyCheck() {

  this.successor = top.IsInLengthCheck.getInstance();
  this.errorMessages = top.IsEmptyErrorMessages;

  this.check = function(el) {
    var error = "";
    if(el.getAttribute("validation").indexOf("required") > -1) {
      if(!this.isDependencyEmpty(el)) {
        error = this.switchType(el);
      }
    }

    if(this.successor != null) {
      return error + this.successor.check(el);
    }
    return error;
  }

  this.switchType = function(el) {
    var error;
    switch(el.type) {
      case "file":
      case "password":
      case "text":
      case "textarea":
        error = this.isEmptyText(el);
        break;
      case "select-one":
        error = this.isEmptySelectOne(el);
        break;
      case "select-multiple":
        error = this.isEmptySelectMulti(el);
        break;
      default:
        error = this.isEmptyGroup(el);
    }
    return error;
  }

  this.isDependencyEmpty = function(el) {
    if(el.getAttribute("depends") == null) return false;
    var a = el.getAttribute("depends").split(",");
    for(var i = 0; i < a.length; i++) {
      if(this.switchType(eval("el.form." + a[i])) == "") {
        return false;
      }
    }
    return true;
  }

  this.isEmptyText = function(el) {
    var str = "";
    if(this.isEmpty(el.value)) {
      str += this.errorMessages.empty;
    }
    return str;
  }

  this.isEmptyGroup = function(el) {
    var str = "";
    var group = eval("el.form." + el.name);
    if(group.length) {
      for(var i = 0; i < group.length; i++) {
        if(group[i].checked == true) {
          return str;
        }
      }
    } else {
      if(group.checked) {
        return str;
      }
    }
    return this.errorMessages.groupEmpty;
  }

  this.isEmptySelectOne = function(el) {
    var str = "";
    if(el.selectedIndex == 0) {
      str += this.errorMessages.selectEmpty;
    }
    return str;
  }

  this.isEmptySelectMulti = function(el) {
    var str = "";
    for(var i = 0; i < el.length; i++) {
      if(el[i].selected) {
        return str;
      }
    }
    str += this.errorMessages.selectEmpty;
    return str;
  }
}
top.IsEmptyCheck.prototype.extendss("GenericCheck");
top.IsEmptyCheck.instance = null;
top.IsEmptyCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.IsEmptyCheck();
  }
  return this.instance;
}

top.FormCheck = function FormCheck() {

  var RETURN_ALL_ERRORS = 1;
  var RETURN_FIELD_ERRORS = 2;

  this.firstCheck = top.IsEmptyCheck.getInstance();
  this.elError = "";
  this.allErrors = "";
  this.returnErrors = RETURN_FIELD_ERRORS;

  this.checkForm = function(f, s, a, t) {
    var e, label;
    for(var i = 0; i < f.elements.length; i++) {
      this.elError = "";
      el = f.elements[i];
      if(el.disabled) {
        continue;
      } else if(el.getAttribute("validation") == undefined) {
        continue;
      }
      switch(el.type) {
        case "hidden":
        case "submit":
        case "button":
        case "reset":
        case "image":
          continue;
          break;
        default:
          this.elError = this.firstCheck.check(el);
      }

      if(this.elError == "") {
        continue;
      }

      label = el.name;
      if(el.getAttribute("label") != null) {
        label = el.getAttribute("label");
      }
      this.elError = top.FormCheckErrorMessages.field + label + this.elError;
      this.allErrors += this.elError;
      if(this.returnErrors == RETURN_FIELD_ERRORS) {
        break;
      }
    }

    if(this.allErrors != "") {
      this.alertStrategy.alert(top.FormCheckErrorMessages.errorsFound + this.allErrors);
    } else {
      if(s) {
        if(a) f.action = a;
        if(t) f.target = t;
        f.submit();
      }
      return (true);
    }

    this.elError = "";
    this.allErrors = "";
    return (false);
  }

//default alert strategy
  var BasicAlert = function () {
    this.alert = function(s) {
      alert(s);
    }
  }
  this.alertStrategy = top.AlertBox.getInstance();
}
top.FormCheck.instance = null;
top.FormCheck.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.FormCheck();
  }
  return this.instance;
}

top.formcheck = function(f, s, a, t) {
  return (top.FormCheck.getInstance().checkForm(f, s, a, t));
}