You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
6.9 KiB
JavaScript

//Javascript
//hotel index page script
//create date:2011-03-30
//author :wst
//copy right : chinahighlight
//TrunMenu("citySwitch","active","li","dealHotels");
//各个函数区
//Obj 单击对像,calback回调函数
function TrunMenu2(Obj,callback){
if($(Obj).size()==0){return;}
$(Obj).siblings("li").removeClass("active").end().addClass("active");
var cmid = $(Obj).attr("mid");
var data = $(Obj).attr("data").split("|");
if($("#"+cmid).size()<1){
$("#waitingtable").siblings("div[name=dealHotels]").hide().end().show();
$.ajax({
type:"POST",
url:'/api/api.asp',
dataType:'json',
data:"method=cht.hotel.offers-for-month&cityID="+data[0],
success:function(data){
ListStr = ""
$.each(data.Hotel,function(i,n){
ListStr += "<div class=\"hotelProList\" onclick=\"location.href=$(this).find('a').eq(0).attr('href')\"> \
<div class=\"hotelPic\"><a href=\""+n.HotelUrl+"\" url=\""+n.HotelPic.replace('-s.','-m.')+"\" class=\"jq_preview\"><img src=\""+n.HotelPic+"\" class=\"hotelSmal\" alt='"+n.HotelName+"'/></a></div>\
<div class=\"hotelInfo\">\
<a class=\"hotelName\" href=\""+n.HotelUrl+"\">"+n.HotelName+"</a> "+n.HotelStar+"\
<div class=\"hotelLocation\">"+(n.HotelIntRate>0?"Customers' Rating: "+EGAP(n.HotelIntRate)+","+n.HotelIntRate:"")+"\
"+ (n.Localtion.length>0?"<br/>Localtion:"+n.Localtion:"")+"</div>\
<div class=\"hotelPrice\">"+ (n.HotelLowPrice>0?"From <span class=\"hotelPrice\">$"+n.HotelLowPrice+"</span>":"")+"</div>\
</div>\
<div class=\"clear\"></div>\
</div>";
});
ListStr = "<div id=\""+cmid+"\" name=\"dealHotels\">" +ListStr+ "</div>";
$("#waitingtable").hide();
$("div[name=dealHotels]").hide();
$("#waitingtable").after(ListStr);
$("#"+cmid).show(1000);
$("[id="+cmid+"]").find("a.jq_preview").preview();
if(typeof callback =="function"){
callback(Obj);
}
}
});
} else {
$("div[name=dealHotels]").hide();
$("#"+cmid).show();
if(typeof callback =="function"){
callback(Obj);
}
}
}
//显示主推酒店
function getMaimHotel(city){
if(city=="Shanghai" || city=="Beijing" || city=="Guangzhou" || city=="Xian" || city=="Shenzhen" || city=="Guilin"){
$("#citySwitch li").filter(function(index){return $(this).text().toLowerCase()==city.toLowerCase()}).trigger("click");
} else {
return;
$.ajax({
type: "GET",
url: "/hotel/ajax-index.asp",
dataType: "html",
data: "city="+city,
success: function(msg){
if(msg=="0"){return;}
var kpNum = $("#citySwitch li").length;
if(kpNum>6){
$("#citySwitch li").eq(0).text(city);
$(".dealBox.roundCorner").eq(0).html(msg);
}else{
var oldHTML = $("#citySwitch").html();
$("#citySwitch").prepend("<li mid='de_"+city+"' data=''>"+city+"</li>");
$('<div class="dealBox roundCorner" style="display: none;" name="dealHotels" id="de_'+city+'">'+msg+'</div>').insertBefore(".dealBox.roundCorner:first");
}
$(".dealBox.roundCorner[id=de_"+city+"]").find("a.jq_preview").preview();
}
});
}
}
//根据评分给出相应的文字评价
function EGAP(RateN){
RateN = parseInt(RateN)
if(RateN>4.5){
return "Excellent";
} else if(RateN<=4.5 && RateN>3.5){
return "Good";
} else if(RateN<=3.5 && RateN>2.5){
return "Average";
} else if(RateN<=2.5 && RateN>0){
return "Poor";
} else {
return "";
}
}
$(function(){
var shcity= $("input[name='city']");
$(".cityClick").click(function(){
$("#hotelcityList2").hide(200);
$("#hotelcityList").fadeIn(200);
});
$(".closeIt").click(function(){
$("#hotelcityList").fadeOut(200);
});
$("#hotelcityList a").click(function(){
shcity.val($(this).text());
$("#hotelcityList").hide();
getMaimHotel($(this).text());
});
shcity.keyup(function(){
var val = $(this).val();
var cityNum = searchHotelInputCity.length;
var resultStr = "";
if(val.length<1){
} else if(val.length==1){
var CodeInt = val.toLowerCase().charCodeAt(0);
$("#hotelcityList").show();
if(CodeInt>=97 && CodeInt<=103){
$("#hotelcityList span").eq(1).trigger("click");
}
if(CodeInt>=104 && CodeInt<=108){
$("#hotelcityList span").eq(2).trigger("click");
}
if(CodeInt>=109 && CodeInt<=118){
$("#hotelcityList span").eq(3).trigger("click");
}
if(CodeInt>=119 && CodeInt<=122){
$("#hotelcityList span").eq(4).trigger("click");
}
} else {
$("#hotelcityList").hide();
$(".dropDownList li").remove()
for(var i=0;i<cityNum;i++){
if(val.toLowerCase() == searchHotelInputCity[i].substring(0,val.length).toLowerCase()){
resultStr += "<li><a href=\"javascript:;\">"+searchHotelInputCity[i]+"</a></li>";
}
}
if(resultStr==""){resultStr="<li>No such city</li>"}
$(".dropDownList").append(resultStr);
$("#hotelcityList2").show();
$("#hotelcityList2 a").click(function(){
shcity.val($(this).text());
$("#hotelcityList2").hide();
getMaimHotel($(this).text());
});
}
});
$("#starttime").datepicker({
showAnim:"fadeIn",
duration:0,
minDate: 0,
maxDate:"2y",
numberOfMonths: 3,
showButtonPanel: true
}).bind('dateSelected',
function(e, selectedDate, $td){
$("#endtime").val(new Date(selectedDate).addDays(3).asString());
$("#endtime").focus();$.datepicker.dpDiv;
}
);
$("#endtime").datepicker({
showAnim:"fadeIn",
duration:0,
minDate: 0,
maxDate:"2y",
numberOfMonths: 3,
showButtonPanel: true,
ortherDP:'starttime'
});
$(".moreOption").find("span:first").click(function(){$(".moreOption").toggle('slow')});
//鼠标移动显示大图
if( typeof $.fn.preview == 'function' ){ $("a.jq_preview").preview(); }
//鼠标移到显示提示
$("img.newReview").hover(
function () {
$("#"+$(this).attr("cm")).show();
},
function () {
$("#"+$(this).attr("cm")).hide();
}
);
$("#citySwitch li").on('click',function(i){
TrunMenu2(this);
});
$("#citySwitch li").filter(function(index){return $(this).text()==$("input[name=city]").val()}).trigger("click");
TrunMenu2($("#citySwitch li").eq(0));
var timers;
var hideObj = function(nObj){timers = setTimeout(function(){nObj.hide()},1000);}
$("#mainMenu img").hover(function(){
//$(this).parents("a").siblings(".subMenu,.subMenuRight").show();
},function(){
//$(this).parents("a").siblings(".subMenu,.subMenuRight").hide();
hideObj($(this).parents("a").siblings(".subMenu,.subMenuRight"));
}).click(function(e){
e.preventDefault();
$(this).parents("a").siblings(".subMenu,.subMenuRight").show();
});
$("#mainMenu .subMenu,#mainMenu .subMenuRight").hover(function(){clearTimeout(timers);},function(){hideObj($(this))});
/*右上角翻角效果肢本*/
$("#pageflip").hover(function() {
$("#pageflip img , .msg_block").stop()
.animate({width: '307px',height: '319px'}, 500);
} , function() {
$("#pageflip img").stop()
.animate({width: '50px',height: '52px'}, 220);
$(".msg_block").stop()
.animate({width: '50px',height: '50px'}, 200);
});
});