

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/, "");
}


function Validation() {
    this.str = "";
    this.IsEmpty = IsEmpty;
    this.IsStandard = IsStandard;
    this.IsText = IsText;
    this.IsNumber = IsNumber;
    this.HasLength = HasLength;
    this.IsPostalCode = IsPostalCode;
    this.IsTelephone = IsTelephone;
    this.IsEmail = IsEmail;
    this.IsStreetNumber = IsStreetNumber;
    this.IsYear = IsYear;
    this.IsAlphaNum = IsAlphaNum;
    this.IsStandardNum = IsStandardNum;
    this.IsAmount = IsAmount;
    this.IsOther = IsOther;
}


function IsEmpty() {
     if (this.str.trim() == "")
         return true;
      else
         return false;
}


function IsText() {
     if (this.str.search(/^[a-zäöüß.\s-]+$/i) != -1)
         return true;
     else
         return false;
}


function IsAlphaNum() {
     if (this.str.search(/^[a-zäöüß0-9.\s-]+$/i) != -1)
         return true;
     else
         return false;
}


function HasLength(min, max) {
     var tmpStr = this.str.trim();

     if (tmpStr.length >= min && tmpStr.length <= max)
        return true;
     else
        return false;
}

function IsNumber() {
    if (this.str.search(/^\d+$/) != -1)
       return true;
    else
       return false;
}

function IsStandard(str) {
      this.str = str;

      if (this.IsEmpty())
          return 1;

      if (!this.HasLength(2, 30))
          return 3;

      if (!this.IsText())
          return 2;

      return 0;
}


function IsStandardNum(str) {
      this.str = str;

      if (this.IsEmpty())
          return 1;

      if (!this.HasLength(2, 30))
          return 3;

      if (!this.IsAlphaNum())
          return 2;

      return 0;
}


function IsStreetNumber(str, min, max) {
    this.str = str;

    if (this.IsEmpty())
        return 1;

    if (!this.HasLength(1, 20))
        return 3;

    return 0;
}

function IsPostalCode(str, length) {
     this.str = str;

     if (this.IsEmpty())
         return 1;

     if (!this.HasLength(length, length))
          return 3;

     if (!this.IsNumber())
         return 4;

     return 0;
}


function IsTelephone(str, min, max) {
     this.str = str;

     if (this.IsEmpty())
         return 1;

     if (!this.IsNumber())
         return 4;

     if (!this.HasLength(min, max))
          return 3;

     return 0;
}

function IsEmail(str) {
     this.str = str;

     if (this.IsEmpty())
         return 1;

     if (!this.HasLength(5, 40))
          return 3;

     regexp = /^[A-Za-z0-9](([_.-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([.-]?[A-Za-z0-9]+)*)\.([A-Za-z]{2,})$/;

     if (this.str.search(regexp) == -1)
        return 2;

     return 0;
}


function IsYear(str) {
     this.str = str;

     if (this.IsEmpty())
         return 1;

     if (!this.IsNumber())
         return 4;

     if (!this.HasLength(4, 4))
          return 3;

     return 0;
}


function IsAmount(str, min) {
     this.str = str;

     if (this.IsEmpty())
         return 1;

     if (!this.IsNumber())
         return 4;

     if (!this.HasLength(4, 8))
          return 3;

     if (parseFloat(str) < min)
        return 5;

     return 0;
}


function IsOther(str, min, max, regexp) {
     this.str = str;

     if (this.IsEmpty())
         return 1;

     if (this.str.search(regexp) == -1)
        return 2;

     if (!this.HasLength(min, max))
        return 3;

     return 0;
}



