(function($) {
  $.fn.validationEngineLanguage = function() {};
  $.validationEngineLanguage = {
    newLang: function() {
      $.validationEngineLanguage.allRules = {
        "required":{
          "regex":"none",
          "alertText":"* This field is required",
          "alertTextCheckboxMultiple":"* Please select an option",
          "alertTextCheckboxe":"* This checkbox is required"},
        "length":{
          "regex":"none",
          "alertText":"*Between ",
          "alertText2":" and ",
          "alertText3": " characters allowed"},
        "maxCheckbox":{
          "regex":"none",
          "alertText":"* Checks allowed Exceeded"},
        "minCheckbox":{
          "regex":"none",
          "alertText":"* Please select ",
          "alertText2":" options"},
        "confirm":{
          "regex":"none",
          "alertText":"* Your field is not matching"},
        "minCheckbox": {
          "regex": "none",
          "alertText": "* Please select at least ",
          "alertText2": " reason"},
        "telephone":{
          "regex":/^[0-9\-\(\)\ ]+$/,
          "alertText":"* Invalid phone number"},
        "email":{
          "regex":/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/,
          "alertText":"* Invalid email address"},
        "date":{
          "regex":/^[0-9]{4}\-\[0-9]{1,2}\-\[0-9]{1,2}$/,
          "alertText":"* Invalid date, must be in YYYY-MM-DD format"},
        "onlyNumber":{
          "regex":/^[0-9\ ]+$/,
          "alertText":"* Numbers only"},
        "noSpecialCaracters":{
          "regex":/^[0-9a-zA-Z]+$/,
          "alertText":"* No special caracters allowed"},
        "ajaxUser":{
          "file":"validateUser.php",
          "extraData":"name=eric",
          "alertTextOk":"* This user is available",
          "alertTextLoad":"* Loading, please wait",
          "alertText":"* This user is already taken"},
        "ajaxName":{
          "file":"validateUser.php",
          "alertText":"* This name is already taken",
          "alertTextOk":"* This name is available",
          "alertTextLoad":"* Loading, please wait"},
        "onlyLetter":{
          "regex":/^[a-zA-Z\ \']+$/,
          "alertText":"* Letters only"},
        "validate2fields":{
          "nname":"validate2fields",
          "alertText":"* You must have a firstname and a lastname"},
        "notDefaultValue":{
          "nname":"notDefaultValue",
          "alertText":"* This field is required."},
        "validateGiftCards":{
          "nname":"validateGiftCards",
          "alertText":"* Please enter a whole number between 5 and 800."}
      }
    }
  }
})(jQuery);

$(document).ready(function() {
  $.validationEngineLanguage.newLang()
});

function notDefaultValue(object) {
  // Note: Returning true means error.
  return $(object).val() == getStartingValue(object); // See jquery.clearField.js
}

// Used as a way around for $(o).attr('value') as this does not work.
function getStartingValue(object) {
  return $(object).attr('title') || object.getAttribute('value') || $(object).text() || null;
}

function validateGiftCards(object) {
  var value = $(object).val();
  var invalid = false;
  if(isNaN(value))
    invalid = true;
  if(!(/^[0-9]+$/.test(value)))
    invalid = true;
  if(!(value >= 5 && value <= 800))
    invalid = true;
  return invalid;
}
