// JavaScript Document
$(function() {
  $("#frmAddUser").validate();
  $("#Zip").mask("99999");
  $("#phone").mask("(999)999-9999");
  $("#Zip").blur( function () {
    var iZipCode = $(this).val();
    $.ajax({
      type: "GET",
      url: "/Components/Zipcode.cfc",
      datatype: "xml",
      data: "method=fnCheckZip&Zip=" + iZipCode,
      success: function (xml) {
        if ($(xml).find('city').text() != '') {
          $('#Zip').css('background','#fff');
          $('#Zip').css('border','1px solid #D3D3D3');
          $('#Zip').css('color','#000');
          $("#zipError").hide();
          $("#zipError").html('');
          $("#city").html($(xml).find('city').text());
          $("#state").html($(xml).find('state').text());
        } 
        else {
          $('#Zip').val('');
          $("#city").html('Please enter a zip code');
          $("#state").html('Please enter a zip code');
          if (iZipCode!='_____') {
            $('#Zip').addClass('error');
            $("#zipError").html( iZipCode.replace(/_/g,'') + ' Is not a valid zip code.');
            $("#zipError").show();
            $('#Zip').focus();
          } else {
            $("#zipError").hide();
          }
        }
      }
    });
  });

});
