﻿var LineDirect = {
    
    //系统地址
    //Url: 'http://hoteldirect.17u.cn/', //网上
    Url: 'http://192.168.1.28/hotelDirectWeb/', //本地
    
    //客户地址
    ClientUrl: '',
    
    //重设大小页面
    ResizePage: 'lineDirectResize.asp',
    
    //是否打开
    hasOpened: false,
    
    //超时时间(ms)
    TimeOut: 1000,
    
    //会话ID
    SessionID: '',
    
    //线路ID
    LineId: 0,
    
    //线路分类（1：组团线路；2：地接线路）
    LClass: '',
    //线路名称
    LName: '',
    //具体出发日（格式：yyyy-MM-dd）
    LDate: '',
    //线路类型（1：短线；2：长线；3：出境）
    LType:'',
    //线路分组Id
    LGroupId:'',

    
    //颜色
    Color: {
        font: '#000',
        font_highlight: 'red',
        link: 'blue',
        link_highlight: 'orange',
        box_border: '#333',
        box_border_highlight: '#999',
        box_background: '#EEE',
        background: '#FFF'
    },
    
    //序列化颜色
    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
        return ret;
    },
    
    /// <summary>
	/// 打开直销系统
	/// </summary>
	/// <param name="module">模块名称</param>
    Open: function(/*string*/ module){
        if(this.ClientUrl != ''){
            if(module.toLowerCase().replace(/^\s|$\s/,"")=="linedetail"||module.toLowerCase().replace(/^\s|$\s/,"")=="linelist"){
                 if(module.toLowerCase()=="linedetail"){
                     document.write('<iframe onreadystatechange="if(this.readyState != \'complete\'){this.style.height=\'0px\';document.getElementById(\'__hotelDirectLoader\').style.display = \'\';}" allowTransparency="true" id="__hotelDirectFrame" src="' + this.Url +'GroupDetail.aspx?' + (this.LineId > 0 ? 'GroupId=' + this.LineId + '&' : '') + 'clientUrl=' + encodeURIComponent(this.ClientUrl) + '&color=' + encodeURIComponent(this.getColorSerial()) + '&ResizePage=' + encodeURIComponent(this.ResizePage) + '" 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" />系统读取中, 请稍后...</div>');
                 }
                 else{
                     document.write('<iframe onreadystatechange="if(this.readyState != \'complete\'){this.style.height=\'0px\';document.getElementById(\'__hotelDirectLoader\').style.display = \'\';}" allowTransparency="true" id="__hotelDirectFrame" src="' + this.Url +'line_list_new.aspx?' + (this.LineId > 0 ? 'GroupId=' + this.LineId + '&' : '') + 'clientUrl=' + encodeURIComponent(this.ClientUrl) + '&color=' + encodeURIComponent(this.getColorSerial()) + '&ResizePage=' + encodeURIComponent(this.ResizePage) + '&LClass=' + encodeURIComponent(this.LClass) + '&LName=' + encodeURIComponent(this.LName) + '&LDate=' + encodeURIComponent(this.LDate) + '&LType=' + encodeURIComponent(this.LType) + '&LGroupId=' + encodeURIComponent(this.LGroupId) + '" 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" />系统读取中, 请稍后...</div>');
                 }
                   
            }
            else{
                 document.write('<iframe onreadystatechange="if(this.readyState != \'complete\'){this.style.height=\'0px\';document.getElementById(\'__hotelDirectLoader\').style.display = \'\';}" allowTransparency="true" id="__hotelDirectFrame" src="' + this.Url + module + '.aspx?' + (this.LineId > 0 ? 'lineId=' + this.LineId + '&' : '') + 'clientUrl=' + encodeURIComponent(this.ClientUrl) + '&color=' + encodeURIComponent(this.getColorSerial()) + '&ResizePage=' + encodeURIComponent(this.ResizePage) + '" 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" />系统读取中, 请稍后...</div>');
            }
        }else
            document.write('<span class="highlight">错误：客户网址未配置！</span>');
        
        if(this.TimeOut > 0)
            setTimeout('LineDirect.LoadTimeOut()', this.TimeOut);
    },
    
    /// <summary>
	/// 打开酒店直销系统登录框
	/// </summary>
    OpenLoginBox: function(){
        if(this.ClientUrl != '')
            document.write('<iframe allowTransparency="true" src="' + this.Url + '/LoginBox.aspx?clientUrl=' + encodeURIComponent(this.ClientUrl) + '&color=' + encodeURIComponent(this.getColorSerial()) + '" 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()) + '" 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 id="__hotelDirectResizeFrame" src="' + this.ClientUrl + this.ResizePage + '?height=' + ps[1] + '&width=' + ps[0] + '" style="display:none;"></iframe>')
        }else{
            document.write('<span class="highlight">错误：客户网址未配置！</span>');
        }
    },
    
    
    /// <summary>
	/// 页面大小重新设定时运行此方法
	/// </summary>
    Page_Resize: function(){
        try{
            var f = document.getElementById('__hotelDirectResizeFrame');
            var ps = this.GetPageSize();
            f.src = this.ClientUrl + this.ResizePage + '?height=' + ps[1] + '&width=' + ps[0];
        } catch(ex) {  }
    },
    
    
    /// <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);
            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.LineDirect.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;
    }

}
