jQuery().ready(function() {
  jQuery('body').ieFixButtons();

//  jQuery("#fm_hotelsearch").submit(function() {
//
//    if ( jQuery('#profitCenterX').length) {
//      if (jQuery('#profitCenterX').val() == 0) {
//        jQuery('#err').html(inner_profitcentre_err);
//        return false;
//      }
//
//      if (!jQuery('#SUserX').length || jQuery('#SUserX').val() == 0) {
//        jQuery('#err').html(inner_suser_err);
//        return false;
//      }
//
//      if (!jQuery('#AgentX').length || jQuery('#AgentX').val() == 0) {
//        jQuery('#err').html(inner_agent_err);
//        return false;
//      }
//
//      if (!jQuery('#BuyerX').length || jQuery('#BuyerX').val() == 0) {
//        jQuery('#err').html(inner_contract_err);
//        return false;
//      }
//    }
//
//    return true;
//  });
});
      
function rateclick (par) {
  var stars_1 = document.getElementById("stars_1");
  var stars_2 = document.getElementById("stars_2");
  var stars_3 = document.getElementById("stars_3");
  var stars_4 = document.getElementById("stars_4");
  var stars_5 = document.getElementById("stars_5");
  var stars_any = document.getElementById("stars_any");

  if (stars_1 != null && stars_2 != null && stars_3 != null
    && stars_4 != null && stars_5 != null && stars_any != null) {

    if (par == 'stars_1') {
      stars_any.checked = null;
    } else if (par == 'stars_2') {
      stars_any.checked = null;
    } else if (par == 'stars_3') {
      stars_any.checked = null;
    } else if (par == 'stars_4') {
      stars_any.checked = null;
    } else if (par == 'stars_5') {
      stars_any.checked = null;
    } else if (par == 'stars_any') {
      stars_1.checked = null;
      stars_2.checked = null;
      stars_3.checked = null;
      stars_4.checked = null;
      stars_5.checked = null;
    }
  }
}

function errh(msg) {
  top.location = path+'/online/fatalsuberror.jsp?m='+msg;
}

function errh() {
  top.location = path+'/online/fatalsuberror.jsp';
}

function doErrorHandler(message, exception) {
  top.location = path+'/online/fatalsuberror.jsp?m='+message;
}

function doWarningHandler() {
  top.location = path+'/online/fatalsuberror.jsp?m=s4';
}

function doTextHtmlHandler() {
  top.location = path+'/online/fatalsuberror.jsp?m=s5';
}

function FirstLoad(country, city, hotel) {
    
  pgEngineSearch.change(
    country, city, hotel,
    function(data) {
      if (data==null) {
        errh('pg_engine_search:FirstLoad'); return false;
      }

      if (data[0] != '') {
        errh(); return false;
      }

      jQuery('#countryCode').hide();
      jQuery('#countryCode').after(data[3]).remove();
      jQuery('#countryCode').show();

      jQuery('#cityCode').hide();
      jQuery('#cityCode').after(data[2]).remove();
      jQuery('#cityCode').show();

      jQuery('#hotelCode').hide();
      jQuery('#hotelCode').after(data[1]).remove();
      jQuery('#hotelCode').show();

      moveCheckedAdditionalFiltr();
    });
  return false;
}



function ChangeCountry() {
  jQuery('#err').html('');
  var lCountry = jQuery('#countryCode').val();
  jQuery.get('/source_new/pg_gethotellist.jsp',
          {country: lCountry, city: "0", pg: "0", cl: "text"},
          function(data) {
            jQuery('#cmbCityCode').html(data);
            ChangeCity();
          }
    )
}

function ChangeCountryDS(CountryDS,CityDS, HotelDS) {
  jQuery('#err').html('');
  var lCountry;
  //alert(CountryDS);
  if (CountryDS ==undefined)
       lCountry = jQuery('#countryCodeDS').val();
  else{
       lCountry = CountryDS;
       jQuery('#countryCodeDS').val(CountryDS);
  }

  jQuery('#cmbCityCodeDS').html('');
  if (lCountry !=undefined && lCountry !='' ){
      jQuery.get('/source_new/pg_gethotellistDS.jsp',
              {country: lCountry, type: "getAreaList"},
              function(data) {

                jQuery('#cmbCityCodeDS').html(data);
                ChangeCityDS(lCountry,CityDS, HotelDS);
              }
        )
    }
}


function ChangeCityDS(CountryDS,CityDS, HotelDS) {
  jQuery('#err').html('');
  jQuery('#disabledImageZone').css('display', 'block');
  var lCountry, lCity;
  lCountry = CountryDS;
  if (CityDS ==undefined)
       lCity = jQuery('#cityCodeDS').val();
  else{
       lCity = CityDS;
       jQuery('#cityCodeDS').val(CityDS)
}
   if (lCity !=undefined && lCity !='' ){
      jQuery.get('/source_new/pg_gethotellistDS.jsp',
              {country: lCountry, city: lCity, type: "getHotelList"},
              function(data) {

                jQuery('#cmbHotelCodeDS').html(data);
                ChangeHotelDS(HotelDS);
              }
        )
   }else{
    jQuery('#disabledImageZone').css('display', 'none');
   }
}

function ChangeHotelDS(HotelDS) {

    jQuery('#err').html("");
    if (HotelDS !=undefined){
       jQuery('#hotelCodeDS').val(HotelDS);
    }
    

//    if ( jQuery ('#d_hotels').val() > 0) {
//
//      jQuery("#categoriesListDS").val(0);
//      //jQuery("#locationList").val(0);
//
//      jQuery("#categoriesListDS").hide();
//      //jQuery("#locationList").hide();
//    } else {
//
//      //jQuery("#categoriesList").show();
//      //jQuery("#locationList").show();
//    }

    jQuery('#disabledImageZone').css('display', 'none');
}



function ChangeCity() {
  jQuery('#err').html('');
  jQuery('#disabledImageZone').css('display', 'block');
  var lCountry = jQuery('#countryCode').val();
  var lCity = jQuery('#cityCode').val();
  jQuery.get('/source_new/pg_gethotellist.jsp',
          {country: lCountry, city: lCity, pg: "4", cl: "text"},
          function(data) {
            jQuery('#cmbHotelCode').html(data);
            ChangeHotel();
          }
    )
}



function ChangeHotel() {
  //var lCountry = jQuery('#countryCode').val();
  //var lCity = jQuery('#cityCode').val();

//   jQuery.get('/source_new/pg_gethotellist.jsp',
//          {country: lCountry, city: lCity, pg: "4"},
//          function(data) {
//            jQuery('#cmbHotelCode').html(data);
//          }
//    )
  jQuery('#disabledImageZone').css('display', 'none');
//  return false;
}

function moveCheckedAdditionalFiltr() {
  var llStars1 = document.getElementById("stars_1");
  var llStars2 = document.getElementById("stars_2");
  var llStars3 = document.getElementById("stars_3");
  var llStars4 = document.getElementById("stars_4");
  var llStars5 = document.getElementById("stars_5");
  var llStarsAny = document.getElementById("stars_any");

  var llStars1Checked = llStars1.checked;
  var llStars2Checked = llStars2.checked;
  var llStars3Checked = llStars3.checked;
  var llStars4Checked = llStars4.checked;
  var llStars5Checked = llStars5.checked;
  var llStarsAnyChecked = llStarsAny.checked;

  var aHotelCode = jQuery("#hotelCode").val();
  var aStars_any = llStarsAnyChecked;
  var aPriceFrom = jQuery("#pricefrom").val();
  var aPriceTo = jQuery("#priceto").val();
  var aAmenityList = jQuery("#amenitylist").val();

  var lViewAddFiltrHRef = false;

  if (aHotelCode!= null && aHotelCode != '' && aHotelCode != '0') {
    jQuery("#recHotelCode").show();
  } else {
    lViewAddFiltrHRef = true;
    jQuery("#recHotelCode").hide();
  }

  if ( (aPriceFrom!= null && aPriceFrom != '' && aPriceFrom != '0')
    || (aPriceTo!= null && aPriceTo != '' && aPriceTo != '0')) {

    jQuery("#recPrices").show();
  }  else {
    lViewAddFiltrHRef = true;
    jQuery("#recPrices").hide();
  }

  if (!aStars_any) {
    jQuery("#recStars").show();
  }  else {
    lViewAddFiltrHRef = true;
    jQuery("#recStars").hide();
  }

  if (lViewAddFiltrHRef) {
    jQuery("#addFiltrHRef").show();
  } else {
    jQuery("#addFiltrHRef").hide();
  }

  if (aAmenityList != null && aAmenityList != '#') {
    jQuery("#recAmenityList").show();
  } else {
    jQuery("#recAmenityList").hide();
  }

  stars_any.checked = llStarsAnyChecked;
  stars_1.checked = llStars1Checked;
  stars_2.checked = llStars2Checked;
  stars_3.checked = llStars3Checked;
  stars_4.checked = llStars4Checked;
  stars_5.checked = llStars5Checked;
}

function clickAmenity( aClickedId ) {
  jQuery("#amenitylist").val('');
  var re = /am_/ig;
  var clickedSet = '';
  var clickedNameSet = '';

  jQuery(".amenitylist_checkbox :checked").each(function(aNum, aVal) {
    var index = jQuery(this).attr('id').replace(re,'');
    clickedSet += index+'#';
    clickedNameSet += jQuery("#amt_"+index).text() +', ';
  });

  if (clickedNameSet != null && clickedNameSet.length > 0 ) {
    clickedNameSet = jQuery.trim(clickedNameSet);
    clickedNameSet = clickedNameSet.substring(0, clickedNameSet.length-1);
  }
  
  jQuery("#amenitylist").val(clickedSet);
  jQuery("#txtAmenities").text(clickedNameSet);
//alert('amenitylist '+jQuery("#amenitylist").val());
//alert('clickedNameSet '+clickedNameSet);
}

function showAdditionalFiltr() {
  jQuery("#recHotelCode").show();
  jQuery("#recPrices").show();
  jQuery("#recStars").show();
  jQuery("#recAmenityList").show();

  jQuery("#hotelList").show();
  jQuery("#prices").show();
  jQuery("#categoriesList").show();
  jQuery("#locationList").show()
  

  jQuery("#addFiltrHRef").hide();
}

function hideAdditionalFiltr() {
  jQuery("#recHotelCode").hide();
  jQuery("#recPrices").hide();
  jQuery("#recStars").hide();
  jQuery("#recAmenityList").hide();

  jQuery("#hotelList").hide();
  jQuery("#prices").hide();
  jQuery("#categoriesList").hide();
  jQuery("#locationList").hide();

  jQuery("#addFiltrHRef").show();

}

function hs_submit_click() {
  jQuery('#fm_hotelsearch').submit();
  return false;
}
