﻿var SearchHotelClient = Elong.Page.SearchHotelClient;
SearchHotelClient = Class.create();

Object.extend(SearchHotelClient.prototype, {
    name: "SearchHotelClient",

    // 初始化服务端数据
    initializeServerData: function() {
        //this.dateRange = FillOrderController.DateRange; // string[]:{今日时间，起飞时间}
        this.strCitySuggestData = "http://www.elong.com/CitySuggestData.aspx?dataId=__tempDataId &dataHotId=__tempDataHotId &dataType=Hotel-All";
    },

    //初始化
    initialize: function() {
        this.initializeDOM();
        this.initializeEvent();
        this.initializeServerData();

        // 字符串html变量，放在此处
        //this.amountFeeHTML = "<span class=\"jhy\">￥{0}</span>";
        //this.mailTemplate = new Template("<li class=\"li_q\" method=\"select\" value=\"#{Value}\">#{Name}</li>");

        this.render(); // 页面加载完成后，处理直接呈现.
    },

    //初始化DOM元素
    initializeDOM: function() {
        this.imgCityChange = $("#imgCityChange");
        this.txtCheckInDate = $("#DateNumCustPickerForSearch_KP1CheckInDate");
        this.txtCheckOutDate = $("#DateNumCustPickerForSearch_KP1CheckOutDate");
        this.aPrice = $("#aprice");
        this.aClose = $("#a_close");
        this.dvContentend = $("#m_contentend");
        this.dvSearch_fl = $("#search_fl");
        this.dvSearch_rs = $("#search_rs");
        this.ulPgs = $("#pgs");
        this.dvTiph = $("#tiph");
        this.dvTipw = $("#tipw");
        this.dvCp_t2h = $("#cp_t2h");
        this.dvCp_t2 = $("#cp_t2");
        this.spanApricew = $("#apricew");
        this.frmHotSrch = $("form");
        this.hidFormCaller = $("#FormCaller");
        this.dvFlashAdMsg = $("#flashAdMsg");
        this.spanSearchList = $("#Search1_HotelRepeated1");

    },

    destroyDOM: function() {
        this.imgCityChange = null;
        this.txtCheckInDate = null;
        this.txtCheckOutDate = null;
        this.aPrice = null;
        this.aClose = null;
        this.dvContentend = null;
        this.dvSearch_fl = null;
        this.dvSearch_rs = null;
        this.ulPgs = null;
        this.dvTiph = null;
        this.dvTipw = null;
        this.dvCp_t2h = null;
        this.dvCp_t2 = null;
        this.spanApricew = null;
        this.frmHotSrch = null;
        this.hidFormCaller = null;
        this.dvFlashAdMsg = null;
        this.spanSearchList = null;

    },

    //初始化DOM事件
    initializeEvent: function() {
        this.imgCityChange.bind("click", this.onCityChange.bindAsEventListener(this));
        this.txtCheckInDate.bind("click", this.onClickCalendar.bindAsEventListener(this));
        this.txtCheckOutDate.bind("click", this.onClickCalendar.bindAsEventListener(this));
        this.aPrice.bind("click", this.onClickCustomPrice.bindAsEventListener(this));
        this.aClose.bind("click", this.onCloseCustomPrice.bindAsEventListener(this));
        this.dvSearch_rs.bind("mouseover", this.onMouseOverdvSearch_rs.bindAsEventListener(this));
        this.dvSearch_rs.bind("mouseout", this.onMouseOutdvSearch_rs.bindAsEventListener(this));
        this.dvSearch_rs.find("div[method='comment']").bind("mouseover", this.onMouseOverdvComment.bindAsEventListener(this));
        this.dvSearch_rs.find("div[method='comment']").bind("mouseout", this.onMouseOutdvComment.bindAsEventListener(this));
        this.dvSearch_rs.find("div[class='cp_txts']").bind("mouseover", this.onMouseOverdvCoupon.bindAsEventListener(this));
        this.dvSearch_rs.find("div[class='cp_txts']").bind("mouseout", this.onMouseOutdvCoupon.bindAsEventListener(this));
        //this.dvSearch_rs.find("img[id='cp_tph']").bind("mouseover", this.onMouseOverdvCoupon.bindAsEventListener(this));
        //this.dvSearch_rs.find("img[id='cp_tph']").bind("mouseout", this.onMouseOutdvCoupon.bindAsEventListener(this));
        //this.dvSearch_rs.find("td[class='tdtitle cp_hd']").bind("mouseover", this.onMouseOverdvCoupon);
        //this.dvSearch_rs.find("td[class='tdtitle cp_hd']").bind("mouseout", this.onMouseOutdvCoupon);

        this.dvSearch_rs.find("a[id='MsgBoxHotelStar']").bind("click", this.onClickStar.bindAsEventListener(this));
        //this.frmHotSrch.bind("submit", this.onSubmitFrmHotSrch.bindAsEventListener(this));
        this.spanSearchList.bind("mouseover", this.onMouseOverspanSearchList.bindAsEventListener(this));

        FunctionExt.defer(this.onOutClick.bindAsEventListener(this), 100);
        //this.onPageInitial();
        $(window).unload(this.dispose.bind(this));
    },

    destroyEvent: function() {
        this.imgCityChange.unbind("click");
        this.txtCheckInDate.unbind("click");
        this.txtCheckOutDate.unbind("click");
        this.aPrice.unbind("click");
        this.aClose.unbind("click");
        this.dvSearch_rs.unbind("mouseover");
        this.dvSearch_rs.unbind("mouseout");
        this.dvSearch_rs.find("div[method='comment']").unbind("mouseover");
        this.dvSearch_rs.find("div[method='comment']").unbind("mouseout");
        this.dvSearch_rs.find("div[class='cp_txts']").unbind("mouseover");
        this.dvSearch_rs.find("div[class='cp_txts']").unbind("mouseout");
        this.dvSearch_rs.find("img[id='cp_tph']").unbind("mouseover");
        this.dvSearch_rs.find("img[id='cp_tph']").unbind("mouseout");
        this.dvSearch_rs.find("a[id='MsgBoxHotelStar']").unbind("click");
        $(document).unbind("click");
        this.frmHotSrch.unbind("submit");
        this.spanSearchList.unbind("mouseover");

    },

    onSubmitFrmHotSrch: function(evt) {
        var element = Event.element(evt);

        if (this.hidFormCaller != null && this.hidFormCaller.val() == "research") {
            this.dvFlashAdMsg.html("请稍等，您查询的酒店正在搜索中......");
        }
        else {
            this.dvFlashAdMsg.html("正在更新酒店结果，请稍候......");
        }
        this.dvFlashAdMsg.html(this.dvFlashAdMsg.html());
        this.dvFlashAdMsg[0].style.display = "block"; //显示正在查询处理等待
        //解决屏幕居中问题 add by minjiang 09-10-23
        this.dvFlashAdMsg[0].style.left = ($(document)[0].body.clientWidth / 2 - 200).toString() + "px";
        this.dvFlashAdMsg[0].style.top = ($(window)[0].screen.availHeight / 2 - 200 + $(document)[0].documentElement.scrollTop).toString() + "px";

    },

    onMouseOverspanSearchList: function(evt) {
        var element = Event.element(evt);
        var method = element.attr("class");
        var elementID = element.attr("id");
        var hotelID = element.attr("hotelid");
        switch (method) {
            case "ht_item":
                HighlightLine(elementID, hotelID);
                break;

        }
    },

    onClickCalendar: function(evt) {
        var element = Event.element(evt);
        var method = element.attr("id");
        switch (method) {
            case "DateNumCustPickerForSearch_KP1CheckInDate":
                new CalendarWindow({
                    eventElement: this.txtCheckInDate,
                    language: "cn",
                    selectedDate: this.txtCheckInDate.val(),
                    enabledTo: "2016-12-30",
                    onSelected: function(date) {
                        this.txtCheckInDate.val(date);
                        this.txtCheckOutDate.click();
                    } .bind(this)
                });
                break;
            case "DateNumCustPickerForSearch_KP1CheckOutDate":
                new CalendarWindow({
                    eventElement: this.txtCheckOutDate,
                    language: "cn",
                    selectedDate: this.txtCheckOutDate.val(),
                    enabledTo: "2016-12-30",
                    onSelected: function(date) {
                        this.txtCheckOutDate.val(date);
                    } .bind(this)
                });
                break;
        }
    },

    onClickCustomPrice: function(evt) {
        //取消冒泡
        Event.cancelBubble = true;
        if ($("#apricew") && $("#apricew")[0].style.display == "none") {
            $("#apricew")[0].style.display = "";
            this.aPrice[0].className = "b";
            var price1 = $("#price1");
            price1[0].focus();
        }
        return false
    },

    onCloseCustomPrice: function(evt) {
        Event.cancelBubble = true;
        if ($("#apricew")) {
            $("#apricew")[0].style.display = "none";
        }
    },

    onOutClick: function() {
        $(document).bind("click", function(evt) {
            var element = Event.element(evt);
            if (this.spanApricew.find("*").index(element) == -1) {
                this.onCloseCustomPrice();
                //this.dispose();
            }
        } .bindAsEventListener(this));
    },

    onPageInitial: function(evt) {
        this.imgCityChange.CitySuggest({ dataId: "__tempDataId", dataHotId: "__tempDataHotId", needGetData: false, needGetDataHot: false, resultId: "InCityName_input", resultField: "CityId", resultId2: "InCityName", resultField2: "CityNameCn", dataType: "Hotel-All", resultExtendMethod: function() { CitySelect_OnCityChange(); }, resultNextId: "CheckInDate" });
    },

    onCityChange: function(evt) {
        LoadJs("hotelcitydata", this.strCitySuggestData, false, "waitId", function() {
            //this.DEPART_CITY_input.CitySuggest({ dataId: "domesticsrc", dataHotId: "domesticsrchot", needGetData: false, needGetDataHot: false, resultId: "DEPART_CITY", resultField: "CityThreeSign", dataType: "Flight-DomesticSrc", resultNextId: "DEST_CITY_input" });
            this.imgCityChange.CitySuggest({ dataId: "__tempDataId", dataHotId: "__tempDataHotId", needGetData: false, needGetDataHot: false, resultId: "InCityName_input", resultField: "CityId", resultId2: "InCityName", resultField2: "CityNameCn", dataType: "Hotel-All", resultExtendMethod: function() { CitySelect_OnCityChange(); }, resultNextId: "CheckInDate" });
            this.imgCityChange.click();
            } .bind(this),null);

    },

    onMouseOverdvSearch_rs: function(evt) {

    },

    onMouseOutdvSearch_rs: function(evt) {

    },

    onMouseOverdvComment: function(evt) {
        var element = Event.element(evt);
        var method = element.attr("method");

        element.parents("div[method='comment']").find("div[method='tipcomment']").show();
    },

    onMouseOutdvComment: function(evt) {
        var element = Event.element(evt);
        var method = element.attr("method");

        element.parents("div[method='comment']").find("div[method='tipcomment']").hide();
    },

    onMouseOverdvCoupon: function(evt) {
        var element = Event.element(evt);
        var method = element.attr("class");
        switch (method) {
            case "cp_txts":
                element.parents("div[class='cp_txtwc cp_hd']").find("div[class='cp_txtw']").show();
                break;
            case "sp-ic_coupon":
                element.parents("td[class='tdtitle cp_hd']").find("div[class='cp_tphw']").show();
                break;
            case "sp-ic_promotion":
                element.parents("td[class='tdtitle cp_hd']").find("div[class='cp_tphw']").show();
                break;
            case "tdtitle cp_hd":
                element.find("div[class='cp_tphw']").show();
                break;
        }
    },

    onMouseOutdvCoupon: function(evt) {
        var element = Event.element(evt);
        var method = element.attr("class");
        switch (method) {
            case "cp_txts":
                element.parents("div[class='cp_txtwc cp_hd']").find("div[class='cp_txtw']").hide();
                break;
            case "sp-ic_coupon":
                element.parents("td[class='tdtitle cp_hd']").find("div[class='cp_tphw']").hide();
                break;
            case "sp-ic_promotion":
                element.parents("td[class='tdtitle cp_hd']").find("div[class='cp_tphw']").hide();
                break;
            case "tdtitle cp_hd":
                element.find("div[class='cp_tphw']").hide();
                break;
        }
    },

    onClickStar: function(evt) {
        var element = Event.element(evt);
        var host = document.domain;
        var loadurl = "http://" + host + "/hotels/script/MsgBox/MsgBoxHotelStar.html";
        this.showChildTip = new TipWindow({
            eventElement: element,
            htmlContent: "<div>testest</div>",
            buildHtmlContent: function(currWindow) {
                // 这里异步获取数据或html

                currWindow.htmlContent = "<div></div>";
                currWindow.show();
                currWindow.windowElement.find("div.bk_1").load(loadurl);
            } .bind(this),
            width: 435
        });

    },

    render: function() {

    },

    dispose: function() {
        this.destroyEvent();
        this.destroyDOM();
    }

});

var client = null;
$(document).ready(function() {
    client = new SearchHotelClient();
});

/**************/

/**********************动态装载js函数*************************/
//scriptId--脚本标签ID,jsUrl--脚本文件位置，isReLoad--是否重新装载，waitId--装载时Loading容器，callbackfunc--回调函数
function LoadJs(scriptId,jsUrl,isReLoad,waitId,callbackfunc,encode) {
	var args = Array.prototype.slice.call(arguments,5);
  headLoc = document.getElementsByTagName("head").item(0);
    
	if (document.getElementById(scriptId) != null && isReLoad) {
        headLoc.removeChild(document.getElementById(scriptId)); 
    } else if (document.getElementById(scriptId) != null && !isReLoad) {
        return;
    }
    
    var waitObj = document.getElementById(waitId);
    if (waitObj!=null && waitObj!='undefine') {    	     	  
        $("#"+waitId).html("请稍候...");
        $("#"+waitId).show();
        //alert(waitObj.innerHTML);               
    }
           
    var scriptObj = document.createElement("script");    
    
    scriptObj[document.all?"onreadystatechange":"onload"] = function() {                
        if (waitObj!=null && waitObj!='undefine') {    	  
            $("#"+waitId).html("");
        		$("#"+waitId).show();
            //alert('onload');                       
        } 
        if (callbackfunc!=null) callbackfunc.apply(null,args);
    }
    
    scriptObj.setAttribute("type", "text/javascript");
    if(encode != null)
   	{
    	scriptObj.setAttribute("charset", encode);
    }
    else
    {
    	scriptObj.setAttribute("charset", "gb2312");
    }
    scriptObj.setAttribute("src", jsUrl);
    scriptObj.setAttribute("id", scriptId);                
    headLoc.appendChild(scriptObj);
}


var taba = new tabs("nav_t", "li", "h_", "t_", "01");    

function getPosition(o){
    var nLt=0;
    var nTp=0;
    var offsetParent = o;
    while (offsetParent!=null && offsetParent!=document.body) {
		    nLt+=offsetParent.offsetLeft;
		    nTp+=offsetParent.offsetTop;
    if(navigator.appName!="Netscape"){
	    parseInt(offsetParent.currentStyle.borderLeftWidth)>0?nLt+=parseInt(offsetParent.currentStyle.borderLeftWidth):"";
	    parseInt(offsetParent.currentStyle.borderTopWidth)>0?nTp+=parseInt(offsetParent.currentStyle.borderTopWidth):"";}
    offsetParent=offsetParent.offsetParent;
 }
  return {x:nLt, y:nTp};
}
function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
}

var maskDiv = getObj("div_masker");
maskDiv.style.top = getPosition(getObj("InCityName_err")).y + "px";
maskDiv.style.left = getPosition(getObj("pgs")).x + "px";
maskDiv.style.width = document.getElementById("search_ht").offsetWidth + "px";
maskDiv.style.height = "2000px";
maskDiv.style.display = "block";

//$(function() {
//    //初始化遮罩类弹出层
//    $("#msgBoxDiv").dialog({
//        show: null,
//        bgiframe: false,
//        autoOpen: false,
//        width: 523,
//        height: 'auto',
//        draggable: true,
//        resizable: false,
//        modal: true
//    });
//});
//function djAlert(title, content, closeMsg, closeCallback) {
//    $("#msgBoxDiv").dialog("option", "title", "登录提示");
//    $("#msgBoxDiv").html("<div>" + content + "</div>").dialog("open");
//}
maskDiv.style.display = "none";   

//PrintBrowseHotelListByPage(CurPage, "cn"); 

var   slt = elt("search_rs").offsetHeight,	fst = elt("search_rs").parentNode.offsetTop,flt = elt("search_fl").offsetHeight;
if(slt<flt){elt("search_rs").style.height=flt+"px";}

var flag = true;
var hotelInfoSet = hotelSet.hotelInfoSet;
  if (hotelInfoSet && hotelInfoSet.length > 0){
    for(var i=0;i < hotelInfoSet.length;i++){
      var hotel = hotelInfoSet[i];
      if(hotel.latitude!=0&&hotel.longitude!=0)
      {
        flag = false;
        break;
      }          
    }
  }
$(function()
{
    $("span[id^=hotelsmap]").click(function(event)
    {
        ShowSACBox("ifmMap",$(event.target).attr("url"), 495, 350, "酒店地图");
    });
    /*地图加载开始 add by minjiang 09-8-27*/
    load(true,flag);    
    try
    {    
    addHotelsListMarkers();
   	}
   	catch(e){}
    window.onunload=unload;  
    /*地图加载结束 add by minjiang 09-8-27*/
});

