/*-------------------------------------------------
版权所有，南京二进制软件有限公司。保留所有权利。
-------------------------------------------------*/

var _nContextId = 0;
var _vActiveObject = null;

function ajax(url) {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("your browser does not support ajax");
                return false;
            }
        }
    }
    if (xmlHttp) {
        xmlHttp.open("GET", url + "&" + Math.random(), false);
        xmlHttp.send(null);
        return xmlHttp.responseText;
    }
}
function ajaxForm(url, objForm) {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("your browser does not support ajax");
                return false;
            }
        }
    }
    if (xmlHttp) {
        var sForm = "_ajaxForm=1";
        var e;
        var sValue = "";
        for (var i = 0; i < objForm.length; i++) {
            e = objForm[i];
            if (e.name != "") {
                if (e.type == "select-one") { sValue = e.options[e.selectedIndex].value; }
                else if (e.type == "radio") { if (e.checked) sValue = e.value; else continue; }
                else if (e.type == "button" || e.type == "submit" || e.type == "reset" || e.type == "image") { continue; }
                else { sValue = e.value; }
                sForm += "&" + e.name + "=" + encodeURIComponent(sValue);
            }
        }
        xmlHttp.open("POST", url + "&" + Math.random(), false);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.send(sForm);
        return xmlHttp.responseText;
    }
}
function htmlEncode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/ /g, "&nbsp;");
    s = s.replace(/&/g, "&amp;");
    s = s.replace(/</g, "&lt;");
    s = s.replace(/>/g, "&gt;");
    s = s.replace(/\"/g, "&quot;");
    return s;
}
function htmlDecode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&nbsp;/g, " ");
    s = s.replace(/&amp;/g, "&");
    s = s.replace(/&lt;/g, "<");
    s = s.replace(/&gt;/g, ">");
    s = s.replace(/&quot;/g, "\"");
    return s;
}

function treeBuild(sContainer, sActiveSid, bFlag) {
    var sPsidOpened = ",0,";
    var aTree = document.getElementById(sContainer).childNodes;
    if (sActiveSid != null) {
        var bActiveFirst = false;
        for (var i = aTree.length - 1; i >= 0; i--) {
            if (aTree[i].getAttribute("sid") == sActiveSid) {
                if (!bActiveFirst) {
                    bActiveFirst = true;
                    aTree[i].className += " textHighlight";
                }
                sPsidOpened += sActiveSid + ",";
                sActiveSid = aTree[i].getAttribute("psid");
                if (sActiveSid == "0") break;
            }
        }
    }

    var nIndentLast = 0;
    var bHasChild = false;
    var bHasHref = false;
    for (var i = aTree.length - 1; i >= 0; i--) {
        if (aTree[i].getAttribute("indent") >= nIndentLast) {
            bHasChild = false;
        }
        else {
            bHasChild = true;
        }
        bHasHref = (aTree[i].getAttribute("href") && aTree[i].getAttribute("href").length > 0);
        nIndentLast = aTree[i].getAttribute("indent");
        if (sPsidOpened.indexOf("," + aTree[i].getAttribute("sid") + ",") >= 0) {
            aTree[i].innerHTML = (bHasChild ? "<img src='../images/minus" + (bFlag ? "Flag" : "") + ".gif' border=0" + (bHasHref ? " onclick=\"javascript:return treeDisplay0('" + sContainer + "'," + i + (bFlag ? ",true" : "") + ");\"" : "") + ">" : "<img src='../images/blank16.gif' border=0>") + aTree[i].innerHTML;
        }
        else {
            if (nIndentLast > 0 && sPsidOpened.indexOf("," + aTree[i].getAttribute("psid") + ",") < 0) {
                aTree[i].style.display = "none";
            }
            aTree[i].innerHTML = (bHasChild ? "<img src='../images/plus" + (bFlag ? "Flag" : "") + ".gif' border=0" + (bHasHref ? " onclick=\"javascript:return treeDisplay0('" + sContainer + "'," + i + (bFlag ? ",true" : "") + ");\"" : "") + ">" : "<img src='../images/blank16.gif' border=0>") + aTree[i].innerHTML;
        }
        if (bHasChild && !bHasHref) {
            aTree[i].setAttribute("href", "javascript:treeDisplay0('" + sContainer + "'," + i + (bFlag ? ",true" : "") + ");void(0);");
        }
    }
}
function treeDisplay0(sContainer, iParent, bFlag) {
    var aTree = document.getElementById(sContainer).childNodes;
    var bDisplay = aTree[iParent].childNodes[0].src.indexOf("plus") > 0 ? true : false;
    if (bDisplay && bFlag) {
        var nPsid = aTree[iParent].getAttribute("psid");
        var nIndent = aTree[iParent].getAttribute("indent");
        for (var i = aTree.length - 1; i >= 0; i--) {
            if (i != iParent && aTree[i].getAttribute("psid") == nPsid && aTree[i].getAttribute("indent") == nIndent && aTree[i].childNodes[0].src.indexOf("minus") > 0) {
                aTree[i].childNodes[0].src = "../images/plusFlag.gif";
                treeDisplay(aTree, i, false);
                break;
            }
        }
    }
    aTree[iParent].childNodes[0].src = (bDisplay ? "../images/minus" : "../images/plus") + (bFlag ? "Flag" : "") + ".gif";
    treeDisplay(aTree, iParent, bDisplay);
    if (window.event) {
        event.cancelBubble = true;
    }
    return false;
}
function treeDisplay(aTree, iParent, bDisplay) {
    var nIndentParent = Number(aTree[iParent].getAttribute("indent"));
    var nIndent;
    var i = iParent + 1;
    if (bDisplay) {
        for (; i < aTree.length; i++) {
            nIndent = Number(aTree[i].getAttribute("indent"));
            if (nIndent == nIndentParent + 1) {
                aTree[i].style.display = "block";
                if (aTree[i].childNodes[0].src.indexOf("minus") > 0) {
                    i = treeDisplay(aTree, i, bDisplay);
                }
            }
            else if (nIndent <= nIndentParent) {
                break;
            }
        }
    }
    else {
        for (; i < aTree.length; i++) {
            nIndent = Number(aTree[i].getAttribute("indent"));
            if (nIndent == nIndentParent + 1) {
                aTree[i].style.display = "none";
                if (aTree[i].childNodes[0].src.indexOf("blank") < 0) {
                    i = treeDisplay(aTree, i, bDisplay);
                }
            }
            else if (nIndent <= nIndentParent) {
                break;
            }
        }
    }
    return i - 1;
}

function treeBuildByTable(sContainer) {
    if (navigator.userAgent.indexOf("MSIE") >= 0) { //ie only
        var sPsidOpened = ",0,";
        var aTree = document.getElementById(sContainer).childNodes;
        var nIndentLast = 0;
        var bHasChild = false;
        for (var i = aTree.length - 1; i >= 0; i--) {
            if (aTree[i].getAttribute("indent") >= nIndentLast) {
                bHasChild = false;
            }
            else {
                bHasChild = true;
            }
            nIndentLast = aTree[i].getAttribute("indent");
            if (sPsidOpened.indexOf("," + aTree[i].getAttribute("sid") + ",") >= 0) {
                aTree[i].childNodes[0].innerHTML = (bHasChild ? "<a href=\"javascript:treeDisplay0ByTable('" + sContainer + "'," + i + ");void(0);\"><img src='../images/minus.gif' border=0>" : "<span><img src='../images/blank16.gif' border=0></span>") + aTree[i].childNodes[0].innerHTML + (bHasChild ? "</a>" : "");
            }
            else {
                if (nIndentLast > 0 && sPsidOpened.indexOf("," + aTree[i].getAttribute("psid") + ",") < 0) {
                    aTree[i].style.display = "none";
                }
                aTree[i].childNodes[0].innerHTML = (bHasChild ? "<a href=\"javascript:treeDisplay0ByTable('" + sContainer + "'," + i + ");void(0);\"><img src='../images/plus.gif' border=0>" : "<span><img src='../images/blank16.gif' border=0></span>") + aTree[i].childNodes[0].innerHTML + (bHasChild ? "</a>" : "");
            }
        }
    }
}
function treeDisplay0ByTable(sContainer, iParent) {
    var aTree = document.getElementById(sContainer).childNodes;
    var bDisplay = aTree[iParent].childNodes[0].childNodes[0].childNodes[0].src.indexOf("plus") > 0 ? true : false;
    aTree[iParent].childNodes[0].childNodes[0].childNodes[0].src = bDisplay ? "../images/minus.gif" : "../images/plus.gif";
    treeDisplayByTable(aTree, iParent, bDisplay);
    if (window.event) {
        event.cancelBubble = true;
    }
    return false;
}
function treeDisplayByTable(aTree, iParent, bDisplay) {
    var nIndentParent = Number(aTree[iParent].getAttribute("indent"));
    var nIndent;
    var i = iParent + 1;
    if (bDisplay) {
        for (; i < aTree.length; i++) {
            nIndent = Number(aTree[i].getAttribute("indent"));
            if (nIndent == nIndentParent + 1) {
                aTree[i].style.display = "block";
                if (aTree[i].childNodes[0].childNodes[0].childNodes[0].src.indexOf("minus") > 0) {
                    i = treeDisplayByTable(aTree, i, bDisplay);
                }
            }
            else if (nIndent <= nIndentParent) {
                break;
            }
        }
    }
    else {
        for (; i < aTree.length; i++) {
            nIndent = Number(aTree[i].getAttribute("indent"));
            if (nIndent == nIndentParent + 1) {
                aTree[i].style.display = "none";
                if (aTree[i].childNodes[0].childNodes[0].childNodes[0].src.indexOf("blank") < 0) {
                    i = treeDisplayByTable(aTree, i, bDisplay);
                }
            }
            else if (nIndent <= nIndentParent) {
                break;
            }
        }
    }
    return i - 1;
}

function catalogue(nStype, nSid, sName) {
    var s = location.href;
    var n = s.indexOf("&ex.stype");
    if (n > 0) s = s.substr(0, n);
    else { n = s.indexOf("&page"); if (n > 0) s = s.substr(0, n); }
    location.href = s + (nStype != null ? "&ex.stype=" + nStype + "&ex.sid=" + nSid + "&ex.name=" + escape(sName) : "");
}

function cataloguePages(nTotal, nPageRows) {
    var nPages = Math.ceil(nTotal / nPageRows);
    if (nPages == 0) nPages = 1;
    var nCurrentPage = 1;
    var s = location.href;
    var n = s.indexOf("&page=");
    if (n > 0) { nCurrentPage = parseInt(s.substr(n + 6)); s = s.substr(0, n); }
    if (nCurrentPage < 1) nCurrentPage = 1;
    else if (nCurrentPage > nPages) nCurrentPage = nPages;
    document.write("<div style='padding:10 5;'><a href='" + s + "&page=" + (nCurrentPage > 1 ? nCurrentPage - 1 : nCurrentPage) + "'>&laquo;上页</a> &nbsp;&nbsp; 共有" + nTotal + "条记录，第" + nCurrentPage + "/" + nPages + "页 &nbsp;&nbsp; <a href='" + s + "&page=" + (nCurrentPage < nPages ? nCurrentPage + 1 : nCurrentPage) + "'>&raquo;下页</a></div>");
}
function cataloguePages2(nTotal, nPageRows) {
    var nPages = Math.ceil(nTotal / nPageRows);
    if (nPages == 0) nPages = 1;
    var nCurrentPage = 1;
    var s = location.href;
    var n = s.indexOf("&page=");
    if (n > 0) { nCurrentPage = parseInt(s.substr(n + 6)); s = s.substr(0, n); }
    if (nCurrentPage < 1) nCurrentPage = 1;
    else if (nCurrentPage > nPages) nCurrentPage = nPages;

    document.write("<div class=pageNumber><a href='" + s + "&page=1' title='首页'>&laquo;</a> ");
    if (nPages > 9) {
        if (nCurrentPage <= 5) {
            for (var i = 1; i <= 9; i++)
                if (nCurrentPage == i) { document.write("<a class=textHighlight href='" + s + "&page=" + i + "'>" + i + "</a> "); }
                else { document.write("<a href='" + s + "&page=" + i + "'>" + i + "</a> "); }
            document.write("... ");
        }
        else if (nPages - nCurrentPage < 5) {
            document.write("... ");
            for (var i = nPages - 8; i <= nPages; i++)
                if (nCurrentPage == i) { document.write("<a class=textHighlight href='" + s + "&page=" + i + "'>" + i + "</a> "); }
                else { document.write("<a href='" + s + "&page=" + i + "'>" + i + "</a> "); }
        }
        else {
            document.write("... ");
            for (var i = nCurrentPage - 4; i <= nCurrentPage + 4; i++)
                if (nCurrentPage == i) { document.write("<a class=textHighlight href='" + s + "&page=" + i + "'>" + i + "</a> "); }
                else { document.write("<a href='" + s + "&page=" + i + "'>" + i + "</a> "); }
            document.write("... ");
        }
    }
    else {
        for (var i = 1; i <= nPages; i++)
            if (nCurrentPage == i) { document.write("<a class=textHighlight href='" + s + "&page=" + i + "'>" + i + "</a> "); }
            else { document.write("<a href='" + s + "&page=" + i + "'>" + i + "</a> "); }
    }
    document.write("<a href='" + s + "&page=" + nPages + "' title='尾页'>&raquo;</a></div>");
}

function catalogueSelectAll(bChecked, sObjectName) {
    var o;
    if (sObjectName) o = document.getElementById(sObjectName);
    if (o == null) o = document.body;
    var ec = o.getElementsByTagName("INPUT");
    for (var i = 0; i < ec.length; i++) {
        var e = ec[i];
        if (e.type == "checkbox" && e.id) {
            if (bChecked) e.checked = true;
            else e.checked = false;
        }
    }
}
function catalogueSelection(sObjectName) {
    var o;
    if (sObjectName) o = document.getElementById(sObjectName);
    if (o == null) o = document.body;
    var ec = o.getElementsByTagName("INPUT");
    var s = "";
    for (var i = 0; i < ec.length; i++) {
        var e = ec[i];
        if (e.type == "checkbox" && e.id) {
            if (e.checked) s += e.id + ",";
        }
    }
    if (s == "") {
        alert("没有选择任何记录。请首先选择记录");
        return null;
    }
    else {
        return s;
    }
}

function workflowListOne(sUrlX, sName, nWorkflowId, sPicture, nCatalogue, sObjects, bPortal, bSelf) {
    var oHome = document.getElementById("oWorkflowList");
    var sUrl = sUrlX + "?sid=" + nWorkflowId + "&name=" + escape(sName) + "&catalogue=" + nCatalogue;
    var sDynObjects;
    if (sObjects) {
        if (sObjects.indexOf("catalogueSelection") == 0) {
            sDynObjects = sObjects;
        }
        else {
            sUrl += "&objects=" + sObjects;
        }
    }
    if(bSelf) {
        if (bPortal) {
            if (sDynObjects)
                document.write("<img style='cursor:pointer;' onclick=\"var v=" + sDynObjects + ";if(v) location.href='" + sUrl + "&objects='+v;\" title='" + sName + "' src='" + sPicture + "'>");
            else
                document.write("<img style='cursor:pointer;' onclick=\"location.href='" + sUrl + "';\" title='" + sName + "' src='" + sPicture + "'>");
        }
        else if(oHome) {
            if (sDynObjects)
                oHome.innerHTML += "<input type='button' onclick=\"javascript:var v=" + sDynObjects + ";if(v) location.href='" + sUrl + "&objects='+v;\" value=" + sName + ">";
            else
                oHome.innerHTML += "<input type='button' onclick=\"javascript:location.href='" + sUrl + "';\" value=" + sName + ">";
        }
        else {
            if (sDynObjects)
                document.write("<input type='button' onclick=\"javascript:var v=" + sDynObjects + ";if(v) location.href='" + sUrl + "&objects='+v;\" value=" + sName + ">");
            else
                document.write("<input type='button' onclick=\"javascript:location.href='" + sUrl + "';\" value=" + sName + ">");
        }
    }
    else {
        if (bPortal) {
            if (sDynObjects)
                document.write("<img style='cursor:pointer;' onclick=\"var v=" + sDynObjects + ";if(v) window.open('" + sUrl + "&objects='+v);\" title='" + sName + "' src='" + sPicture + "'>");
            else
                document.write("<img style='cursor:pointer;' onclick=\"window.open('" + sUrl + "');\" title='" + sName + "' src='" + sPicture + "'>");
        }
        else if (oHome) {
            if (sDynObjects)
                oHome.inneHTML += "<input type='button' onclick=\"javascript:var v=" + sDynObjects + ";if(v) window.open('" + sUrl + "&objects='+v).focus();\" value=" + sName + ">";
            else
                oHome.innerHTML += "<input type='button' onclick=\"javascript:window.open('" + sUrl + "').focus();\" value=" + sName + ">";
        }
        else {
            if (sDynObjects)
                document.write("<input type='button' onclick=\"javascript:var v=" + sDynObjects + ";if(v) window.open('" + sUrl + "&objects='+v).focus();\" value=" + sName + ">");
            else
                document.write("<input type='button' onclick=\"javascript:window.open('" + sUrl + "').focus();\" value=" + sName + ">");
        }
    }
}

function workflow(sName, nWorkflowId, sRequest, bSelf) {
    if (bSelf) location.href="workflow.aspx?sid=" + nWorkflowId + "&name=" + escape(sName) + "&" + sRequest;
    else window.open("workflow.aspx?sid=" + nWorkflowId + "&name=" + escape(sName) + "&" + sRequest);
}
function workflowTask(sName, nTaskId) {
    window.open("workflowTask.aspx?taskSid=" + nTaskId + "&name=" + escape(sName));
}

function workflowActionShow(sName, nActionId, bPostForm, bInsertBefore, sPicture) {
    var s = "<input type='button' onclick=\"javaScript:workflowAction('" + sName + "'," + nActionId + "," + bPostForm + ");return false;\" value="
    s += sName + ">"
    if(bInsertBefore)
        document.getElementById("_vWorkflowActionsShow").innerHTML = s + document.getElementById("_vWorkflowActionsShow").innerHTML;
    else
        document.write(s);
}
function workflowActionsShow(sName, sStatus) {
    document.write("<div id=_vWorkflowActionsStatus style='float:left'>");
    if (sStatus)
        document.write(sStatus);
    else
        document.write("&nbsp;");
    document.write("</div><div id=_vWorkflowActionsShow style='float:right'>");
    if (sName) {
        if (sName == "okAllCancel") {
            workflowActionShow("全部确定", 2, 0);
            workflowActionShow("确定", 1, 0);
            workflowActionShow("取消", 0, 0);
        }
        else if (sName == "okCancel") {
            workflowActionShow("确定", 1, 0);
            workflowActionShow("取消", 0, 0);
        }
        else if (sName == "okCancelWithForm") {
            workflowActionShow("确定", 1, 1);
            workflowActionShow("取消", 0, 0);
        }
        else if (sName == "saveOKCancelWithForm") {
            workflowActionShow("保存", 10, 1);
            workflowActionShow("保存并退出", 1, 1);
            workflowActionShow("取消", 0, 0);
        }
        else if (sName == "ok") {
            workflowActionShow("确定", 1, 0);
        }
        else if (sName == "cancel") {
            workflowActionShow("取消", 0, 0);
        }
        else if (sName == "cancelByOK") {
            workflowActionShow("确定", 0, 0);
        }
        else if (sName == "quit") {
            workflowActionShow("退出", 0, 0);
        }
        else {
            var aName = sName.split(",");
            for (var i = 0; i < aName.length - 1; i++) {
                workflowActionShow(aName[i], 1, 1);
            }
            workflowActionShow("取消", 0, 0);
        }
    }
    document.write("</div>");
}
function removeUrlAbsolute(sValue) {
    if(!sValue || sValue.length==0)
        return "";
    var sPrefix; //to replace absolute url with relative one
    var sUrl = location.href;
    var nHost = sUrl.indexOf("http://");
    if (nHost >= 0) {
        var n1 = sUrl.indexOf("/", nHost + 7);
        if (n1 > 0) {
            var n2 = sUrl.indexOf("/", n1 + 1);
            if (n2 > 0) {
                if(sUrl.indexOf("/", n2 + 1) > 0 )
                    sPrefix = sUrl.substring(nHost, n2);
                else
                    sPrefix = sUrl.substring(nHost, n1);
            }
        }
    }
    return sPrefix ? sValue.replace(new RegExp(sPrefix, "g"), "..") : sValue;
}
function workflowAction(sName, nActionId, bPostForm) {
    if (_vActiveObject) {
        _vActiveObject.style.display = "none";
        _vActiveObject = null;
    }
    if (formOnAction(nActionId, bPostForm) > 0) {
        if (bPostForm) {
            var ec = document.forms[0].getElementsByTagName("DIV");
            for (var i = 0; i < ec.length; i++) {
                var e = ec[i];
                if (e.id.indexOf("fieldGetValueBySource.") > -1) {
                    var pe = e.parentNode;
                    if (pe) pe.removeChild(e);
                }
            }
            ec = document.forms[0].getElementsByTagName("TEXTAREA");
            if (navigator.userAgent.indexOf("MSIE") < 0) { //for firefox
                ec = document.forms[0].elements;
                for (var i = 0; i < ec.length; i++) {
                    var e = ec[i];
                    if (e.tagName == "INPUT") {
                        if (e.type == "text") {
                            e.setAttribute("value", e.value);
                        }
                        else if (e.type == "checkbox") {
                            if (e.checked) e.setAttribute("checked", true);
                            else e.removeAttribute("checked");
                        }
                        else if (e.type == "radio") {
                            if (e.checked) e.setAttribute("checked", true);
                            else e.removeAttribute("checked");
                        }
                    }
                    else if (e.tagName == "TEXTAREA") {
                        e.innerHTML = e.value;
                    }
                }
            }
            var sPrefix; //to replace absolute url with relative one
            var sUrl = location.href;
            var nHost = sUrl.indexOf("http://");
            if (nHost >= 0) {
                var n1 = sUrl.indexOf("/", nHost + 7);
                if (n1 > 0) {
                    var n2 = sUrl.indexOf("/", n1 + 1);
                    if (n2 > 0) {
                        if(sUrl.indexOf("/", n2 + 1) > 0 )
                            sPrefix = sUrl.substring(nHost, n2);
                        else
                            sPrefix = sUrl.substring(nHost, n1);
                    }
                }
            }
            document.forms[1].viewState.value = sPrefix ? document.forms[0].innerHTML.replace(new RegExp(sPrefix, "g"), "..") : document.forms[0].innerHTML;
            document.forms[1].action = (document.forms[1].action ? document.forms[1].action : location.href) + '&action=' + nActionId + "&actionName=" + escape(sName);
            _nContextId = 0;
            document.forms[1].submit();
        }
        else if (nActionId > 0 && document.forms.length > 1) {
            _nContextId = 0;
            location.href = (document.forms[1].action ? document.forms[1].action : location.href) + '&action=' + nActionId + "&actionName=" + escape(sName) + "&viewState=" + document.forms[1].viewState.value;
        }
        else {
            _nContextId = 0;
            location.href = location.href + '&action=' + nActionId + "&actionName=" + escape(sName);
        }
    }
}

function formOnLoad() {
    var sSearch = location.search;
    var nPos = sSearch.indexOf("context=");
    if (nPos <= 0)
        return;

    sSearch = sSearch.substr(nPos + 8);
    nPos = sSearch.indexOf("&");
    if (nPos > 0)
        _nContextId = parseInt(sSearch.substr(0, nPos));
    else
        _nContextId = parseInt(sSearch);
    nPos = sSearch.indexOf("name=");
    if (nPos > 0) {
        sSearch = sSearch.substr(nPos + 5);
        nPos = sSearch.indexOf("&");
        if(nPos > 0){
            document.title = document.title.replace("colloa", decodeURI(sSearch.substr(0, nPos)));
            if(document.getElementById("tagCaptionTitle")){
            		document.getElementById("tagCaptionTitle").innerHTML = decodeURI(sSearch.substr(0, nPos));
            } 
        }
        else {
            document.title = document.title.replace("colloa", decodeURI(sSearch));
            if(document.getElementById("tagCaptionTitle")){
            		document.getElementById("tagCaptionTitle").innerHTML = decodeURI(decodeURI(sSearch));
            }
        }
    }
    window.onbeforeunload = function () {
        if (_nContextId > 0) return ("页面上的数据可能没有被保存。");
    }
    window.onunload = function () {
        if (_nContextId > 0) {
            ajax('../view/workflowStop.aspx?context=' + _nContextId + "&flag=1");
        }
    }
/********************
   document.body.onclick = function (evt) {
        if (_vActiveObject) {
            var e;
            if (evt) e = evt.target; else e = event.srcElement;
            if (e.className != "fieldGetValueBySource") {
                var x = 0; var y = 0;
                if (window.event) { x = event.clientX; y = event.clientY; }
                else { x = evt.clientX; y = evt.clientY; }
                if (x < _vActiveObject.offsetLeft || y < _vActiveObject.offsetTop || x > (_vActiveObject.offsetLeft + _vActiveObject.offsetWidth) || y > (_vActiveObject.offsetTop + _vActiveObject.offsetHeight)) {
                    _vActiveObject.style.display = "none"; _vActiveObject = null;
                }
            }
        }
    }
********************/
    if (typeof (window.onLoad) == "function")
        onLoad();
}

function formRefreshOpener(flag) {
    try { if (top.opener && top.opener._nContextId<=0) top.opener.location.reload(true); }
    catch (e) { }
}

function onFieldFileUploaded(sFieldName, sContentType, sName, sExtension, sFile, nSize) {
    if (_vActiveObject) {
        _vActiveObject.style.display = "none";
        _vActiveObject = null;
    }
    if (typeof (window.onFileUploaded) == "function") {
        onFileUploaded(sFieldName, sContentType, sName, sExtension, sFile, nSize);
    }
    else {
        if (sExtension == "") sExtension = "dat";
        if (document.getElementById(sFieldName).getAttribute("dbf.source") == "files")
            document.getElementById("e." + sFieldName).innerHTML += "<a href=\"../view/file.aspx?attachment=1&name=" + escape(sName) + "&contentType=" + escape(sContentType) + "&file=" + escape(sFile) + "\" target=_blank><img src='../images/fileExt/" + sExtension + ".gif' border=0> " + sName + "</a> (" + (parseInt(nSize / 1024) + 1) + "k) ";
        else
            document.getElementById("e." + sFieldName).innerHTML = "<a href=\"../view/file.aspx?attachment=1&name=" + escape(sName) + "&contentType=" + escape(sContentType) + "&file=" + escape(sFile) + "\" target=_blank><img src='../images/fileExt/" + sExtension + ".gif' border=0> " + sName + "</a> (" + (parseInt(nSize / 1024) + 1) + "k) ";
        if (typeof (window.onFileUploadedAfter) == "function") {
            onFileUploadedAfter(sFieldName, sContentType, sName, sExtension, sFile, nSize);
        }
    }
}

function quickFilter(oList,sValue,iStart) {
	if(sValue.length>0) {
		for(var i=iStart;i<oList.length;i++) {if(oList[i].childNodes[0].tagName=="INPUT"&&oList[i].childNodes[0].name.indexOf(sValue)>=0) oList[i].style.display="block";else oList[i].style.display="none";}
	}
	else{
		for(var i=iStart;i<oList.length;i++) {oList[i].style.display="block";}
	}
}
function fieldGetValueBySource(sFieldName) {
    var sFieldGetValueBySource = "fieldGetValueBySource." + sFieldName;
    var eFieldGetValueBySource = document.getElementById(sFieldGetValueBySource);
    if (eFieldGetValueBySource) {
        if (eFieldGetValueBySource.style.display == "none") {
            if (_vActiveObject) _vActiveObject.style.display = "none";
            var vWidth = document.getElementById(sFieldName).clientWidth;
            eFieldGetValueBySource.style.width = vWidth - 40;
            eFieldGetValueBySource.style.display = "inline";
            _vActiveObject = eFieldGetValueBySource;
        }
        else {
            eFieldGetValueBySource.style.display = "none";
            _vActiveObject = null;
        }
    }
    else{
        var eField = document.getElementById(sFieldName);
        var sSource = eField.getAttribute("dbf.source");
        if (sSource) {
            if (_vActiveObject) _vActiveObject.style.display = "none";
            var eNew = document.createElement("DIV");
            eNew.id = sFieldGetValueBySource;
            eNew.style.position = "absolute";
            eNew.style.zIndex = "10";
            eNew.style.backgroundColor = "#fff";
            eNew.style.border = "1px solid #ccc";
            eNew.style.cursor = "default";
            eNew.style.width = eField.clientWidth - 40;
            if (sSource.indexOf("files") == 0) {
                eNew.style.height = "220px";
                if (sSource.indexOf("(") > 0 && sSource.indexOf(")") > 0)
                    eNew.innerHTML = "<iframe src='fieldFile.aspx?type=" + sSource.substring(sSource.indexOf("(") + 1, sSource.indexOf(")")) + "&field=" + sFieldName + "&n=5' style='width:100%;height:220px;' frameborder=0></iframe>";
                else
                    eNew.innerHTML = "<iframe src='fieldFile.aspx?field=" + sFieldName + "&n=5' style='width:100%;height:220px;' frameborder=0></iframe>";
            }
            else if (sSource.indexOf("file") == 0) {
                eNew.style.height = "120px";
                if (sSource.indexOf("(") > 0 && sSource.indexOf(")") > 0)
                    eNew.innerHTML = "<iframe src='fieldFile.aspx?type=" + sSource.substring(sSource.indexOf("(") + 1, sSource.indexOf(")")) + "&field=" + sFieldName + "' style='width:100%;height:120px;' frameborder=0></iframe>";
                else
                    eNew.innerHTML = "<iframe src='fieldFile.aspx?field=" + sFieldName + "' style='width:100%;height:120px;' frameborder=0></iframe>";
            }
            else if (sSource.indexOf("datetime") == 0) {
                eNew.style.height = "400px";
                eNew.innerHTML = "<iframe src='../viewPhone/fieldDatetime.htm?" + sSource + "&field=" + encodeURI(sFieldName) + "' style='width:100%;height:400px;' frameborder=0></iframe>";
            }
            else if (sSource.indexOf("date") == 0) {
                eNew.style.height = "220px";
                eNew.innerHTML = "<iframe src='../viewPhone/fieldDate.htm?" + sSource + "&field=" + encodeURI(sFieldName) + "' style='width:100%;height:220px;' frameborder=0></iframe>";
            }
            else if (sSource.indexOf("signature") == 0) {
                eNew.style.height = "220px";
                eNew.style.padding = "5px";
                eNew.style.overflowX = "hidden";
                eNew.style.overflowY = "auto";
                eNew.innerHTML = ajax("fieldSource.aspx?source=form.fieldSource.signature");
                eNew.onclick = function (evt) {
                    var e = window.event ? event.srcElement : evt.target;
										if (e.id && e.id.indexOf("fieldGetValueBySource") < 0) {
												document.getElementById("e." + sFieldName).innerHTML = (e.id == "0") ? "" : e.getAttribute("_pictureX");
                        this.style.display = "none";
                        _vActiveObject = null;
                    }
                }
            }
            else if (sSource.indexOf("list2:") == 0) {
                eNew.style.height = "220px";
                eNew.style.padding = "5px";
                eNew.style.overflowX = "hidden";
                eNew.style.overflowY = "auto";
                var sInnerHTML = "";
                var aValues = sSource.substr(6).split(",");
                for(var i=0; i<aValues.length; i++) {
                    var aValue = aValues[i].split("=");
                    sInnerHTML += "<div onmouseover=\"this.className='fieldEditable';\" onmouseout=\"this.className='';\" id=\"" + aValue[0] + "\" style='height:auto;'>" + aValue[1] + "</div>";
                }
                eNew.innerHTML = sInnerHTML;
                eNew.onclick = function (evt) {
                    var e = window.event ? event.srcElement : evt.target;        
										if (e.id && e.id.indexOf("fieldGetValueBySource") < 0) {
                        document.getElementById("e." + sFieldName).value = e.id;  
                        document.getElementById("e." + sFieldName + "Source").innerHTML = e.innerHTML;
                        this.style.display = "none";
                        _vActiveObject = null;
                    }
                }
            }
            else if (sSource.indexOf("list:") == 0) {
                eNew.style.height = "220px";
                eNew.style.padding = "5px";
                eNew.style.overflowX = "hidden";
                eNew.style.overflowY = "auto";
                var sInnerHTML = "";
                var aValues = sSource.substr(5).split(",");
                for(var i=0; i<aValues.length; i++) {
                    sInnerHTML += "<div onmouseover=\"this.className='fieldEditable';\" onmouseout=\"this.className='';\" id=\""+aValues[i]+"\" style='height:auto;'>" + aValues[i] + "</div>";
                }
                eNew.innerHTML = sInnerHTML;
                eNew.onclick = function (evt) {
                    var e = window.event ? event.srcElement : evt.target;
										if (e.id && e.id.indexOf("fieldGetValueBySource") < 0) {
                        document.getElementById("e." + sFieldName).innerHTML = e.id;
                        this.style.display = "none";
                        _vActiveObject = null;
                    }
                }
            }
            else {
                eNew.style.height = "300px";
                eNew.style.padding = "5px";
                eNew.style.overflowX = "hidden";
                eNew.style.overflowY = "auto";
                eNew.innerHTML = ajax("fieldSource.aspx?source=" + escape(sSource));
                eNew.onclick = function (evt) {
                    var e = window.event ? event.srcElement : evt.target;
                    if (e.tagName == "INPUT" && e.type == "checkbox") {
                        var ec = this.getElementsByTagName("INPUT"); var e; var s = ""; var s2 = "";
                        for (var i = 0; i < ec.length; i++) { e = ec[i]; if (e.type == "checkbox" && e.checked) { s += e.id + ","; s2 += e.name + ","; } }
                        document.getElementById("e." + sFieldName).value = s; document.getElementById("e." + sFieldName + "Source").innerHTML = s2;
                    }
                    else if (e.id && e.id.indexOf("fieldGetValueBySource") < 0) {
                        document.getElementById("e." + sFieldName).value = e.id;
                        document.getElementById("e." + sFieldName + "Source").innerHTML = e.innerHTML;
                        this.style.display = "none";
                        _vActiveObject = null;
                    }
                }
                //initilize
                var s = document.getElementById("e." + sFieldName).value;
                var ec = eNew.getElementsByTagName("INPUT"); var e;
                for (var i = 0; i < ec.length; i++) { e = ec[i]; if (e.type == "checkbox" && s.indexOf(e.id + ",") >= 0) { e.checked = true; } }
            }
            eField.appendChild(eNew);
            _vActiveObject = eNew;
        }
    }
}

function fieldCheckByForm(sType, sValue, e) {
    var sValueTrimmed = sValue.replace(/&nbsp;/g, " ").replace(/(^\s*)|(\s*$)/g, "");
    var nReturn = 1;
    if (sType) {
        if (nReturn > 0 && sType.indexOf("required") >= 0 && sValueTrimmed.length == 0) {
            alert("请输入正确的值"); nReturn = 0;
        }
        if (nReturn > 0 && sType.indexOf("required!0") >= 0 && sValue == "0") {
            alert("请输入正确的值"); nReturn = 0;
        }
        if (nReturn > 0 && sType.indexOf("!quotation") >= 0 && (sValue.indexOf("\"") >= 0 || sValue.indexOf("'") >= 0)) {
            alert("请不要输入单引号或双引号"); nReturn = 0;
        }
        if (nReturn > 0 && sValueTrimmed.length > 0 && sType.indexOf("number") >= 0 && !(/^-?\d+$/.test(sValueTrimmed))) {
            alert("请输入正确的数字值"); nReturn = 0;
        }
        if (nReturn > 0 && sValueTrimmed.length > 0 && sType.indexOf("amount") >= 0 && !(/^-?\d+\.?\d{0,2}$/.test(sValueTrimmed))) {
            alert("请输入正确的金额，小数点后保留两位"); nReturn = 0;
        }
        if (nReturn > 0 && sValueTrimmed.length > 0 && sType.indexOf("date") >= 0) {
            sValueTrimmed = sValueTrimmed.replace("<br>",""); //for div in firefox
            var reg = /^(\d+)\/(\d{1,2})\/(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
            var r = sValueTrimmed.match(reg);
            if (r) {
                r[2] = r[2] - 1;
                var d = new Date(r[1], r[2], r[3], r[4], r[5], r[6]);
                if (d.getFullYear() != r[1] || d.getMonth() != r[2] || d.getDate() != r[3] || d.getHours() != r[4] || d.getMinutes() != r[5] || d.getSeconds() != r[6]) nReturn = 0;
            }
            else {
                reg = /^(\d+)\/(\d{1,2})\/(\d{1,2})$/;
                r = sValueTrimmed.match(reg);
                if (r) {
                    r[2] = r[2] - 1;
                    var d = new Date(r[1], r[2], r[3]);
                    if (d.getFullYear() != r[1] || d.getMonth() != r[2] || d.getDate() != r[3]) nReturn = 0;
                }
                else {
                    nReturn = 0;
                }
            }
            if (nReturn > 0) { if (e.tagName == "DIV") e.innerHTML = sValueTrimmed; }
            else alert("请输入正确的日期或时间，格式为 yyyy/MM/dd hh:mm:ss");
        }
        if (nReturn > 0) {
            var n = sType.indexOf("unique(");
            if (n >= 0) {
                var s = sType.substr(n + 7); s = s.substr(0, s.indexOf(")"));
                var wh; var fn;
		if (s.indexOf(" where ") > 0) { wh = s.substr(s.indexOf(" where ")) + " and "; s = s.substr(0, s.indexOf(" where ")); } else { wh = " where "; }
		if (s.indexOf(".") > 0) { fn = s.substr(s.indexOf(".") + 1); s = s.substr(0, s.indexOf(".")); } else { fn = e.id.substr(e.id.lastIndexOf(".") + 1); }
                if (sType.indexOf("number") >= 0) s = "select count(*) from " + s + wh + fn + "=" + sValue;
                else s = "select count(*) from " + s + wh + fn + "=\"" + sValue.replace("\"", "\"\"") + "\"";
                if (ajax("fieldScalar.aspx?source=" + escape(s)) != "0") {
                    alert("在相关数据集中已经存在一条重复的记录，请重新输入"); nReturn = 0;
                }
            }
        }
        if (nReturn > 0 && sValue != "0") {
            var n = sType.indexOf("existed(");
            if (n >= 0) {
                var s = sType.substr(n + 8); s = s.substr(0, s.indexOf(")"));
                var fn; if (s.indexOf(".") > 0) { fn = s.substr(s.indexOf(".") + 1); s = s.substr(0, s.indexOf(".")); } else { fn = e.id.substr(e.id.lastIndexOf(".") + 1); }
                if (sType.indexOf("number") >= 0) s = "select count(*) from " + s + " where " + fn + "=" + sValue;
                else s = "select count(*) from " + s + " where " + fn + "=\"" + sValue.replace("\"", "\"\"") + "\"";
                if (ajax("fieldScalar.aspx?source=" + escape(s)) == "0") {
                    alert("在相关数据集中找不到对应的记录，请重新输入"); nReturn = 0;
                }
            }
        }
    }
    return nReturn;
}
function fieldsCheckByForm() {
    var ec = document.getElementsByTagName("TD");
    for (var i = 0; i < ec.length; i++) {
        var ep = ec[i];
        if (ep.id) {
            var e = document.getElementById("e." + ep.id);
            if (e) {
                ep.style.backgroundColor = "";
                e.style.backgroundColor = "";
                if (e.tagName == "DIV") {
                    if (fieldCheckByForm(ep.getAttribute("dbf.type"), e.innerHTML, e) == 0) {
                        if (e.className)
                            e.style.backgroundColor = "lightyellow";
                        else
                            ep.style.backgroundColor = "lightyellow";
                        return 0;
                    }
                }
                else if (e.tagName == "TEXTAREA") {
                    if (fieldCheckByForm(ep.getAttribute("dbf.type"), e.value, e) == 0) {
                        e.style.backgroundColor = "lightyellow";
                        e.focus();
                        return 0;
                    }
                }
                else if (fieldCheckByForm(ep.getAttribute("dbf.type"), e.value, e) == 0) {
                    if (e.type == "hidden") ep.style.backgroundColor = "lightyellow";
                    else {e.style.backgroundColor = "lightyellow"; e.focus(); }
                    return 0;
                }
            }
        }
    }
    return 1;
}
function formOnAction(nActionId, bPostForm) {
    var nReturn = 1;
    if (typeof (window.onActionBefore) == "function")
        nReturn = onActionBefore(nActionId, bPostForm);
    if (nReturn == 1 && bPostForm)
        nReturn = fieldsCheckByForm();
    if (nReturn == 1 && typeof (window.onActionAfter) == "function")
        nReturn = onActionAfter(nActionId, bPostForm);
    return nReturn;
}

//slide for images
var $slide = new Object();
$slide.base = {
    e: function (a, f) {
        for (var i = 0, j = a.length; i < j; i++) { f.call(a[i], i); }
    }
}
$slide.play = function (id, arg) {
    var arg = arg || {},
		t = document.getElementById(id),
		a = t.getElementsByTagName("a"),
		lis = [],
		cl = arg.color || 'orange',
		ctm = arg.time * 1000 || 8000,
		mode = arg.mode || 0,
		w = t.clientWidth,
		h = t.clientHeight,
		b = ['<ul style="margin:0; padding:0; list-style:none; display:block; position:absolute; bottom:10px; right:10px;">'],
		lastIndex = 0,
		index = 0,
		offset = w,
		$$ = null,
		$ = null;
    function change(i) {
        if (!!$$) { clearTimeout($$); $$ = null; }
        if (!!$) {
            if (mode == 0) //right to left
            { a[lastIndex].style.left = -1 * w + 'px'; a[index].style.left = '0px'; }
            else if (mode == 1) //left to right
            { a[lastIndex].style.left = w + 'px'; a[index].style.left = '0px'; }
            else if (mode == 2) //bottom to top
            { a[lastIndex].style.top = -1 * h + 'px'; a[index].style.top = '0px'; }
            else //top to bottom
            { a[lastIndex].style.top = h + 'px'; a[index].style.top = '0px'; }
        }
        lastIndex = index;
        index = !isNaN(i) ? i : index + 1;
        if (index >= a.length) { index = 0; }
        $slide.base.e(lis, function (k) { if (k == index) { c(1, this); } else { c(0, this) } });
        if (mode == 0) { //right to left
            if (a[index].style.left == (-1 * w) + 'px') a[index].style.left = w + 'px';
            offset = w;
        }
        else if (mode == 1) { //left to right
            if (a[index].style.left == w + 'px') a[index].style.left = (-1 * w) + 'px';
            offset = 0;
        }
        else if (mode == 2) { //bottom to top
            if (a[index].style.top == (-1 * h) + 'px') a[index].style.top = h + 'px';
            offset = h;
        }
        else { //top to bottom
            if (a[index].style.top == h + 'px') a[index].style.top = (-1 * h) + 'px';
            offset = 0;
        }
        if (!$) {
            if (mode == 0) //right to left
                $ = setInterval(function () {
                    offset -= 15;
                    if (offset <= 0) { a[lastIndex].style.left = (-1 * w) + 'px'; a[index].style.left = '0px'; clearInterval($); $ = null; st(); }
                    else { a[lastIndex].style.left = (offset - w) + 'px'; a[index].style.left = offset + 'px'; }
                }, 30);
            else if (mode == 1) //left to right
                $ = setInterval(function () {
                    offset += 15;
                    if (offset >= w) { a[lastIndex].style.left = w + 'px'; a[index].style.left = '0px'; clearInterval($); $ = null; st(); }
                    else { a[lastIndex].style.left = offset + 'px'; a[index].style.left = (offset - w) + 'px'; }
                }, 30);
            else if (mode == 2) //bottom to top
                $ = setInterval(function () {
                    offset -= 15;
                    if (offset <= 0) { a[lastIndex].style.top = (-1 * h) + 'px'; a[index].style.top = '0px'; clearInterval($); $ = null; st(); }
                    else { a[lastIndex].style.top = (offset - h) + 'px'; a[index].style.top = offset + 'px'; }
                }, 30);
            else //top to bottom
                $ = setInterval(function () {
                    offset += 15;
                    if (offset >= h) { a[lastIndex].style.top = h + 'px'; a[index].style.top = '0px'; clearInterval($); $ = null; st(); }
                    else { a[lastIndex].style.top = offset + 'px'; a[index].style.top = (offset - h) + 'px'; }
                }, 30);
        }
    }
    function c(b, o) {
        o.style.backgroundColor = !!b ? cl : "#fff";
        o.style.color = !!b ? "#fff" : cl;
    }
    function st() {
        if (!!$$) clearTimeout($$);
        $$ = setTimeout(function () { change() }, ctm);
    }
    with (t.style) { overflow = 'hidden'; position = 'relative'; }
    $slide.base.e(a, function (n) {
        this.style.position = "absolute";
        with (this.firstChild.style) { borderWidth = '0'; width = w + 'px'; height = h + 'px'; }
        if (n > 0) {
            if (mode == 0) //right to left
                this.style.left = w + 'px';
            else if (mode == 1) //left to right
                this.style.left = -1 * w + 'px';
            else if (mode == 2) //bottom to top
                this.style.top = h + 'px';
            else //top to bottom
                this.style.top = -1 * h + 'px';
        }
        b.push('<li style="width:16px; height:16px; line-height:16px; display:block; float:left; margin-left:5px; border:1px solid ' + cl + '; background-color:#fff; color:' + cl + '; font-size:12px; text-align:center; cursor:pointer;">' + (n + 1) + '</li>');
    });
    b.push('</ul>');
    t.innerHTML += b.join("");
    lis = t.getElementsByTagName("li");
    $slide.base.e(lis, function (n) {
        if (n == index) { c(1, this); }
        this.onmouseover = function () {
            if (n != index) change(n);
        }
    });
    st();
}