/**左側選單收合**/
function leftMenuShow(site,id){
if(site == 'left'){
if( $( "#leftSubmenu"+id ).is( ":hidden" ) ){
$( "#leftSubmenu"+id ).slideDown(400);
$( "#leftTriangle"+id ).prop( "class","fTriangle02" );
}else{
$( "#leftSubmenu"+id ).hide(400);
$( "#leftTriangle"+id ).prop( "class","fTriangle" );
}
}else if(site == 'mobile'){
if( $( "#mobileSubmenu"+id ).is( ":hidden" ) ){
$( "#mobileSubmenu"+id ).slideDown(400);
$( "#mobileTriangle"+id ).prop( "class","fTriangle02" );
}else{
$( "#mobileSubmenu"+id ).hide(400);
$( "#mobileTriangle"+id ).prop( "class","fTriangle" );
}
}
}
/**顯示手機版搜尋框**/
function showMobSearch(type){
if(type == "show"){
$( "#leftbg" ).show();
$( "#right" ).hide();
$( "#mfooterNew" ).hide();
}else if(type == "hide"){
$( "#leftbg" ).hide();
$( "#right" ).show();
$( "#mfooterNew" ).show();
}
}
//國別->地區
function getCountryAreas(countryName,countryAreaName,areaValue){
var countryId = $("#"+countryName).val();
$.ajax({
type: "GET",
url: "/ajax/get_country_area_hotel.php",
data: {'countryId': countryId},
dataType: "json",
cache: false,
success: function(data) {
//Remove目前選擇的鄉鎮市區選單內容
$("#"+countryAreaName+" option").remove();
$("#"+countryAreaName).append($('').val("").html("城市"));
for (var i = 0; i < data.length; i++){
$("#"+countryAreaName).append($('').val(data[i]['id']).html(data[i]['name']));
}
if(areaValue != ''){
$("#"+countryAreaName).val(areaValue);
}
}
});
}
var searchTimeout=new Object();
/**搜尋選擇/取消(更新form)**/
function conditionSet(type,id,source){
clearTimeout( searchTimeout );
searchTimeout=setTimeout(function(){
$( "#last_update" ).val("O"); //預設最後觸發者
if(source == "web"){
if(type == "keyword"){
var formObj = $('.searchBar');
//搜尋目的地
var fieldObj1 = formObj.find("#webKeyword");
if(fieldObj1.val() <= 0){
alert("請填寫搜尋目的地!");
fieldObj1.focus();
return false;
}
//入住日期
var fieldObj2 = formObj.find("#webSdate");
if(fieldObj2.val() <= 0){
alert("請選擇入住日期!");
fieldObj2.focus();
return false;
}
//退房日期
var fieldObj3 = formObj.find("#webEdate");
if(fieldObj3.val() <= 0){
alert("請選擇退房日期!");
fieldObj3.focus();
return false;
}
//房間數
var fieldObj4 = formObj.find("#webRoomQty");
if(fieldObj4.val() <= 0){
alert("請選擇房間數!");
fieldObj4.focus();
return false;
}
//大人數
var fieldObj5 = formObj.find("#webAdultQty");
if(fieldObj5.val() <= 0){
alert("請選擇大人人數!");
fieldObj5.focus();
return false;
}
//大人入住人數
if(parseInt(fieldObj5.val()) < parseInt(fieldObj4.val())){
alert("大人入住人數需大於房間數!");
fieldObj4.focus();
return false;
}
//關鍵字、日期、人數
var keywordValue = fieldObj1.val();
var sdateValue = fieldObj2.val();
var edateValue = fieldObj3.val();
var roomQtyValue = fieldObj4.val();
var adultQtyValue = fieldObj5.val();
var childQtyValue = $( "#webChildQty" ).val();
$( "#mobKeyword" ).val(keywordValue);
$( "#mobHotelSdate" ).val(sdateValue);
$( "#mobHotelEdate" ).val(edateValue);
$( "#mobRoomQty" ).val(roomQtyValue);
$( "#mobAdultQty" ).val(adultQtyValue);
$( "#mobChildQty" ).val(childQtyValue);
$("form#mobForm input[name='mobChildAge[]']").remove();
if($("select[name='pageChildAge[]']").length > 0){
$("select[name='pageChildAge[]']").each(function(ageIndex) {
var ageData = $(this).val();
var tempInput = ``;
$("form#mobForm").append(tempInput);
});
}
}else if(type == "country_id"){
//國家
var countryValue = $( "#webCountry" ).val();
$( "#mobCountry" ).val(countryValue);
getCountryAreas('mobCountry','mobCity');
$( "#webCity" ).val("");
$( "#mobCity" ).val("");
$( "#last_update" ).val("S"); //預設最後觸發者
}else if(type == "area_id"){
//地區
var cityValue = $( "#webCity" ).val();
$( "#mobCity" ).val(cityValue);
$( "#last_update" ).val("S"); //預設最後觸發者
}else{
//其他選項
if($( "#"+type+"_"+id ).prop("checked")){
$( "#"+type+"_"+id ).prop("checked","");
}else{
$( "#"+type+"_"+id ).prop("checked","true");
}
}
}else if(source == "mob"){
if(type == "keyword"){
var formObj = $('form#pageSearchHotelForm');
//搜尋目的地
var fieldObj1 = formObj.find("#pageHotelKeyword");
if(fieldObj1.val() <= 0){
alert("請填寫搜尋目的地!");
fieldObj1.focus();
return false;
}
//入住日期
var fieldObj2 = formObj.find("#pageHotelSdate");
if(fieldObj2.val() <= 0){
alert("請選擇入住日期!");
fieldObj2.focus();
return false;
}
//退房日期
var fieldObj3 = formObj.find("#pageHotelEdate");
if(fieldObj3.val() <= 0){
alert("請選擇退房日期!");
fieldObj3.focus();
return false;
}
//房間數
var fieldObj4 = formObj.find("#pageRoomQty");
if(fieldObj4.val() <= 0){
alert("請選擇房間數!");
fieldObj4.focus();
return false;
}
//大人數
var fieldObj5 = formObj.find("#pageAdultQty");
if(fieldObj5.val() <= 0){
alert("請選擇大人人數!");
fieldObj5.focus();
return false;
}
//大人入住人數
if(parseInt(fieldObj5.val()) < parseInt(fieldObj4.val())){
alert("大人入住人數需大於房間數!");
fieldObj4.focus();
errorQty++;
return false;
}
//關鍵字、日期、人數
var keywordValue = fieldObj1.val();
var sdateValue = fieldObj2.val();
var edateValue = fieldObj3.val();
var roomQtyValue = fieldObj4.val();
var adultQtyValue = fieldObj5.val();
var childQtyValue = $( "#pageChildQty" ).val();
$( "#mobKeyword" ).val(keywordValue);
$( "#mobHotelSdate" ).val(sdateValue);
$( "#mobHotelEdate" ).val(edateValue);
$( "#mobRoomQty" ).val(roomQtyValue);
$( "#mobAdultQty" ).val(adultQtyValue);
$( "#mobChildQty" ).val(childQtyValue);
$("form#mobForm input[name='mobChildAge[]']").remove();
if($("select[name='pageMBChildAge[]']").length > 0){
$("select[name='pageMBChildAge[]']").each(function(ageIndex) {
var ageData = $(this).val();
var tempInput = ``;
$("form#mobForm").append(tempInput);
});
}
}else{
$( "#right" ).show();
//國家
var countryValue = $( "#mobCountry" ).val();
$( "#webCountry" ).val(countryValue);
getCountryAreas('webCountry','webCity');
}
}
$.ajax({
type: "POST",
url: "/ajax/search_from_mobile_hotel.php",
data: $("form#mobForm").serialize(),
dataType: "json",
cache: false,
success: function(data) {
$( "#country_id" ).val(data['country_id']);
$( "#area_id" ).val(data['area_id']);
$( "#city_id" ).val(data['city_id']);
var attr_total = $( "#attr_total" ).val();
for(var ac=1;ac<=attr_total;ac++){
$( "#attr_id_"+ac ).val(data['attr_id_'+ac]);
}
$( "#keyword_id" ).val(data['keyword_id']);
$( "#hotel_sdate" ).val(data['hotel_sdate']);
$( "#hotel_edate" ).val(data['hotel_edate']);
$( "#room_qty" ).val(data['room_qty']);
$( "#adult_qty" ).val(data['adult_qty']);
$( "#child_qty" ).val(data['child_qty']);
$("form#sendForm input[name='child_age[]']").remove();
if(data['child_age_total'] > 0){
for(var cat=0;cat < data['child_age_total'];cat++){
var ageData = data['child_age'][cat];
var tempInput = ``;
$("form#sendForm").append(tempInput);
}
}
$( "#topCount" ).val(data['topCount']);
if(source == "mob"){
$( "#leftbg" ).hide();
$( "#mfooterNew" ).show();
$('.search_m_box').hide();
}
screenSet(source);
showPageNo = "YES";
$("#pageNo").val('0');
$("#pageType").val('down');
$("#gotoPageNo").val('0');
$("#showMoreStatus").val('YES');
//載入第一次資料
$( "#nodataShow" ).hide();
$("#mcontainer").html("");
$("#morebutton").html('MORE');
loading.data("on", true).fadeIn(function() {
getListCon('down','');
});
}
});
}, 500);
}
/**更新ui畫面**/
function screenSet(source){
var temp = "";
//關鍵字
$( "#webKeyword" ).val("");
$( "#mobKeyword" ).val("");
if($( "#keyword_id" ).val().length > 0){
temp = $( "#keyword_id" ).val();
var keywordValue = temp.substr(0,temp.length-1);
$( "#webKeyword" ).val(keywordValue);
$( "#mobKeyword" ).val(keywordValue);
}
//國家
$( "#webCountry" ).val("");
$( "#mobCountry" ).val("");
if($( "#country_id" ).val().length > 0){
temp = $( "#country_id" ).val();
temp = temp.replace(/@/g,'');
temp = temp.split(',');
$( "#webCountry" ).val(temp[0]);
$( "#mobCountry" ).val(temp[0]);
if($( "#area_id" ).val().length <= 0){
getCountryAreas('webCountry','webCity','');
getCountryAreas('mobCountry','mobCity','');
}
}
//地區
$( "#webCity" ).val("");
$( "#mobCity" ).val("");
if($( "#area_id" ).val().length > 0){
temp = $( "#area_id" ).val();
temp = temp.replace(/@/g,'');
temp = temp.split(',');
getCountryAreas('webCountry','webCity',temp[0]);
getCountryAreas('mobCountry','mobCity',temp[0]);
}
//屬性
var attr_total = $( "#attr_total" ).val();
for(var ac=1;ac<=attr_total;ac++){
$( 'input[name="attrWeb"+ac+"[]"]:checkbox' ).prop("checked","");
$( 'input[name="attrMob"+ac+"[]"]:checkbox' ).prop("checked","");
if($( "#attr_id_"+ac ).val().length > 0){
temp = $( "#attr_id_"+ac ).val();
temp = temp.replace(/@/g,'');
temp = temp.split(',');
for(var i=0;i < temp.length;i++){
$( "#attrWeb_"+ac+temp[i] ).prop("checked","true");
$( "#attrMob_"+ac+temp[i] ).prop("checked","true");
}
}
}
//AsiaYo查詢條件(日期、房間人數)
var hotelSdateVal = $( "#hotel_sdate" ).val(),
hotelEedateVal = $( "#hotel_edate" ).val(),
roomQtyVal = $("#room_qty").val(),
adultQtyVal = $("#adult_qty").val(),
childQtyVal = $("#child_qty").val();
$( "#webSdate" ).val("");
$( "#mobHotelSdate" ).val("");
if(hotelSdateVal.length > 0){
$( "#webSdate" ).val(hotelSdateVal);
$( "#mobHotelSdate" ).val(hotelSdateVal);
}
$( "#webEdate" ).val("");
$( "#mobHotelEdate" ).val("");
if(hotelEedateVal.length > 0){
$( "#webEdate" ).val(hotelEedateVal);
$( "#mobHotelEdate" ).val(hotelEedateVal);
}
$( "#webRoomQty" ).val("");
$( "#mobRoomQty" ).val("");
if(roomQtyVal.length > 0){
$( "#webRoomQty" ).val(roomQtyVal);
$( "#mobRoomQty" ).val(roomQtyVal);
}
$( "#webAdultQty" ).val("");
$( "#mobAdultQty" ).val("");
if(adultQtyVal.length > 0){
$( "#webAdultQty" ).val(adultQtyVal);
$( "#mobAdultQty" ).val(adultQtyVal);
}
$( "#webChildQty" ).val("");
$( "#mobChildQty" ).val("");
if(childQtyVal.length > 0){
$( "#webChildQty" ).val(childQtyVal);
$( "#mobChildQty" ).val(childQtyVal);
}
roomQtyVal = ckVFN( roomQtyVal );
adultQtyVal = ckVFN( adultQtyVal );
childQtyVal = ckVFN( childQtyVal );
var totalTxt = `${adultQtyVal + childQtyVal}人 - ${roomQtyVal}房`;
$('[data-starget=roominfo]').val( totalTxt );
$('[data-starget=roominfo_m]').val( totalTxt );
$('[data-starget=roominfo_m]').attr( "data-search-page", totalTxt );
var webChildBox = $(`.sear_newbox`).find('.durooom').find('.childbox');
var mobileChildBox = $(`.search_m_box02[data-starget=room_m_lightbox]`).find('.durooom').find('.childbox');
webChildBox.empty();
mobileChildBox.empty();
$("form#mobForm input[name='mobChildAge[]']").remove();
$('[data-age=Y]').each(function(ageIndex) {
var ageData = $(this).val();
webChildBox.append( createChildrenTemplete( 'header', { 'n_now' :(ageIndex+1), 'def-child-age' :ageData } ) );
mobileChildBox.append( createChildrenTemplete( 'page', { 'n_now' :(ageIndex+1), 'def-child-age' :ageData } ) );
var tempInput = ``;
$("form#mobForm").append(tempInput);
});
$.ajax({
type: "POST",
url: "/ajax/searchbox_defult_show_hotel.php",
data: $("#sendForm").serialize(),
dataType: "json",
cache: false,
success: function(data) {
if(source == "mob"){
$( "#searchBox" ).show();
}else{
$( "#searchBox" ).hide();
}
if(data['total'] > 0){
$( "#mobSearchBtn" ).addClass("hold");
}else{
$( "#mobSearchBtn" ).removeClass("hold");
}
$("#searchBoxTxt").html("");
$("#searchBoxTxt").html(data['searchBoxTxt']);
$("#searchBox").html("");
$("#searchBox").append(datatopTemplate.render.tmp2(data));
changeTitle();
}
});
}
/**手機版選國家地區清除keyword**/
function clearKeyword(){
$.ajax({
type: "POST",
url: "/ajax/check_search_keyword_hotel.php",
data: {keyword_id : $( "#keyword_id" ).val()},
dataType: "json",
cache: false,
success: function(data) {
if(data['checkType'] == "Y"){
$( "#webKeyword" ).val("");
$( "#mobKeyword" ).val("");
}
}
});
}
/**替換title與h1**/
function changeTitle(){
var keyWord = $("#keyword_id").val();
if(keyWord.length > 0){
var showStr = keyWord.substr(0,keyWord.length-1);
$(document).prop("title", showStr+' 搜尋結果 | Tripbaa趣吧!');
$("#searchResult h2").html(''+showStr+' 搜尋結果');
}else{
$(document).prop("title", 'Tripbaa趣吧!');
$("#searchResult h2").html('搜尋結果');
}
}