function initialize() {

  geocoder = new google.maps.Geocoder();

}



function getCountryStates(countryId, stateId, dv) {

  //alert(fcom.makeUrl('DriverRegistration', 'getStates', [countryId, stateId]));

  fcom.ajax(

    fcom.makeUrl("DriverRegistration", "getStates", [countryId, stateId]),

    "",

    function (res) {

      //alert(res);

      $(dv).empty();

      $(dv).append(res);

    }

  );

}

function getModelsMake(makeId, modelId, dv) {

  fcom.ajax(

    fcom.makeUrl("DriverRegistration", "getCarModels", [makeId, modelId]),

    "",

    function (res) {

      //alert(res); alert(dv);

      $(dv).empty();

      $(dv).append(res);

    }

  );

}

function resendVerificationLink(user) {

  if (user == "") {

    return false;

  }

  $(document).trigger("closeMsg.systemMessage");

  $.mbsmessage(langLbl.processing, false, "alert--process alert");

  fcom.updateWithAjax(

    fcom.makeUrl("DriverRegistration", "resendVerification", [user]),

    "",

    function (ans) {

      $.mbsmessage(ans.msg, false, "alert alert--success");

    }

  );

}



function getCardType(number) {

  // visa

  var re = new RegExp("^4");

  if (number.match(re) != null) return "Visa";



  // Mastercard

  re = new RegExp("^5[1-5]");

  if (number.match(re) != null) return "Mastercard";



  // AMEX

  re = new RegExp("^3[47]");

  if (number.match(re) != null) return "AMEX";



  // Discover

  re = new RegExp(

    "^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)"

  );

  if (number.match(re) != null) return "Discover";



  // Diners

  re = new RegExp("^36");

  if (number.match(re) != null) return "Diners";



  // Diners - Carte Blanche

  re = new RegExp("^30[0-5]");

  if (number.match(re) != null) return "Diners - Carte Blanche";



  // JCB

  re = new RegExp("^35(2[89]|[3-8][0-9])");

  if (number.match(re) != null) return "JCB";



  // Visa Electron

  re = new RegExp("^(4026|417500|4508|4844|491(3|7))");

  if (number.match(re) != null) return "Visa Electron";



  return "";

}



(function ($) {

  $.extend(fcom, {

    getLoader: function () {

      return '<div class="loader-yk"><div class="loader-yk-inner"></div></div>';

    },
	
	removeLoader:function(e){
		$(document.body).css({cursor:"default"}),$(".loaderJs").remove(),$(".submitBtnJs").removeClass("loading").removeAttr("disabled")
	},
	
	displayProcessing:function(){
		$.ykmsg.clear(),fcom.processingCounter++,$.ykmsg.info(langLbl.processing,-1,fcom.processingClass+" "+fcom.processingClass+"-"+fcom.processingCounter)
	},
	
	closeProcessing:function(e){
		var t=fcom.processingClass;void 0!==e&&(t+="-"+e),$("."+t).remove()
	},
	
	displaySuccessMessage:function(e){
		$.ykmsg.close(),$.ykmsg.success(e)
	},
	
	displayErrorMessage:function(e){
		$.ykmsg.close(),$.ykmsg.error(e)
	},



    scrollToTop: function (obj) {

      if (typeof obj == undefined || obj == null) {

        $("html, body").animate(

          { scrollTop: $("html, body").offset().top - 100 },

          "slow"

        );

      } else {

        $("html, body").animate(

          { scrollTop: $(obj).offset().top - 100 },

          "slow"

        );

      }

    },

    resetEditorInstance: function () {

      if (extendEditorJs == true) {

        var editors = oUtil.arrEditor;

        for (x in editors) {

          eval("delete window." + editors[x]);

        }

        oUtil.arrEditor = [];

      }

    },

    setEditorLayout: function (lang_id) {

      if (extendEditorJs == true) {

        var editors = oUtil.arrEditor;

        layout = langLbl["language" + lang_id];

        for (x in editors) {

          $("#idContent" + editors[x])

            .contents()

            .find("body")

            .css("direction", layout);

        }

      }

    },

  });



  $(document).bind("loading.facebox", function () {

    $("#facebox .content").addClass("fbminwidth");

  });



  $(document).bind("afterClose.facebox", fcom.resetEditorInstance);

  $(document).bind("beforeReveal.facebox", function () {

    $("#facebox .content").addClass("fbminwidth");

  });



  $(document).bind("reveal.facebox", function () {

    $("#facebox .content").addClass("fbminwidth");

  });



  $.systemMessage = function (data, cls) {

    initialize();

    $.systemMessage.loading();

    $.systemMessage.fillSysMessage(data, cls);

  };



  $.extend($.systemMessage, {

    settings: {

      closeimage: siteConstants.webroot + "images/facebox/close.gif",

    },

    loading: function () {

      $(".system_message").show();

    },

    fillSysMessage: function (data, cls) {

      if (cls) $(".system_message").addClass(cls);

      $(".system_message .content").html(data);

      $(".system_message").fadeIn();



      if (CONF_AUTO_CLOSE_SYSTEM_MESSAGES == 1) {

        var time = CONF_TIME_AUTO_CLOSE_SYSTEM_MESSAGES * 1000;

        setTimeout(function () {

          $.systemMessage.close();

        }, time);

      }



      /* $('.system_message').css({top:10}); */

    },

    close: function () {

      $(document).trigger("closeMsg.systemMessage");

    },

  });



  $(document).bind("closeMsg.systemMessage", function () {

    $(".system_message").fadeOut();

  });



  function initialize() {

    $(".system_message .closeMsg").click($.systemMessage.close);

  }

  /* [ */

  $.fn.serialize_without_blank = function () {

    var $form = this,

      result,

      $disabled = $([]);



    $form.find(":input").each(function () {

      var $this = $(this);

      if ($.trim($this.val()) === "" && !$this.is(":disabled")) {

        $disabled.add($this);

        $this.attr("disabled", true);

      }

    });



    result = $form.serialize();

    $disabled.removeAttr("disabled");

    return result;

  };

  /* ] */

})(jQuery);



function isUserLogged() {

  var isUserLogged = 0;

  $.ajax({

    url: fcom.makeUrl("DriverRegistration", "checkAjaxUserLoggedIn"),

    async: false,

    dataType: "json",

  }).done(function (ans) {

    isUserLogged = parseInt(ans.isUserLogged);

  });

  return isUserLogged;

}



$(window).scroll(function () {

  $(this).scrollTop() > 50

    ? $("header").addClass("js--scrolled")

    : $("header").removeClass("js--scrolled");

});


function setSiteDefaultLang(langId) {
		var url = window.location.pathname;
		var srchString = window.location.search;
		var data = "pathname=" + url;
		fcom.ajax(
			fcom.makeUrl("Home", "setLanguage", [langId]),
			data,
			function (res) {
				var ans = $.parseJSON(res);
				if (ans.status == 1) {
					window.location.href = ans.redirectUrl + srchString;
				}
			}
		);
	}