$(document).ready(function() {
  //searchbox blogu yukleniyor..
  var uUrl = "/blocks/search/bSearchFormCityGuide.php";
  if(typeof(destinationInfo) != 'undefined') uUrl += "?destination=" + destinationInfo.destinationName + "&cityId=" + destinationInfo.cityId;
  $.ajax({
    url       : uUrl,
    type      : "GET",
    dataType  : "text/html",
    cache     : true,
    success   : function(data, textStatus) {
      if(textStatus == "success") {
        $("#travelGuideSearchBox").html(data);
        $()
        //*************************** Datepicker Definations Start ****************
        /*
        search formundaki check-in date girisi icin
        daettimepicker nesnesi hazirlaniyor.
        */
        oCheckInDateParameters.buttonImage = '/images/calendarSmll.gif'
        $("#showCheckInDateInfo").datepicker(oCheckInDateParameters);
        /*
        .change(function() {
          var oDate = new Date($(this).val());
          iDay = oDate.getUTCDate();
          oDate.setUTCDate(iDay+2);
          $("#showCheckOutDateInfo").datepicker("setDate", oDate);
        });
        */
        /*
        search formundaki check-out date girisi icin
        daettimepicker nesnesi hazirlaniyor.
        */
        oCheckOutDateParameters.buttonImage = '/images/calendarSmll.gif'
        $("#showCheckOutDateInfo").datepicker(oCheckOutDateParameters);
        //*************************** Datepicker Definations End ******************
        
        
        //*************************** AutoComplete Definations Start **************
        //search destination autocomplete initialize ediliyor.
        //destinationSearchAutoComplete();
        //Ana sayfadaki destination search autocomplete initialize ediliyor.
          initializeAutoComplete({
            acObjectId        : 'showDestination',
            searchType        : 'city',
            width             : function() {return (iAutoCompleteWidth) ? iAutoCompleteWidth : 370},
            setOnSelect       : [
              {hiddenFieldName : 'cityId',      dataFieldName : 'cityId'},
              {hiddenFieldName : 'latitude',    dataFieldName : 'latitude'},
              {hiddenFieldName : 'longitude',   dataFieldName : 'longitude'}
            ],
            fields            : ["cityId", "cityName", "stateCode", "countryName", "latitude", "longitude"],
            resultFormat      : "[cityName], [stateCode][stateCode^,] [countryName]",
            displayFormat     : "[cityName], [stateCode][stateCode^,] [countryName]"
          });
          if(typeof(sbCityId)!='undefined') $("#cityId").val(sbCityId);
          if(typeof(sbSearchText) != 'undefined') $("#showDestination").val(sbSearchText);
        //*************************** AutoComplete Definations End ****************
        
        
        /**********************************incdec start**************************/
        $("form div.incdec.guests").incdec("initialize",  {defaultValue: 2, minValue: 1, maxValue : 5});
        $("form div.incdec.rooms").incdec("initialize",   {defaultValue: 1, minValue: 1, maxValue : 3});
        /**********************************incdec end***************************/
        
        
        //***********************  Map Event(s) Definations Start *****************
        var Conts  = new Array(0,0,0,0,0,0,0,0);
        var Conts2 = new Array(0,0,0,0,0,0,0,0);

        $(".continentMenu li a").click(function () {
          $(".continentMenu li a").removeClass("active");
          $(this).addClass("active");
        });
        
        $(".continentMenu li").mouseover(function () {
          var Class = $(this).attr('class');
          var num = Class.split('-');
          $(".worldmap li#ctnt-"+num[1]).addClass("active");
        })
        .mouseout(function () {
          var Class = $(this).attr('class');
          var num = Class.split('-');
          if(Conts[num[1]-1]==0)
          $(".worldmap li#ctnt-"+num[1]).removeClass("active");
        })
        .click(function () {
          var Class = $(this).attr('class');
          var num = Class.split('-');
          $(".worldmap li").removeClass("active");
          for(var i = 0; i<Conts.length; i++)
          Conts[i]=0;
          Conts[num[1]-1] = 1;
          $(".worldmap li#ctnt-"+num[1]).addClass("active");
        });
        
        /* Harita */
        $(".worldmap li").click(function(){
        var ID = $(this).attr('id');
          var num = ID.split('-');
          $(".continentMenu li a").removeClass("active");
          $(".worldmap li").removeClass("active");
          $(".item-"+num[1]+" a").addClass("active");
          $("#ctnt-"+num[1]).addClass("active");
          for(var i = 0; i<Conts2.length; i++)
          Conts2[i]=0;
          Conts2[num[1]-1]=1;
        })
        .mouseover(function(){
          var ID = $(this).attr('id');
          var num = ID.split('-');
          $(".item-"+num[1]+" a").addClass("active");
        })
        .mouseout(function(){
          var ID = $(this).attr('id');
          var num = ID.split('-');
          if(Conts2[num[1]-1]==0)
          $(".item-"+num[1]+" a").removeClass("active");
        });
        //***********************  Map Event(s) Definations End *******************
        
        /*
        Ana sayfadaki search formunun submit olayinda 
        gerceklestirilen kontrol islemleri
        */
        $("#searchForm").submit(function() {
          var sMessage = '';
          
          $('.searchFormAlert').hide();
          $('.searchFormAlert').html('');
          if($("#showDestination").val()=="") {
            sMessage = "Please enter a valid city.";
            $("#destinationAlert").html('<span class="red-1 s10">' + sMessage + '</span>');
            $("#destinationAlert").show(100);
            $("#showDestination").focus();
            return false;
          }

          var sCheckInDate = $('#showCheckInDateInfo').val();
          var sCheckOutDate = $('#showCheckOutDateInfo').val();
          
          if(jQuery.trim(sCheckInDate)=="") {
            sMessage = 'Please select check-in date.';
            $('#dateAlert').html('<span class="red-1 s10">' + sMessage + '</span>');
            $('#dateAlert').show(100);
            //$('#showCheckInDate').focus();
            return false;
          }
          
          if(jQuery.trim(sCheckOutDate)=="") {
            sMessage = 'Please select check-out date.';
            $('#dateAlert').html('<span class="red-1 s10">' + sMessage + '</span>');
            $('#dateAlert').show(100);
            return false;
          }
          
          
          var dCheckInDate = new Date(sCheckInDate);
          var dCheckOutDate = new Date(sCheckOutDate);
          
          if(dCheckInDate >= dCheckOutDate) {
            sMessage = 'Please select valid date range.';
            $('#dateAlert').html('<span class="red-1 s10">' + sMessage + '</span>');
            $('#dateAlert').show(100);
            return false;
          }    
        });    
      }
    }
  });
});


$(document).ready(function() {  
  
});
