/**左側選單收合**/ 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.php", data: {'countryId': countryId}, dataType: "json", cache: false, success: function(data) { //Remove目前選擇的鄉鎮市區選單內容 $("#"+countryAreaName+" option").remove(); $("#"+countryAreaName).append($('').val("").html("city")); 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("Please input something to search"); fieldObj1.focus(); return false; } //關鍵字和日期 var keywordValue = fieldObj1.val(); $( "#mobKeyword" ).val(keywordValue); }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 == "groupMob"){ //包團 if($( "#"+type ).prop("checked")){ $( "#"+type ).prop("checked",""); }else{ $( "#"+type ).prop("checked","true"); } }else if(type == "catLevelMob"){ //類型第一階 if($( "#"+type+"_"+id ).prop("checked")){ $( "#"+type+"_"+id ).prop("checked",""); $('input[data-main='+type+"_"+id+']').prop("checked",""); }else{ $( "#"+type+"_"+id ).prop("checked","true"); $('input[data-main='+type+"_"+id+']').prop("checked","true"); } }else if(type == "catMob"){ //類型 if($( "#"+type+"_"+id ).prop("checked")){ $( "#"+type+"_"+id ).prop("checked",""); }else{ $( "#"+type+"_"+id ).prop("checked","true"); } var mainId = $("#"+type+"_"+id).attr("data-main"); var catMobLength = parseInt( $('input[data-main='+mainId+']:checked').length ); if(catMobLength <= 0){ $( "#"+mainId ).prop("checked",""); } }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("Please input something to search"); fieldObj1.focus(); return false; } //關鍵字和日期 var keywordValue = fieldObj1.val(); $( "#mobKeyword" ).val(keywordValue); }else{ $( "#right" ).show(); //國家 var countryValue = $( "#mobCountry" ).val(); $( "#webCountry" ).val(countryValue); getCountryAreas('webCountry','webCity'); } } $.ajax({ type: "POST", url: "/ajax/search_from_mobile.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']); $( "#cat_level_id" ).val(data['cat_level_id']); $( "#cat_id" ).val(data['cat_id']); $( "#hour_id" ).val(data['hour_id']); $( "#price_id" ).val(data['price_id']); $( "#language_id" ).val(data['language_id']); $( "#group_id" ).val(data['group_id']); $( "#keyword_id" ).val(data['keyword_id']); $( "#sdate_id" ).val(data['sdate_id']); $( "#edate_id" ).val(data['edate_id']); $( "#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]); } //類型第一階 $( 'input[name="catLevelWeb[]"]:checkbox' ).prop("checked",""); $( 'input[name="catLevelMob[]"]:checkbox' ).prop("checked",""); if($( "#cat_level_id" ).val().length > 0){ temp = $( "#cat_level_id" ).val(); temp = temp.replace(/@/g,''); temp = temp.split(','); for(var i=0;i < temp.length;i++){ $( "#catLevelWeb_"+temp[i] ).prop("checked","true"); $( "#catLevelMob_"+temp[i] ).prop("checked","true"); } } //類型 $( 'input[name="catWeb[]"]:checkbox' ).prop("checked",""); $( 'input[name="catMob[]"]:checkbox' ).prop("checked",""); if($( "#cat_id" ).val().length > 0){ temp = $( "#cat_id" ).val(); temp = temp.replace(/@/g,''); temp = temp.split(','); for(var i=0;i < temp.length;i++){ $( "#catWeb_"+temp[i] ).prop("checked","true"); $( "#catMob_"+temp[i] ).prop("checked","true"); checkFTwoBox('sub', "#catWeb_"+temp[i]); checkFTwoBox('sub', "#catMob_"+temp[i]); } } //時數 $( 'input[name="hourWeb[]"]:checkbox' ).prop("checked",""); $( 'input[name="hourMob[]"]:checkbox' ).prop("checked",""); if($( "#hour_id" ).val().length > 0){ temp = $( "#hour_id" ).val(); temp = temp.replace(/@/g,''); temp = temp.split(','); for(var i=0;i < temp.length;i++){ $( "#hourWeb_"+temp[i] ).prop("checked","true"); $( "#hourMob_"+temp[i] ).prop("checked","true"); } } //價錢 $( 'input[name="priceWeb[]"]:checkbox' ).prop("checked",""); $( 'input[name="priceMob[]"]:checkbox' ).prop("checked",""); if($( "#price_id" ).val().length > 0){ temp = $( "#price_id" ).val(); temp = temp.replace(/@/g,''); temp = temp.split(','); for(var i=0;i < temp.length;i++){ $( "#priceWeb_"+temp[i] ).prop("checked","true"); $( "#priceMob_"+temp[i] ).prop("checked","true"); } } //語言 $( 'input[name="languageWeb[]"]:checkbox' ).prop("checked",""); $( 'input[name="languageMob[]"]:checkbox' ).prop("checked",""); if($( "#language_id" ).val().length > 0){ temp = $( "#language_id" ).val(); temp = temp.replace(/@/g,''); temp = temp.split(','); for(var i=0;i < temp.length;i++){ $( "#languageWeb_"+temp[i] ).prop("checked","true"); $( "#languageMob_"+temp[i] ).prop("checked","true"); } } //包團 $( "#webGroup" ).prop("checked",""); $( "#groupMob" ).prop("checked",""); if($( "#group_id" ).val().length > 0){ $( "#webGroup" ).prop("checked","true"); $( "#groupMob" ).prop("checked","true"); } $.ajax({ type: "POST", url: "/ajax/searchbox_defult_show.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.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+' search result | Tripbaa趣吧!'); $("#searchResult h2").html(''+showStr+' search result'); }else{ $(document).prop("title", 'Tripbaa趣吧!'); $("#searchResult h2").html('search result'); } }