﻿var _MapExpandingState = true;       //标记右侧栏收缩状态
var _TabControl;                //选项卡

//得到窗口宽度
function fnGetWindowWidth() {
    var vw = 0;
    var _dEt = document.documentElement;
    var _dBy = document.body;
    if (typeof window.innerWidth == 'number') {
        vw = window.innerWidth;
    }
    else {
        if (_dEt && _dEt.clientWidth) {
            vw = _dEt.clientWidth;
        }
        else {
            if (_dBy && _dBy.clientWidth) vw = _dBy.clientWidth;
        }
    }
    if (!vw || vw < 100) {
        vw = 100;
    }
    return vw;
}

//得到窗口高度
function fnGetWindowHeight() {
    var vh = 0;
    var _dEt = document.documentElement;
    var _dBy = document.body;
    if (typeof window.innerHeight == 'number') {
        vh = window.innerHeight;
    }
    else {
        if (_dEt && _dEt.clientHeight) {
            vh = _dEt.clientHeight;
        }
        else {
            if (_dBy && _dBy.clientHeight) vh = _dBy.clientHeight;
        }
    }
    if (!vh || vh < 100) {
        vh = 100;
    }
    return vh;
}

//触发选项卡里的Iframe onresize事件
function fnAttachIframeResize() {
    if (typeof _TabControl != 'undefined') {
        for (var i = 0; i < _TabControl.TabList.length; i++) {
            _TabControl.TabList[i].TabBody.style.height = _TabControl.TabList[i].TabBody.parentNode.clientHeight - 8 + 'px';
            _TabControl.TabList[i].resize();
        }
    }
}

//重写窗口缩放事件
window.onresize = function() {

var h = fnGetWindowHeight(), w = fnGetWindowWidth();
if (h < 450 || w < 750) {
    h = 450;
    w = 750;
    document.body.style.width = '750px';
    document.body.style.height = '450px';
}
else {
    document.body.style.width = w + 'px';
    document.body.style.height = (h - 62) + 'px';
}
if (_MapExpandingState) {
    document.getElementById('NavContent').style.display = 'block';
    document.getElementById('Content').style.marginRight = '312px';
    document.getElementById('Content').style.width = w - 312 + 'px';
    document.getElementById('Navigation').style.marginLeft = '-312px';
    document.getElementById('Navigation').style.width = '312px';
    document.getElementById('EdushiMap').style.width = w - 312 + 'px';
    document.getElementById('DetailMap').style.width = w - 312 + 'px';

    //vM.MapWidth(w-342);            
}
else {
    document.getElementById('NavContent').style.display = 'none';
    document.getElementById('Content').style.marginRight = '11px';
    document.getElementById('Content').style.width = w - 11 + 'px';
    document.getElementById('Navigation').style.marginLeft = '-12px';
    document.getElementById('Navigation').style.width = '12px';
    document.getElementById('EdushiMap').style.width = w - 12 + 'px';
    document.getElementById('DetailMap').style.width = w - 12 + 'px';
    //vM.MapWidth(w-13);  
}
var iShrinkDHHeight = h - 75;
var iShrinkDHPaddingTop = (iShrinkDHHeight - 105) / 2;
document.getElementById('ShrinkDH').style.paddingTop = iShrinkDHPaddingTop + 'px';
document.getElementById('ShrinkDH').style.height = (h - 75 - iShrinkDHPaddingTop) + 'px';
document.getElementById('NavContent').style.height = (h - 84) + 'px';
document.getElementById('Navigation').style.height = (h - 79) + 'px';
document.getElementById('EdushiMap').style.height = h - 77 + 'px';
document.getElementById('DetailMap').style.height = h - 77 + 'px';
document.getElementById('Wrapper').style.height = h - 85 + 'px';
document.getElementById('BodyContainer').style.height = h - 245 + 'px';
//vM.MapHeight(h-76);
fnAttachIframeResize();    
}

//右侧搜索栏收缩展开
function fnExpanding(obj) {
    if (_MapExpandingState) {
        _MapExpandingState = false;
        obj.src = 'Images/Expanding.gif';
    }
    else {
        _MapExpandingState = true;
        obj.src = 'Images/DrawBack.gif';
    }
    window.onresize();
}

function fnActive() {
    alert('fnactive');
}

//初始化选项卡
function fnInitTabControl() {
    if (!_TabControl) {
        var HeadContainer = document.getElementById('HeadContainer');
        var BodyContainer = document.getElementById('BodyContainer');
        var LeftBtn = document.getElementById('LeftBtn');
        var RightBtn = document.getElementById('RightBtn');
        _TabControl = new TabControl(HeadContainer, BodyContainer, LeftBtn, RightBtn);

    }
}

//添加选项卡
function fnAddTab(tab, height) {

    if (!height) {
        tab.TabBody.style.height = '100%';
    }
    else {
        tab.TabBody.style.height = height;
    }
    _TabControl.AddTab(tab);
}


//页面初始化
function fnLoadInit() {
    window.onresize();
    fnInitTabControl();
    //cuowu();
}


function fnCustomSearch() {
    var a = $('txtsearchkey').value.trim();
    var b = $('typecode').value.trim();
    if (a.length > 1) {
        tab = new TabControl.Tab(document, 'search', a, 'CustomSearch.aspx?type=' + b + '&key=' + escape(a) + '&edsx=0&edsy=0', true, true, 80);
        fnAddTab(tab);
    } else {
        alert('请输入模糊搜索条件!');
    }
}

function cuowu() {
    var tab = new TabControl.Tab(document, 'search', '错误', 'a.aspx?aa=' + Math.random(), true, true, 80);
    fnAddTab(tab);
}
