﻿function _COM_I(strID) {
    return document.getElementById(strID);
}

function _COM_N(strName) {
    var oName = document.getElementsByName(strName);
    if (oName.length > 0) { return oName[0]; }
    else { return null; }
}

function _COM_Target(event) {
    event = window.event || event;
    return event.srcElement || event.target;
}

///     备注:Tab切换
/// numIndex:[Number]被选中的Tab序号
/// strTabID:[String]Panel控件父节点的ID
/// strTabTN:[String]Panel控件的TagName
///strMenuID:[String]Tab控件父节点的ID
///strMenuTN:[String]Tab控件的TagName
function COM_Tab(strTabName, strContentName, oSelf, classClose, classOpen) {
    var jqTab = $("[name=" + strTabName + "]");
    var jqContent = $("[name=" + strContentName + "]");
    var numIndex = jqTab.index($(oSelf));
    jqTab.attr("class", classClose);
    jqContent.hide();
    $(oSelf).attr("class", classOpen);
    $(jqContent.get(numIndex)).show();
}

///备注:判断是否为空
/// obj:[Object]被判断的对象
function _COM_IsNull(obj) {
    return (obj == "" || obj == "undefined" || obj == null);
}

function _COM_Show(obj) { obj.style.display = "block"; }

function _COM_Hidden(obj) { obj.style.display = "none"; }

function _COM_ShowVideo(src, width, height) {
    var strTemp = "";
    strTemp = "<object ";
    if (!_COM_IsNull(width)) { strTemp = strTemp + " width=\"" + width + "\" "; }
    if (!_COM_IsNull(height)) { strTemp = strTemp + " height=\"" + height + "\" "; }
    strTemp = strTemp + ">"

    strTemp = strTemp + "<param name=\"movie\" value=\"" + src + "\" ></param>";
    strTemp = strTemp + "<param name=\"allowFullScreen\" value=\"true\" ></param>";
    strTemp = strTemp + "<param name=\"allowscriptaccess\" value=\"always\" ></param>";
    strTemp = strTemp + "<param name=\"wmode\" value=\"opaque\" ></param>";
    strTemp = strTemp + "<embed  src=\"" + src + "\" type=\"application/x-shockwave-flash\" ";
    strTemp = strTemp + " allowscriptaccess=\"always\" allowfullscreen=\"true\" wmode=\"opaque\" "
    if (!_COM_IsNull(width)) { strTemp = strTemp + " width=\"" + width + "\" "; }
    if (!_COM_IsNull(height)) { strTemp = strTemp + " height=\"" + height + "\" "; }
    strTemp = strTemp + "></embed></object>";
    return strTemp;
}

///     备注:格式化表格，合并相同列
function TableFormat_MyStep() {
    var tbl = _COM_I("mytable");
    var cellIndex = 0;
    if (tbl.rows.length < 2) return;
    var i, j;
    var last = tbl.rows(0).cells(cellIndex).innerHTML;
    var lastIndex = 0;
    for (i = 1; i < tbl.rows.length; i++) {
        if (tbl.rows(i).cells(cellIndex).innerHTML != last)   //   发现新的值
        {
            if (i > lastIndex + 1) {
                for (j = lastIndex + 1; j < i; j++) {
                    tbl.rows(j).cells(cellIndex).removeNode();
                }
                tbl.rows(lastIndex).cells(cellIndex).rowSpan = i - lastIndex;
            }
            last = tbl.rows(i).cells(cellIndex).innerHTML;
            lastIndex = i;
        }
    }
    //   最后一行要特别处理   
    if (lastIndex != tbl.rows.length - 1) {
        for (j = lastIndex + 1; j < tbl.rows.length; j++) {
            tbl.rows(j).cells(cellIndex).removeNode();
        }
        tbl.rows(lastIndex).cells(cellIndex).rowSpan = tbl.rows.length - lastIndex + 1;
    }
}

function TableFormat_Account() {
    var tbl = _COM_I("mytable");
    var cellIndex = 0;
    if (tbl.rows.length < 2) return;
    var i, j;
    var last = tbl.rows(0).cells(cellIndex).innerHTML;
    var lastIndex = 0;
    for (i = 1; i < tbl.rows.length; i++) {
        if (tbl.rows(i).cells(cellIndex).innerHTML != last)   //   发现新的值
        {
            if (i > lastIndex + 1) {
                for (j = lastIndex + 1; j < i; j++) {
                    tbl.rows(j).cells(cellIndex).removeNode();
                }
                tbl.rows(lastIndex).cells(cellIndex).rowSpan = i - lastIndex;
            }
            last = tbl.rows(i).cells(cellIndex).innerHTML;
            lastIndex = i;
        }
    }
    //   最后一行要特别处理   
    if (lastIndex != tbl.rows.length - 1) {
        for (j = lastIndex + 1; j < tbl.rows.length; j++) {
            tbl.rows(j).cells(cellIndex).removeNode();
        }
        tbl.rows(lastIndex).cells(cellIndex).rowSpan = tbl.rows.length - lastIndex + 1;
    }
}

/*****String.Format********/
String.format = function() {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

function getWeek() {
    //取当前日期、星期
    today = new Date();
    //建立一个数组，存储星期日到星期六7个中文名称
    var d = new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六"
);
    //格式化输出,注意这里的getFullYear()不能为getYear()，否则在Firefox将显示不太正常
    document.write(
today.getFullYear(), "年", today.getMonth() + 1, "月",
today.getDate(), "日", " ", d[today.getDay() + 1] + ""
);
}

function initArray() {
    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++)
    //依次读取星期日至星期六7个中文名称
        this[i + 1] = initArray.arguments[i];
}


function getCookieVal(a) { var b = document.cookie.indexOf(";", a); if (b == -1) b = document.cookie.length; return unescape(document.cookie.substring(a, b)) }
function getCookie(a) { a = a + "="; for (var b = a.length, d = document.cookie.length, c = 0; c < d; ) { var e = c + b; if (document.cookie.substring(c, e) == a) return getCookieVal(e); c = document.cookie.indexOf(" ", c) + 1; if (c == 0) break } return "" }
function setCookie1(a, b, d, c, e, f) { document.cookie = a + "=" + escape(b) + (d ? "; expires=" + d : "") + (c ? "; path=" + c : "") + (e ? "; domain=" + e : "") + (f ? "; secure" : "") }
function setCookie(name, value) {
    var Days = 3;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);

    setCookie1(name, value, exp.toGMTString(), "/", ".ynpt.cn");
}
function onsubmit(type,INVESTIGATIONCD) {
    var exp = new Date();
    var tosub1 = getCookie("kx");
    var tosub2 = getCookie("qt");
    if (type == '1') {
        var kexue = "";
        for (var i = 0; i < document.all["kexue"].length; i++) {
            if (document.all["kexue"][i].checked == true) {
                kexue = i + 1;
                break;
            }
        }

        if (tosub1 != INVESTIGATIONCD) {
            setCookie("kx", INVESTIGATIONCD, exp.toGMTString(), "/", ".ynpt.cn");
            $.ajax({
                url: "/Home/Diaocha/?question=" + kexue + "&INVESTIGATIONCD=" + INVESTIGATIONCD,
                type: "POST",
                dataType: "json",
                timeout: 60000,
                success: function(result) {
                    if (result != null) {
                        alert(result);
                    } else {
                        alert("调查已提交！");
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        } else {
            alert("请不要重复提交！");
        }
    } else if (type == '2') {
        //if (tosub2 == "") {
            //setCookie("qt", "2", exp.toGMTString(), "/", ".ynpt.cn");
            $.ajax({
                url: "/Home/Answer/?message=" + escape(document.all["message"].value),
                type: "POST",
                dataType: "json",
                timeout: 60000,
                success: function(result) {
                    if (result != null) {
                        alert(result);
                    } else {
                        alert("问题已提交！");
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) { }
            });
//        } else {
//            alert("请不要重复提交！");
//        }
    }
}
