//index.js
//导航页面专用脚本
//创建 zhaoshunlu 2013-12-20
//更新：zhao 2014-09-18 增加按钮禁用与隐藏效果

//加载导航按钮
//参数：tables 导航项集合
//调用实例：
// var tables = [
//        { id: "p1", icon: "car.png", url: "../SupplierList.html", title: "供应商信息", info: "管理如酒店、餐厅、景点等供应商信息" },
//        { id: "p2", icon: "rengys.png", url: "../ContactList.html", title: "查看供应商联系人", info: "查看供应商联系人" }
//     ];
// LoadNavBtn(tables);//加载导航按钮
//2013-5-8 赵 增加以弹窗方式显示URL链接 参数url 是链接路径,参数IsTab如果为false，将以弹窗打开链接
//维护： 赵 2013-12-27 解决360,IE 浏览器弹窗显示问题
function LoadNavBtn(divId, tables, lookPws) {
    
    //在这里填上表格ID,可以实现若干个表格同时改变
    for (var i = 0; i < tables.length; i++) {
        var btn = tables[i];
        if (lookPws && (btn.pw || btn.pw == "")) {
            var spw = (btn.pw != "") ? btn.pw : btn.title;
            if (lookPws.indexOf(spw) < 0) {
                continue;
            }
        }
        var navbtnhtml = "";
        navbtnhtml += "<table class=\"navbutton\" id=\"" + btn.id + "\" ";
        navbtnhtml += " style=\"";
        if (btn.enable == false) {
            //禁用按钮
            navbtnhtml += "cursor: default;filter: Alpha(opacity=10);-moz-opacity:.1;opacity:0.2;";
        }
        if (btn.visible == false) {
            //隐藏按钮
            navbtnhtml +="display:NONE;";
        }
        navbtnhtml += " \"";
        var str = "";
        if (btn.IsTab && btn.IsTab=="true") {
            str = btn.url + "|" + btn.IsTab;
        } else if (btn.target) {            
            str = btn.url + "|" + btn.target;
        } else {
            str = btn.url; //默认是选项卡
        }
        navbtnhtml += " summary=\"" + str + "\"";      //str 保存有地址url和目标target
        navbtnhtml += " title=\"" + btn.title + "\">"; //
        navbtnhtml += "  <tr>";
        navbtnhtml += "    <td style=\"width:40px;\"><img src=\"../images/baseset/" + btn.icon + "\" /></td>";
        navbtnhtml += "    <td>";
        navbtnhtml += "         <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: none;\">";
        navbtnhtml += "           <tr><td class=\"navtitle\">" + btn.title + "</td></tr>";
        navbtnhtml += "           <tr><td class=\"navinfo\">" + btn.info + "</td></tr>";
        navbtnhtml += "         </table>";
        navbtnhtml += "    </td>";
        navbtnhtml += "  </tr>";
        navbtnhtml += "</table>";
        $("#" + divId).append(navbtnhtml);        //插入新节点
        //
        if (btn.enable != false) {//没有被禁用按钮
            var table = document.getElementById(btn.id);
            //table.onmouseover = function () { this.style.backgroundColor = "#d9e7f8"; }
            //table.onmouseout = function () { this.style.backgroundColor = "transparent"; }
            table.onmouseover = function () { $(this).addClass("mini-nav-page"); }
            table.onmouseout = function () { $(this).removeClass("mini-nav-page"); }
            table.onclick = function () {
                // this.style.backgroundColor = "transparent";
                $(this).removeClass("mini-nav-page");
                //           
                var target = "", url = "";
                if (this.summary.indexOf("|") > 0) {
                    var arrs = this.summary.split("|");
                    url = arrs[0];
                    target = arrs[1];
                } else {
                    url = this.summary;
                }                
                if (target == "" || target == "true" || target == "tab" || target == "_self") {
                    window.parent.AddDockTab(this.id, this.icon, this.title, url);
                } else if (target == "mini.open") {
                    OpenDialog(this.title, url, false, 0);
                } else {
                    //弹开新窗口显示网页(缺点：容易被拦截)
                    window.open(url);
                }
            }
        }
    }
}
//加载小图标导航按钮
//除是小图标外其他与LoadNavBtn方法的功用说明相同
function LoadMiniNavBtn(divId, tables,lookPws) {

    //在这里填上表格ID,可以实现若干个表格同时改变
    for (var i = 0; i < tables.length; i++) {
        var btn = tables[i];
        if (lookPws && (btn.pw || btn.pw=="")) {
            var spw = (btn.pw != "") ? btn.pw : btn.title;
            if (lookPws.indexOf(spw) < 0) {
                continue;
            }
        }
        var navbtnhtml = "";
        navbtnhtml += "<table class=\"mininavbutton\" id=\"" + btn.id + "\" ";
        navbtnhtml += " style=\"";
        if (btn.enable == false) {
            //禁用按钮
            navbtnhtml += "cursor: default;filter: Alpha(opacity=10);-moz-opacity:.1;opacity:0.2;";
        }
        if (btn.visible == false) {
            //隐藏按钮
            navbtnhtml += "display:NONE;";
        }
        navbtnhtml += " \"";
        var str = "";
        if (btn.IsTab && btn.IsTab == "true") {
            str = btn.url + "|" + btn.IsTab;
        } else if (btn.target) {
            str = btn.url + "|" + btn.target;
        } else {
            str = btn.url; //默认是选项卡
        }
        if (!btn.icon || btn.icon == "") {
            btn.icon = "set.png";
        }
        navbtnhtml += " summary=\"" + str + "\"";
        navbtnhtml += " title=\"" + btn.title + "\">"; //
        navbtnhtml += "  <tr>";
        navbtnhtml += "    <td style=\"width:16px;\"><img src=\"../images/common/" + btn.icon + "\" style=\"width:16px;height:16px;\" /></td>";
        navbtnhtml += "    <td class=\"navtitle\" title=\"" + btn.info + "\">" + btn.title + "</td>";
        navbtnhtml += "  </tr>";
        navbtnhtml += "</table>";
        $("#" + divId).append(navbtnhtml);        //插入新节点
        //
        if (btn.enable != false) {
            //没有被禁用按钮
            var table = document.getElementById(btn.id);
            table.onmouseover = function () { $(this).addClass("mini-nav-page"); }
            table.onmouseout = function () { $(this).removeClass("mini-nav-page"); }
            table.onclick = function () {               
                $(this).removeClass("mini-nav-page");
                //           
                var target = "", url = "";
                if (this.summary.indexOf("|") > 0) {
                    var arrs = this.summary.split("|");
                    url = arrs[0];
                    target = arrs[1];
                } else {
                    url = this.summary;
                }
                if (target == "" || target == "true" || target == "tab" || target == "_self") {
                    window.parent.AddDockTab(this.id, this.icon, this.title, url);
                } else if (target == "mini.open") {
                    OpenDialog(this.title, url, 0);
                } else {
                    //弹开新窗口显示网页(缺点：容易被拦截)
                    window.open(url);
                }
            }
        }
    }
}

/*
*获取权限编号字符串
*lookPws 输入字符串
*tables 按钮集合
*repeat 是否有重复编号
*创建：zhao 2014-8-8
*/
function GetLookPws(tables, lookPws, repeat) {
    if (!lookPws) lookPws = "";
    if (!repeat) repeat = false;
    for (var i = 0; i < tables.length; i++) {
        var btn = tables[i];
        var spw = "";
        if (btn.pw || btn.pw=="") {
            if (repeat == true) {
                spw = (btn.pw != "") ? btn.pw : btn.title;
                if (lookPws.indexOf(spw) == -1) {
                    lookPws += spw + ",";
                }
            } else {
                spw = (btn.pw != "") ? btn.pw : btn.title;
                lookPws += spw + ",";
            }
        }
    }
    return lookPws;
}

//打开表单窗口进行修改
function OpenDialog(wintitle,url,isEdit, rowId) {
    mini.open({
        title: wintitle,
        url: url,       
        width: 650,
        height: 420,
        showMaxButton: true,
        showToolbar: false,
        showFooter: true,
        showModal: true,
        allowResize: true,
        allowDrag: true,
        onload: function () {
          
        },
        ondestroy: function (action) {           
        }
    });
}