$(document).ready(function () {
  //disabled for further development
//  $("#value").get(0).validationRules.push(JLTA.Validation.rule.server);
//  $("#accValue").get(0).validationRules.push(JLTA.Validation.rule.server);
//  $("#value").get(0).serverValidation = 
//  $("#accValue").get(0).serverValidation = {
//    path: "validation.svc/PremiumValueInRange?bike=",
//    getValue: function () {
//      return $("#value").get(0).value + "&acc=" + $("#accValue").get(0).value;
//    },
//    handler: handleValueValidation
//  }
})

function handleValueValidation(data) {
  var el = $("#" + data.Caller).get(0);
  el.form.deferredValidators.splice(el.validationIndex, 1);//boot deferred validation from list
  if (data.Message != "") {
    el.form["value"].valid = 
    el.form["accValue"].valid = false;
    el.form["value"].displayError();
    el.form["accValue"].error = data.Message;
    el.form["accValue"].displayError();
  } else {
    el.form.valid = true;
    markFieldValid(el.form["value"]);
    markFieldValid(el.form["accValue"]);
  }
}

// clears an element's parent's "invalid" class if the element itself is valid
function markFieldValid(field) {
  field.validationRules.pop();//clear custom valdiation
  if (field.error == "") {
    field.clearError();
  }
  field.validated = true;
  field.validationRules.push(JLTA.Validation.rule.server);//and bring it right back
  field.valid = true;
}
