$(document).ready(function(){
  if ($(".bxslider").length > 0) {
    $('.bxslider').bxSlider({
        auto:true,
        mode:"fade",
        pause: 1500,
    });
  };
});

jQuery(function($){
  $(function() {
    $('a[href*=#]:not([href=#])').click(function() {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
        if (target.length) {
          $('html,body').animate({
            scrollTop: target.offset().top
          }, 1000);
          return false;
        }
      }
    });
  });
  if ($("#personal_phone").length > 0) {
    $("#personal_phone").mask("(999) 999-9999");
  };
  if ($("#credit_number").length > 0) {
    $("#credit_number").mask("9999-9999-9999-9999");
  };
  if ($("#credit_expire_date").length > 0) {
    $("#credit_expire_date").datepicker({dateFormat: "dd-mm-yy"});
    $("#credit_expire_date").mask("99-99-9999");
  };
  if ($("#reservation_date_in").length > 0) {
    $(function() {
        $( "#reservation_date_in" ).datepicker({
          // defaultDate: "+1w",
          changeMonth: true,
          numberOfMonths: 1,
          dateFormat:"dd-mm-yy",
          onClose: function( selectedDate ) {
            $( "#reservation_date_out" ).datepicker( "option", "minDate", selectedDate );
          }
        });
        $( "#reservation_date_out" ).datepicker({
          // defaultDate: "+1w",
          changeMonth: true,
          numberOfMonths: 1,
          dateFormat:"dd-mm-yy",
          onClose: function( selectedDate ) {
            $( "#reservation_date_in" ).datepicker( "option", "maxDate", selectedDate );
          }
        });
    });
    $("#reservation_date_in").mask("99-99-9999");
  };
  if ($("#reservation_date_out").length > 0) {
    $("#reservation_date_out").mask("99-99-9999");
  };
});

function init_contact_form() {
  $("#contact-form > form").on("submit", function(){
      $.get( "contact-form.php", {name:$("input[id=name]").val() ,email:$("input[id=email]").val() ,subject:$("input[id=subject]").val() ,message:$("textarea[id=message]").val()}, function(data){
        //return respond data...
      });
      $("input, textarea").val("");
      alert("Email sent successfully, Our staff will get back to you soon!");
      return false;
  });
}

function init_map() {
        var var_location = new google.maps.LatLng(5.666600,100.531185);
 
        var var_mapoptions = {
          center: var_location,
          zoom: 14
        };
 
        var var_marker = new google.maps.Marker({
            position: var_location,
            map: var_map,
            title:"Venice"});
 
        var var_map = new google.maps.Map(document.getElementById("google-maps"),
            var_mapoptions);
 
        var_marker.setMap(var_map);    
 
}

//Validate email function with regualr expression
function validateEmail(email){
	if ($(email).val()) {
		var emailReg = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		var valid = emailReg.test($(email).val());

		if(!valid) {
	        alert("Please enter correct email address!");
	        $(email).val("");
	    	$(email).focus();
	    }
	};
}
