/**
 Title:框架控制所需要的JS代码
 author:康志强
 date:2005年07-07日
 */

//var rootpath = "/TopIcms";
var webroot = document.location.href;
webroot = webroot.substring(webroot.indexOf('//') + 2, webroot.length);
webroot = webroot.substring(webroot.indexOf('/') + 1, webroot.length);
webroot = webroot.substring(0, webroot.indexOf('/'));
var rootpath = '/' + webroot;

/*以下几个方法是利Dreamweaver自动产生的代码，主要用于控制图片的变换效果*/
function MM_preloadImages() { //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i,j = d.MM_p.length,a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function MM_swapImgRestore() { //v3.0
    var i,x,a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;
    if (!d) d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n);
    return x;
}

function MM_swapImage() { //v3.0
    var i,j = 0,x,a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) x.oSrc = x.src;
            x.src = a[i + 2];
        }
}

//隐藏整个功能视图区
function hideViewArea() {
    /*top.viewArea.cols = "0,15";
     top.main.cols = "15,*";
     var imageId = top.sizeControlFrame.document.getElementById("image");
     var imgSrc = "<a href=" + "javascript:showViewArea();" + "><img src='etc/blue/images/showRight.gif' name='leftImage' width='5' height='50' border='0' id='leftImage' onMouseOver=" + " MM_swapImage('leftImage','','etc/blue/images/showRightOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
     imageId.innerHTML = imgSrc;
     if (top.mainFrame.document.all["webfx-tab-style-sheet"]) {
         top.mainFrame.resetPanelSize();
     }*/
    var viewArea = document.getElementById("viewArea");
    var imageId = document.getElementById("image_1");
    viewArea.style.display = "none";
    var imgSrc = "<a href=" + "javascript:showViewArea();" + "><img style='z-index:15000' src='etc/default/images/showRight.gif' name='leftImage' width='5' height='50' border='0' id='leftImage' onMouseOver=" + " MM_swapImage('leftImage','','etc/default/images/showRightOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
    imageId.innerHTML = imgSrc;
    top.mainFrame.resetPanelSize();
}

//显示整个功能视图区
function showViewArea() {
    /*top.viewArea.cols = "200,12";
     //top.mainFrame.resetPanelSize();
     top.main.cols = "212,*";
     if (top.mainFrame.document.all["webfx-tab-style-sheet"]) {
         top.mainFrame.resetPanelSize();
     }
     var imageId = top.sizeControlFrame.document.getElementById("image");
     var imgSrc = "<a href=" + "javascript:hideViewArea();" + "><img src='etc/blue/images/hideLeft.gif' name='leftImage' width='5' height='50' border='0' id='leftImage' onMouseOver=" + " MM_swapImage('leftImage','','etc/blue/images/hideLeftOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
     imageId.innerHTML = imgSrc;
     if (top.mainFrame.document.all["webfx-tab-style-sheet"]) {
         top.mainFrame.resetPanelSize();
     }*/
    var viewArea = document.getElementById("viewArea");
    var imageId = document.getElementById("image_1");
    viewArea.style.display = "";
    var imgSrc = "<a href=" + "javascript:hideViewArea();" + "><img style='z-index:15000' src='etc/default/images/hideLeft.gif' name='leftImage' width='5' height='50' border='0' id='leftImage' onMouseOver=" + " MM_swapImage('leftImage','','etc/default/images/hideLeftOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
    imageId.innerHTML = imgSrc;
    top.mainFrame.resetPanelSize();
}
//向下隐藏导航视图
function hideNavigateView() {
    /*try {
         top.navigateView.rows = "*,12";
         var menu = top.menuFrame.document.getElementById("menuDiv");
         menu.style.height = top.menuFrame.document.body.offsetHeight - 28;
         var imageId = top.navigateFrame.document.getElementById("image");
         var imgSrc = "<img onclick='showNavigateView();' src='etc/blue/images/showUp.gif' name='Image2' width='50' height='5' border='0' id='Image2' onMouseOver=" + " MM_swapImage('Image2','','etc/blue/images/showUpOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + ">";
         imageId.innerHTML = imgSrc;
     }
     catch (e) {
     }*/
    var navArea = top.document.getElementById("navArea").parentNode;
    var imageId = top.document.getElementById("image_2");
    navArea.style.display = "none";
    var imgSrc = "<a href=" + "javascript:showNavigateView();" + "><img src='etc/default/images/showUp.gif' name='Image2' height='5' width='50' border='0' id='Image2' onMouseOver=" + " MM_swapImage('Image2','','etc/default/images/showUpOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
    imageId.innerHTML = imgSrc;
}
//向上显示导航视图
function showNavigateView() {
    /*try {
         top.navigateView.rows = "*,250";
         var menu = top.menuFrame.document.getElementById("menuDiv");
         menu.style.height = top.menuFrame.document.body.offsetHeight - 26;
         var imageId = top.navigateFrame.document.getElementById("image");
         var imgSrc = "<img onclick='hideNavigateView();' src='etc/blue/images/hideDown.gif' name='Image2' width='50' height='5' border='0' id='Image2' onMouseOver=" + " MM_swapImage('Image2','','etc/blue/images/hideDownOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + ">";
         imageId.innerHTML = imgSrc;
     }
     catch (e) {
     }*/
    var navArea = top.document.getElementById("navArea").parentNode;
    var imageId = top.document.getElementById("image_2");
    navArea.style.display = "";
    var imgSrc = "<a href=" + "javascript:hideNavigateView();" + "><img src='etc/default/images/hideDown.gif' name='Image2' height='5' width='50' border='0' id='Image2' onMouseOver=" + " MM_swapImage('Image2','','etc/default/images/hideDownOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
    imageId.innerHTML = imgSrc;
}
function showNewNavigateView() {
    /*try {
         top.navigateView.rows = "*,250";
         var menu = top.menuFrame.document.getElementById("menuDiv");
         menu.style.height = top.menuFrame.document.body.offsetHeight - 26;
         var imageId = top.navigateFrame.document.getElementById("image");
         var imgSrc = "<img onclick='hideNavigateView();' src='etc/blue/images/hideDown.gif' name='Image2' width='50' height='5' border='0' id='Image2' onMouseOver=" + " MM_swapImage('Image2','','etc/blue/images/hideDownOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + ">";
         imageId.innerHTML = imgSrc;
     }
     catch (e) {
     }*/
    updateTabs('img2');
    showLayer('two');
    hideLayer('one');
    var navArea = top.document.getElementById("navArea").parentNode;
    var imageId = top.document.getElementById("image_2");
    navArea.style.display = "";
    var imgSrc = "<a href=" + "javascript:hideNavigateView();" + "><img src='etc/default/images/hideDown.gif' name='Image2' height='5' width='50' border='0' id='Image2' onMouseOver=" + " MM_swapImage('Image2','','etc/default/images/hideDownOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
    imageId.innerHTML = imgSrc;
}

//菜单转向时把页面标题提到headFrame中去，然后在改变主页面的href地址
function toURL(name, url) {
    //把页面标题提交到Head页面中
    //top.headFrame.pageTitle.value = name;
    //清空导航栏，并隐藏
    //clearNavList();
    //跳转页面
    //top.mainFrame.location.href = url;
    parent.mainFrame.createNewWindnow(name, url);
    clearNavList();
    //记录首个页面的url
    var frame = top.mainFrame.window.mainTablePane.getSelectedFrame();
    frame._navURL = url;
}

//布局框架页面中提取headFrame中题的值
function getPageTitle() {
    return;
    var pageTitleStr = top.headFrame.pageTitle.value;
    var pageTitleId = document.getElementById("pageTitle");
    pageTitleId.innerHTML = pageTitleStr;
}

//导航栏上的资料入口
/*function navToURL(url) {
//    top.headFrame.isShowNav.value = 'true';
    parent.mainFrame.createNewWindnow("导航栏", url);
}*/

function goUrlWithMainArea(url, index) {
    top.mainFrame.document.frames["container_frame_" + index].window.location = url;
    if (top.mainFrame.window.mainTablePane.getSelectedIndex() != index)   top.mainFrame.window.mainTablePane.setSelectedIndex(index);
}
//修改工作空间链接
function navToURL(url) {
    /*
    var index = top.mainFrame.window.mainTablePane.getSelectedIndex()
    top.mainFrame.document.frames["container_frame_" + index].location = url;
    */
    parent.icibBody.document.location = url;
}


/** -----------------导航栏使用的函数--------------------- **/
//checks browser and sets up layers accordingly
//var path = "default/images/navigate/";
var path = rootpath + "/frame/" + "default/images/navigate/";
//imgArray 是一个二维数组：[imgName,on_img_src,off_img_src]
var imgArray = [
        ["img1",path + "tab1_on.gif", path + "tab1_off.gif"] ,
        ["img2",path + "tab2_on.gif", path + "tab2_off.gif"] ]

//显示导航栏中的第一个面板，并隐藏其他面板
function showOne() {
    initnavigate();
    //updateTabs('img1');
    //showLayer('one');
    //hideLayer('two');
    showNavigateView();
}

//显示导航栏中的第二个面板，并隐藏其他面板
function showTwo() {
    initnavigate();
    //updateTabs('img2');
    //showLayer('two');
    //hideLayer('one');
    showNavigateView();
}
function showNewTwo() {
    initnavigate();
    //updateTabs('img2');
    //showLayer('two');
    //hideLayer('one');
    showNewNavigateView();
}


function showLayer(layerName) {
    if (top.navigateFrame.document.layers) {
        eval(layerRef + layerName + '.style.display="block"');
    } else {
        eval('top.navigateFrame.document.getElementById(' + "'" + layerName + "'" + ').style.display = "block"');
    }
}

function hideLayer(layerName) {
    if (top.navigateFrame.document.layers) {
        eval(layerRef + layerName + '.style.display="none"');
    } else {
        eval('top.navigateFrame.document.getElementById(' + "'" + layerName + "'" + ').style.display = "none"');
    }
}

function initnavigate() {
    if (top.navigateFrame.document.layers) {
        layerRef = "top.navigateFrame.document.layers.";
    }
    if (top.navigateFrame.document.images) {
    }
}

function updateTabs(imgName) {
    with (top.navigateFrame) {
        if (document.images) {
            for (var i = 0; i < imgArray.length; i++) {
                if (imgArray[i][0] == imgName) {
                    document.all(imgArray[i][0]).src = imgArray[i][1];
                } else {
                    document.all(imgArray[i][0]).src = imgArray[i][2];
                }
            }
        }
    }

}


/**-------------------错误提示使用的函数-----------------**/
//聚焦到错误域中
function errorFocus(errId, index) {
    index = index || 0;
    top.mainFrame.window.mainTablePane.setSelectedIndex(index);
    top.mainFrame.document.frames["container_frame_" + index].document.all(errId).focus();

}

//填充错误信息到错误提示面板中
function fillError() {
    var tdiv = top.navigateFrame.document.getElementById('error_id');
    //为解决机构管理（aaf）中的js错误，在2006年3月31日被迫在此进行修改
    //原来代码为：tdiv.innerHTML = top.mainFrame.document.all("__errorInfo").innerHTML;
    //wangpu
    tdiv.innerHTML = document.all("__errorInfo").innerHTML;

}

//填充导航列表到导航面板中
function fillNavList() {
    /*
    //保存导航信息,如果页面导航信息为空则填充缓存的导航信息
    var frame = top.mainFrame.window.mainTablePane.getSelectedFrame();
    //先读取页面内容
    if (document.all("__nav_id")) {
        frame._navInfo = document.all("__nav_id").innerHTML
    } else {    //否则读取缓存
        frame._navInfo = frame._navInfo || "";
    }
    var tdiv = top.navigateFrame.document.getElementById('nav_id');
    //原来内容为top.mainFrame
    tdiv.innerHTML = frame._navInfo;
    */

    var tdiv = parent.icibView.document.getElementById('nav_id');
    tdiv.innerHTML = document.all("__nav_id").innerHTML;
}

//填充导航列表，并显示导航列表
function fillNavAndShow() {
    /*
    //填充导航栏导航内容
    fillNavList();
    //显示导航栏
    showOne();

    //设置导航栏状态为隐藏状态
    //top.headFrame.isShowNav.value = "true";
    */

    try {
        //填充导航栏导航内容
        fillNavList();
        //显示导航栏
        //showOne();
        parent.icibMain.rows = "60,*";

        //设置导航栏状态为隐藏状态
        //top.headFrame.isShowNav.value = "true";
    }
    catch(e)
    {
    }
}
function onSelectPanel() {
    var frame = (parent.window.mainTablePane || parent.parent.window.mainTablePane).getSelectedFrame();
    var navInfo = document.getElementById("__nav_id");
    //导航信息先读取页面再读取缓存
    if (navInfo || frame._navInfo) {
        top.navigateFrame.showNavigateView();
        fillNavList();
        showOne();
    }
    var errorInfo = document.getElementById("__errorInfo");
    if (errorInfo) {
        top.navigateFrame.showNavigateView();
        fillError();
        showTwo();
    }
}
function onClosePanel() {
    var tdiv = top.navigateFrame.document.getElementById('nav_id');
    //原来内容为top.mainFrame
    if (tdiv)tdiv.innerHTML = "";
    var tdiv2 = top.navigateFrame.document.getElementById('error_id');
    if (tdiv2)tdiv2.innerHTML = "";
    hideNavigateView();
    return true;
}
function onBlurPanel() {
    onClosePanel();
}

//清空导航栏列表，并隐藏
function clearNavList() {
    /*
    var tdiv = top.navigateFrame.document.getElementById('nav_id');
    tdiv.innerHTML = "";
    //清导航的缓存
    var frame = top.mainFrame.window.mainTablePane.getSelectedFrame();
    frame._navInfo = "";
    //设置导航栏状态为隐藏状态
    //top.headFrame.isShowNav.value = "false";
    //隐藏导航栏
    hideNavigateView();
    */

    try {
        parent.icibMain.rows = "0,*";
    }
    catch(e) {
    }
}


//从错误提示面板中清空错误信息,并显示导航面板
function clearError() {
    var tdiv = top.navigateFrame.document.getElementById('error_id');
    tdiv.innerHTML = "";
    //if (top.headFrame.isShowNav.value == "true") {
    //导航栏有内容则显示
    if (top.navigateFrame.document.getElementById('nav_id').innerHTML) {
        //显示导航面板
        showOne();
    } else {//隐藏导航栏
        hideNavigateView();
    }
}

function fillJsErrorAndShow(errs) {
    var tdiv = top.navigateFrame.document.getElementById('error_id');
    var strHtml = "<TABLE cellSpacing=0 cellPadding=0 width='100%' align=center border=0>";
    for (var i = 0; i < errs.length; i++) {
        strHtml += "<TR>";
        strHtml += "<TD><IMG src='" + rootpath + "/frame/default/images/navigate/error_light.gif'></TD>";
        strHtml += "<TD class='TD_guide_line_test'><A href=\"javascript:errorFocus('" + errs[i][0] + "');\">" + errs[i][1] + "</A></TD>";
        strHtml += "</TR>";
    }
    strHtml += "</TABLE>";
    tdiv.innerHTML = strHtml;
    showTwo();
    window.attachEvent("onunload", clearError);
}

//显示等待页面
function _showWait() {
    var win = top.headFrame;
    if (win == null)return;
    if (win._wait != null)return;
    win._wait = win.showModelessDialog(rootpath + "/frame/loading.jsp", window, "dialogTop:550px;dialogLeft:750px;dialogHeight: 100px; dialogWidth: 200px; center: yes; help: no; scroll: no; status: no;");
    ;
}
//隐藏等待页面
function _hiddenWait() {
    var win = top.headFrame;
    if (win == null)return;
    if (win._wait != null) {
        if (!win._wait.closed)win._wait.close();
        win._wait = null;
    }
}
//先清，后添事件，防止添加重复事件
//清事件
//window.detachEvent("onload",_hiddenWait);
//window.detachEvent("onunload",_showWait);
////添加事件
//window.attachEvent("onload",_hiddenWait);
//window.attachEvent("onunload",_showWait);
// 默认为隐藏导航窗口
window.attachEvent("onload", function() {
    try {
        if (!parent.window.mainTablePane && !parent.parent.window.mainTablePane)return;
        var frame = (parent.window.mainTablePane || parent.parent.window.mainTablePane).getSelectedFrame();
        if (!frame)return;
        frame.onSelectPanel = onSelectPanel;
        frame.onClosePanel = onClosePanel;
        frame.onBlurPanel = onBlurPanel;
        //重新加载第一个页面则清空导航
        var curUrl = location.pathname + location.search;
        curUrl = curUrl.substr(curUrl.length - frame._navURL.length);
        if (curUrl == frame._navURL) {
            clearNavList();
        }
    } catch(e) {
    }

}
        );

function fillErrorAndShow(item, content) {
    var tdiv = top.navigateFrame.document.getElementById('error_id');
    var strHtml = "<TABLE cellSpacing=0 cellPadding=0 width='100%' align=center border=0>";
    strHtml += "<TR>";
    strHtml += "<TD><IMG src='" + rootpath + "/frame/default/images/navigate/error_light.gif'></TD>";
    strHtml += "<TD class='TD_guide_line_test'><A href=\"javascript:errorFocus('" + item + "');\">" + content + "</A></TD>";
    strHtml += "</TR>";
    strHtml += "</TABLE>";
    tdiv.innerHTML = strHtml;
    showTwo();
    window.attachEvent("onunload", clearError);
}


function fillErrorAndShowForm(form) {
    var tdiv = top.navigateFrame.document.getElementById('error_id');
    var strHtml = "<TABLE cellSpacing=0 cellPadding=0 width='100%' align=center border=0>";
    for (var i = 0; i < form.length; i++) {
        if (form[i].alt == "true") {
            if (form[i].value == "") {
                strHtml += "<TR>";
                strHtml += "<TD><IMG src='" + rootpath + "/frame/default/images/navigate/error_light.gif'></TD>";
                strHtml += "<TD class='TD_guide_line_test'><A href=\"javascript:errorInfoFocus('" + form[i].name + "');\">" + form[i].parentElement.previousSibling.innerText.substring(0, form[i].parentElement.previousSibling.innerText.length - 1) + "不能为空！" + "</A></TD>";
                strHtml += "</TR>";
                if (form[i].type !== "hidden") {
                    form[i].focus();
                    form[i].select();
                }
            }
        }
    }
    strHtml += "</TABLE>";
    if (strHtml.indexOf("<TR>") == -1) {
        return true;
    } else {
        tdiv.innerHTML = strHtml;
        showTwo();
        window.attachEvent("onunload", clearError);
        return false;
    }

}

function errorInfoFocus(errId, index) {
    index = index || top.mainFrame.window.mainTablePane.getSelectedIndex() || 0;

    //top.mainFrame.window.mainTablePane.setSelectedIndex(index);
    top.mainFrame.document.frames["container_frame_" + index].document.all(errId).focus();
}