jQuery.ketchup

.validation('required', '', function(form, el, value) {
  var type = el.attr('type').toLowerCase();
  
  if(type == 'checkbox' || type == 'radio') {
    return (el.attr('checked') == true);
  } else {
    return (value.length != 0);
  }
})

.validation('minlength', 'Minimalna długość to {arg1} znaków.', function(form, el, value, min) {
  if(value != 'Treść wiadomości') return (value.length >= +min);
  else return false;
})

.validation('person', 'Podaj ilość osób', function(form, el, value, min) {
  return (value.length > 0);
})

.validation('maxlength', 'Maksymalna długość to {arg1}.', function(form, el, value, max) {
  return (value.length <= +max);
})

.validation('maxlength_', 'Maksymalna długość to {arg1}.', function(form, el, value, max) {
 if(value.length > 0) return (value.length <= +max);
 return true;
})

.validation('rangelength', 'This field must have a length between {arg1} and {arg2}.', function(form, el, value, min, max) {
  return (value.length >= min && value.length <= max);
})

.validation('min', 'Must be at least {arg1}.', function(form, el, value, min) {
  return (this.isNumber(value) && +value >= +min);
})

.validation('max', 'Can not be greater than {arg1}.', function(form, el, value, max) {
  return (this.isNumber(value) && +value <= +max);
})

.validation('range', 'Wymagana wartość pomiędzy {arg1} a {arg2}.', function(form, el, value, min, max) {
  return (this.isNumber(value) && +value >= +min && +value <= +max);
})

.validation('number', 'Podaj format cyfrowy.', function(form, el, value) {
  return this.isNumber(value);
})

.validation('kodserwisowy', 'Podaj kod serwisowy.', function(form, el, value) {
  return this.isKodserwisowy(value);
})

.validation('product', 'Musisz wypełnić pole nazwy produktu.', function(form, el, value) {
  return this.isProduct(value);
})

.validation('companyname', 'Wpisz nazwę firmy.', function(form, el, value) {
  return this.isCompanyName(value);
})

.validation('costumer', 'Podaj nazwisko osoby zgłaszającej.', function(form, el, value) {
  return this.isCostumer(value);
})

.validation('phoneDefault', 'Nieprawidłowy format numeru telefonu.', function(form, el, value) {
  if(value.length > 0 & value != 'Numer telefonu') return this.isPhone(value);
  return true;
})

.validation('phone', 'Nieprawidłowy format numeru telefonu.', function(form, el, value) {
  return this.isPhone(value);
})

.validation('def', 'Musisz podać e-mail lub telefon', function(form, el, value) {
  var email = jQuery("#Qe").val();
  var phone = jQuery("#Qp").val();
  
  if(email.length > 0 & email != 'Adres e-mail') return true;
  if(phone.length > 0 & phone != 'Numer telefonu') return true;
})

.validation('deff', 'Musisz podać e-mail lub telefon', function(form, el, value) {
  var email = jQuery("#Qemail").val();
  var phone = jQuery("#Qphone").val();
  
  if(email.length > 0) return true;
  if(phone.length > 0) return true;
})

.validation('digits', 'Must be digits.', function(form, el, value) {
  return /^\d+$/.test(value);
})

.validation('emailDefault', 'Podaj poprawny adres e-mail.', function(form, el, value) {
  if(value.length > 0 & value != 'Adres e-mail' ) return this.isEmail(value);
  return true;
})

.validation('email', 'Podaj poprawny adres e-mail.', function(form, el, value) {
  return this.isEmail(value);
})

.validation('url', 'Nieprawidłowy adres url.', function(form, el, value) {
  return this.isUrl(value);
})

.validation('username', 'Podaj prawidłową nazwę.', function(form, el, value) {
  return this.isUsername(value);
})

.validation('name', 'Prawidłowy format to np. Jan Kowalski.', function(form, el, value) {
  return this.isName(value);
})

.validation('subject', 'Podaj temat wiadomości.', function(form, el, value) {
  return this.isSubject(value);
})

.validation('match', 'Must be {arg1}.', function(form, el, value, word) {
  return (el.val() == word);
})

.validation('contain', 'Must contain {arg1}', function(form, el, value, word) {
  return this.contains(value, word);
})

.validation('date', 'Podaj prawidłowy format daty.', function(form, el, value) {
  return this.isDate(value);
})

.validation('minselect', 'Select at least {arg1} checkboxes.', function(form, el, value, min) {
  return (min <= this.inputsWithName(form, el).filter(':checked').length);
}, function(form, el) {
  this.bindBrothers(form, el);
})

.validation('maxselect', 'Select not more than {arg1} checkboxes.', function(form, el, value, max) {
  return (max >= this.inputsWithName(form, el).filter(':checked').length);
}, function(form, el) {
  this.bindBrothers(form, el);
})

.validation('rangeselect', 'Select between {arg1} and {arg2} checkboxes.', function(form, el, value, min, max) {
  var checked = this.inputsWithName(form, el).filter(':checked').length;
  
  return (min <= checked && max >= checked);
}, function(form, el) {
  this.bindBrothers(form, el);
});
