﻿var HotelDirect = {
    
    //系统地址    
    Url: 'http://hotelzx.51zfx.com/',
    
    //客户地址
    ClientUrl: '',
    
    //语言设置，zh-cn表示简体中文，en-us表示英文，默认值为zh-cn
    Language:'zh-cn',
    
    //是否打开
    hasOpened: false,
    
    //超时时间(ms)
    TimeOut: 1000,
    
    //会话ID
    SessionID: '',
    
    //颜色
    Color: {
        font: '#000',
        font_highlight: 'red',
        link: 'blue',
        link_highlight: 'orange',
        box_border: '#333',
        box_border_highlight: '#999',
        box_background: '#EEE',
        background: '#FFF',
        txtStyle:'' ,
        ddlStyle:'' ,
        btnStyle:'' ,
        ddlBorderStyle:'' 
    },
    
    //序列化颜色
    getColorSerial: function(){
        var ret = this.Color.font + "," +
            this.Color.font_highlight + "," +
            this.Color.link + "," +
            this.Color.link_highlight + "," +
            this.Color.box_border + "," +
            this.Color.box_border_highlight + "," +
            this.Color.box_background + "," +
            this.Color.background+","+
            this.Color.txtStyle+","+
            this.Color.ddlStyle +","+
            this.Color.btnStyle+","+
            this.Color.ddlBorderStyle 
        return ret;
    },
    
    /// <summary>
	/// 打开酒店直销系统
	/// </summary>
	/// <param name="module">模块名称</param>
	/// <param name="hotelId">酒店Id</param>
    Open: function(/*string*/ module, /*int*/ hotelId){        
        if(this.ClientUrl != ''){
            var sessionstr = '';            
            if(this.SessionID != '')
                sessionstr = '(S(' + this.SessionID + '))/';            
            var html='<iframe onreadystatechange="if(this.readyState != \'complete\'){this.style.height=\'0px\';document.getElementById(\'__hotelDirectLoader\').style.display = \'\';}" allowTransparency="true" id="__hotelDirectFrame" src="' + this.Url + sessionstr + module + '.aspx?hotelId=' + hotelId + '&clientUrl=' + encodeURIComponent(this.ClientUrl) + '&color=' + encodeURIComponent(this.getColorSerial()) + '&Language=' + this.Language + '" frameborder="0" style="width:100%; height:0px;" scrolling="no"></iframe><div id="__hotelDirectLoader" style="padding:150px 0; background:#FFF; font-size:16px; text-align:center;"><img src="' + this.Url + 'images/loading.gif" align="absmiddle" />';
            if(this.Language=='en-us')
            {            
                html=html+'Loading, please wait...</div>';
            }
            else
            {
                html=html+'系统读取中，请稍后...</div>';
            }
            document.write(html);
        }else
            document.write('<span class="highlight">错误：客户网址未配置！</span>');
        
        if(this.TimeOut > 0)
            setTimeout('HotelDirect.LoadTimeOut()', this.TimeOut);
    },
    
    /// <summary>
	/// 打开酒店直销系统登录框
	/// </summary>
	/// <param name="hotelId">酒店Id</param>
    OpenLoginBox: function(/*int*/ hotelId){
        if(this.ClientUrl != ''){
            var sessionstr = '';
            if(this.SessionID != '')
                sessionstr = '(S(' + this.SessionID + '))/';
            document.write('<iframe allowTransparency="true" src="' + this.Url + sessionstr + 'LoginBox.aspx?hotelId=' + hotelId + '&clientUrl=' + encodeURIComponent(this.ClientUrl) + '&color=' + encodeURIComponent(this.getColorSerial()) + '&Language=' + this.Language + '" frameborder="0" style="width:200px; height:100px;" scrolling="no"></iframe>');
        }else
            document.write('<span class="highlight">错误：客户网址未配置！</span>');
    },
    
    
    /// <summary>
	/// 打开酒店直销系统预订框
	/// </summary>
	/// <param name="hotelId">酒店Id</param>
    OpenOrderBox: function(/*int*/ hotelId){
        if(this.ClientUrl != ''){
            var sessionstr = '';
            if(this.SessionID != '')
                sessionstr = '(S(' + this.SessionID + '))/';
            document.write('<iframe allowTransparency="true" src="' + this.Url + sessionstr + 'OrderBox.aspx?hotelId=' + hotelId + '&clientUrl=' + encodeURIComponent(this.ClientUrl) + '&color=' + encodeURIComponent(this.getColorSerial()) + '&Language=' + this.Language + '" frameborder="0" style="width:200px; height:220px;" scrolling="no"></iframe>');
        }else
            document.write('<span class="highlight">错误：客户网址未配置！</span>');
    },
    
    
    /// <summary>
	/// 系统读取完成后自动运行该方法
	/// </summary>
    LoadComplete: function(){
        if(this.ClientUrl != ''){
            var ps = this.GetPageSize();            
            document.write('<iframe src="' + this.ClientUrl + 'hotelDirectResize.asp?height=' + ps[1] + '&width=' + ps[0] + '&sessionId=' + this.SessionID + '" style="display:none;"></iframe>')
        }else{
            if(this.Language=='en-us')
            {
                document.write('<span class="highlight">Error:ClientUrl is not configured！</span>');
            }
            else
            {
                document.write('<span class="highlight">错误：客户网址未配置！</span>');
            }            
        }
    },
    
    
    /// <summary>
	/// 系统超时后自动运行该方法
	/// </summary>
    LoadTimeOut: function(){
        if(!this.hasOpened){
            document.getElementById('__hotelDirectLoader').style.display = 'none';
            var f = document.getElementById('__hotelDirectFrame');
            f.style.display = 'none';
            var errinfo = document.createElement('span');
            f.parentNode.appendChild(errinfo);
            if(this.Language=='en-us')
            {            
                errinfo.innerHTML = 'Error:timeout for loading data!';
            }
            else
            {
                errinfo.innerHTML = '错误：系统读取超时！';
            }            
            errinfo.style.color = 'red';
        }
    },
    
    
    /// <summary>
	/// 改变直销系统显示大小
	/// </summary>
	/// <param name="width">宽度</param>
	/// <param name="height">高度</param>
    Resize: function(/*int*/ width, /*int*/ height){
        try{
            var f = parent.parent.document.getElementById('__hotelDirectFrame');
            f.style.display = '';
            //f.style.width = width + 'px';
            f.style.height = height + 'px';
            parent.parent.document.getElementById('__hotelDirectLoader').style.display = 'none';
            parent.parent.HotelDirect.hasOpened = true;
        }catch(e){
            document.write('<span class="highlight">错误：' + e.description + '！</span>');
        }
    },


    /// <summary>
	/// 获取页面大小
	/// </summary>
	/// <returns>[页面宽, 页面高, 窗口宽, 窗口高]</returns>
    GetPageSize: function(){

        var xScroll, yScroll;

        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }

        var windowWidth, windowHeight;
        if (self.innerHeight) { // all except Explorer
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        // for small pages with total height less then height of the viewport
        if(yScroll < windowHeight){
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }

        // for small pages with total width less then width of the viewport
        if(xScroll < windowWidth){
            pageWidth = windowWidth;
        } else {
            pageWidth = xScroll;
        }
        
        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
        return arrayPageSize;
    }

}