﻿//公用函数
function parseDate(str) {
    if (typeof str == 'string') {
        var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);
        if (results && results.length > 3)
            return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]));
        results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);
        if (results && results.length > 6)
            return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]), parseInt(results[4]), parseInt(results[5]), parseInt(results[6]));
        results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);
        if (results && results.length > 7)
            return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]), parseInt(results[4]), parseInt(results[5]), parseInt(results[6]), parseInt(results[7]));
    }
    return null;
}

//审批处理页面：ApplyInfoApprove.aspx
$(function () {
    $("#ApplyInfoApprove_aspx,#ReportInfoActionEdit_aspx,#RecordInfoActionEdit_aspx,#RecordPlanInfoActionEdit_aspx,#RecordFormulateInfoActionEdit_aspx,#DepRecordFormulateInfoActionEdit_aspx").each(function () {
        var auditCommentListBox = $(".auditCommentListBox");
        auditCommentListBox.attr("show", "0");
        auditCommentListBox.hide();
        var auditCommentList = $(".auditCommentList");
        var auditCommentTextBox = $(".auditCommentTextBox");
        var hidAuditId = $(".hidAuditCommentTextBox");
        var myLi = "";
        auditCommentList.find("option").each(function (i) {
            var myText = $(this).text();
            var myValue = $(this).val();
            myLi = myLi + '<li><a href="#">' + myText + "</a></li>";
        });

        auditCommentListBox.find("ul").html(myLi);

        $(".auditCommentBoxLink").click(
		function () {
		    if (auditCommentListBox.attr("show") == "0") {
		        auditCommentListBox.show();
		        auditCommentListBox.attr("show", "1");
		    }
		    else {
		        auditCommentListBox.hide();
		        auditCommentListBox.attr("show", "0");
		    }
		    return false;
		}).blur(function () {
		    setTimeout(function () {
		        auditCommentListBox.hide();
		        auditCommentListBox.attr("show", "0");
		    }
				, 200);
		});
        var txt = "";
        auditCommentListBox.find("a").click(function () {
            auditCommentTextBox.val($(this).text());
            txt = $(this).text();
            SetValue();
            auditCommentListBox.hide();
            auditCommentListBox.attr("show", "0");
            return false;
        });

        function SetValue() {
            auditCommentList.find("option").each(function (i) {
                var myText = $(this).text();
                var myValue = $(this).val();
                if (myText.valueOf() == txt && hidAuditId != null) {
                    hidAuditId.val(myValue);
                }
            });
        }

        //下一环节选择事件处理
        var selectPrivilegeDepartmentsBox = $(".selectPrivilegeDepartmentsBox");
        var selectPrivilegeDepartmentsBt = $(".selectPrivilegeDepartmentsBt");
        var privilegeDepartmentList = $(".privilegeDepartmentList");
        var selectPrivilegeDepartmentsBoxHide = $(".selectPrivilegeDepartmentsBoxHide");

        $(".btnApprove").each(function () {
            var btnApprove = $(this);
            if (btnApprove.attr("SelectPrivilegeDepartments") == "true") {
                var newBt = btnApprove.clone();
                btnApprove.unbind("click").click(function () {
                    newBt.val("提交");
                    //加入确定按钮对输入数据验证
                    newBt.click(function () {
                        if (privilegeDepartmentList.find("input:checked").size() < 1) {
                            alert("请选择下一环节处理人");
                            return false;
                        }
                    });

                    selectPrivilegeDepartmentsBoxHide.before(newBt);

                    selectPrivilegeDepartmentsBox.show();
                    return false;
                });

            }

        });

        selectPrivilegeDepartmentsBoxHide.click(function () {
            selectPrivilegeDepartmentsBox.hide();
        });

    });

});

function ajaxPageLoad() {
    var toolListBox = $(".toolListBox");
    toolListBox.attr("show", "0");
    $(".toolLink").click(function () {
        if (toolListBox.attr("show") == "0") {
            toolListBox.show();
            toolListBox.attr("show", "1");
        }
        else {
            toolListBox.hide();
            toolListBox.attr("show", "0");
        }
    })
}
$(function () {
    if (typeof (Sys) != 'undefined') {
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(ajaxPageLoad);
    }
});

//标题样式
$(function () {
    $("#InformationEditTable,#BulletinEditTable").each(function () {
        //颜色选择
        $(".colorPicker").each(function () {
            //读取初始值
            var myColorGif = $(this);
            var mySetColor = myColorGif.prevAll('.fcTitle');
            var myHiddenValue = myColorGif.prev(':hidden');
            var myColor = myColorGif.prevAll(':hidden').val();
            if (myColor != "" && myColor != null) {
                mySetColor.css("color", myColor);
                myColorGif.css("background-color", myColor);
            }
            myColorGif.unbind("click").click(function () {
                myColorGif.colorPicker({
                    setColor: mySetColor,
                    align: "left",
                    fn: function (c) {
                        if (c != "transparent") {
                            myHiddenValue.val(c);
                        }
                        else {
                            myHiddenValue.val("");

                        }
                    }
                });
            });
        })

        //加粗
        $(".bold").each(function () {
            var myBold = $(this);
            var myTitleTextBox = myBold.prevAll('.fcTitle');
            var boldHidden = myBold.prev(':hidden');

            function showBold() {
                boldValue = boldHidden.val();
                if (boldValue == "True") {
                    myTitleTextBox.css("font-weight", "bolder");
                    myBold.css("background-color", "#CCC");
                }
                else {
                    myTitleTextBox.css("font-weight", "normal");
                    myBold.css("background-color", "#fff");
                }
            }
            myBold.unbind("click").click(function () {
                boldValue = boldHidden.val();
                if (boldValue == "True") {
                    boldHidden.val("False");
                }
                else {
                    boldHidden.val("True");
                }
                showBold();
            });
            showBold();
        });

        //斜体
        $(".italic").each(function () {
            var myItalic = $(this);
            var myTitleTextBox = myItalic.prevAll('.fcTitle');
            var italicHidden = myItalic.prev(':hidden');

            function showItalic() {
                italicValue = italicHidden.val();
                if (italicValue == "True") {
                    myTitleTextBox.css('font-style', 'italic');
                    myItalic.css("background-color", "#CCC");
                }
                else {
                    myTitleTextBox.css("font-style", "normal");
                    myItalic.css("background-color", "#fff");
                }
            }

            myItalic.unbind("click").click(function () {
                italicValue = italicHidden.val();
                if (italicValue == "True") {
                    italicHidden.val("False");
                }
                else {
                    italicHidden.val("True");
                }
                showItalic();
            });
            showItalic();
        });

        //显示函数，传递当前选中的值
        function showType(typeVal) {
            var infoType0 = $(".infoType0").hide();
            var infoType1 = $(".infoType1").hide();
            var infoType2 = $(".infoType2").hide();
            if (typeVal == 0) {
                infoType0.show();
            }
            else if (typeVal == 1) {
                infoType1.show();
            }
            else if (typeVal == 2) {
                infoType2.show();
            }
        }
    });

});

