﻿// JScript 文件
DianCMS_$ = function(em) {
    if (document.getElementById) { return document.getElementById(em); }
    else if (document.all) { return document.all[em]; }
    else if (document.layers) { return document.layers[em]; }
    else { return null; }
}

var tid = 0;
function ShowTabs(cid) {
    if (cid != tid) {
        DianCMS_$("TabTitle" + tid).className = "title5";
        DianCMS_$("TabTitle" + cid).className = "title6";
        DianCMS_$("Tabs" + tid).style.display = "none";
        DianCMS_$("Tabs" + cid).style.display = "";
        tid = cid;
    }
}

function WinOpen(url, n, w, h) {
    var left = (screen.width - w) / 2;
    var top = (screen.height - h) / 2;
    var f = "width=" + w + ",height=" + h + ",top=" + top + ",left=" + left + ",scrollbars=1";
    var c = window.open(url, n, f);
    return c;
}

function Win_Open(url, n, w, h) {
    var left = (screen.width - w) / 2;
    var top = (screen.height - h) / 2;
    var f = "width=" + w + ",height=" + h + ",top=" + top + ",left=" + left + "";
    var c = window.open(url, n, f);
    return c;
}

function WinOpenDialog(url, w, h) {
    var feature = "dialogWidth:" + w + "px;dialogHeight:" + h + "px;center:yes;status:no;help:no;scrollbars:no";
    showModalDialog(url, window, feature);
}

function WinOpenLhgDialog(name, url, w, h, css) {
    if (css.length == 0)
        css = "default";
    lhgdialog.opendlg('' + name + '', '' + url + '', w, h, true, false, '', false, { css: '' + css + '.css' });
}

var range;
function WinOpenLhgFocusDialog(Control, name, url, w, h, css) {
    DianCMS_$('' + Control + '').focus();
    range = document.selection.createRange();
    if (css.length == 0)
        css = "default";
    lhgdialog.opendlg('' + name + '', '' + url + '', w, h, true, false, '', false, { css: '' + css + '.css' });
}

function SizePlus(name) {
    var _height = document.getElementById(name).style.height.replace("px", "");
    var __height = Number(_height) + 50;

    document.getElementById(name).style.height = __height + "px";
}

function SizeMinus(name) {
    var _height = document.getElementById(name).style.height.replace("px", "");

    if (Number(_height) > 50) {
        var __height = Number(_height) - 50;

        document.getElementById(name).style.height = __height + "px";
    }
}

//运行代码
function runEx(cod1) {
    cod = document.getElementById(cod1)
    var code = cod.value;
    if (code != "") {
        var newwin = window.open('', '', '');
        newwin.opener = null
        newwin.document.write("<table>" + code + "</table>");
        newwin.document.close();
    }
}

function CreateRange(name, val) {
    document.getElementById(name).focus();
    document.selection.createRange().text = val;
}

function chooseOne(cb, id) {
    var obj = document.getElementById(id);
    for (i = 0; i < obj.children.length; i++) {
        if (obj.children[i] != cb) obj.children[i].checked = false;
        else obj.children[i].checked = cb.checked;
        //若要至少勾选一个的话，则把上面那行else拿掉，换用下面那行   
        //else obj.children[i].checked = true;   
    }
}

function choose_One(cb, id) {
    var obj = document.getElementById(id);
    for (i = 0; i < obj.children.length; i++) {
        if (obj.children[i] != cb) obj.children[i].checked = false;
        else obj.children[i].checked = true;
    }
}

String.prototype.getQuery = function(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = this.substr(this.indexOf("\?") + 1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

function getUrlParam(id, name) {
    var str = window.location.href.toLowerCase();
    DianCMS_$(id).value = str.getQuery(name.toLowerCase());
}


//Ctrl+s保存
function Save() {
    if (event.ctrlKey == true && event.keyCode == 83) {
        event.returnvalue = false;
        DianCMS_$("DianCMS_Submit").click();
    }
}