var BrowserDetect = {
    init: function() {
        var b = navigator.userAgent.toLowerCase();
        var m = false;
        var d = false;
        var o = false;
        var l = false;
        var j = false;
        var k = false;
        if (b.indexOf("firefox/") != -1) {
            var n = b.indexOf("firefox/");
            n += "firefox/".length;
            var a = b.substring(n, n + 3);
            if (a >= 3.6) {
                d = true
            }
        } else {
            if (b.indexOf("msie ") != -1) {
                var e = b.indexOf("msie ");
                e += "msie ".length;
                var h = b.substring(e, e + 3);
                if (h >= 7) {
                    m = true
                }
            } else {
                if (b.indexOf("chrome/") != -1) {
                    var p = b.indexOf("chrome/");
                    p += "chrome/".length;
                    var c = b.substring(p, p + 3);
                    if (c >= 8) {
                        l = true
                    }
                } else {
                    var g = b.indexOf("trident");
                    var f = b.indexOf("rv");
                    var k = (b.indexOf("trident") > 1 && b.indexOf("rv:") > 1) ? true : false
                }
            }
        }
        return (m || d || k || l)
    },
    checkBrowser: function() {
        var a = BrowserDetect.init();
        if (!a) {
            alert(" MICROSOFT INTERNET EXPLORER 7.0 AND ABOVE IS REQUIRED. PLEASE CHECK THE MINIMUM REQUIREMENT(S) FOR USING THIS APPLICATION.");
            return false
        }
    },
    redirectTo: function(b, a) {
        if (b == "grse") {
            window.location = a + "/security/getGRSESignInAction.do"
        } else {
            if (b == "ccl") {
                window.location = a + "/security/getCCLSignInAction.do"
            } else {
                window.location = a + "/security/getSignInAction.do"
            }
        }
    }
};
var AdminController = {
    activateSupplier: function(formName, csrfToken, methodName, supplierId, supplierAuthOrgId, supplierAuthCode, supplierIntenssion) {
        eval("document." + formName).supplierId.value = supplierId;
        eval("document." + formName).supplierAuthOrgId.value = supplierAuthOrgId;
        eval("document." + formName).supplierAuthCode.value = supplierAuthCode;
        eval("document." + formName).supplierIntenssion.value = supplierIntenssion;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    activate: function(formName, csrfToken, methodName, supplierId) {
        var mjAuthCode;
        if (AdminController.trim(eval("document." + formName).mjAuthCode.value) == "") {
            alert("Please provide MJ AUTH CODE");
            return false
        } else {
            if (document.getElementById("messageDiv").innerHTML.indexOf("available") >= 0) {
                eval("document." + formName).newUserSelectedFlag.value = "Y";
                mjAuthCode = AdminController.trim(eval("document." + formName).mjAuthCode.value);
                eval("document." + formName).selectedUser.value = supplierId + "|" + mjAuthCode;
                eval("document." + formName).reject.value = "false";
                Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
            }
        }
    },
    mjAuthCodeValidation: function(mjAuthCodeInput) {
        var mjAuthCode = AdminController.trim(mjAuthCodeInput);
        if (mjAuthCode.length >= 6 && mjAuthCode.length <= 14) {
            document.getElementById("messageDiv").innerHTML = "";
            var pattern = /^[a-z0-9]+$/i;
            if (!mjAuthCode.match(pattern)) {
                document.getElementById("messageDiv").innerHTML = "Provide proper MJ Auth code without using any special character.";
                document.getElementById("messageDiv").style.color = "#E90404";
                return false
            }
            eval("document.checkMJForm").mjAuthCode.value = mjAuthCodeInput;
            eval("document.checkMJForm").authenticationOrganization.value = eval("document.userActivationForm").authenticationOrganization.value;
            var csrfToken = document.userActivationForm.token.value;
            Controller.onSubmitWithCsrf("checkMJForm", csrfToken, "chechMJCode", null, AdminController.checkMJAuthCodeValidation)
        } else {
            if (mjAuthCode.length < 6) {
                document.getElementById("messageDiv").innerHTML = "MJ Auth Code has to be atleast 6 alphanumeric character."
            }
            document.getElementById("messageDiv").style.color = "#E90404";
            return false
        }
    },
    checkMJAuthCodeValidation: function(a) {
        if (a.json == "true") {
            document.getElementById("messageDiv").innerHTML = "MJ AUTH CODE : " + document.userActivationForm.mjAuthCode.value + " already exists.";
            document.getElementById("messageDiv").style.color = "#E90404"
        } else {
            if (a.json == "false") {
                document.getElementById("messageDiv").innerHTML = "MJ AUTH CODE : " + document.userActivationForm.mjAuthCode.value + " available.";
                document.getElementById("messageDiv").style.color = "#06A409"
            }
        }
    },
    LTrim: function(b) {
        var a = /\s*((\S+\s*)*)/;
        return b.replace(a, "$1")
    },
    RTrim: function(b) {
        var a = /((\s*\S+)*)\s*/;
        return b.replace(a, "$1")
    },
    trim: function(a) {
        return AdminController.LTrim(AdminController.RTrim(a))
    },
    reject: function(formName, csrfToken, methodName) {
        if (AdminController.trim(eval("document." + formName).rejectReason.value) == "") {
            alert("Please provide the comment");
            return false
        }
        if (AdminController.trim(eval("document." + formName).rejectReason.value).length > 100) {
            alert("Comment cannot contain more than 100 characters");
            return false
        }
        eval("document." + formName).reject.value = "true";
        eval("document." + formName).selectedUser.value = 100 + "|BLANK";
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    printReg: function(formName, csrfToken, methodName, userId) {
        eval("document." + formName).userId.value = userId;
        eval("document." + formName).tableName.value = "EPS.DRAFTUSER";
        eval("document." + formName).target = "_blank";
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    modifySupplier: function(userId, sellerOrgId, buyerOrganization, userAuthentication, formName, csrfToken, methodName, supplierIntenssion) {
        var selectId = userId + "|" + sellerOrgId;
        eval("document." + formName).selectId.value = selectId;
        eval("document." + formName).buyerOrganization.value = buyerOrganization;
        eval("document." + formName).userAuthentication.value = userAuthentication;
        eval("document." + formName).supplierIntenssion.value = supplierIntenssion;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    checkingAdminAction: function(flagForadminaction, formName, csrfToken, methodName) {
        eval("document." + formName).elements["additionalContact.mobileNo"].value = eval("document." + formName).elements["contact.mobileNo"].value;
        eval("document." + formName).elements["additionalContact.phoneNo"].value = eval("document." + formName).elements["contact.phoneNo"].value;
        eval("document." + formName).elements["additionalContact.contactFax"].value = eval("document." + formName).elements["contact.contactFax"].value;
        eval("document." + formName).elements["additionalContact.address1"].value = eval("document." + formName).elements["contact.address1"].value;
        eval("document." + formName).elements["additionalContact.address2"].value = eval("document." + formName).elements["contact.address2"].value;
        eval("document." + formName).elements["additionalContact.country.id"].value = eval("document." + formName).elements["country.id"].value;
        eval("document." + formName).elements["additionalContact.state.id"].value = eval("document." + formName).elements["state.id"].value;
        eval("document." + formName).elements["additionalContact.city.id"].value = eval("document." + formName).elements["city.id"].value;
        eval("document." + formName).elements["additionalContact.postalCode"].value = eval("document." + formName).elements["contact.postalCode"].value;
        eval("document." + formName).functionPerformed.value = flagForadminaction;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    modifyProcCat: function(formName, csrfToken, methodName) {
        eval("document." + formName).methodName.value = "populateProcurementCategory";
        eval("document." + formName).elements["additionalContact.mobileNo"].value = eval("document." + formName).elements["contact.mobileNo"].value;
        eval("document." + formName).elements["additionalContact.phoneNo"].value = eval("document." + formName).elements["contact.phoneNo"].value;
        eval("document." + formName).elements["additionalContact.contactFax"].value = eval("document." + formName).elements["contact.contactFax"].value;
        eval("document." + formName).elements["additionalContact.address1"].value = eval("document." + formName).elements["contact.address1"].value;
        eval("document." + formName).elements["additionalContact.address2"].value = eval("document." + formName).elements["contact.address2"].value;
        eval("document." + formName).elements["additionalContact.country.id"].value = eval("document." + formName).elements["country.id"].value;
        eval("document." + formName).elements["additionalContact.state.id"].value = eval("document." + formName).elements["state.id"].value;
        eval("document." + formName).elements["additionalContact.city.id"].value = eval("document." + formName).elements["city.id"].value;
        eval("document." + formName).elements["additionalContact.postalCode"].value = eval("document." + formName).elements["contact.postalCode"].value;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    submitPrefCat: function(formName, csrfToken, methodName) {
        var length = eval("document." + formName).subCat.length;
        var checking = false;
        if (length > 1) {
            for (var i = 0; i < eval("document." + formName).subCat.length; i++) {
                if (eval("document." + formName).subCat[i].checked) {
                    checking = true;
                    break
                }
            }
        } else {
            if (eval("document." + formName).subCat.checked == true) {
                checking = true
            }
        }
        if (!checking) {
            alert("Select at least one subcategory");
            return false
        }
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    changeDigitalCertStatus: function(formName, digCertId, rowNum, csrfToken, methodName, certificateOwnerId) {
        var status = document.getElementsByName("approveStatus")[rowNum].value;
        var bOrgName = document.getElementsByName("orgName")[rowNum].value;
        var authCode = document.getElementsByName("authCode")[rowNum].value;
        eval("document." + formName).buyerOrgName.value = bOrgName;
        eval("document." + formName).authenticationCode.value = authCode;
        eval("document." + formName).approvalStatus.value = status;
        eval("document." + formName).userDigitalCertId.value = digCertId;
        eval("document." + formName).certificateOwnerId.value = certificateOwnerId;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    updateProfile: function(formName, csrfToken, methodName, exUserId, updateStatus) {
        var flagString = "";
        if (updateStatus == "U") {
            flagString = "UPDATE THE EXISTING PROFILE ?"
        } else {
            if (updateStatus == "UA") {
                flagString = "UPDATE AND ACTIVATE THE PROFILE ?"
            }
        }
        var submit = confirm("DO YOU WANT TO " + flagString);
        if (submit == true) {
            eval("document." + formName).exUserId.value = exUserId;
            eval("document." + formName).updateStatus.value = updateStatus;
            Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
        }
    },
    hideMsgBox: function(a) {
        $("." + a).hide()
    },
    saveProcGrpUser: function(formName, methodName, selectedUserList, csrfToken) {
        var nLength = eval("document." + formName + "." + selectedUserList).options.length;
        for (var nIndex = 0; nIndex < nLength; nIndex++) {
            eval("document." + formName + "." + selectedUserList)[nIndex].selected = true
        }
        Controller.onSubmit(formName, null, methodName, null, null)
    },
    remove: function(formName, userList, selectedUserList) {
        var nLength = eval("document." + formName + "." + selectedUserList).options.length;
        if (nLength >= 0) {
            for (var nIndex = --nLength; nIndex >= 0; nIndex--) {
                if (eval("document." + formName + "." + selectedUserList).options[nIndex].selected) {
                    var optionValue = "",
                        optionText = "";
                    optionValue = eval("document." + formName + "." + selectedUserList).options[nIndex].value;
                    optionText = eval("document." + formName + "." + selectedUserList).options[nIndex].text;
                    var optionName = new Option(optionText, optionValue);
                    var nlength = eval("document." + formName + "." + userList).length;
                    eval("document." + formName + "." + userList).options[nlength] = optionName;
                    eval("document." + formName + "." + selectedUserList).options[nIndex] = null
                }
            }
        }
    },
    add: function(formName, userList, selectedUserList) {
        var nLength = eval("document." + formName + "." + userList).options.length;
        if (nLength > 0) {
            for (var nIndex = --nLength; nIndex >= 0; nIndex--) {
                if (eval("document." + formName + "." + userList).options[nIndex].selected) {
                    var optionValue = "",
                        optionText = "";
                    optionValue = eval("document." + formName + "." + userList).options[nIndex].value;
                    optionText = eval("document." + formName + "." + userList).options[nIndex].text;
                    var optionName = new Option(optionText, optionValue);
                    var nlength = eval("document." + formName + "." + selectedUserList).length;
                    eval("document." + formName + "." + selectedUserList).options[nlength] = optionName;
                    eval("document." + formName + "." + userList).options[nIndex] = null
                }
            }
        }
    },
    addHoliday: function(g) {
        tbody = document.getElementById(g);
        var e = tbody.rows.length;
        if (e < 0) {
            e = 0
        }
        if (!AdminController.validateAddHoliday(e)) {
            return
        }
        var d = tbody.insertRow(tbody.rows.length);
        var f = d.insertCell(0);
        f.setAttribute("class", "dataClass");
        f.setAttribute("align", "left");
        f.setAttribute("width", "25%");
        f.innerHTML = '<input type="text" size="20" name="holidays[' + e + '].description"/>';
        var c = d.insertCell(1);
        c.setAttribute("class", "dataClass");
        c.setAttribute("align", "left");
        c.setAttribute("width", "40%");
        c.innerHTML = '<input type="text" size="22" maxlength="99" readonly="true" id="holidays[' + e + '].date" name="holidays[' + e + '].date"/><a href="javascript:calendar(\'holidays[' + e + "].date','ddMMyyyy',false,24);\"><img src=\"" + contextRoot + '/image/Calendar.gif" border="0" /></a>';
        var b = d.insertCell(2);
        b.setAttribute("width", "15%");
        b.innerHTML = '<a href="#" onclick="AdminController.delHoliday(\'' + g + "', this.parentNode.parentNode.rowIndex);\">DELETE</a>";
        var a = d.insertCell(3);
        a.setAttribute("width", "20%")
    },
    validateAddHoliday: function(c) {
        var d = 5;
        if (c == d) {
            alert("Maximum " + d + " holidays can be added");
            return false
        }
        if (c > 0) {
            var a = document.getElementById("holidays[" + (c - 1) + "].description");
            if (null != a) {
                if ((a.value == "") || (a.value == null)) {
                    alert("Please specify the Description for previous row");
                    return false
                }
            }
            var b = document.getElementById("holidays[" + (c - 1) + "].date");
            if (null != b) {
                if ((b.value == "") || (b.value == null)) {
                    alert("Please specify the Date for previous row");
                    return false
                }
            }
        }
        return true
    },
    delHoliday: function(b, a) {
        tbody = document.getElementById(b);
        if (confirm("Delete the holiday?")) {
            tbody.deleteRow(a)
        }
    }
};
var TemplateController = {
    saveAnswer: function() {
        $("#_msgBox").empty();
        Controller.onSubmit("answerAddForm", null, "saveDocumentSectionAnswer", null, null)
    },
    showQuestionAttr: function(b, a) {
        var c = "_" + b + "_" + a;
        document.getElementById(c).style.display = "block"
    },
    openQuestionAttrList: function(b, c) {
        var a = contextRoot + "/business/template.handle?methodName=getQuestionAttrList&index=" + b + "&" + c;
        window.open(a, "getQuestionAttrList_window", "width=460,height=500,scrollbars=yes,resizable=yes")
    },
    openDocumentQuestionAttrList: function(a, c, f, d) {
        var b = contextRoot + "/business/template.handle?methodName=getDocumentQuestionAttrList&index=" + c + "&questionIndex=" + a + "&integrated=" + f + "&isRow=" + d;
        var g = document.documentQuestionAddForm.OWASP_CSRFTOKEN;
        if (typeof g != "undefined") {
            var e = document.documentQuestionAddForm.OWASP_CSRFTOKEN.value;
            b = b + "&OWASP_CSRFTOKEN=" + e
        }
        window.open(b, "getDocumentQuestionAttrList_window", "width=460,height=500,scrollbars=yes,resizable=yes")
    },
    openQuestionAttrList: function(f, b, e, c) {
        var a = contextRoot + "/business/template.handle?methodName=getQuestionAttrList&index=" + b + "&questionIndex=" + f + "&integrated=" + e + "&isRow=" + c;
        var g = document.questionAddForm.OWASP_CSRFTOKEN;
        if (typeof g != "undefined") {
            var d = document.questionAddForm.OWASP_CSRFTOKEN.value;
            a = a + "&OWASP_CSRFTOKEN=" + d
        }
        window.open(a, "getQuestionAttrList_window", "width=720,height=400,scrollbars=yes,resizable=no,titlebar=no,toolbar=no")
    },
    getQuestionGroupByGoToPage: function(a) {
        var c = $("form[id!='dummyForm']", "#_content");
        var b = $('input[id="searchPageNumber"]', c).get(0);
        if (b.value == "") {
            return
        }
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=getQuestionGroupListByPagination&pageNumber=" + b.value + "&" + a, null, null)
    },
    searchQuestionGroupByCode: function(a) {
        var c = $("form[id!='dummyForm']", "#_content");
        var b = $('input[name="searchByLotCode"]', c).get(0);
        if (b.value == "") {
            return
        }
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=searchQuestionGroupByCode&code=" + b.value + "&" + a, null, null)
    },
    getQuestionGroup: function(a) {
        var c = $("form[id!='dummyForm']", "#_content");
        var b = $('input[name="code"]', c).get(0);
        if (b.value == "") {
            return
        }
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=initAddQuestionGroup&code=" + b.value + "&" + a, null, null)
    },
    addRow: function(y) {
        var e = document.getElementById(y);
        var w = e.rows.length;
        if (w < 0) {
            w = 0
        }
        var r = e.rows[w - 1];
        var h = r.id;
        var k = h.substring(3);
        w = parseInt(k) + 1;
        newRow = e.rows[1].cloneNode(true);
        newRow.setAttribute("id", "row" + w);
        var n = newRow.getElementsByTagName("td");
        var B = n[0];
        var F = B.getElementsByTagName("select");
        var s = F[0];
        s.setAttribute("id", "questionAttributeList[" + w + "].attributeValueType.id");
        s.setAttribute("name", "questionAttributeList[" + w + "].attributeValueType.id");
        s.setAttribute("onchange", "javascript:TemplateController.changeAttValType(" + y + "," + w + ");");
        var d = n[1];
        var G = d.getElementsByTagName("input");
        var j = G[0];
        j.setAttribute("id", "questionAttributeList[" + w + "].description");
        j.setAttribute("name", "questionAttributeList[" + w + "].description");
        j.value = "";
        var C = n[2];
        var L = C.getElementsByTagName("input");
        var u = L[0];
        u.setAttribute("id", "questionAttributeList[" + w + "].minVal");
        u.setAttribute("name", "questionAttributeList[" + w + "].minVal");
        u.value = "0.00";
        var c = n[3];
        var m = c.getElementsByTagName("input");
        var H = m[0];
        H.setAttribute("id", "questionAttributeList[" + w + "].maxVal");
        H.setAttribute("name", "questionAttributeList[" + w + "].maxVal");
        H.value = "0.00";
        var o = n[4];
        var D = o.getElementsByTagName("input");
        var A = D[0];
        A.setAttribute("id", "questionAttributeList[" + w + "].defaultValue");
        A.setAttribute("name", "questionAttributeList[" + w + "].defaultValue");
        A.value = "";
        var l = n[5];
        var f = l.getElementsByTagName("input");
        var v = f[0];
        v.setAttribute("id", "questionAttributeList[" + w + "].optionValues");
        v.setAttribute("name", "questionAttributeList[" + w + "].optionValues");
        v.value = "";
        var J = n[6];
        var g = J.getElementsByTagName("select");
        var x = g[0];
        x.setAttribute("id", "questionAttributeList[" + w + "].visibility");
        x.setAttribute("name", "questionAttributeList[" + w + "].visibility");
        var K = n[7];
        var t = K.getElementsByTagName("select");
        var a = t[0];
        a.setAttribute("id", "questionAttributeList[" + w + "].mandatory");
        a.setAttribute("name", "questionAttributeList[" + w + "].mandatory");
        var E = n[8];
        var M = E.getElementsByTagName("select");
        var I = M[0];
        I.setAttribute("id", "questionAttributeList[" + w + "].editable");
        I.setAttribute("name", "questionAttributeList[" + w + "].editable");
        var z = n[9];
        var p = z.getElementsByTagName("input");
        var b = p[0];
        b.setAttribute("id", "questionAttributeList[" + w + "].maxSize");
        b.setAttribute("name", "questionAttributeList[" + w + "].maxSize");
        b.value = "0";
        var q = n[10];
        b.setAttribute("display", "block");
        q.innerHTML = '<a class="pageContentLink" href="javascript:TemplateController.deleteRow(' + y + "," + w + ');">DELETE ROW</a>';
        e.appendChild(newRow)
    },
    deleteRow: function(b, a) {
        var c = document.getElementById("row" + a);
        if (confirm("Delete The Row?")) {
            document.questionAttributeAddForm.deletedQuestionIndex.value = document.questionAttributeAddForm.deletedQuestionIndex.value + "," + a;
            c.parentNode.removeChild(c)
        }
    },
    setDefaultValue: function(l, h) {
        var o = document.getElementById(l);
        var k = "row" + h;
        var g = document.getElementById(k);
        var r = g.getElementsByTagName("td");
        var q = r[2];
        var p = q.getElementsByTagName("input");
        var d = p[0];
        var f = r[3];
        var b = f.getElementsByTagName("input");
        var m = b[0];
        var v = r[4];
        var e = v.getElementsByTagName("input");
        var t = e[0];
        var c = r[5];
        var n = c.getElementsByTagName("input");
        var a = n[0];
        var u = r[9];
        var j = u.getElementsByTagName("input");
        var s = j[0];
        m.value = "0.00";
        s.value = "0";
        d.value = "0.00";
        a.value = "";
        t.value = ""
    },
    changeAttValType: function(E, C) {
        var h = document.getElementById(E);
        var g = "row" + C;
        var q = document.getElementById(g);
        var u = q.getElementsByTagName("td");
        var K = u[0];
        var P = K.getElementsByTagName("select");
        var l = P[0].value;
        var f = u[1];
        var Q = f.getElementsByTagName("input");
        var m = Q[0];
        var L = u[2];
        var X = L.getElementsByTagName("input");
        var A = X[0];
        var c = u[3];
        var t = c.getElementsByTagName("input");
        var R = t[0];
        var v = u[4];
        var M = v.getElementsByTagName("input");
        var I = M[0];
        var s = u[5];
        var j = s.getElementsByTagName("input");
        var B = j[0];
        var U = u[6];
        var k = U.getElementsByTagName("select");
        var D = k[0];
        var V = u[7];
        var z = V.getElementsByTagName("select");
        var a = z[0];
        var N = u[8];
        var Y = N.getElementsByTagName("select");
        var S = Y[0];
        var F = u[9];
        var w = F.getElementsByTagName("input");
        var b = w[0];
        var W = "minValDiv" + C;
        var G = "maxValDiv" + C;
        var p = "optionValDiv" + C;
        var r = "maxSizeDiv" + C;
        var o = "minValCalDiv" + C;
        var H = "maxValCalDiv" + C;
        var d = "dfltValCalDiv" + C;
        var J = document.getElementById(W);
        var e = document.getElementById(G);
        var n = document.getElementById(p);
        var x = document.getElementById(r);
        var T = document.getElementById(o);
        var y = document.getElementById(H);
        var O = document.getElementById(d);
        if (l == 100) {
            x.style.visibility = "hidden";
            e.style.visibility = "visible";
            J.style.visibility = "visible";
            n.style.visibility = "hidden";
            T.style.visibility = "hidden";
            y.style.visibility = "hidden";
            O.style.visibility = "hidden";
            TemplateController.setDefaultValue(E, C)
        } else {
            if (l == 101) {
                x.style.visibility = "hidden";
                e.style.visibility = "visible";
                J.style.visibility = "visible";
                n.style.visibility = "hidden";
                T.style.visibility = "hidden";
                y.style.visibility = "hidden";
                O.style.visibility = "hidden";
                TemplateController.setDefaultValue(E, C)
            } else {
                if (l == 102) {
                    x.style.visibility = "visible";
                    e.style.visibility = "hidden";
                    J.style.visibility = "hidden";
                    n.style.visibility = "hidden";
                    T.style.visibility = "hidden";
                    y.style.visibility = "hidden";
                    O.style.visibility = "hidden";
                    TemplateController.setDefaultValue(E, C)
                } else {
                    if (l == 103) {
                        x.style.visibility = "visible";
                        e.style.visibility = "hidden";
                        J.style.visibility = "hidden";
                        n.style.visibility = "hidden";
                        T.style.visibility = "hidden";
                        y.style.visibility = "hidden";
                        O.style.visibility = "hidden";
                        TemplateController.setDefaultValue(E, C)
                    } else {
                        if (l == 104) {
                            x.style.visibility = "hidden";
                            e.style.visibility = "visible";
                            J.style.visibility = "visible";
                            n.style.visibility = "hidden";
                            T.style.visibility = "visible";
                            y.style.visibility = "visible";
                            O.style.visibility = "visible";
                            TemplateController.setDefaultValue(E, C)
                        } else {
                            if (l == 105) {
                                x.style.visibility = "hidden";
                                e.style.visibility = "hidden";
                                J.style.visibility = "hidden";
                                n.style.visibility = "visible";
                                T.style.visibility = "hidden";
                                y.style.visibility = "hidden";
                                O.style.visibility = "hidden";
                                TemplateController.setDefaultValue(E, C)
                            }
                        }
                    }
                }
            }
        }
    },
    validateTemplateSearch: function(b) {
        var a = document.getElementById("templateCreateDateFrom").value;
        var c = document.getElementById("templateCreateDateTo").value;
        if (a != "") {
            if (c == "") {
                alert("Please specify the Proposal Create Date To correctly");
                return false
            }
        } else {
            if (c != "") {
                if (a == "") {
                    alert("Please specify the Proposal Create Date From correctly");
                    return false
                }
            }
        }
        if (c < a) {
            alert("To date should be greater than From date ");
            return false
        }
        return true
    },
    validateQuestionSearch: function(a) {
        return true
    },
    search: function search(a) {
        var b = TemplateController.validateTemplateSearch(a);
        if (b) {
            SearchController.searchWithForm("templateSearch", ["lastId"], "searchResult")
        }
    },
    searchQuestion: function(a) {
        var b = TemplateController.validateQuestionSearch(a);
        if (b) {
            SearchController.searchWithForm("questionSearch", ["lastId"], "searchResult")
        }
    },
    viewTemplate: function(c, b, a) {
        if (null == c) {
            alert("Please select an Template");
            return
        }
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=showTemplate&viewMode=true&templateId=" + c + "&documentType=" + b + "&" + a + "&_documentId=109&_subDocumentId=100&_stepId=1", null, null)
    },
    viewQTemplate: function(b, a) {
        if (null == b) {
            alert("Please select an Template");
            return
        }
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=showQTemplate&viewMode=true&templateId=" + b + "&" + a + "&_documentId=109&_subDocumentId=100&_stepId=1", null, null)
    },
    viewQuestion: function(b, a) {
        if (null == b) {
            alert("Please select an Question");
            return
        }
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=getQuestion&viewMode=true&questionId=" + b + "&" + a, null, null)
    },
    viewSection: function(b, a) {
        if (null == b) {
            alert("Please select an Section");
            return
        }
        var c = contextRoot + "/business/template.handle?methodName=getSection&viewMode=true&selectedSectionId=" + b + "&" + a;
        window.open(c, "getTemplateSectionList_window", "width=800,height=500,scrollbars=yes,resizable=yes,menubar=no,directories=no,location=no")
    },
    randomString: function() {
        var d = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
        var e = 11;
        var b = "";
        for (var c = 0; c < e; c++) {
            var a = Math.floor(Math.random() * d.length);
            b += d.substring(a, a + 1)
        }
        return b
    },
    viewDocSectionForAnswer: function(g, j, b, d, k, f, c, e) {
        var h = TemplateController.randomString();
        if (null == b) {
            alert("Please select an Section");
            return
        }
        var a = contextRoot + "/business/template.handle?methodName=getDocSection&viewMode=" + d + "&selectedDocSectionId=" + b + "&entityId=" + g + "&docId=" + j + "&editQuestionScoreFlag=" + k + "&viewScoreFlag=" + c + "&randomNumber=" + h + "&" + f + "&entityValueId=" + e;
        window.open(a, "getTemplateSectionListForAnswer_window")
    },
    viewDocSection: function(e, a, d, b) {
        if (null == e) {
            alert("Please select an Section");
            return
        }
        var c = contextRoot + "/business/template.handle?methodName=getDocumentSection&viewMode=true&docSectionId=" + e + "&entityId=" + d + "&entityValue=" + b + "&" + a;
        window.open(c, "getDocumentConfigTemplateSection_window", "width=800,height=500,scrollbars=yes,resizable=yes,menubar=no,directories=no,location=no")
    },
    checkIfAllRowsFilledUp: function(d, c) {
        var b = null;
        for (var a = d; a >= 0; a--) {
            b = document.getElementById("section.secQuesRelList[" + a + "].question.code").value;
            if (b == "") {
                alert(c);
                return false
            }
        }
        document.getElementById("buttonValue").value = "next";
        Controller.onSubmit("questionAddForm", null, "saveSectionQuestionRelList", "next")
    },
    checkIfAllDocumentRowsFilledUp: function(d, c) {
        var b = null;
        for (var a = d; a >= 0; a--) {
            b = document.getElementById("docSection.docSecQuesRelList[" + a + "].docQuestion.code").value;
            if (b == "") {
                alert(c);
                return false
            }
        }
        document.getElementById("buttonValue").value = "next";
        document.documentQuestionAddForm.submit()
    },
    saveSectionQuestionRelList: function(formName, methodname, buttonName) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmit(formName, null, methodname, null, null)
    },
    saveSectionQuestionRelListWithCsrf: function(formName, methodname, buttonName, csrfToken) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodname, null, null)
    },
    saveDocumentSectionQuestionRelListWithCsrf: function(formName, methodname, buttonName, csrfToken) {
        eval("document." + formName).buttonValue.value = buttonName;
        document.documentQuestionAddForm.submit()
    },
    moreRowForQuesAttr: function() {
        var b = "_AttrTab";
        var e = document.getElementById(b);
        var f = e.insertRow(e.rows.length);
        for (var c = 0; c < e.rows[0].cells.length; c++) {
            var d = e.rows.length;
            var a = f.insertCell(c);
            TemplateController.crtQuesAttrCell(a, d - 1, c, "row")
        }
    },
    moreRowForAttr: function(g) {
        var b = "_AttrTab_" + g;
        var e = document.getElementById(b);
        var f = e.insertRow(e.rows.length);
        for (var c = 0; c < e.rows[0].cells.length; c++) {
            var d = e.rows.length;
            var a = f.insertCell(c);
            TemplateController.crtCell(a, d - 1, c, "row", g)
        }
    },
    moreDocumentRowForAttr: function(g) {
        var b = "_AttrTab_" + g;
        var e = document.getElementById(b);
        var f = e.insertRow(e.rows.length);
        for (var c = 0; c < e.rows[0].cells.length; c++) {
            var d = e.rows.length;
            var a = f.insertCell(c);
            TemplateController.crtDocumentCell(a, d - 1, c, "row", g)
        }
    },
    moreColForQuesAttr: function() {
        var b = "_AttrTab";
        var e = document.getElementById(b);
        for (var c = 0; c < e.rows.length; c++) {
            var d;
            if (c == 0) {
                d = e.rows[0].cells.length
            }
            var a = e.rows[c].insertCell(e.rows[c].cells.length);
            TemplateController.crtQuesAttrCell(a, c, d, "col")
        }
    },
    moreColForAttr: function(f) {
        var b = "_AttrTab_" + f;
        var e = document.getElementById(b);
        for (var c = 0; c < e.rows.length; c++) {
            var d;
            if (c == 0) {
                d = e.rows[0].cells.length
            }
            var a = e.rows[c].insertCell(e.rows[c].cells.length);
            TemplateController.crtCell(a, c, d, "col", f)
        }
    },
    moreDocumentColForAttr: function(f) {
        var b = "_AttrTab_" + f;
        var e = document.getElementById(b);
        for (var c = 0; c < e.rows.length; c++) {
            var d;
            if (c == 0) {
                d = e.rows[0].cells.length
            }
            var a = e.rows[c].insertCell(e.rows[c].cells.length);
            TemplateController.crtDocumentCell(a, c, d, "col", f)
        }
    },
    deleteLastRowForAttr: function(d) {
        var a = "_AttrTab_" + d;
        var c = document.getElementById(a);
        var b = c.rows.length - 1;
        if (b != 0) {
            c.deleteRow(b)
        }
    },
    deleteLastColumnForAttr: function(e) {
        var b = "_AttrTab_" + e;
        var d = document.getElementById(b);
        var a = d.rows[0].cells.length - 1;
        for (var c = 0; c < d.rows.length; c++) {
            if (a == 1 && c == 0) {} else {
                if (a > 1 && c == 0) {
                    d.rows[c].deleteCell(a)
                } else {}
            }
        }
    },
    deleteLastRow: function() {
        var a = "_AttrTab";
        var c = document.getElementById(a);
        var b = c.rows.length - 1;
        if (b != 0) {
            c.deleteRow(b)
        }
    },
    deleteLastColumn: function() {
        var b = "_AttrTab";
        var d = document.getElementById(b);
        var a = d.rows[0].cells.length - 1;
        for (var c = 0; c < d.rows.length; c++) {
            if (a == 1 && c == 0) {} else {
                if (a > 1 && c == 0) {
                    d.rows[c].deleteCell(a)
                } else {}
            }
        }
    },
    crtDocumentCell: function(j, g, h, a, c) {
        if (g == 0) {
            var b = h - 1;
            var e = "<table><tr><td><input id='docSection.docSecQuesRelList[" + c + "].docQuestion.documentQuestionColumnAttribute[" + b + "].docQuestionAttribute.id' name='docSection.docSecQuesRelList[" + c + "].docQuestion.documentQuestionColumnAttribute[" + b + "].docQuestionAttribute.id' type='hidden' value= '0' /> <input id='docSection.docSecQuesRelList[" + c + "].docQuestion.documentQuestionColumnAttribute[" + b + "].docQuestionAttribute.parentQuestionAttribute.id' name='docSection.docSecQuesRelList[" + c + "].docQuestion.documentQuestionColumnAttribute[" + b + "].docQuestionAttribute.parentQuestionAttribute.id' type='hidden' value= '0' /> <input type='text' id='docSection.docSecQuesRelList[" + c + "].docQuestion.documentQuestionColumnAttribute[" + b + "].documentQuestionAttribute.description' name='docSection.docSecQuesRelList[" + c + "].docQuestion.documentQuestionColumnAttribute[" + b + "].description'  /> &nbsp;<a href='javascript:TemplateController.addDocumentQuestionAttr(" + c + "," + b + ");' ><img src='../image/icon_add_large.gif' title='ADD ATTRIBUTE' border='0'></a>&nbsp;<a href='javascript:TemplateController.openDocumentQuestionAttrList(" + c + "," + b + ",true,false);' ><img src='../image/paperclip.gif' title='ATTACH ATTRIBUTE' border='0'></a></td></tr></table>";
            j.innerHTML = e
        } else {
            if (h == 0) {
                var f = g - 1;
                var d = document.createElement("input");
                d.setAttribute("name", "docSection.docSecQuesRelList[" + c + "].docQuestion.documentQuestionRowAttribute[" + f + "].description");
                d.setAttribute("id", "docSection.docSecQuesRelList[" + c + "].docQuestion.documentQuestionRowAttribute[" + f + "].description");
                j.appendChild(d)
            } else {}
        }
    },
    crtCell: function(j, g, h, a, c) {
        if (g == 0) {
            var b = h - 1;
            var e = "<table><tr><td><input id='section.secQuesRelList[" + c + "].question.questionColumnAttribute[" + b + "].questionAttribute.id' name='section.secQuesRelList[" + c + "].question.questionColumnAttribute[" + b + "].questionAttribute.id' type='hidden' value= '0' /> <input type='text' id='section.secQuesRelList[" + c + "].question.questionColumnAttribute[" + b + "].description' name='section.secQuesRelList[" + c + "].question.questionColumnAttribute[" + b + "].description'  > &nbsp;<a href='javascript:TemplateController.addQuestionAttr(" + c + "," + b + ");' ><img src='../image/icon_add_large.gif' title='ADD ATTRIBUTE' border='0'></a>&nbsp;<a href='javascript:TemplateController.openQuestionAttrList(" + c + "," + b + ",true,false);' ><img src='../image/paperclip.gif' title='ATTACH ATTRIBUTE' border='0'></a></td></tr></table>";
            j.innerHTML = e
        } else {
            if (h == 0) {
                var f = g - 1;
                var d = document.createElement("input");
                d.setAttribute("name", "section.secQuesRelList[" + c + "].question.questionRowAttribute[" + f + "].description");
                d.setAttribute("id", "section.secQuesRelList[" + c + "].question.questionRowAttribute[" + f + "].description");
                d.setAttribute("cols", "20");
                d.setAttribute("rows", "2");
                j.appendChild(d)
            } else {}
        }
    },
    crtQuesAttrCell: function(a, h, c, d) {
        if (h == 0) {
            var f = c - 1;
            var g = "<table><tr><td><input id='questionColumnAttribute[" + f + "].questionAttribute.id' name='questionColumnAttribute[" + f + "].questionAttribute.id' type='hidden' value= '0' /> <input type='text' id='questionColumnAttribute[" + f + "].description' name='questionColumnAttribute[" + f + "].description'  > &nbsp;<a href='javascript:TemplateController.addQuestionAttr(-1," + f + ");' ><img src='../image/icon_add_large.gif' title='ADD ATTRIBUTE' border='0'></a>&nbsp;<a href='javascript:TemplateController.openQuestionAttrList(-1," + f + ",false,false);' ><img src='../image/paperclip.gif' title='ATTACH ATTRIBUTE' border='0'></a></td></tr></table>";
            a.innerHTML = g
        } else {
            if (c == 0) {
                var b = h - 1;
                var e = document.createElement("input");
                e.setAttribute("name", "questionRowAttribute[" + b + "].description");
                e.setAttribute("id", "questionRowAttribute[" + b + "].description");
                e.setAttribute("cols", "20");
                e.setAttribute("rows", "2");
                a.appendChild(e)
            } else {}
        }
    },
    addQuestionAttr: function(d, b) {
        var a = contextRoot + "/business/template.handle?methodName=initCreateAttribute&index=" + b + "&questionIndex=" + d;
        var e = document.questionAddForm.OWASP_CSRFTOKEN;
        if (typeof e != "undefined") {
            var c = document.questionAddForm.OWASP_CSRFTOKEN.value;
            a = a + "&OWASP_CSRFTOKEN=" + c
        }
        window.open(a, "addQuestionAttr_window", "width=700,height=360")
    },
    addDocumentQuestionAttr: function(g, d) {
        var c = $("input[name='docSection.entityValue.entityId']").val();
        var a = $("input[name='docSection.entityValue.entityValue']").val();
        var b = contextRoot + "/business/template.handle?methodName=initCreateDocumentAttribute&index=" + d + "&documentQuestionIndex=" + g + "&entityId=" + c + "&entityValue=" + a;
        var f = document.documentQuestionAddForm.OWASP_CSRFTOKEN;
        if (typeof f != "undefined") {
            var e = document.documentQuestionAddForm.OWASP_CSRFTOKEN.value;
            b = b + "&OWASP_CSRFTOKEN=" + e
        }
        window.open(b, "addDocumentQuestionAttr_window", "width=700,height=360")
    },
    retrieveSection: function(formName, csrfToken, methodname, sectionId, templateId) {
        eval("document." + formName).sectionId.value = sectionId;
        eval("document." + formName).configTemplateId.value = templateId;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodname, null, null)
    },
    deleteSection: function(formName, csrfToken, methodname, sectionId, templateId) {
        eval("document." + formName).sectionId.value = sectionId;
        eval("document." + formName).configTemplateId.value = templateId;
        if (confirm("Delete the Section from the Template?")) {
            Controller.onSubmitWithCsrf(formName, csrfToken, methodname, null, null)
        }
    },
    submitScore: function() {
        document.sectionAddForm.methodName.value = "saveDocSectionQtnScore";
        document.sectionAddForm.submit()
    },
    selectItem: function(b, a) {
        if (null == b) {
            alert("Please select an Attribute Master");
            return
        }
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=addAttMaster&id=" + b + "&" + a, null, null)
    },
    searchPerticularPage: function(a) {
        var b = document.attrMasterForm.searchPageNumber.value;
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=getAttrMasterListByPagination&pageNumber=" + b + "&" + a, null, null)
    },
    saveTemplate: function(c, a, d, b) {
        if ($("#templateStatus").length > 0) {
            document.getElementById("templateStatus").value = d
        }
        document.getElementById("buttonValue").value = b;
        var f = true;
        if ($("#templateDocumentType").val() == "203") {
            $("select[name$='dfltValSource']").each(function() {
                if ($(this).val() != "201" && $(this).val() != "0" && $(this).val() != "1") {
                    alert("Please select QTN ITEM ATTR for Default Val Source");
                    f = false;
                    return
                }
            })
        }
        if ($("#templateDocumentType").val() == "202") {
            $("select[name$='dfltValSource']").each(function() {
                if ($(this).val() != "200" && $(this).val() != "0" && $(this).val() != "1") {
                    alert("Please select QTN HEADER ATTR for Default Val Source");
                    f = false;
                    return
                }
            })
        }
        if (f == false) {
            return
        }
        if (b == "FORMULA") {
            var e = confirm("Template,once saved for formula,can not be modified further");
            if (e == true) {
                Controller.onSubmitWithCsrf(c, a, "saveTemplate", "FORMULA", null)
            }
        } else {
            if (b == "VALIDATION") {
                var e = confirm("Template,once saved for validation, can not be modified further");
                if (e == true) {
                    Controller.onSubmitWithCsrf(c, a, "saveTemplate", "VALIDATION", null)
                }
            } else {
                Controller.onSubmitWithCsrf(c, a, "saveTemplate", "SAVE", null)
            }
        }
    },
    openSequence: function(c, b, a) {
        var d = "templateBlockMap[" + c + "].attributeMaster[" + b + "].attribute.sequence";
        if (a) {
            document.getElementById(d).value = 0;
            document.getElementById(d).removeAttribute("readOnly")
        } else {
            document.getElementById(d).value = sequence;
            document.getElementById(d).setAttribute("readOnly", "readonly")
        }
    },
    displayOrgPcpn: function(a) {
        var b = contextRoot + "/business/template.handle?methodName=getOrgPcnpFlgByOrgId&" + a;
        window.open(b, "getOrgPcnpFlgByOrgId_window", "width=800,height=500,scrollbars=yes,resizable=yes,menubar=no,directories=no,location=no")
    },
    templatePreview: function(b, c, a) {
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=getTemplatePreview&templateId=" + b + "&templateStatus=" + c + "&" + a, null, null)
    },
    editTemplate: function(c, d, a, b) {
        document.getElementById("buttonValue").value = b;
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=getAttributeList&templateId=" + c + "&buttonValue=" + b + "&templateStatus=" + d + "&" + a, null, null)
    },
    saveTemplateFormula: function(c, a, b) {
        alert("templateId:::" + c);
        document.getElementById("buttonValue").value = b;
        Controller.onSubmitWithCsrf("templateView", a, "saveTemplateFormula", "SAVE", null)
    },
    activeTemplate: function(c, a, b, d) {
        alert("templateId:::" + c);
        alert("buttonValue:::" + b);
        document.getElementById("templateId").value = c;
        document.getElementById("templateStatus").value = d;
        alert("templateStatus:::" + d);
        document.getElementById("buttonValue").value = b;
        alert("buttonValue:::" + b);
        Controller.onSubmitWithCsrf("templateActiveForm", a, "activeTemplate", null, null)
    },
    getFormula: function(c, a, b) {
        alert("templateId:::" + c);
        Controller.loadPage(contextRoot + "/business/template.handle?methodName=getTemplateFormula&templateId=" + c + "&" + a, null, null)
    }
};
var OrderController = {
    selectOrder: function(d, a, b, c, e) {
        pageScope.order = {
            "order.id": a,
            "order.code": d,
            "order.orderInheritanceCode": b,
            "order.createDate": c,
            "order.orderOrganization.id": e
        };
        if (sessionScope._currDocId == 106) {
            if (sessionScope._currPrivId == 100) {
                $("#raiseIr").css("display", "inline")
            }
        }
    },
    signOrder: function(h, c, g, e, j) {
        var b = document.getElementById("code").value;
        var d = document.getElementById("orderDateSign").value;
        var f = b + "#|#" + d;
        var a = true;
        if (e && j) {
            a = a && signDocument(f)
        }
        if (a) {
            Controller.onSubmitWithCsrf(h, c, g, null, null)
        }
    },
    signOrderAttachmentFile: function(c) {
        var e = true;
        var b = "attachments[" + c + "].file";
        var a = "attachments[" + c + "].digitalCert.signHash";
        var f = "attachments[" + c + "].digitalCert.id";
        var d = document.getElementById(b).value;
        e = signFileAndAssignValue(d, a)
    },
    verifyOrder: function() {
        var b = document.getElementById("code").value;
        var a = document.getElementById("orderDate").value;
        var c = b + "#|#" + a;
        verifyDocument(c)
    },
    getRfqsAndQuotationsByOrgId: function(b, f, c, a) {
        var d = 0;
        if (null != document.getElementById("ordCatId")) {
            d = document.getElementById("ordCatId").value
        }
        var e = $("form[id!='dummyForm']");
        Util.clearContent($("#_msgBox"));
        Util.clearContent($("#rfqList"));
        Controller.loadPage(contextRoot + "/business/order.handle?methodName=getRfqsAndQuotationsByOrgId&rfqDate.rfqStartDate=" + b + "&rfqDate.rfqEndDate=" + f + "&ordCatId=" + d + "&code=" + c + "&" + a, null, null)
    },
    getUsers: function(b, a) {
        var c = $("form[id!='dummyForm']");
        Controller.loadData(contextRoot + "/business/order.handle?methodName=getUsers&orgId=" + a, null, function(h) {
            log("Inside call back::::");
            if (h._errors != null) {
                Util.showMessage(h);
                return
            }
            var g = new Array();
            var e = 0;
            if (h.userList.length == 0) {
                return
            }
            g[e++] = '<select id="orderSellerUsers[' + b + '].id" name="orderSellerUsers[' + b + '].id">';
            for (var f = 0; f < h.userList.length; f++) {
                g[e++] = '<option value="';
                g[e++] = h.userList[f].id;
                g[e++] = '">';
                g[e++] = h.userList[f].userFirstName;
                g[e++] = "</option>"
            }
            g[e++] = "</select>";
            var d = document.getElementById("sellerTab");
            d.rows[2 + b].cells[2].innerHTML = g.join("")
        })
    },
    getItemDetail: function(f) {
        var b = document.getElementById("docItemList[" + f + "].code").value;
        var c = document.getElementById("csrfTokenName").value;
        var e = document.getElementById("csrfTokenValue").value;
        var a = c + "=" + e;
        if (b == "") {
            alert("Please specify the Code to get the Description");
            return false
        }
        var d = $("form[id!='dummyForm']");
        $('input[id$=".code"]', d).each(function() {
            this.disabled = true
        });
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getItem&code=" + b + "&" + a, null, function(g) {
            $('input[id$=".code"]', d).each(function() {
                this.disabled = false
            });
            if (g._errors != null) {
                Util.clearContent($("#_msgBox"));
                Util.showMessage(g);
                document.getElementById("docItemList[" + f + "].code").value = "";
                return
            }
            Util.clearContent($("#_msgBox"));
            document.getElementById("docItemList[" + f + "].bigOrderItemDesc").value = Controller.unescapeHtml(g.item.description)
        })
    },
    openSellers: function(b, c) {
        var a = contextRoot + "/business/order.handle?methodName=getOrderSellers&index=" + b + "&" + c;
        window.open(a, "orderSeller_window", "width=460,height=500,scrollbars=yes,resizable=yes")
    },
    findRfqs: function(a) {
        var c = 0;
        if (null != document.getElementById("categoryId")) {
            c = document.getElementById("categoryId").value
        }
        var b = contextRoot + "/business/order.handle?methodName=getRfqList&categoryId=" + c + "&" + a;
        window.open(b, "rfqPrint_window", "width=580,height=500,scrollbars=yes")
    },
    validate: function() {
        var a = false;
        var b = document.orderAddForm.code.value;
        var j = document.orderAddForm.description.value;
        var e = document.orderAddForm.orderValue.value;
        var g = document.orderAddForm.orderDate.value;
        var f = document.orderAddForm.groupId.value;
        var h = document.getElementById("orderSellerUsers[0].organization.organizationName").value;
        var k = document.getElementById("orderSellerUsers[0].userFirstName").value;
        var d = document.getElementById("orderSellerUsers[1].organization.organizationName").value;
        var c = document.getElementById("orderSellerUsers[1].userFirstName").value;
        if (b.length == 0) {
            alert("Order Reference Code Required");
            a = false
        } else {
            if (j.length == 0) {
                alert("Description Required");
                a = false
            } else {
                if (e.length == 0) {
                    alert("Value Required");
                    a = false
                } else {
                    if (!Util.IsNumeric(Util.trim(e))) {
                        alert("Enter numeric date for Value");
                        a = false
                    } else {
                        if (g.length == 0) {
                            alert("Order Date Required");
                            a = false
                        } else {
                            if (!OrderController.isValidOrderDate(g)) {
                                alert("Invalid Order Date");
                                a = false
                            } else {
                                if (f == "") {
                                    alert("Inspection Group Rrequired");
                                    a = false
                                } else {
                                    if (h.length == 0) {
                                        alert("Supplier Organization Name Rrequired");
                                        a = false
                                    } else {
                                        if (k.length == 0) {
                                            alert("Supplier Name Rrequired");
                                            a = false
                                        } else {
                                            if (d.length == 0) {
                                                alert("Payee Organization Name Rrequired");
                                                a = false
                                            } else {
                                                if (c.length == 0) {
                                                    alert("Payee Name Rrequired");
                                                    a = false
                                                } else {
                                                    a = true
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return a
    },
    isValidOrderDate: function(b) {
        var a = false;
        var j = b.substring(0, 4);
        var g = b.substring(5, 7);
        var k = b.substring(8, 10);
        var e = b.substring(11, 13);
        var f = b.substring(14, 16);
        var c = b.substring(17, 19);
        var h = new Date();
        var d = g - 1;
        var b = new Date(j, g - 1, k, e, f, c);
        h.setHours(0);
        h.setMinutes(0);
        h.setSeconds(0);
        var l = b.getTime() - h.getTime();
        if (l > 0) {
            a = true
        }
        return a
    },
    fetchAttribute: function(d, c, e, b) {
        if (document.getElementById("docItemList[" + b + "].deleted").checked) {
            alert("Attributes of deleted item can not be seen");
            return false
        }
        var f = document.getElementById("docItemList[" + b + "].id").value;
        if (f = "") {
            alert("id null");
            return false
        }
        var a = {
            "currItem.id": d,
            "currItem.code": c,
            "currItem.docItmSrlNo": e
        };
        document.orderitemAddForm.buttonValue.value = "attr";
        Controller.onSubmit("orderitemAddForm", a, "saveDocItemList", "attr", null)
    },
    checkIfAllRowsFilledUp: function(d, c) {
        var b = null;
        for (var a = d; a >= 0; a--) {
            b = document.getElementById("docItemList[" + a + "].code").value;
            if (b == "") {
                alert(c);
                return false
            }
        }
        document.orderitemAddForm.buttonValue.value = "next";
        Controller.onSubmit("orderitemAddForm", null, "saveDocItemList", "next")
    },
    goToOrder: function() {
        document.orderitemAddForm.button.value = "doc";
        return true
    },
    doPrev: function() {
        document.orderitemAddForm.button.value = "prev";
        return true
    },
    doNext: function() {
        document.orderitemAddForm.button.value = "next";
        return true
    },
    loadOrder: function(b) {
        var a = pageScope.order;
        if (null == a) {
            alert("Please select an order");
            return
        }
        a.id = a["order.id"];
        Controller.loadPage(contextRoot + "/business/order.handle?methodName=getDoc&" + b, pageScope.order, null)
    },
    viewOrder: function(b, a) {
        if (null == b) {
            alert("Please select an order");
            return
        }
        Controller.loadPage(contextRoot + "/business/order.handle?methodName=getDoc&viewMode=true&id=" + b + "&" + a, null, null)
    },
    ammend: function(c, b, e, d) {
        var a = document.updateForm.orderId.value;
        if (a == null || a == "") {
            alert("Please select an order");
            return
        }
        document.updateForm.flag.value = c;
        document.updateForm.oldOrderId.value = a;
        if (!b) {
            Controller.onSubmit("updateForm", {
                orderId: a,
                flag: c,
                tokenName: d
            }, "ammendOrder", null)
        } else {
            Controller.loadPage(contextRoot + "/business/work.handle?methodName=initApproval&spec.code=ORDER_CREATION&" + e + "=" + d + "&addlBusinessRefStr=ammendOrder$" + a + "$" + c, null, null)
        }
    },
    cancelPO: function(c, b, e, d) {
        var a = document.cancelForm.orderId.value;
        if (a == null || a == "") {
            alert("Please select an order for cancel");
            return
        }
        document.cancelForm.flag.value = c;
        if (!b) {
            Controller.onSubmit("cancelForm", {
                orderId: a,
                flag: c,
                tokenName: d
            }, "cancelOrder", null)
        } else {
            Controller.loadPage(contextRoot + "/business/work.handle?methodName=initApproval&spec.code=ORDER_CREATION&" + e + "=" + d + "&addlBusinessRefStr=cancelOrder$" + a + "$" + c, null, null)
        }
    },
    respondToOrder: function(a) {
        document.orderViewForm.action = "getOrderResponseAction.do";
        document.orderViewForm.action = contextRoot + "/business/getOrderResponseAction.do?documentIdentity=" + a;
        document.orderViewForm.target = "_self";
        document.orderViewForm.submit()
    },
    printOrder: function(b, c, a) {
        document.printOrderForm.orgId.value = b;
        document.printOrderForm.formulaEnabled.value = c;
        document.printOrderForm.flag.value = a;
        document.printOrderForm.target = "_blank";
        document.printOrderForm.submit()
    },
    modalwin: function(orgType, csrfToken) {
        var entityId = document.getElementById("id").value;
        var docCode = document.getElementById("code").value;
        var docCreateDate = document.getElementById("updateDate").value;
        var docOwnerId = document.getElementById("createId").value;
        var url = contextRoot + "/business/clarification.action?popUp=Y&methodName=getClarification&clarType=ORDCLAR_BUYER&entityId=" + entityId + "&docCode=" + docCode + "&docCreateDate=" + docCreateDate + "&" + csrfToken;
        if (orgType == "SELLER") {
            url = contextRoot + "/business/clarification.action?popUp=Y&methodName=getClarification&clarType=ORDCLAR_SELLER&entityId=" + entityId + "&docCode=" + docCode + "&docCreateDate=" + docCreateDate + "&docOwnerId=" + docOwnerId + "&" + csrfToken
        }
        eval('window.showModalDialog(url,"","resizable:1;dialogWidth:800px; dialogHeight:600px; dialogLeft:300px;")')
    },
    viewDeliverySchedule: function() {
        Controller.onSubmit("orderitemAddForm", null, "viewDeliverySchedule", null, null)
    },
    manualEntry: function(a) {
        $("tr[id^='sellerUser_role_']").each(function(c) {
            var h = this.id;
            var b = h.split("_index_");
            var g = b[1];
            var f = "btn_index_" + a;
            f = f.toString();
            var e = document.getElementById(f).innerHTML;
            e = e.toString();
            if (a == g) {
                var d = "orderSellerUsers[" + g + "].sellerInformation";
                if (e == "INPUT") {
                    field_information_id = document.getElementById(d);
                    field_information_id.style.display = "block"
                }
            }
        })
    },
    printSupplierOrder: function(b, c, a, d) {
        document.printSupplierOrderForm.orgId.value = b;
        document.printSupplierOrderForm.flag.value = a;
        document.printSupplierOrderForm.orgTypeId.value = d;
        document.printSupplierOrderForm.formulaEnabled.value = c;
        document.printSupplierOrderForm.target = "_blank";
        document.printSupplierOrderForm.submit()
    }
};
var InspectionController = {
    selectIR: function(g, f, a, b, d, e, h, m, l, j, k, n, c) {
        pageScope.ir = {
            "order.id": f,
            "order.code": g,
            "order.orderInheritanceCode": a,
            "order.createDate": b,
            code: e,
            inspectionDate: h,
            id: d,
            rejectionReason: m,
            groupId: l,
            status: k,
            uniqueEntNo: n,
            "order.orderDate": c
        };
        pageScope.irForIc = {
            "insReq.order.id": f,
            "insReq.order.code": g,
            "insReq.order.orderInheritanceCode": a,
            "insReq.order.createDate": b,
            "insReq.code": e,
            "insReq.inspectionDate": h,
            "insReq.id": d,
            "insReq.irType": j,
            "insReq.uniqueEntNo": n
        };
        if (sessionScope._currPrivId == 101) {
            $("#editIr").css("display", "inline")
        }
        if (sessionScope._currPrivId == 107) {
            $("#assIr").css("display", "inline")
        }
        if (sessionScope._currPrivId == 122) {
            $("#forIr").css("display", "inline")
        }
        if (sessionScope._currPrivId == 104) {
            $("#resIr").css("display", "inline")
        }
        if (sessionScope._currPrivId == 123) {
            $("#clrIr").css("display", "inline")
        }
        if (sessionScope._currDocId == 107 && sessionScope._currPrivId == 100) {
            $("#addIc").css("display", "inline")
        }
        if (sessionScope._currPrivId == 102) {
            $("#viewIr").css("display", "inline")
        }
    },
    selectIRItem: function(a, c, b, d) {
        pageScope.irItem = {
            "currItem.orderItem.id": a,
            "currItem.orderItem.code": c,
            "currItem.orderItem.docItmSrlNo": b,
            "currItem.id": d
        };
        $("#attr").css("display", "inline")
    },
    selectICItem: function(b, c, d, a) {
        pageScope.icItem = {
            "insReqItem.id": b,
            "currItem.srlNo": c,
            "currItem.id": d,
            "currItem.code": a
        };
        $("#attr").css("display", "inline")
    },
    selectIC: function(e, a, d, b, c) {
        pageScope.ic = {
            id: e,
            "insReq.code": a,
            "insReq.inspectionDate": d,
            certCode: b,
            certDate: c
        };
        if (sessionScope._currDocId == 107) {
            if (sessionScope._currPrivId == 101) {
                $("#editIc").css("display", "inline")
            }
        }
        if (sessionScope._currPrivId == 106) {
            $("#appIc").css("display", "inline")
        }
        if (sessionScope._currPrivId == 102) {
            $("#viewIc").css("display", "inline")
        }
    },
    showIC: function(f, b, e, c, d, a) {
        pageScope.ic = {
            id: f,
            "insReq.code": b,
            "insReq.inspectionDate": e,
            certCode: c,
            certDate: d
        };
        if (sessionScope._currPrivId == 102 || sessionScope._currPrivId == 106) {
            InspectionController.viewIC(f, b, e, c, d, a)
        }
    },
    viewIC: function(g, b, f, e, d, a) {
        var c = contextRoot + "/business/ic.action?methodName=getDoc&viewMode=true&id=" + g + "&certCode=" + e + "&certDate=" + d + "&insReq.code=" + b + "&insReq.inspectionDate=" + f + "&" + a;
        window.open(c, "_newWindow", "top=0, left=0, height=500,menubar=yes,scrollable=yes,scrollbars=1,width=600,resizable=yes")
    },
    modalwin: function(orgType) {
        var entityId = document.getElementById("id").value;
        var docCode = document.getElementById("code").value;
        var docCreateDate = document.getElementById("createDate").value;
        var docOwnerId = document.getElementById("createId").value;
        var url = contextRoot + "/business/clarification.action?popUp=Y&methodName=getClarification&clarType=IRCLAR_BUYER&entityId=" + entityId + "&docCode=" + docCode + "&docCreateDate=" + docCreateDate + "&docOwnerId=" + docOwnerId;
        if (orgType == "SELLER") {
            url = contextRoot + "/business/clarification.action?popUp=Y&methodName=getClarification&clarType=IRCLAR_SELLER&entityId=" + entityId + "&docCode=" + docCode + "&docCreateDate=" + docCreateDate
        }
        eval('window.showModalDialog(url,"","resizable:1,dialogHeight:600,dialogWidth:400")')
    },
    initRevalidation: function() {
        Controller.onSubmit("inspectionCertViewForm", null, "initRevalidation", null, null)
    },
    viewRevalidationHistory: function() {
        Controller.onSubmit("inspectionCertViewForm", null, "viewRevalidationHistory", null, null)
    },
    saveForeclosure: function() {
        Controller.onSubmit("inspectionForm", null, "saveForeclosure", null, null)
    },
    revalidateIC: function() {
        Controller.onSubmit("inspectionCertViewForm", null, "revalidateIC", null, null)
    },
    showPrint: function() {
        document.printIrForm.target = "_blank";
        document.printIrForm.submit()
    },
    showIcPrint: function() {
        document.printIcForm.target = "_blank";
        document.printIcForm.submit()
    }
};
var IndentController = {
    fetchAttribute: function(b, a) {
        document.indentItemForm.selectedIndentItemId.value = b;
        IndentController.saveDocItemListWithCsrf("indentItemForm", "saveDocItemList", "attr", a)
    },
    saveDocItemListWithCsrf: function(formName, methodname, buttonName, csrfToken) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodname, null, null)
    },
    addRow: function(g) {
        tbody = document.getElementById(g);
        var d = tbody.rows.length;
        if (d < 0) {
            d = 0
        }
        if (d > 0) {
            var e = document.getElementById("indentSpecialTerm[" + (d - 1) + "].bigIndentTermLineDescription")
        }
        var c = document.indentForm.termCount.value;
        c = c - 1;
        var f = document.getElementById(g);
        var a = f.getElementsByTagName("tr")[c].parentNode;
        var h = f.getElementsByTagName("tr")[c].cloneNode(true);
        var b = h.getElementsByTagName("input");
        b[0].setAttribute("name", "indentSpecialTerm[" + d + "].indentTermSerialNumber");
        b[0].setAttribute("value", (d + 1));
        var b = h.getElementsByTagName("select");
        b[0].setAttribute("name", "indentSpecialTerm[" + d + "].indentTermTerm.id");
        b[0].setAttribute("value", "-1");
        var b = h.getElementsByTagName("textarea");
        b[0].setAttribute("name", "indentSpecialTerm[" + d + "].bigIndentTermLineDescription");
        b[0].setAttribute("value", "");
        h.setAttribute("id", "r" + c);
        a.appendChild(h);
        document.indentForm.termCount.value = parseFloat(c) + 1
    },
    deleteRow: function(b, a) {
        var c = document.getElementById("r" + a.id);
        tbody = document.getElementById(b);
        if (tbody.rows.length == 2) {
            alert("The first row cannot be removed.");
            return
        }
        if (confirm('<fmt:message key="global.field.delete.specialTerm" />')) {
            tbody.deleteRow(a + 1)
        }
    },
    onTermAdd: function() {
        var a = $("#termTab tr:last");
        var b = $("#termTab tr").length;
        $("td:first", a).text(b);
        $('[id$=".srlNo"]', a).attr("value", b)
    },
    selectIndent: function(b, a) {
        pageScope.indent = {
            id: b,
            categoryId: a
        };
        if (sessionScope._currPrivId == 102) {
            $("#viewIndent").css("display", "inline")
        }
        if (sessionScope._currPrivId == 101) {
            $("#editIndent").css("display", "inline")
        }
    },
    selectIndentItem: function(c, d, b, a) {
        pageScope.indentItem = {
            "currItem.id": c,
            "currItem.code": d,
            "currItem.docItmSrlNo": b,
            index: a
        };
        log("Page setting done" + pageScope.indentItem.index);
        $("#attr").css("display", "inline")
    },
    toAttribute: function() {
        if (document.getElementsByName("docItemList[" + pageScope.indentItem.index + "].deleted")[0].checked) {
            alert("Please uncheck the delete box before viewing attributes");
            return false
        }
        Controller.onSubmit(null, pageScope.indentItem, "saveDocItemList", "attr")
    },
    nextItemList: function(b) {
        var a = null;
        if (Controller.getBlankRows("].code") > 0) {
            alert("Please populate all the rows before proceeding to next page");
            return false
        }
        Controller.onSubmit(null, null, "saveDocItemList", "next")
    },
    getItemDetail: function(f, c) {
        var b = document.getElementById("csrfTokenName").value;
        var e = document.getElementById("csrfTokenValue").value;
        var a = b + "=" + e;
        var d = $("form[id!='dummyForm']");
        $('input[id$=".code"]', d).each(function() {
            this.disabled = true
        });
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getItem&code=" + c.value + "&" + a, null, function(g) {
            $('input[id$=".code"]', d).each(function() {
                this.disabled = false
            });
            if (g._errors != null) {
                Util.showMessage(g);
                document.getElementById("docItemList[" + f + "].code").value = "";
                return
            }
            Util.clearContent($("#_msgBox"));
            document.getElementById("docItemList[" + f + "].bigIndentItemLineDescription").value = Controller.unescapeHtml(g.item.description)
        })
    }
};
var RfqController = {
    attachItemListWithSeller: function(c, e, f, d, a) {
        var b = contextRoot + "/business/rfq.action?methodName=getItemListforSeller&viewMode=" + d + "&selectedSellerId=" + f + "&entityId=" + c + "&partNumber=" + e + "&" + a;
        window.open(b, "getAttachItemListWithSeller_window", "width=800,height=500,scrollbars=yes,resizable=yes,menubar=no,directories=no,location=no")
    },
    rejectionItemSubmit: function(d, a, c, b) {
        document.getElementById("rfqPartNo").value = d;
        Controller.onSubmitWithCsrf(c, a, b, null, null)
    },
    getItemDetail: function(f, d, a) {
        var e = $("form[id!='dummyForm']");
        var b = 0;
        var c = $("input[name='nonExistingRfqItemAdd']", e).val();
        $('input[id$=".code"]', e).each(function() {
            this.disabled = true
        });
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getItem&code=" + d.value + "&" + a, null, function(o) {
            $('input[id$=".code"]', e).each(function() {
                this.disabled = false
            });
            if (o._errors != null) {
                Util.showMessage(o);
                document.getElementById("rfqItem[" + f + "].code").value = "";
                return
            }
            Util.clearContent($("#_msgBox"));
            if (o.item.id == 0 && c == "false") {
                alert("Item does not exist");
                document.getElementById("rfqItem[" + f + "].bigRfqItemLineDescription").value = "";
                document.getElementById("rfqItem[" + f + "].bigRfqItemLineDescription").disabled = true
            }
            if (o.item.id > 0) {
                document.getElementById("rfqItem[" + f + "].bigRfqItemLineDescription").disabled = false
            }
            if (Controller.unescapeHtml(o.item.description) != null && Controller.unescapeHtml(o.item.description) != "") {
                document.getElementById("rfqItem[" + f + "].bigRfqItemLineDescription").value = Controller.unescapeHtml(o.item.description)
            }
            var m = document.getElementById("rfqItem[" + f + "].rfqItemQuantity").value;
            var l = m * o.item.estimatedValue;
            document.getElementById("rfqItem[" + f + "].rfqItemItem.estimatedValue").value = o.item.estimatedValue;
            document.getElementById("rfqItem[" + f + "].rfqItemPrice").value = l;
            if (document.getElementById("buyerOrgId")) {
                b = document.getElementById("buyerOrgId").value
            }
            if (b == 2350) {
                if (o.item.isServiceItemYN == "Y") {
                    document.getElementById("rfqItem[" + f + "].bigRfqItemLineDescription").readOnly = false;
                    document.getElementById("rfqItem[" + f + "].bigRfqItemLineDescription").removeAttribute("readonly")
                } else {
                    document.getElementById("rfqItem[" + f + "].bigRfqItemLineDescription").readOnly = true
                }
            }
            var n = new Array();
            var h = 0;
            if (o.length == 0) {
                return
            }
            var g = "item.action?popUp=Y&methodName=openItemAttachment&itemId=" + o.item.id + "&fileName=";
            for (var k = 0; k < o.item.attachments.length; k++) {
                n[h++] = '<div><input name="rfqItem[';
                n[h++] = f;
                n[h++] = "].possibleAttachments[";
                n[h++] = k;
                n[h++] = "].selected";
                n[h++] = '" type="checkbox" value="true"/>';
                n[h++] = '<a target = "_new" href="';
                n[h++] = g + o.item.attachments[k].fileName + "&ext=" + o.item.attachments[k].extention + "&" + a;
                n[h++] = '">';
                n[h++] = o.item.attachments[k].label;
                n[h++] = "</a>";
                n[h++] = '<input name="rfqItem[';
                n[h++] = f;
                n[h++] = "].possibleAttachments[";
                n[h++] = k;
                n[h++] = "].fileName";
                n[h++] = '" type="hidden" value="';
                n[h++] = o.item.attachments[k].fileName;
                n[h++] = '"/>';
                n[h++] = "</div>"
            }
            var p = document.getElementById("inItemTab" + f);
            p.rows[3].cells[1].innerHTML = n.join("")
        })
    },
    getItem: function(a) {
        var d = $("form[id!='dummyForm']", "#_content");
        var c = $('input[id="code"]', d).get(0);
        if (c.value == "") {
            return
        }
        var b = document.getElementById("isServiceItemYN").value;
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getItem&code=" + c.value + "&isServiceItemYN=" + b + "&" + a, null, function(e) {
            if (e._errors != null) {
                log(e);
                Util.showMessage(e);
                return
            } else {}
            if (e.item.id == 0) {
                alert("This item does not exist")
            }
            Util.clearContent($("#_msgBox"));
            $('input[id="code"]', d).attr("readonly", "readonly");
            $("#attachmentTab", d).css("display", "block");
            $('input[id="id"]', d).val(e.item.id);
            $('textarea[id="description"]', d).val(Controller.unescapeHtml(e.item.description));
            $('input[id="estimatedValue"]', d).val(e.item.estimatedValue)
        })
    },
    viewUserContact: function(b) {
        var a = 600;
        var c = 600;
        var e = (screen.width / 2) - (a / 2);
        var d = (screen.height / 2) - (c / 2);
        document.viewUserContactForm.profileIdentity.value = b;
        window.open("", "userContactView_window", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + a + ", height=" + c + ", top=" + d + ", left=" + e);
        document.viewUserContactForm.target = "userContactView_window";
        document.viewUserContactForm.submit()
    },
    submitPaymentForm: function() {
        document.PaymentInitForm.methodName.value = "getRfqsByPaymentStatus";
        document.PaymentInitForm.submit()
    },
    viewDelegateToUserListContact: function(c, b, a) {
        var d = contextRoot + "/business/rfq.action?methodName=getRfqDelegateToUserListContactDetail&rfqId=" + b + "&rfqSellerUserId=" + c + "&rfqPartNumber=" + a;
        window.open(d, "rfqDelegateToUserContactView_window", "top=0, left=510, height=400, width=700, toolbar=no, status=no,scrollbars=yes")
    },
    deleteRfqSection: function(formName, csrfToken, methodName, entityId, entityValue, docSectionId, docTemplateId) {
        eval("document." + formName).entityId.value = entityId;
        eval("document." + formName).entityValue.value = entityValue;
        eval("document." + formName).documentSectionId.value = docSectionId;
        eval("document." + formName).documentConfigTemplateId.value = docTemplateId;
        eval("document." + formName).methodName.value = methodName;
        if (entityId == 100) {
            if (confirm("Delete the Section from the Rfq?")) {
                eval("document." + formName).submit()
            }
        }
    },
    retrieveRfqSection: function(formName, csrfToken, methodName, entityId, entityValue, docSectionId, docTemplateId) {
        eval("document." + formName).entityId.value = entityId;
        eval("document." + formName).entityValue.value = entityValue;
        eval("document." + formName).documentSectionId.value = docSectionId;
        eval("document." + formName).documentConfigTemplateId.value = docTemplateId;
        eval("document." + formName).methodName.value = methodName;
        eval("document." + formName).submit()
    },
    getCorrigendumItemDetail: function(e, c, a) {
        var d = $("form[id!='dummyForm']");
        var b = 0;
        $('input[id$=".code"]', d).each(function() {
            this.disabled = true
        });
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getItem&code=" + c.value + "&" + a, null, function(n) {
            $('input[id$=".code"]', d).each(function() {
                this.disabled = false
            });
            if (n._errors != null) {
                Util.showMessage(n);
                document.getElementById("domain.rfqItem[" + e + "].code").value = "";
                return
            }
            Util.clearContent($("#_msgBox"));
            document.getElementById("domain.rfqItem[" + e + "].bigRfqItemLineDescription").value = n.item.description;
            var l = document.getElementById("domain.rfqItem[" + e + "].rfqItemQuantity").value;
            var k = l * n.item.estimatedValue;
            document.getElementById("domain.rfqItem[" + e + "].rfqItemItem.estimatedValue").value = n.item.estimatedValue;
            document.getElementById("domain.rfqItem[" + e + "].rfqItemPrice").value = k;
            if (document.getElementById("buyerOrgId")) {
                b = document.getElementById("buyerOrgId").value
            }
            if (b == 2350) {
                if (n.item.isServiceItemYN == "Y") {
                    document.getElementById("domain.rfqItem[" + e + "].bigRfqItemLineDescription").readOnly = false;
                    document.getElementById("domain.rfqItem[" + e + "].bigRfqItemLineDescription").removeAttribute("readonly")
                } else {
                    document.getElementById("domain.rfqItem[" + e + "].bigRfqItemLineDescription").readOnly = true
                }
            }
            var m = new Array();
            var g = 0;
            if (n.length == 0) {
                return
            }
            var f = "item.action?popUp=Y&methodName=openItemAttachment&itemId=" + n.item.id + "&fileName=";
            for (var h = 0; h < n.item.attachments.length; h++) {
                m[g++] = '<div><input name="domain.rfqItem[';
                m[g++] = e;
                m[g++] = "].possibleAttachments[";
                m[g++] = h;
                m[g++] = "].selected";
                m[g++] = '" type="checkbox" value="true"/>';
                m[g++] = '<a target = "_new" href="';
                m[g++] = f + n.item.attachments[h].fileName + "&ext=" + n.item.attachments[h].extention + "&" + a;
                m[g++] = '">';
                m[g++] = n.item.attachments[h].label;
                m[g++] = "</a>";
                m[g++] = '<input name="domain.rfqItem[';
                m[g++] = e;
                m[g++] = "].possibleAttachments[";
                m[g++] = h;
                m[g++] = "].fileName";
                m[g++] = '" type="hidden" value="';
                m[g++] = n.item.attachments[h].fileName;
                m[g++] = '"/>';
                m[g++] = "</div>"
            }
            var o = document.getElementById("inItemTab" + e);
            o.rows[3].cells[1].innerHTML = m.join("")
        })
    },
    initRfqNoteSheet: function(rfqId, partNo, csrfToken, methodName, formName) {
        if (document.quotationSearchForm.quotationRfqId.value == "") {
            alert("Please select a rfq");
            return
        }
        eval("document." + formName).methodName.value = methodName;
        eval("document." + formName).submit()
    },
    attachTermWithSeller: function(h, e, g, d, b, f, a) {
        var c = contextRoot + "/business/rfq.handle?methodName=" + b + "&viewMode=" + f + "&selectedSellerId=" + g + "&id=" + h + "&rfqDate.partNumber=" + e + "&rfqCategory.id=" + d + "&" + a;
        window.open(c, "rfqTermUser_window", "width=800,height=500,scrollbars=yes,resizable=yes,menubar=no,directories=no,location=no")
    },
    trialQuotationItemSubmit: function(c, b, a) {
        document.getElementById("rfqPartNo").value = c;
        Controller.onSubmit(b, a, null, null)
    }
};
var CategoryController = {
    selectCat: function(a) {
        pageScope.cat = {
            categoryId: a
        };
        $("#catDtl").css("display", "inline")
    }
};
var ItemController = {
    selectItem: function(c, b, a) {
        pageScope.item = {
            itemId: c,
            itemCode: b,
            isServiceItemYN: a
        };
        $("#itemDtl").css("display", "inline")
    },
    getLot: function(a) {
        var c = $("form[id!='dummyForm']", "#_content");
        var b = $('input[id="itemCatCode"]', c).get(0);
        if (b.value == "") {
            return
        }
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getLot&itemCatCode=" + b.value + "&" + a, null, function(d) {
            if (d._errors != null) {
                log(d);
                Util.showMessage(d);
                return
            }
            Util.clearContent($("#_msgBox"));
            $('input[id="itemCatCode"]', c).attr("readonly", "readonly");
            $('input[id="id"]', c).val(d.lot.id);
            $('textarea[id="description"]', c).val(d.lot.description)
        })
    },
    getUnit: function(a) {
        var c = $("form[id!='dummyForm']", "#_content");
        var b = $('input[id="code"]', c).get(0);
        if (b.value == "") {
            return
        }
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getUnit&code=" + b.value + "&" + a, null, function(d) {
            if (d._errors != null) {
                log(d);
                Util.showMessage(d);
                return
            }
            Util.clearContent($("#_msgBox"));
            $('input[id="code"]', c).attr("readonly", "readonly");
            $('input[id="id"]', c).val(d.unit.id);
            $('textarea[id="description"]', c).attr("readonly", "readonly");
            $('textarea[id="description"]', c).val(d.unit.description);
            $('select[id="allowDecimal"]', c).attr("disabled", "true");
            $('select[id="allowDecimal"]', c).val(d.unit.allowDecimal);
            $('button[id="submitDoc"]', c).hide()
        })
    },
    getDescriptionByLotCode: function(d) {
        var c = $("form[id!='rfqAddForm']", "#_content");
        var b = $("#selectId option:selected", c).text();
        var a = $("#csrfToken").val();
        if ($("#selectId option:selected", c).val() == "0") {
            $("#selectDescription", c).html("");
            return
        }
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getLotDescriptionByLotCode&itemCatCode=" + b + "&" + a, null, function(e) {
            if (e._errors != null) {
                log(e);
                Util.showMessage(e);
                return
            }
            Util.clearContent($("#_msgBox"));
            $("#selectDescriptionId", c).html("<textarea  name='rfqItemCatList[" + d + "].description' rows='3' cols='20'>" + e.lot.description + "</textarea>");
            $("#lastPurchasedPriceId", c).html("<input type='text' name='rfqItemCatList[" + d + "].lastPurchasedPrice' value='0.0' />")
        })
    }
};
var ReceiptController = {
    selectReceiptItem: function(c, d, b, a) {
        pageScope.receiptItem = {
            "currItem.id": c,
            "currItem.code": d,
            "currItem.docItmSrlNo": b,
            index: a,
            "currItem.description": document.getElementById("docItemList[" + a + "].description").value,
            "currItem.quantityAdviced": document.getElementById("docItemList[" + a + "].quantityAdviced").value,
            "currItem.quantityReceived": document.getElementById("docItemList[" + a + "].quantityReceived").value,
            "currItem.quantityAccepted": document.getElementById("docItemList[" + a + "].quantityAccepted").value
        };
        log("Page setting done" + pageScope.receiptItem.index);
        $("#attr").css("display", "inline")
    },
    selectReceipt: function(d, b, c, a) {
        pageScope.receipt = {
            id: d,
            "order.code": b
        };
        if (null != c) {
            Controller.loadPage(contextRoot + "/business/receipt.handle?methodName=getDoc&viewMode=true&" + a, pageScope.receipt, null)
        }
    },
    selectDraftReceipt: function(b, a) {
        pageScope.receipt = {
            "receipt.id": b,
            "receipt.code": a
        }
    },
    onDiscAdd: function() {
        log("onDiscAdd ");
        var a = $("#discTab tr:last");
        $('[id$=".id"]', a).attr("value", "0")
    },
    loadReceipt: function(a) {
        var b = pageScope.receipt;
        if (null == b) {
            alert("Please select a receipt");
            return
        }
        b.id = b["receipt.id"];
        Controller.loadPage(contextRoot + "/business/receipt.handle?methodName=getDoc&" + a, pageScope.receipt, null)
    },
    printReceipt: function(c, a, b) {
        document.receiptPrintForm.action = "report.action";
        document.receiptPrintForm.methodName.value = "showReport";
        document.receiptPrintForm.reportName.value = "receiptViewPrint";
        document.receiptPrintForm.popUp.value = "Y";
        document.receiptPrintForm.receiptId.value = c;
        document.receiptPrintForm.orgId.value = a;
        document.receiptPrintForm.orgName.value = b;
        document.receiptPrintForm.target = "_blank";
        document.receiptPrintForm.submit()
    },
    viewReceipt: function(b, a) {
        if (null == b) {
            alert("Please select an Receipt");
            return
        }
        Controller.loadPage(contextRoot + "/business/receipt.handle?methodName=getDoc&viewMode=true&id=" + b + "&" + a, null, null)
    },
    calculateRejectedItem: function(c) {
        var e = +$("input:text[name='docItemList[" + c + "].quantityAdviced']").val();
        var b = +$("input:text[name='docItemList[" + c + "].quantityReceived']").val();
        var a = +$("input:text[name='docItemList[" + c + "].quantityAccepted']").val();
        var d = b - a;
        if (a > b || d < 0) {
            alert("Accepted Item Quantity must be lesser than Received Item Quantity");
            return
        }
        $("input:text[name='docItemList[" + c + "].quantityRejected']").val(d)
    },
    showAcceptedItemDetails: function(c) {
        var e = document.getElementById("_div_" + c).style;
        if (e.display == "none") {
            document.getElementById("_div_" + c).style.display = "block";
            $("#_accept_item_" + c).html("Click to minimize")
        } else {
            var a = $("input:text[name='docItemList[" + c + "].quantityAccepted']").val();
            var d = $("input:text[name='docItemList[" + c + "].quantityFresh']").val();
            var f = $("input:text[name='docItemList[" + c + "].quantityReplaced']").val();
            var b = d + f;
            document.getElementById("_div_" + c).style.display = "none";
            $("#_accept_item_" + c).html("Details")
        }
    },
    hideAcceptedItemDetails: function(a) {
        document.getElementById("_div_" + a).style.display = "none";
        $("#_accept_item_" + a).html("Details")
    },
    fetchAttribute: function(b, a) {
        var c = {
            "currItem.id": b
        };
        document.receiptItemAddForm.buttonValue.value = "attr";
        Controller.onSubmit("receiptItemAddForm", c, "saveDocItemList", "attr", null)
    },
    submitReceipt: function() {
        if (confirm("Once Activated, the RECEIPT details can not be changed. Do you want to activate?")) {
            Controller.onSubmitWithCsrf("receiptAddForm", "<csrf:token-name/>=<csrf:token-value/>", "submitDoc", null, null)
        }
    },
    getAttachments: function(formName) {
        window.open("", "Receipt_Attachments", "top=150, left=110, height=500, width=1000, toolbar=no, status=no ,scrollbars=1,resizable=1");
        eval("document." + formName).target = "Receipt_Attachments";
        eval("document." + formName).submit()
    }
};
var attachmentController = {
    addAttach: function(g) {
        tbody = document.getElementById(g);
        var e = tbody.rows.length - 2;
        if (e < 0) {
            e = 0
        }
        if (!attachmentController.validateAttach(e)) {
            return
        }
        e = e - 1;
        var d = tbody.insertRow(tbody.rows.length);
        var f = d.insertCell(0);
        f.setAttribute("class", "dataClass");
        f.innerHTML = '<input type="text" size="20" name="attachments[' + e + '].label"/>';
        var c = d.insertCell(1);
        c.setAttribute("class", "dataClass");
        c.innerHTML = '<input type="text" size="20" id="attachments[' + e + '].fileName" name="attachments[' + e + '].fileName"/><input type="hidden" name="attachments[' + e + '].digitalCert.signHash"/>';
        var b = d.insertCell(2);
        b.setAttribute("class", "dataClass");
        b.setAttribute("title", "Allowable Extensions:" + $("input[name='fileExtension']").val());
        b.setAttribute("style", "word-wrap:break-word");
        b.innerHTML = '<input type="file" size="20" name="attachments[' + e + '].file" />';
        var a = d.insertCell(3);
        a.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + (e + 1) + ');">DELETE ROW</a>'
    },
    addAttachCorrigendum: function(a, d) {
        tbody = document.getElementById(a);
        var b = tbody.rows.length - 2;
        if (b < 0) {
            b = 0
        }
        if (!attachmentController.validateAttach(b)) {
            return
        }
        var j = tbody.insertRow(tbody.rows.length);
        var h = j.insertCell(0);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" name="domain.attachments[' + b + '].label"/>';
        var g = j.insertCell(1);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="domain.attachments[' + b + '].fileName"/><input type="hidden" name="domain.attachments[' + b + '].digitalCert.signHash"/>';
        var f = j.insertCell(2);
        f.setAttribute("class", "dataClass");
        f.setAttribute("title", "Allowable Extensions:" + $("input[name='fileExtension']").val());
        f.setAttribute("style", "word-wrap:break-word");
        f.innerHTML = '<input type="file" size="20" name="domain.attachments[' + b + '].file" />';
        var e = j.insertCell(3);
        e.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + b + ');">DELETE ROW</a>';
        if (d) {
            var c = j.insertCell(4);
            c.innerHTML = '<a class="pageContentLink" href="javascript:signCorrigendumAttachmentFile(' + b + ');">SIGN FILE</a>'
        }
    },
    addCorrAttach: function(b, d, f) {
        var a = "attachTab_" + d;
        tbody = document.getElementById(a);
        var c = tbody.rows.length - 2;
        if (c < 0) {
            c = 0
        }
        if (!attachmentController.validateCorrItemAttach(c, d)) {
            return
        }
        var l = tbody.insertRow(tbody.rows.length);
        var k = l.insertCell(0);
        k.setAttribute("class", "dataClass");
        k.innerHTML = '<input type="text" size="20" name="domain.rfqItem[' + d + "].attachments[" + c + '].label"/>';
        var j = l.insertCell(1);
        j.setAttribute("class", "dataClass");
        j.innerHTML = '<input type="text" size="20" name="domain.rfqItem[' + d + "].attachments[" + c + '].fileName"/><input type="hidden" name="domain.rfqItem[' + d + "].attachments[" + c + '].digitalCert.signHash"/>';
        var h = l.insertCell(2);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="file" size="20" name="domain.rfqItem[' + d + "].attachments[" + c + '].file"/>';
        var g = l.insertCell(3);
        g.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delItemAttach(' + c + "," + d + ');">DELETE ROW</a>';
        if (f == true) {
            var e = l.insertCell(4);
            e.innerHTML = '<a class="pageContentLink" href="javascript:signCorrigendumAttachmentFile(' + c + "," + d + ');">SIGN FILE</a>'
        }
    },
    validateCorrItemAttach: function(b, a) {
        var d = 30;
        if (b == d) {
            alert("Maximum " + d + " attachments can be added");
            return false
        }
        if (b > 0) {
            var c = document.getElementById("domain.rfqItem[" + a + "].attachments[" + (b - 1) + "].label");
            if (null != c) {
                if ((c.value == "") || (c.value == null)) {
                    alert("Please specify the Label for previous row");
                    return false
                }
            }
        }
        return true
    },
    addItemAttach: function(a, d) {
        var b = document.getElementById(a);
        var c = b.rows.length - 2;
        if (c < 0) {
            c = 0
        }
        if (!attachmentController.validateItemAttach(c, d)) {
            return
        }
        var j = b.insertRow(b.rows.length);
        var h = j.insertCell(0);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" name="docItemList[' + d + "].attachments[" + c + '].label"/>';
        var g = j.insertCell(1);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="docItemList[' + d + "].attachments[" + c + '].fileName"/><input type="hidden" name="docItemList[' + d + "].attachments[" + c + '].digitalCert.signHash"/>';
        var f = j.insertCell(2);
        f.setAttribute("class", "dataClass");
        f.innerHTML = '<input type="file" size="40" name="docItemList[' + d + "].attachments[" + c + '].file"/>';
        var e = j.insertCell(3);
        e.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delItemAttach(' + c + "," + d + ');">DELETE ROW</a>'
    },
    addPostActivationAttach: function(g) {
        tbody = document.getElementById(g);
        var e = tbody.rows.length - 2;
        if (e < 0) {
            e = 0
        }
        if (!attachmentController.validatePostActivationAttach(e)) {
            return
        }
        var d = tbody.insertRow(tbody.rows.length);
        var f = d.insertCell(0);
        f.setAttribute("class", "dataClass");
        f.innerHTML = '<input type="text" size="20" name="postActivationAttachments[' + e + '].label"/>';
        var c = d.insertCell(1);
        c.setAttribute("class", "dataClass");
        c.innerHTML = '<input type="text" size="20" name="postActivationAttachments[' + e + '].fileName"/><input type="hidden" name="postActivationAttachments[' + e + '].digitalCert.signHash"/>';
        var b = d.insertCell(2);
        b.setAttribute("class", "dataClass");
        b.innerHTML = '<input type="file" size="20" name="postActivationAttachments[' + e + '].file"/>';
        var a = d.insertCell(3);
        a.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + e + ');">DELETE ROW</a>'
    },
    addClarAttachment: function(a, d) {
        tbody = document.getElementById(a);
        var b = tbody.rows.length - 2;
        if (b < 0) {
            b = 0
        }
        if (!attachmentController.validateAttach(b)) {
            return
        }
        var j = tbody.insertRow(tbody.rows.length);
        var h = j.insertCell(0);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" name="attachments[' + b + '].label"/>';
        var g = j.insertCell(1);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="attachments[' + b + '].fileName" id="attachments[' + b + '].fileName" /><input type="hidden" name="attachments[' + b + '].digitalCert.signHash" name="attachments[' + b + '].digitalCert.signHash"/>';
        var f = j.insertCell(2);
        f.setAttribute("class", "dataClass");
        f.innerHTML = '<input type="file" size="20" name="attachments[' + b + '].file" name="attachments[' + b + '].file"/>';
        var e = j.insertCell(3);
        e.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + b + ');">DELETE ROW</a>';
        if (d) {
            var c = j.insertCell(4);
            c.innerHTML = '<a class="pageContentLink" href="javascript:signClarAttachmentFile(' + b + ');">SIGN FILE</a> <FONT COLOR="RED"><B> [Please sign the file before pressing SEND button] </B></FONT>'
        }
    },
    addRfqAttach: function(h) {
        tbody = document.getElementById(h);
        var f = tbody.rows.length - 2;
        if (f < 0) {
            f = 0
        }
        if (!attachmentController.validateAttach(f)) {
            return
        }
        f = f - 1;
        var e = tbody.insertRow(tbody.rows.length);
        var g = e.insertCell(0);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="attachments[' + f + '].label"/>';
        var d = e.insertCell(1);
        d.setAttribute("class", "dataClass");
        d.innerHTML = '<input type="text" size="20" name="attachments[' + f + '].fileName"/><input type="hidden" id="attachments[' + f + '].digitalCert.signHash" name="attachments[' + f + '].digitalCert.signHash"/>';
        var c = e.insertCell(2);
        c.setAttribute("class", "dataClass");
        c.innerHTML = '<input type="file" size="20" id="attachments[' + f + '].file" name="attachments[' + f + '].file"/>';
        var b = e.insertCell(3);
        b.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + f + ');">DELETE ROW</a>';
        var a = e.insertCell(4);
        a.innerHTML = '<a class="pageContentLink" href="javascript:signRfqAttachmentFile(' + f + ');">SIGN FILE</a> <FONT COLOR="RED"><B> [Please sign the file before pressing ATTACH/DEATCH button] </B></FONT>'
    },
    addPkiOrderAttach: function(h) {
        tbody = document.getElementById(h);
        var f = tbody.rows.length - 2;
        if (f < 0) {
            f = 0
        }
        if (!attachmentController.validateAttach(f)) {
            return
        }
        f = f - 1;
        var e = tbody.insertRow(tbody.rows.length);
        var g = e.insertCell(0);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="attachments[' + f + '].label"/>';
        var d = e.insertCell(1);
        d.setAttribute("class", "dataClass");
        d.innerHTML = '<input type="text" size="20" name="attachments[' + f + '].fileName"/><input type="hidden" id="attachments[' + f + '].digitalCert.signHash" name="attachments[' + f + '].digitalCert.signHash"/>';
        var c = e.insertCell(2);
        c.setAttribute("class", "dataClass");
        c.innerHTML = '<input type="file" size="20" id="attachments[' + f + '].file" name="attachments[' + f + '].file"/>';
        var b = e.insertCell(3);
        b.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + f + ');">DELETE ROW</a>';
        var a = e.insertCell(4);
        a.innerHTML = '<a class="pageContentLink" href="javascript:OrderController.signOrderAttachmentFile(' + f + ');">SIGN FILE</a>'
    },
    delAttach: function(c, b) {
        var a = "attachTab";
        tbody = document.getElementById(a);
        if (confirm("Delete The Attachment?")) {
            tbody.deleteRow(b + 2)
        }
    },
    delItemAttach: function(c, a) {
        var b = "attachTab_" + a;
        tbody = document.getElementById(b);
        if (confirm("Delete The Attachment?")) {
            tbody.deleteRow(c + 2)
        }
    },
    validateAttach: function(a) {
        var b = 30;
        if (a == b) {
            alert("Maximum " + b + " attachments can be added");
            return false
        }
        return true
    },
    validateItemAttach: function(b, a) {
        var d = 30;
        if (b == d) {
            alert("Maximum " + d + " attachments can be added");
            return false
        }
        if (b > 0) {
            var c = document.getElementById("docItemList[" + a + "].attachments[" + (b - 1) + "].label");
            if (null != c) {
                if ((c.value == "") || (c.value == null)) {
                    alert("Please specify the Label for previous row");
                    return false
                }
            }
        }
        return true
    },
    validatePostActivationAttach: function(a) {
        var c = 30;
        if (a == c) {
            alert("Maximum " + c + " attachments can be added");
            return false
        }
        if (a > 0) {
            var b = document.getElementById("postActivationAttachments[" + (a - 1) + "].label");
            if (null != b) {
                if ((b.value == "") || (b.value == null)) {
                    alert("Please specify the Label for previous row");
                    return false
                }
            }
        }
        return true
    },
    addRfiAttach: function(h) {
        alert("in moreRow");
        tbody = document.getElementById(h);
        var f = tbody.rows.length - 2;
        if (f < 0) {
            f = 0
        }
        if (!attachmentController.validateAttach(f)) {
            return
        }
        var e = tbody.insertRow(tbody.rows.length);
        var g = e.insertCell(0);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="attachments[' + f + '].label"/>';
        var d = e.insertCell(1);
        d.setAttribute("class", "dataClass");
        d.innerHTML = '<input type="text" size="20" name="attachments[' + f + '].fileName"/><input type="hidden" name="attachments[' + f + '].digitalCert.signHash"/>';
        var c = e.insertCell(2);
        c.setAttribute("class", "dataClass");
        c.innerHTML = '<input type="file" size="20" name="attachments[' + f + '].file"/>';
        var b = e.insertCell(3);
        b.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + f + ');">DELETE ROW</a>';
        var a = e.insertCell(4);
        a.innerHTML = '<a class="pageContentLink" href="javascript:signRfqAttachmentFile(' + f + ');">SIGN FILE</a>'
    },
    popupCenter: function(k, d) {
        $("input[name=attachFileHash]").val(k);
        var g = contextRoot + "/security/getVerifyFile.do?verifyFormname=" + d;
        var f = "selectFile";
        var j = 400;
        var b = 200;
        var a = (screen.width / 2) - (j / 2);
        var e = (screen.height / 2) - (b / 2);
        var c = window.open(g, f, "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=" + j + ", height=" + b + ", top=" + e + ", left=" + a)
    },
    validateFileName : function(formName){
    	//$('#'+formName).submit(function() {
    	var fileNameList = new Array();
    	var breakOut = false; 
    	$('input[type=text][id*=attachments][id$=fileName],input[type=text][id*=Attachments][id$=fileName],input[type=text][id*=quotationUploadFiles][id$=fileName]').each(function(){
    	var thisName=this.name;
        var labelName=thisName.replace('fileName','label');
     	var fileNameValue = $(this).val();

    	var alphaNumericUnderScorePattern = /[^a-zA-Z0-9 _-]/;
    	var mandatory="Y";
    	var mandatoryName=thisName.replace('fileName','mandatory');
    	if(document.getElementsByName(mandatoryName)[0]!=null){
    		mandatory=document.getElementsByName(mandatoryName)[0].value;
    	}
    	var availExemption="N";
    	var availExemptionName=thisName.replace('fileName','availExemption');
    	if(document.getElementsByName(availExemptionName)[0]!=null){
    		availExemption=document.getElementsByName(availExemptionName)[0].value;
    	}

    	var element =  document.getElementById(thisName.replace('fileName','id'));
    	if (typeof(element) != 'undefined' && element != null){
    		//doing nothing
    	}else{
    		if(document.getElementsByName(thisName.replace('fileName','file'))[0] != null){
    			var myFileVal=document.getElementsByName(thisName.replace('fileName','file'))[0].value;
    			var extension =   myFileVal.substr((myFileVal.lastIndexOf('.')));
    			fileNameValue = $.trim(fileNameValue).toLowerCase() + extension.toLowerCase();
    		}
    	}

    	if(!$.trim(fileNameValue).length && mandatory=="Y" && availExemption!="Y") {
    		alert('file name can not be empty');
    		$(this).focus();
    		breakOut = true;
    		return false;
    	}
    	if($.trim(fileNameValue).length){
    	if(jQuery.inArray(fileNameValue, fileNameList) == -1){
    		fileNameList.push($.trim(fileNameValue));
    	}else{
    		alert('duplicate file names are not allowed. Note that file name(s) considered are not case-sensitive.');
    		fileNameList.length = 0;
    		breakOut = true;
    		return false;
    	}
    	}
    	if(alphaNumericUnderScorePattern.test(fileNameValue.split('.')[0])) {
    	alert('your file name contains special characters');
    	$(this).focus();
    	breakOut = true;
    	return false;
    	}
    	//check for Label
    	//alert("1");
    	if(document.getElementsByName(labelName)[0]!=null){
    		var labelValue =document.getElementsByName(labelName)[0].value;
    		if(alphaNumericUnderScorePattern.test(labelValue.split('.')[0])) {
    		alert('your file label contains special characters');
    		document.getElementsByName(labelName)[0].value="";
    		$(this).focus();
    		breakOut = true;
    		return false;
    		}

    	}

    	});

    	if(breakOut){
    	breakOut=false;
    	return false;
    	}
    	//});
    	
    	
    	
    	}
};
var quotationattAttachmentController = {
    addAttach: function(a, b) {
        tbody = document.getElementById(a);
        var c = tbody.rows.length - 1;
        if (c < 0) {
            c = 0
        }
        if (!quotationattAttachmentController.validateAttach(c)) {
            return
        }
        var k = tbody.insertRow(tbody.rows.length);
        k.setAttribute("id", "_" + a + "_row_" + c);
        var j = 0;
        var h = k.insertCell(j);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" name="specificAttachments[' + c + '].label"/>';
        j++;
        var g = k.insertCell(j);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="specificAttachments[' + c + '].fileName" id="specificAttachments[' + c + '].fileName" />';
        j++;
        if (b) {
            var d = k.insertCell(j);
            d.setAttribute("class", "dataClass");
            d.innerHTML = '<select name="specificAttachments[' + c + '].type"><option value="Q">SUPPORTIVE DOCUMENT</option><option value="M">MAIN DOCUMENT </option></select>';
            j++
        }
        var f = k.insertCell(j);
        f.setAttribute("class", "dataClass");
        f.setAttribute("title", "Allowable Extensions:" + $("input[name='fileExtension']").val());
        f.setAttribute("style", "word-wrap:break-word");
        f.innerHTML = '<input type="file" size="20" name="specificAttachments[' + c + '].file"/>';
        j++;
        var e = k.insertCell(j);
        e.innerHTML = '<a class="pageContentLink" class="pageContentLink" href="javascript:quotationattAttachmentController.delAttach(attachTab,' + c + ');">DELETE ROW</a>'
    },
    addSignAttach: function(a, b) {
        tbody = document.getElementById(a);
        var c = tbody.rows.length - 1;
        if (c < 0) {
            c = 0
        }
        if (!quotationattAttachmentController.validateAttach(c)) {
            return
        }
        var l = tbody.insertRow(tbody.rows.length);
        l.setAttribute("id", "_" + a + "_row_" + c);
        var k = 0;
        var j = l.insertCell(k);
        j.setAttribute("class", "dataClass");
        j.innerHTML = '<input type="text" size="20" name="specificAttachments[' + c + '].label" id="specificAttachments[' + c + '].label"/>';
        k++;
        var h = l.insertCell(k);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" id="specificAttachments[' + c + '].fileName" name="specificAttachments[' + c + '].fileName"/><input type="hidden" id="specificAttachments[' + c + '].digitalCert.signHash" name="specificAttachments[' + c + '].digitalCert.signHash"/><input type="hidden" id="specificAttachments[' + c + '].digitalCert.publicKey" name="specificAttachments[' + c + '].digitalCert.publicKey"/>';
        k++;
        if (b) {
            var g = l.insertCell(k);
            g.setAttribute("class", "dataClass");
            g.innerHTML = '<select name="specificAttachments[' + c + '].type"><option value="Q">SUPPORTIVE DOCUMENT</option><option value="M">MAIN DOCUMENT </option></select>';
            k++
        }
        var f = l.insertCell(k);
        f.setAttribute("class", "dataClass");
        f.setAttribute("title", "Allowable Extensions:" + $("input[name='fileExtension']").val());
        f.setAttribute("style", "word-wrap:break-word");
        f.innerHTML = '<input type="file" id="specificAttachments[' + c + '].file" name="specificAttachments[' + c + '].file"/>';
        k++;
        var e = l.insertCell(k);
        e.innerHTML = '<a class="pageContentLink" href="javascript:quotationattAttachmentController.delAttach(attachTab,' + c + ');">DELETE ROW</a>';
        k++;
        var d = l.insertCell(k);
        d.innerHTML = '<a class="pageContentLink" href="#" onclick="javascript:signQuotationAttachmentFile(' + c + ');">SIGN FILE</a>'
    },
    delAttach: function(c, b) {
        var a = "attachTab";
        tbody = document.getElementById(a);
        row = document.getElementById("_" + a + "_row_" + b);
        if (confirm("Delete The Attachment?")) {
            tbody.removeChild(row)
        }
    },
    validateAttach: function(a) {
        var c = 30;
        if (a == c) {
            alert("Maximum " + c + " attachments can be added");
            return false
        }
        if (a > 0) {
            var b = document.getElementById("specificAttachments[" + (a - 1) + "].label");
            if (null != b) {
                if ((b.value == "") || (b.value == null)) {
                    alert("Please specify the Label for previous row");
                    return false
                }
            }
        }
        return true
    }
};
var ClarificationController = {
    reply: function() {
        $("#reply").css("display", "inline");
        $("#_send").css("display", "inline");
        $("#_reply").css("display", "none");
        $("#_print").css("display", "none")
    },
    viewClarification: function(m, d, h, l, c, a, g, k, j, f) {
        var e;
        if (m == "C") {
            e = "N"
        } else {
            e = "Y"
        }
        var b = contextRoot + "/business/clarification.action?methodName=viewClarificationMsg&reply=" + e + "&id=" + d + "&clarificationId=" + h + "&parentEntityId=" + l + "&parentPartNo=" + c + "&parentClarType=" + a + "&createId=" + g + "&parentWorkFlowId=" + k + "&parentFlowId=" + j + "&msgStatus=" + m + "&" + f;
        window.open(b, "_self", "width=800,height=500,scrollbars=yes,resizable=yes,menubar=no,directories=no,location=no")
    },
    viewRfqClarHistory: function(b, a) {
        $("input[name='rfqId']", "#rfqClarHistoryForm").val($("input[name='id']", "#rfqViewForm").val());
        SearchController.searchWithForm(b, ["rfqId"], a)
    },
    expandClarification: function(b) {
        var a = "clarification[" + b + "]";
        document.getElementById(a).style.display = "block";
        var c = "clarificationCollapse[" + b + "]";
        var d = "clarificationExpand[" + b + "]";
        document.getElementById(c).style.display = "block";
        document.getElementById(d).style.display = "none"
    },
    collapseClarification: function(b) {
        var a = "clarification[" + b + "]";
        document.getElementById(a).style.display = "none";
        var c = "clarificationCollapse[" + b + "]";
        var d = "clarificationExpand[" + b + "]";
        document.getElementById(c).style.display = "none";
        document.getElementById(d).style.display = "block"
    }
};
var WFController = {
    showPaymentDetails: function(a) {
        document.paymentDetails.rfqId.value = a;
        document.paymentDetails.submit()
    },
    showPaymentDetailsByRfqId: function(a) {
        document.paymentDetailsByRfqId.rfqId.value = a;
        document.paymentDetailsByRfqId.submit()
    },
    viewQuotationEvaluationSpringCS: function() {
        qtnEvalExlForm.submit()
    },
    viewQuotationPartOneEvaluationSpringCS: function() {
        document.qtnPartOneEvalExlForm.submit()
    },
    showSellerAttachments: function(a, b) {
        document.sellerAttachments.rfqId.value = a;
        document.sellerAttachments.partNo.value = b;
        document.sellerAttachments.submit()
    },
    getUsers: function() {
        Controller.onSubmit(null, null, "getWFTransfers", null)
    },
    selectTransfer: function(f, d, b, c, a, e) {
        pageScope.transfer = {
            id: f,
            procCatId: d,
            srcUser: b,
            dstUser: c,
            startDate: a,
            endDate: e
        };
        if (sessionScope._currPrivId == 116) {
            $("#editTransfer").css("display", "inline")
        }
    },
    selectTenderCom: function(e, c, b, a, d) {
        pageScope.tenderCom = {
            id: e,
            code: c,
            description: b,
            createDate: a,
            updateDate: d
        };
        if (sessionScope._currPrivId == 118) {
            $("#viewTenderCom").css("display", "inline")
        }
    },
    signNoteSheet: function(f, e, a, c, b) {
        var g = true;
        if (f) {
            var d = $("input[name='entityId']", "#" + e).val() + "#|#" + $("input[name='entityTypeId']", "#" + e).val() + "#|#" + $("input[name='partNumber']", "#" + e).val() + "#|#" + $("input[name='createId']", "#" + e).val();
            g = g && signDocument(d)
        }
        $("input[name='entityId']", "#" + e).val();
        $("input[name='status']", "#" + e).val(b);
        $("input[name='work.status']", "#" + e).val(b);
        $("input[name='buttonValue']", "#" + e).val(c);
        if (g && Controller.alertSignHashFile()) {
            document.noteSheetForm.submit()
        }
    },
    addWorkAttach: function(a, d) {
        tbody = document.getElementById(a);
        var b = tbody.rows.length - 2;
        if (b < 0) {
            b = 0
        }
        if (!attachmentController.validateAttach(b)) {
            return
        }
        var j = tbody.insertRow(tbody.rows.length);
        var h = j.insertCell(0);
        h.setAttribute("class", "dataClass");
        h.innerHTML = "<input type='text'  id='attachments[" + b + "].label' name='attachments[" + b + "].label' />";
        var g = j.insertCell(1);
        g.setAttribute("class", "dataClass");
        g.innerHTML = "<input type='text' size='20' name='attachments[" + b + "].fileName' /><input type='hidden' id='attachments[" + b + "].digitalCert.signHash' name='attachments[" + b + "].digitalCert.signHash' />";
        var f = j.insertCell(2);
        f.setAttribute("class", "dataClass");
        f.innerHTML = "<input type='file' size='20' id='attachments[" + b + "].file' name='attachments[" + b + "].file' />";
        var e = j.insertCell(3);
        e.innerHTML = "<a class='pageContentLink' href='javascript:attachmentController.delAttach(attachTab," + b + ");'>DELETE ROW</a>";
        if (d == "true") {
            var c = j.insertCell(4);
            c.innerHTML = "<a class='pageContentLink' href='javascript:WFController.signWorkAttachmentFile(" + b + ");'>SIGN FILE</a>"
        }
    },
    signNoteSheetWork: function(m, h, k, g, f, e, j) {
        var a = true;
        var n = "X";
        var b = $("input[name='work.currentFlow.id']").val();
        if (m) {
            var l = b + "#|#" + j;
            var c = signText(l);
            document.getElementById("work.currentFlow.digitalCert.signHash").value = c;
            var d = getClientCertString();
            document.getElementById("work.currentFlow.digitalCert.publicKey").value = getPublicKeyStrFromCertStr(d);
            document.getElementById("work.currentFlow.digitalCert.clientCertString").value = d;
            document.getElementById("work.currentFlow.digitalCert.certSerialNo").value = getSrNoFromCertStr(d);
            document.getElementById("work.currentFlow.digitalCert.expiryDate").value = getFmtExpiryDateFromCertStr(d, "yyyy-MM-dd HH:mm:ss");
            document.getElementById("work.currentFlow.digitalCert.thumbPrint").value = getThumbprintFromCertStr(d);
            document.getElementById("work.currentFlow.digitalCert.clientCertSubject").value = getSubjectDNFromCertStr(d);
            if (c == null || c == "") {
                a = false
            }
        }
        $("input[name='work.currentFlow.workStatus']").val(e);
        $("input[name='work.currentFlow.status']").val(e);
        $("input[name='buttonValue']", "#" + h).val(g);
        if (confirm("Do you want to proceed?") && a && Controller.alertSignHashFile()) {
            Controller.onSubmitWithCsrf(h, f, k, null, null);
            return a
        } else {
            return false
        }
    },
    signWork: function signWork(s, m, l, k, q, f) {
        var o = true;
        var n = "X";
        $("input[name='currentFlow.workStatus']").val(q);
        $("input[name='currentFlow.status']").val(q);
        var g = $("input[name='currentFlow.id']").val();
        if (s) {
            for (var r = 0; r < document.getElementsByName("currentFlow.workStatus").length; r++) {
                if (document.getElementsByName("currentFlow.workStatus").item(r).checked) {
                    var q = document.getElementsByName("currentFlow.workStatus").item(r).value;
                    if (q == "APPROVE") {
                        n = "A"
                    }
                    if (q == "REVIEW") {
                        n = "W"
                    }
                    break
                }
            }
            var d = g + "#|#" + f;
            var h = signText(d);
            document.getElementById("currentFlow.digitalCert.signHash").value = h;
            var a = getClientCertString();
            document.getElementById("currentFlow.digitalCert.publicKey").value = getPublicKeyStrFromCertStr(a);
            document.getElementById("currentFlow.digitalCert.clientCertString").value = a;
            document.getElementById("currentFlow.digitalCert.certSerialNo").value = getSrNoFromCertStr(a);
            document.getElementById("currentFlow.digitalCert.expiryDate").value = getFmtExpiryDateFromCertStr(a, "yyyy-MM-dd HH:mm:ss");
            document.getElementById("currentFlow.digitalCert.thumbPrint").value = getThumbprintFromCertStr(a);
            document.getElementById("currentFlow.digitalCert.clientCertSubject").value = getSubjectDNFromCertStr(a);
            var b = document.getElementById("documentCode").value;
            var j = document.getElementById("partCount").value;
            var e = document.getElementById("owner.id").value;
            var c = b + "#|#" + j + "#|#" + e + "#|#" + n;
            var p = signText(c);
            document.getElementById("digitalCert.signHash").value = p;
            if (h == null || h == "" || p == null || p == "") {
                o = false
            }
        }
        if (confirm("Do you want to proceed?") && o && Controller.alertSignHashFile()) {
            Controller.onSubmitWithCsrf(m, k, l, null, null);
            return o
        } else {
            return false
        }
    },
    initApproval: function() {
        Controller.onSubmit("workCatForm", null, "getWFApprovers", null, null)
    },
    signWorkAttachmentFile: function(c) {
        var e = true;
        var b = "attachments[" + c + "].file";
        var a = "attachments[" + c + "].digitalCert.signHash";
        var d = document.getElementById(b).value;
        e = signFileAndAssignValue(d, a)
    },
    signWorkAttachment: function(c) {
        var e = true;
        var b = "work.attachments[" + c + "].file";
        var a = "work.attachments[" + c + "].digitalCert.signHash";
        var d = document.getElementById(b).value;
        e = signFileAndAssignValue(d, a)
    },
    signWorkFlowAttachmentFile: function(c) {
        var e = true;
        var b = "currentFlow.attachments[" + c + "].file";
        var a = "currentFlow.attachments[" + c + "].digitalCert.signHash";
        var d = document.getElementById(b).value;
        e = signFileAndAssignValue(d, a)
    },
    transferWorkTo: function(b, a) {
        Controller.onSubmitWithCsrf(b, a, "updateWorkStatus", null, null)
    },
    addWorkFlowAttach: function(a, d) {
        tbody = document.getElementById(a);
        var b = tbody.rows.length - 2;
        if (b < 0) {
            b = 0
        }
        if (!attachmentController.validateAttach(b)) {
            return
        }
        var j = tbody.insertRow(tbody.rows.length);
        var h = j.insertCell(0);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" name="currentFlow.attachments[' + b + '].label"/>';
        var g = j.insertCell(1);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="currentFlow.attachments[' + b + '].fileName"/><input type="hidden" id="currentFlow.attachments[' + b + '].digitalCert.signHash" name="currentFlow.attachments[' + b + '].digitalCert.signHash"/>';
        var f = j.insertCell(2);
        f.setAttribute("class", "dataClass");
        f.innerHTML = '<input type="file" size="20" id="currentFlow.attachments[' + b + '].file" name="currentFlow.attachments[' + b + '].file"/>';
        var e = j.insertCell(3);
        e.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + b + ');">DELETE ROW</a>';
        if (d) {
            var c = j.insertCell(4);
            c.innerHTML = '<a class="pageContentLink" href="javascript:WFController.signWorkFlowAttachmentFile(' + b + ');">SIGN FILE</a>'
        }
    },
    addWorkFlowQualAttach: function(a, d) {
        tbody = document.getElementById(a);
        var b = tbody.rows.length - 2;
        if (b < 0) {
            b = 0
        }
        if (!attachmentController.validateAttach(b)) {
            return
        }
        var j = tbody.insertRow(tbody.rows.length);
        var h = j.insertCell(0);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" name="work.currentFlow.attachments[' + b + '].label"/>';
        var g = j.insertCell(1);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="work.currentFlow.attachments[' + b + '].fileName" id="work.currentFlow.attachments[' + b + '].fileName" /><input type="hidden" id="work.currentFlow.attachments[' + b + '].digitalCert.signHash" name="work.currentFlow.attachments[' + b + '].digitalCert.signHash" />';
        var f = j.insertCell(2);
        f.setAttribute("class", "dataClass");
        f.innerHTML = '<input type="file" size="20" id="work.currentFlow.attachments[' + b + '].file" name="work.currentFlow.attachments[' + b + '].file"/>';
        var e = j.insertCell(3);
        e.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + b + ');">DELETE ROW </a>';
        if (d) {
            var c = j.insertCell(4);
            c.innerHTML = '<a class="pageContentLink" href="javascript:WFController.signWorkFlowAttachmentQualFile(' + b + ');">SIGN FILE</a>'
        }
    },
    signWorkFlowAttachmentQualFile: function(c) {
        var e = true;
        var b = "work.currentFlow.attachments[" + c + "].file";
        var a = "work.currentFlow.attachments[" + c + "].digitalCert.signHash";
        var d = document.getElementById(b).value;
        e = signFileAndAssignValue(d, a)
    },
    addWorkAttachment: function(a, d) {
        tbody = document.getElementById(a);
        var b = tbody.rows.length - 2;
        if (b < 0) {
            b = 0
        }
        if (!attachmentController.validateAttach(b)) {
            return
        }
        var j = tbody.insertRow(tbody.rows.length);
        var h = j.insertCell(0);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" name="work.attachments[' + b + '].label"/>';
        var g = j.insertCell(1);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="work.attachments[' + b + '].fileName"/><input type="hidden" id="work.attachments[' + b + '].digitalCert.signHash" name="work.attachments[' + b + '].digitalCert.signHash"/>';
        var f = j.insertCell(2);
        f.setAttribute("class", "dataClass");
        f.innerHTML = '<input type="file" size="20" id="work.attachments[' + b + '].file" name="work.attachments[' + b + '].file"/>';
        var e = j.insertCell(3);
        e.innerHTML = '<a class="pageContentLink" href="javascript:attachmentController.delAttach(attachTab,' + b + ');">DELETE ROW</a>';
        if (d) {
            var c = j.insertCell(4);
            c.innerHTML = '<a class="pageContentLink" href="javascript:WFController.signWorkAttachment(' + b + ');">SIGN FILE</a>'
        }
    },
    viewDiscussion: function(a) {
        document.discussionForm.id.value = a;
        document.discussionForm.submit()
    },
    viewDiscussionDetails: function(formName, discussionId) {
        eval("document." + formName).id.value = discussionId;
        eval("document." + formName).submit()
    },
    branchFlow: function() {
        document.branchForm.submit()
    },
    getQuotaionList: function() {
        document.quotationForm.submit()
    },
    verifyWorkFlow: function(d, c, e, b, a) {
        $("input[name='digitalCert.clientCertString']").val(e);
        $("input[name='digitalCert.signHash']").val(b);
        $("input[name='userDigitalCertId']").val(a);
        var f = c + "#|#" + d;
        verifyDocument(f)
    },
    viewCorrigendum: function(c, b) {
        var a = contextRoot + "/business/corrigendum.handle?methodName=viewCorrigendum&rfqId=" + c + "&" + b;
        alert("url" + a);
        window.open(a, "viewCorrigendum_window", "top=150, left=110, height=500, width=800, toolbar=no, status=no ,scrollbars=1,resizable=1")
    },
    discussionFormSubmit: function(b) {
        var c = true;
        if (b) {
            var a = $("input[name='id']", "#discussionForm").val() + "#|#" + $("input[name='userId']", "#discussionForm").val();
            c = c && signDocument(a);
            $("input[name='digitalCert.publicKey']", "#discussionForm").val($("input[name='digitalCert.publicKey']").val());
            $("input[name='digitalCert.clientCertString']", "#discussionForm").val($("input[name='digitalCert.clientCertString']").val());
            $("input[name='digitalCert.certSerialNo']", "#discussionForm").val($("input[name='digitalCert.certSerialNo']").val());
            $("input[name='digitalCert.expiryDate']", "#discussionForm").val($("input[name='digitalCert.expiryDate']").val());
            $("input[name='digitalCert.thumbPrint']", "#discussionForm").val($("input[name='digitalCert.thumbPrint']").val());
            $("input[name='digitalCert.clientCertSubject']", "#discussionForm").val($("input[name='digitalCert.clientCertSubject']").val());
            $("input[name='digitalCert.signHash']", "#discussionForm").val($("input[name='digitalCert.signHash']").val());
            $("input[name='digitalCert.id']", "#discussionForm").val($("input[name='digitalCert.id']").val());
            $("input[name='digitalCert.certType']", "#discussionForm").val($("input[name='digitalCert.certType']").val())
        }
        if (c) {
            document.discussionForm.submit()
        }
    },
    getQuotationList: function() {
        document.searchForm.submit()
    },
    getWorkflowStatus: function(c, b, a) {
        Controller.loadData(contextRoot + "/business/work.handle?methodName=getWorkflowStatus&rfqId=" + c + "&worKSpecCode=" + b + "&" + a, null, function(d) {
            var e = d.map.WORK_STATUS;
            if (e != "APPROVED") {
                alert("YOU CAN'T VIEW THE QUOTATION BEFORE 'VIEW L1 SUPPLIER' APPROVAL")
            } else {
                document.quotationSearchForm.action = "getQuotationListAction.do";
                document.quotationSearchForm.submit()
            }
        })
    },
    checkWorkflowStatus: function(c, b, a) {
        Controller.loadData(contextRoot + "/business/work.handle?methodName=getWorkflowStatus&rfqId=" + c + "&worKSpecCode=" + b + "&" + a, null, function(e) {
            var d = e.map.RA_ENABLED;
            var f = e.map.WORK_STATUS;
            if (d == "Y") {
                if (f == "OPEN") {
                    alert("WORKFLOW HAS ALREADY BEEN INITIATED FOR THIS RFQ")
                } else {
                    if (f == "APPROVED") {
                        document.qtnEvalExlForm.L1DetailsDoc.value = "Y";
                        qtnEvalExlForm.submit()
                    } else {
                        document.viewL1SupplierCSForm.submit()
                    }
                }
            } else {
                alert("'L1 SUPPLIER CS' CAN ONLY BE DISPLAYED FOR RA ENABLED RFQ")
            }
        })
    }
};
var QuotationController = {
    refreshParent: function() {
        if (!window.opener.location) {
            window.opener.location = self
        }
        window.opener.viewConfigTemplateForm.itemCatFlag.value = "true";
        window.opener.viewConfigTemplateForm.methodName.value = "viewDocConfTemplateListDetails";
        window.opener.viewConfigTemplateForm.submit();
        window.close()
    },
    backToQuotationList: function() {
        document.quotationSearchForm.action = "getQuotationListAction.do";
        document.quotationSearchForm.submit()
    },
    returnLoadFactor: function() {
        var b = document.getElementById("loadFactor").value;
        var a = document.getElementById("id").value;
        var c = document.getElementById("loadAttributeId").value;
        opener.document.getElementById("quotationItemLoadFactor(" + a + "_" + c + ")").value = b;
        opener.document.getElementById("quotationItemLoadFactor(" + a + "_" + c + ")").focus();
        window.close()
    },
    decryptQuotation: function(b, a) {
        itemLength = document.getElementsByName("decryptQuotation").length;
        var c = "";
        for (i = 0; i < itemLength; i++) {
            if (document.getElementsByName("decryptQuotation").item(i).checked) {
                quotationId = document.getElementsByName("decryptQuotation").item(i).value;
                c = c + quotationId + ","
            }
        }
        if (c != "") {
            c = c.substring(0, c.length - 1);
            window.open(b + "?methodName=getQuotationHeaderByQuotationId&data=" + c + "&" + a, "_blank")
        }
    },
    viewQuotationComments: function(c, a) {
        var b = contextRoot + "/business/quotation.action?methodName=viewQuotationComments&popUp=Y&quotationId=" + c + "&userId=" + a;
        window.open(b, "userContactView_window", "top=0, left=400, height=600, width=600, toolbar=no, status=no, scrollbars=yes, resizable=yes")
    },
    addQuotationComment: function(a) {
        document.addCommentForm.id.value = a;
        document.addCommentForm.submit()
    },
    auctionTermAcceptance: function(e, c) {
        var a = document.getElementById("auctionID").value;
        var d = a + "#|#" + c;
        var g = true;
        if (e) {
            var g = signDocumentAndAsingnValue(d, "digitalCert.signHash")
        }
        var b = 1;
        if (document.getElementById("termNotAccepted").checked) {
            var b = document.getElementById("termNotAccepted").value
        }
        var f = document.getElementById("termComment").value;
        if (confirm("Do you want to proceed?") && g) {
            document.auctionAcceptanceForm.submit()
        }
    },
    getSelectedAucQuotation: function() {
        var b = $("input[name='quotSelect']:checked").val().split("|")[0];
        var a = $("input[name='quotSelect']:checked").val().split("|")[1];
        document.auctionAcceptanceForm.aucQuotation.value = b;
        document.auctionAcceptanceForm.aucStatus.value = a;
        document.auctionAcceptanceForm.submit()
    }
};
var DashBoardController = {
    backToDashBoard: function() {
        document.dashboardForm.methodName.value = "getDashBoard";
        document.dashboardForm.target = "_self";
        document.dashboardForm.submit()
    },
    viewRfq: function(rfqId, rfqPartNumber, rfqStatus, rfqOwner) {
        eval(document.viewRfqForm).rfqId.value = rfqId;
        eval(document.viewRfqForm).documentStatus.value = rfqStatus;
        eval(document.viewRfqForm).documentOwner.value = rfqOwner;
        eval(document.viewRfqForm).rfqPartNumber.value = rfqPartNumber;
        document.viewRfqForm.submit()
    },
    respondToRfq: function() {
        document.dashboardForm.action = "getRfqResponseAction.do";
        document.dashboardForm.target = "_self";
        document.dashboardForm.submit()
    },
    viewQuotationList: function(rfqCode, rfqStatus, rfqType, orgId) {
        eval(document.rfqSearchForm).documentCode.value = rfqCode;
        eval(document.rfqSearchForm).documentSearchStatus.value = rfqStatus;
        eval(document.rfqSearchForm).rfqType.value = rfqType;
        eval(document.rfqSearchForm).documentSearchOrganization.value = orgId;
        document.rfqSearchForm.submit()
    },
    viewDecryptionList: function(rfqId, partNo) {
        eval(document.rfqDecryptionForm).quotationRfqStatus.value = "AAEO";
        eval(document.rfqDecryptionForm).quotationRfqId.value = rfqId;
        eval(document.rfqDecryptionForm).quotationRfqPartIdentifier.value = rfqId + "|" + partNo;
        document.rfqDecryptionForm.submit()
    },
    searchSupplierList: function(a, d, c, b) {
        document.userSearchByUserInfoForm.searchReportType.value = c;
        document.userSearchByUserInfoForm.methodName.value = a;
        document.userSearchByUserInfoForm.userStatus.value = b;
        document.userSearchByUserInfoForm.searchRequestFrom.value = "fromDashboard";
        document.userSearchByUserInfoForm.target = "_self";
        SearchController.searchWithForm("userSearchByUserInfoForm", ["lastId"], d)
    },
    dscPendingApproval: function(a, c, b) {
        document.dscPendingApprovalForm.searchReportType.value = b;
        document.dscPendingApprovalForm.methodName.value = a;
        document.dscPendingApprovalForm.searchRequestFrom.value = "fromDashboard";
        document.dscPendingApprovalForm.target = "_self";
        SearchController.searchWithForm("dscPendingApprovalForm", ["lastId"], c)
    },
    issuedPODetails: function() {
        document.purchaseOrderDetailsForm.target = "_self";
        document.purchaseOrderDetailsForm.submit()
    },
    pendingPODetails: function(a) {
        document.pendingPurchaseOrderDetailsForm.methodName.value = a;
        document.pendingPurchaseOrderDetailsForm.target = "_self";
        document.pendingPurchaseOrderDetailsForm.submit()
    },
    getQuotationEval: function(b, c, a) {
        document.evalForm1.quotationEvaluationRfq.value = b;
        document.evalForm1.quotationEvaluationRfqPart.value = c;
        document.evalForm1.quotationRfqPartIdentifier.value = b + "|" + c;
        document.evalForm1.partNumber.value = c;
        document.evalForm1.quotationEvaluationRfqOwner.value = a;
        document.evalForm1.quotationRfqOwner.value = a;
        document.evalForm1.submit()
    },
    initiateQualFlow: function(b, c, a) {
        document.initQualForm.id.value = b;
        document.initQualForm.partNumber.value = c;
        document.initQualForm.quotationRfqOwner.value = a;
        document.initQualForm.quotationRfqPartIdentifier.value = b + "|" + c;
        document.initQualForm.submit()
    },
    loadAndEval: function(a, b) {
        document.loadAndEvalForm.id.value = a;
        document.loadAndEvalForm.partNumber.value = b;
        document.loadAndEvalForm.quotationRfqPartIdentifier.value = a + "|" + b;
        document.loadAndEvalForm.submit()
    },
    getQuotationLoad: function(b, c, a) {
        document.loadForm1.action = "getQuotationLoadAddAction.do";
        document.loadForm1.quotationEvaluationRfq.value = b;
        document.loadForm1.quotationEvaluationRfqPart.value = c;
        document.loadForm1.quotationRfqPartIdentifier.value = b + "|" + c;
        document.loadForm1.partNumber.value = c;
        document.loadForm1.quotationRfqOwner.value = a;
        document.loadForm1.quotationEvaluationRfqOwner.value = a;
        document.loadForm1.submit()
    },
    evaluationLoading: function(b, c, d, a) {
        document.evaluateLoadingForm.id.value = b;
        document.evaluateLoadingForm.rfqId.value = b;
        document.evaluateLoadingForm.partNumber.value = c;
        document.evaluateLoadingForm.partCount.value = d;
        document.evaluateLoadingForm.quotationRfqPartIdentifier.value = b + "|" + c;
        document.evaluateLoadingForm.quotationRfqOwner.value = a;
        document.evaluateLoadingForm.submit()
    },
    archiveRfq: function(c, f, a) {
        document.rfqArchiveForm.rfqId.value = c;
        document.rfqArchiveForm.partCount.value = f;
        if (confirm("Do you want to proceed?")) {
            window.scroll(0, 0);
            $(".ui-tooltip-content").parents("div").remove();
            Controller.onSubmitWithCsrf("rfqArchiveForm", a, null, null);
            var e = document.getElementById("archiveImage_" + c);
            var b = document.getElementById("archiveButton_" + c);
            e.removeChild(b);
            var d = document.createElement("img");
            d.setAttribute("src", "../image/tick.gif");
            d.setAttribute("title", "Archived");
            d.style.height = "20px";
            d.style.width = "20px";
            document.getElementById("archiveImage_" + c).appendChild(d);
            return true
        } else {
            return false
        }
    },
    assignAuditor: function(d, h, f, a) {
        document.assignToAuditorForm.rfqId.value = d;
        document.assignToAuditorForm.partCount.value = h;
        document.assignToAuditorForm.actionStatus.value = f;
        if (confirm("Do you want to proceed?")) {
            window.scroll(0, 0);
            $(".ui-tooltip-content").parents("div").remove();
            Controller.onSubmitWithCsrf("assignToAuditorForm", a, null, null);
            var e = document.createElement("img");
            e.setAttribute("src", "../image/tick.gif");
            e.setAttribute("title", "Assigned To Auditor");
            e.style.height = "20px";
            e.style.width = "20px";
            if (f == "assigned") {
                var g = document.getElementById("auditorStatusDiv_" + d);
                var c = document.getElementById("auditorStatusButton_" + d);
                g.removeChild(c);
                g.style.display = "none";
                var b = document.getElementById("deAuditorStatusDiv_" + d);
                b.innerHTML = '<button type="button" id="deAuditorStatusButton_' + d + '" class="epsSubmitNew" title="DeAssign To Auditor"       onclick="javascript:DashBoardController.assignAuditor(' + d + "," + h + ",'deAssigned','" + a + "');\"> Deassign To Auditor</button>";
                b.style.display = "block"
            } else {
                if (f == "deAssigned") {
                    var g = document.getElementById("deAuditorStatusDiv_" + d);
                    var c = document.getElementById("deAuditorStatusButton_" + d);
                    g.removeChild(c);
                    g.style.display = "none";
                    var b = document.getElementById("auditorStatusDiv_" + d);
                    b.innerHTML = '<button type="button" id="auditorStatusButton_' + d + '" class="epsSubmitNew" title="Assign To Auditor" onclick="javascript:DashBoardController.assignAuditor(' + d + "," + h + ",'assigned','" + a + "');\">Assign To Auditor</button>";
                    b.style.display = "block"
                }
            }
            return true
        } else {
            return false
        }
    },
    autoEval: function(a, b) {
        document.autoEval.rfqIdPartNo.value = a + "|" + b;
        document.autoEval.submit()
    }
};
var SecurityController = {
    buttonSelector: function(b, a) {
        if (b == "exitOut") {
            document.cerFileUploadForm.submit()
        }
        if (b == "home") {
            document.cerFileUploadForm.action = contextRoot + "/security/getHomeAction.do";
            document.cerFileUploadForm.submit()
        }
        if (b == "proceed") {
            document.cerFileUploadForm.action = contextRoot + "/security/getHomeAction.do";
            document.cerFileUploadForm.submit()
        }
        if (b == "dashBoard") {
            document.cerFileUploadForm.methodName.value = "getDashBoard";
            document.cerFileUploadForm.action = contextRoot + "/business/dashboard.action";
            document.cerFileUploadForm.target = "_self";
            document.cerFileUploadForm.submit()
        }
        if (b == "showRegisterDscDiv") {
            var c = document.getElementById("registerDscDiv");
            var d = document.getElementById("viewDscDetailDiv");
            if (c.style.display == "none") {
                c.style.display = "block"
            }
            if (d.style.display != "none") {
                d.style.display = "none"
            }
            document.digitalCertAddForm.cerFileValidationArea.value = a
        }
        if (b == "hideRegisterDscDiv") {
            var c = document.getElementById("registerDscDiv");
            if (c.style.display !== "none") {
                c.style.display = "none"
            }
        }
        if (b == "hideViewDscDetailDiv") {
            var d = document.getElementById("viewDscDetailDiv");
            if (d.style.display !== "none") {
                d.style.display = "none"
            }
        }
    },
    generateDscListReport: function(formName, csrfToken, methodname) {
        eval("document." + formName).methodName.value = methodname;
        eval("document." + formName).action = contextRoot + "/business/security.action";
        eval("document." + formName).target = "_self";
        eval("document." + formName).submit()
    },
    signCerFile: function() {
        var d = true;
        var b = "digitalCert.cerFile";
        var a = "digitalCert.cerFileSignHash";
        var c = document.getElementById(b).value;
        d = signFileAndAssignValue(c, a)
    },
    stoteCerFile: function(formName, csrfToken, methodName, cerFileValidationArea) {
        eval("document." + formName).methodName.value = methodName;
        eval("document." + formName).cerFileValidationArea.value = cerFileValidationArea;
        eval("document." + formName).action = contextRoot + "/business/security.action";
        eval("document." + formName).submit()
    },
    selectDigitalCert: function(b, c, a) {
        pageScope.digi = {
            digitalCertId: b,
            cerFileValidationArea: a
        }
    },
    submitDSC: function(c, f, a) {
        var d = false;
        var e = document.getElementsByName("radioSelect");
        for (var b = 0; b < e.length; b++) {
            if (e[b].checked) {
                d = true
            }
        }
        if (!d) {
            alert("PLEASE SELECT ONE DIGITAL CERTIFICATE TO CONTINUE")
        } else {
            Controller.onSubmit(c, f, a, null, null)
        }
    },
    signDoc: function signDoc(f) {
        var d = false;
        var g = document.getElementsByName("selectOption");
        for (var b = 0; b < g.length; b++) {
            if (g[b].checked) {
                d = true
            }
        }
        if (!d) {
            alert("PLEASE SELECT ONE DIGITAL CERTIFICATE TYPE TO CONTINUE");
            return false
        }
        var a = null;
        var c = false;
        if ($("input[name='selectOption']:checked").val() == "1") {
            a = decryptText(null);
            c = true
        } else {
            a = signText("dummy")
        }
        if (getClientPublicKeyString() != null || c) {
            var e = getClientCertString();
            log("certSrNo: " + getSrNoFromCertStr(e));
            log("certThumbPrint: " + getThumbprintFromCertStr(e));
            log("clientCertStr: " + e);
            log("clientPubKey: " + getPublicKeyStrFromCertStr(e));
            log("clientExprDay: " + getExpiryDateFromCertStr(e));
            log("clientCertSubject: " + getSubjectDNFromCertStr(e));
            displayCertInfo(e);
            $("input[name='digitalCert.certSerialNo']", "#" + f).val(getSrNoFromCertStr(e));
            $("input[name='digitalCert.thumbPrint']", "#" + f).val(getThumbprintFromCertStr(e));
            $("input[name='digitalCert.publicKey']", "#" + f).val(getPublicKeyStrFromCertStr(e));
            $("input[name='digitalCert.expiryDate']", "#" + f).val(getFmtExpiryDateFromCertStr(e, "yyyy-MM-dd HH:mm:ss"));
            $("input[name='digitalCert.clientCertString']", "#" + f).val(e);
            $("input[name='digitalCert.clientCertSubject']", "#" + f).val(getSubjectDNFromCertStr(e));
            $("input[name='digitalCert.certType']", "#" + f).val(getKeyUsageFromCertStr(e));
            Controller.onSubmit(f, null, "storeDigitalCert", null, null)
        }
    }
};
var InvoiceController = {
    viewInvoice: function(b, a) {
        if (null == b) {
            alert("Please select an invoice");
            return
        }
        Controller.loadPage(contextRoot + "/business/invoice.handle?methodName=getDoc&viewMode=true&id=" + b + "&" + a, null, null)
    },
    printInvoice: function(c, a, b) {
        document.invoicePrintForm.action = contextRoot + "/business/report.action";
        document.invoicePrintForm.methodName.value = "showReport";
        document.invoicePrintForm.reportName.value = "invoiceDtlViewPrint";
        document.invoicePrintForm.popUp.value = "Y";
        document.invoicePrintForm.invoiceId.value = c;
        document.invoicePrintForm.orgId.value = a;
        document.invoicePrintForm.orgName.value = b;
        document.invoicePrintForm.target = "_blank";
        document.invoicePrintForm.submit()
    },
    viewInvoiceHdr: function(b, a) {
        if (null == b) {
            alert("Please select an invoice");
            return
        }
        Controller.loadPage(contextRoot + "/business/invoice.handle?methodName=getDoc&viewMode=true&hdrView=true&id=" + b + "&" + a, null, null)
    }
};
var IRController = {
    saveAssignment: function() {
        Controller.onSubmit("inspectionForm", null, "saveAssignment", null, null)
    }
};
var ProposalController = {
    searchInbox: function() {
        document.inboxForm.methodName.value = "getInboxBySearch";
        document.inboxForm.submit()
    },
    changeRow: function() {
        var e = $("#selectionTable tr").length;
        var a = e - 1;
        var c = $("input[name='maxNumber']").val();
        var d = $("input[name='maxNumber']").val().replace(/^\s\s*/, "").replace(/\s\s*$/, "");
        var b = /^\d+$/;
        if (!b.test(d)) {
            alert("Field must be numeric");
            return false
        }
        if (parseInt(c, 10) >= parseInt(e, 10)) {
            while (parseInt(c, 10) > parseInt(a, 10)) {
                $("#selectionTable tr:last").clone().find("select").attr("name", "proposalCommitteeMap[" + a + "]").attr("value", "0").end().appendTo("#selectionTable");
                $("#selectionTable tr:last").find($(".counterClass")).html(a + 1);
                a++
            }
        } else {
            while (parseInt(c, 10) < parseInt(a, 10)) {
                $("#selectionTable tr:last").remove();
                a--
            }
        }
    },
    changeRowForProposalCommittee: function() {
        var e = $("#selectionTable tr").length;
        var a = e - 1;
        var c = $("input[name='maxNumber']").val();
        var d = $("input[name='maxNumber']").val().replace(/^\s\s*/, "").replace(/\s\s*$/, "");
        var b = /^\d+$/;
        if (!b.test(d)) {
            alert("Field must be numeric");
            return false
        }
        if (parseInt(c, 10) >= parseInt(e, 10)) {
            while (parseInt(c, 10) > parseInt(a, 10)) {
                $("#selectionTable tr:last").clone().find("select").attr("name", "proposalCommitteeUserMap[" + a + "]").attr("value", "0").end().appendTo("#selectionTable");
                $("#selectionTable tr:last").find($(".counterClass")).html(a + 1);
                a++
            }
        } else {
            while (parseInt(c, 10) < parseInt(a, 10)) {
                $("#selectionTable tr:last").remove();
                a--
            }
        }
    },
    initAddPropComm: function(c, b, a) {
        if (c == 0) {
            $("#searchResult").empty();
            $("#proposalCommSearchPrev").css("display", "none");
            $("#proposalCommSearchNext").css("display", "none")
        }
        $("input[name='id']", "#addPropCommForm").val(c);
        SearchController.searchWithForm(b, ["id"], a)
    },
    initAddPropCommRel: function(formName, divId) {
        var priceRangeId = eval("document.proposalCommRelSearch").priceRangeId.value;
        if (priceRangeId == "") {
            alert("Please first add Price Range for the Procurement Type");
            return
        }
        $("input[name='proposalCategory.id']", "#addPropCommRelForm").val($("select[name='procurementTypeId']", "#proposalCommRelSearch").val());
        $("input[name='priceRange.id']", "#addPropCommRelForm").val($("select[name='priceRangeId']", "#proposalCommRelSearch").val());
        $("input[name='buUnit.buCode']", "#addPropCommRelForm").val($("select[name='buCode']", "#proposalCommRelSearch").val());
        SearchController.searchWithForm(formName, ["proposalCategory.id", "priceRange.id", "buUnit.buCode"], divId)
    },
    getPriceRangeList: function(b, a) {
        $("input[name='procurementTypeId']", "#viewPriceRangeForm").val($("select[name='procurementTypeId']", "#proposalCommRelSearch").val());
        SearchController.searchWithForm(b, ["procurementTypeId"], a)
    },
    getPriceRangeListForProposalAdd: function(b, a) {
        Util.clearContent($("#initialPriceRangeDiv"));
        $("input[name='procurementType.id']", "#viewPriceRangeForm").val($("select[name='procurementType.id']", "#proposalAddForm").val());
        SearchController.searchWithForm(b, ["procurementType.id"], a)
    },
    initPriceRangeSave: function(e, d, c, a) {
        if (c == 0) {
            alert("Select any Procurement Type");
            return
        }
        var b = 600;
        var f = 250;
        var j = (screen.width / 2) - (b / 2);
        var g = (screen.height / 2) - (f / 2);
        window.open(contextRoot + "/business/proposal.handle?methodName=initPriceRangeSave&id=" + d + "&procurementType.id=" + c + "&" + a, null, "top=" + g + ", left=" + j + ", height=" + f + ", width=" + b + ", toolbar=no, status=no, scrollbars=yes ")
    },
    updateProcurementTypeStatus: function(d, e, b, a) {
        var f = "";
        if (b == "A") {
            f = "ARE YOU SURE TO ACTIVATE THE PROCUREMENT TYPE " + e
        } else {
            if (b == "X") {
                f = "ARE YOU SURE TO DEACTIVATE THE PROCUREMENT TYPE " + e
            }
        }
        var c = confirm(f);
        if (c == true) {
            Controller.loadPage(contextRoot + "/business/proposal.handle?methodName=updateProcurementTypeStatus&status=" + b + "&id=" + d + "&description=" + e + "&" + a, null, null)
        }
    },
    viewProposal: function(b, a) {
        if (null == b) {
            alert("Please select an Proposal");
            return
        }
        Controller.loadPage(contextRoot + "/business/proposal.handle?methodName=getDoc&viewMode=true&id=" + b + "&" + a, null, null)
    },
    viewProposalForVerify: function(b, a) {
        if (null == b) {
            alert("Please select an Proposal");
            return
        }
        Controller.loadPage(contextRoot + "/business/proposal.handle?methodName=getDoc&viewMode=true&id=" + b + "&verify=true&" + a, null, null)
    },
    viewProposalForRecommend: function(b, a) {
        if (null == b) {
            alert("Please select an Proposal");
            return
        }
        Controller.loadPage(contextRoot + "/business/proposal.handle?methodName=getDoc&viewMode=true&id=" + b + "&recommend=true&" + a, null, null)
    },
    viewProposalForApprove: function(d, b, c, a) {
        if (null == d) {
            alert("Please select an Proposal");
            return
        }
        Controller.loadPage(contextRoot + "/business/proposal.handle?methodName=getDoc&viewMode=true&id=" + d + "&work.id=" + b + "&work.currentFlow.id=" + c + "&approve=true&" + a, null, null)
    },
    checkIfAllRowsFilledUp: function(e, d, a) {
        var c = null;
        for (var b = e; b >= 0; b--) {
            c = document.getElementById("docItemList[" + b + "].heading").value;
            if (c == "") {
                alert(d);
                return false
            }
        }
        document.getElementById("buttonValue").value = "next";
        Controller.onSubmitWithCsrf("proposalCSAddForm", a, "saveDocItemList", "next")
    },
    saveDocItemList: function(formName, methodname, buttonName) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmit(formName, null, methodname, null, null)
    },
    saveDocItemListWithCsrf: function(formName, methodname, buttonName, csrfToken) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodname, null, null)
    },
    printProposal: function() {
        document.printProposalForm.target = "_blank";
        document.printProposalForm.submit()
    },
    moreRowForAttr: function(c, a) {
        var e = document.getElementById(c);
        var f = e.insertRow(e.rows.length);
        for (var b = 0; b < e.rows[0].cells.length; b++) {
            var d = e.rows.length;
            ProposalController.createCell(f.insertCell(b), d - 1, b, "row", a)
        }
    },
    moreColForAttr: function(d, a) {
        var e = document.getElementById(d);
        for (var b = 0; b < e.rows.length; b++) {
            var c;
            if (b == 0) {
                c = e.rows[0].cells.length
            }
            ProposalController.createCell(e.rows[b].insertCell(e.rows[b].cells.length), b, c, "col", a)
        }
    },
    deleteLastRow: function(b) {
        var c = document.getElementById(b);
        var a = c.rows.length - 1;
        if (a != 0) {
            c.deleteRow(a)
        }
    },
    deleteLastColumn: function(c) {
        var d = document.getElementById(c);
        var a = d.rows[0].cells.length - 1;
        for (var b = 0; b < d.rows.length; b++) {
            if (a == 0 && b == 0) {} else {
                d.rows[b].deleteCell(a)
            }
        }
    },
    createCell: function(j, g, h, b, d) {
        var a = document.createElement("div");
        var e = document.createElement("input");
        if (g == 0) {
            var f = h - 1;
            e.setAttribute("name", "docItemList[" + d + "].columnAttributeList[" + f + "].description");
            e.setAttribute("id", "docItemList[" + d + "].columnAttributeList[" + f + "].description");
            e.setAttribute("value", "COLUMN " + h)
        } else {
            if (h == 0) {
                var c = g - 1;
                e.setAttribute("name", "docItemList[" + d + "].rowAttributeList[" + c + "].description");
                e.setAttribute("id", "docItemList[" + d + "].rowAttributeList[" + c + "].description");
                e.setAttribute("value", "ROW " + g)
            } else {
                var c = g - 1;
                var f = h - 1;
                e.setAttribute("name", "docItemList[" + d + "].proposalCsAttributeValueList[" + c + "].cellList[" + f + "].attributeVal");
                e.setAttribute("id", "docItemList[" + d + "].proposalCsAttributeValueList[" + c + "].cellList[" + f + "].attributeVal");
                e.setAttribute("value", "")
            }
        }
        a.appendChild(e);
        if (g == 0 || h == 0) {
            a.setAttribute("class", "columnClass")
        }
        j.appendChild(a);
        if ((g % 2) == 0) {
            j.setAttribute("class", "columnClass");
            j.setAttribute("class", "columnClass")
        } else {
            j.setAttribute("class", "alternateColumnClass");
            j.setAttribute("class", "alternateColumnClass")
        }
    },
    selectProposal: function(a) {
        pageScope.proposal = {
            "proposal.id": a
        }
    },
    loadProposal: function(a) {
        var b = pageScope.proposal;
        if (null == b) {
            alert("Please select an proposal");
            return
        }
        b.id = b["proposal.id"];
        Controller.loadPage(contextRoot + "/business/proposal.handle?methodName=getDoc&" + a, pageScope.proposal, null)
    },
    search: function search(a) {
        var b = ProposalController.validate(a);
        if (b) {
            SearchController.searchWithForm("proposalSearch", ["lastId"], "searchResult")
        }
    },
    proposalCommRelSearch: function(a) {
        var b = ProposalController.validateProposalCommRel(a);
        if (b) {
            $("#addPropCommRel").empty();
            SearchController.searchWithForm("proposalCommRelSearch", ["lastId"], "searchResult")
        }
    },
    showPropCommRelUsr: function(a) {
        $("#propCommRelDiv").fadeToggle("slow", "linear")
    },
    proposalCommSearch: function(a) {
        $("#addPropComm").empty();
        SearchController.searchWithForm("proposalCommSearch", ["lastId"], "searchResult")
    },
    validateProposalCommRel: function(a) {
        var b = document.getElementById("procurementTypeId").value;
        var c = document.getElementById("buCode").value;
        if (b == 0) {
            alert("Please specify Procurement Type");
            return false
        }
        if (c == "") {
            alert("Please specify FU/BU");
            return false
        }
        return true
    },
    clarification: function(e, d, c, f, b, g, a) {
        Controller.loadPage(contextRoot + "/business/clarification.handle?methodName=getClarification&clarType=" + e + "&entityId=" + d + "&docCode=" + c + "&docCreateDate=" + f + "&docOwnerId=" + b + "&proposalWorkFlow.id=" + g + "&" + a, null, null)
    },
    clarificationForApproval: function(a, g, c, e, j, h, b, d, f) {
        Controller.loadPage(contextRoot + "/business/clarification.handle?methodName=getClarification&clarType=" + a + "&entityId=" + g + "&docCode=" + c + "&docCreateDate=" + e + "&docOwnerId=" + j + "&proposalWorkFlow.id=" + h + "&flow.id=" + b + "&flowId=" + b + "&commId=" + d + "&" + f, null, null)
    },
    showExcelReport: function showExcelReport(a) {
        document.getElementById(a).submit()
    },
    validate: function validate(b) {
        var a = document.getElementById("proposalCreateDateFrom").value;
        var c = document.getElementById("proposalCreateDateTo").value;
        if (a != "") {
            if (c == "") {
                alert("Please specify the Proposal Create Date To correctly");
                return false
            }
        } else {
            if (c != "") {
                if (a == "") {
                    alert("Please specify the Proposal Create Date From correctly");
                    return false
                }
            }
        }
        if (c < a) {
            alert("To date should be greater than From date ");
            return false
        }
        return true
    },
    showReportView: function showReportView(a) {
        var b = ProposalController.validate(a);
        if (b) {
            Controller.onSubmitWithCsrf("proposalReport", a, "viewProposalReport", null, null)
        }
    },
    doTimer: function(b) {
        var a = b + "=" + document.getElementById(b).value;
        if (!timer_is_on) {
            timer_is_on = 1;
            timedCount(a)
        }
    },
    manageWorkFlow: function(c, b, a) {
        if (null == c) {
            alert("Please select an Proposal");
            return
        }
        var d = "&approve=true&manageFlowMode=true";
        if (b == "IV") {
            d = "&verify=true&manageFlowMode=true"
        } else {
            if (b == "IR") {
                d = "&recommend=true&manageFlowMode=true"
            } else {
                if (b == "IA") {
                    d = "&approve=true&manageFlowMode=true"
                }
            }
        }
        Controller.loadPage(contextRoot + "/business/proposal.handle?methodName=getDoc&viewMode=true&id=" + c + d + "&" + a, null, null)
    },
    manageWorkFlowForApproval: function(e, c, a, d, b) {
        var f = "&approve=true&manageFlowMode=true";
        Controller.loadPage(contextRoot + "/business/proposal.handle?methodName=manageWorkFlow&viewMode=true&id=" + e + "&work.id=" + a + "&work.currentFlow.id=" + d + f + "&" + b, null, null)
    },
    otherRecipientClar: function otherRecipientClar() {
        if (document.getElementById("othersEnableSelected").checked == true) {
            document.getElementById("clarDiv").style.visibility = "visible"
        }
        if (document.getElementById("othersEnableSelected").checked == false) {
            document.getElementById("clarDiv").style.visibility = "hidden"
        }
    },
    alertForNotRecommendation: function() {
        alert("If 'Not recommended' then the proposal would be treated as Dropped proposal and  can't be modified further.")
    },
    selectProcComm: function(a) {
        if (a == "102") {
            var b = document.getElementById("commTypeId_103");
            if (null != b) {
                b.checked = true
            }
        }
    }
};
var PaymentController = {
    viewPayment: function(b, a) {
        if (null == b) {
            alert("Please select an payment");
            return
        }
        Controller.loadPage(contextRoot + "/business/payment.handle?methodName=getDoc&viewMode=true&id=" + b + "&" + a, null, null)
    },
    printPayment: function(a, b, c) {
        document.paymentPrintForm.action = contextRoot + "/business/report.action";
        document.paymentPrintForm.methodName.value = "showReport";
        document.paymentPrintForm.reportName.value = "paymentDtlViewPrint";
        document.paymentPrintForm.popUp.value = "Y";
        document.paymentPrintForm.paymentId.value = a;
        document.paymentPrintForm.orgId.value = b;
        document.paymentPrintForm.orgName.value = c;
        document.paymentPrintForm.target = "_blank";
        document.paymentPrintForm.submit()
    }
};
var DocumentController = {
    saveDocItemList: function(formName, methodname, buttonName) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmit(formName, null, methodname, null, null)
    }
};
var PreRfqController = {
    selectPreRfq: function(b, a) {
        pageScope.preRfq = {
            id: b,
            categoryId: a
        };
        if (sessionScope._currPrivId == 102) {
            $("#viewPreRfq").css("display", "inline")
        }
        if (sessionScope._currPrivId == 101) {
            $("#editPreRfq").css("display", "inline")
        }
    },
    addSupplier: function() {
        var d = document.preRfqSellerForm.preRfqSeller.options.length;
        if (d > 0) {
            for (var a = --d; a >= 0; a--) {
                if (document.preRfqSellerForm.preRfqSeller.options[a].selected) {
                    var g = "",
                        f = "",
                        c = "";
                    f = document.preRfqSellerForm.preRfqSeller.options[a].text;
                    c = document.preRfqSellerForm.preRfqSeller.options[a].id;
                    var b = new Option(f, c);
                    var e = document.preRfqSellerForm.selectedSellerIds.length;
                    document.preRfqSellerForm.selectedSellerIds.options[e] = b;
                    document.preRfqSellerForm.preRfqSeller.options[a] = null
                }
            }
        }
    },
    removeSupplier: function() {
        var d = document.preRfqSellerForm.selectedSellerIds.options.length;
        if (d >= 0) {
            for (var a = --d; a >= 0; a--) {
                if (document.preRfqSellerForm.selectedSellerIds.options[a].selected) {
                    var g = "",
                        f = "",
                        c = "";
                    c = document.preRfqSellerForm.selectedSellerIds.options[a].id;
                    f = document.preRfqSellerForm.selectedSellerIds.options[a].text;
                    var b = new Option(f, c);
                    var e = document.preRfqSellerForm.preRfqSeller.length;
                    document.preRfqSellerForm.preRfqSeller.options[e] = b;
                    document.preRfqSellerForm.selectedSellerIds.options[a] = null
                }
            }
        }
    },
    selectSuppliersAndSubmit: function(d, g, b, c, f) {
        var e = document.preRfqSellerForm.selectedSellerIds.options.length;
        for (var a = 0; a < e; a++) {
            document.preRfqSellerForm.selectedSellerIds.options[a].selected = true
        }
        Controller.onSubmit(d, g, b, c, f)
    },
    modalwin: function(orgType, csrfToken) {
        var entityId = document.getElementById("id").value;
        var docCode = document.getElementById("code").value;
        var docCreateDate = document.getElementById("createDate").value;
        var docOwnerId = document.getElementById("owner.id").value;
        var url = contextRoot + "/business/clarification.action?popUp=Y&methodName=getClarification&clarType=PRERFQCLAR_BUYER&entityId=" + entityId + "&docCode=" + docCode + "&docCreateDate=" + docCreateDate + "&" + csrfToken;
        if (orgType == "SELLER") {
            url = contextRoot + "/business/clarification.action?popUp=Y&methodName=getClarification&clarType=PRERFQCLAR_SELLER&entityId=" + entityId + "&docCode=" + docCode + "&docCreateDate=" + docCreateDate + "&docOwnerId=" + docOwnerId + "&" + csrfToken
        }
        eval('window.showModalDialog(url,"","resizable:1,dialogHeight:600,dialogWidth:500")')
    },
    addInvitee: function(a, b) {
        tbody = document.getElementById(a);
        var e = tbody.rows.length - 2;
        var c = e - b;
        if (c < 0) {
            c = 0
        }
        if (!PreRfqController.validateInvitee(c)) {
            return
        }
        var j = tbody.insertRow(tbody.rows.length);
        var h = j.insertCell(0);
        h.setAttribute("class", "dataClass");
        h.innerHTML = '<input type="text" size="20" name="invitees[' + c + '].userFirstName"/>';
        var g = j.insertCell(1);
        g.setAttribute("class", "dataClass");
        g.innerHTML = '<input type="text" size="20" name="invitees[' + c + '].userMail"/>';
        var f = j.insertCell(2);
        f.setAttribute("class", "dataClass");
        f.innerHTML = '<input type="text" size="30" name="invitees[' + c + '].organization.organizationName"/>';
        var d = j.insertCell(3);
        d.innerHTML = '<a class="pageContentLink" href="javascript:PreRfqController.delInvitee(inviteeTab,' + e + ');">DELETE ROW</a>'
    },
    delInvitee: function(c, b) {
        var a = "inviteeTab";
        tbody = document.getElementById(a);
        if (confirm("Delete The Invitee?")) {
            tbody.deleteRow(b + 2)
        }
    },
    onSubmit: function(j, d, h, g, k) {
        if (!Util.assertNoServerCall()) {
            return
        }
        log("formId=" + j);
        var b;
        if (j == null) {
            b = $("form[id!='dummyForm']")
        } else {
            b = $("#" + j)
        }
        var f = b.serialize();
        var e = "";
        if (h != null) {
            log("methodName=" + h);
            f += "&methodName=" + h;
            e = "methodName=" + h
        }
        if (typeof g != "undefined" && g != null) {
            f += "&button=" + g;
            e += "&button=" + g
        }
        if (d != null) {
            f += "&" + $.param(d);
            e += "&" + d
        }
        log("action=" + b.attr("action"));
        log("param=" + f);
        if (b.attr("enctype") == "multipart/form-data") {
            var a = b.attr("action") + "?" + e;
            var l = {
                url: a,
                type: b.attr("method"),
                timeout: 6000
            };
            var c = $(b, "#_content");
            c.ajaxSubmit(l)
        } else {
            if (b.attr("method") == "post") {
                $.post(b.attr("action"), f, k)
            } else {
                if (b.attr("method") == "get") {
                    $.get(b.attr("action"), f, k)
                }
            }
        }
    },
    validateInvitee: function(b) {
        var e = 15;
        if (b == e) {
            alert("Maximum " + e + " invitee can be added");
            return false
        }
        if (b > 0) {
            var c = document.getElementById("invitees[" + (b - 1) + "].userFirstName");
            if (null != c) {
                if ((c.value == "") || (c.value == null)) {
                    alert("Please specify the Name for previous row");
                    return false
                }
            }
            var a = document.getElementById("invitees[" + (b - 1) + "].userMail");
            if (null != a) {
                if ((a.value == "") || (a.value == null)) {
                    alert("Please specify the email for previous row");
                    return false
                }
            }
            var d = document.getElementById("inviteeTab[" + (b - 1) + "].organization.organizationName");
            if (null != d) {
                if ((d.value == "") || (d.value == null)) {
                    alert("Please specify the Organization for previous row");
                    return false
                }
            }
        }
        return true
    }
};
var RfiController = {
    viewSectionSummary: function() {
        $("input[name='methodName']").val("viewDocumentSummeryReport");
        Controller.onSubmit("ModifyRfiDetailForm", null, "viewDocumentSummeryReport", null, null)
    },
    showConfigTemplateList: function(a) {
        $("input[name='userId']").val(a);
        $("input[name='methodName']").val("showDocumentConfigTemplateList");
        Controller.onSubmit("viewConfigTemplateForm", null, "showDocumentConfigTemplateList", null, null)
    },
    goToRfiResponseList: function() {
        $("input[name='methodName']").val("viewRfiResponseList");
        Controller.onSubmit("ModifyRfiDetailForm", null, "viewRfiResponseList", null, null)
    },
    viewRfiResponse: function() {
        $("input[name='methodName']").val("viewRfiUserSubmission");
        Controller.onSubmit("ModifyRfiDetailForm", null, "viewRfiUserSubmission", null, null)
    },
    finalSubmission: function(a) {
        $("input[name='methodName']").val("finalRfiSubmission");
        Controller.onSubmitWithCsrf("viewConfigTemplateForm", a, "finalRfiSubmission", null, null)
    },
    getSubmission: function() {
        $("input[name='methodName']").val("addRfiSubmission");
        Controller.onSubmit("rfiSubmissionAddForm", null, "addRfiSubmission", null, null)
    },
    setValue: function(a, b) {
        $("input[name='oldDocumentSubmssionId']").val(a);
        if ($("input[name='selectOption']:checked").val() != "2") {
            $("#tr4").hide()
        } else {
            $("#tr4").show()
        }
        $("input[name='code']").val(b)
    },
    addSubmission: function() {
        $("input[name='methodName']").val("checkRfiSubmission");
        Controller.onSubmit("rfiResponseAddForm", null, "checkRfiSubmission", null, null)
    },
    viewConfigTemplateList: function() {
        $("input[name='methodName']").val("showDocumentConfigTemplateList");
        Controller.onSubmit("rfiResponseAddForm", null, "showDocumentConfigTemplateList", null, null)
    },
    response: function() {
        $("input[name='methodName']").val("addDocumentResponse");
        Controller.onSubmit("rfiResponseAddForm", null, "addDocumentResponse", null, null)
    },
    allowInputForText: function() {
        if ($("input[name='responseFlag']:checked").val() == "N") {
            $("textarea[name='responseComment']").removeAttr("readonly");
            $("textarea[name='responseComment']").css("background", "white")
        } else {
            $("textarea[name='responseComment']").attr("readonly", "true");
            $("textarea[name='responseComment']").css("background", "lightGrey")
        }
    },
    addRfiResponse: function() {
        $("input[name='methodName']").val("getDocumentResponse");
        Controller.onSubmit("ModifyRfiDetailForm", null, "getDocumentResponse", null, null)
    },
    backToView: function(a) {
        document.BackToRfiViewForm.responseFlag.value = a;
        document.BackToRfiViewForm.submit()
    },
    showSpecAttachment: function(b, a) {
        window.open(contextRoot + "/business/rfi.handle?methodName=getSpecificAttachments&itemId=" + b + "&" + a, "attachment", "top=0, left=510, height=400, width=500, toolbar=no, status=no, scrollbars=yes ")
    },
    viewRfiItemAttDesc: function(e, d, c, b, a) {
        window.open(contextRoot + "/business/rfi.handle?methodName=getDocumentLine&entityId=" + e + "&entityValue=" + c + "&tableName=" + d + "&documentCode=" + b + "&" + a, "openline", "top=0, left=510, height=400, width=500, toolbar=no, status=no, scrollbars=yes ")
    },
    showRfiItemByItemCat: function(a) {
        $("input:hidden[name='rfiItemCatId']").val($("input:hidden[name='rfiItemCatList[" + a + "].id']").val());
        document.rfiViewForm.submit()
    },
    viewUserContact: function(a) {
        document.viewUserContactForm.profileIdentity.value = a;
        window.open("", "userContactView_window", "scrollbars=1, top=0, left=510, height=400, width=500, toolbar=no, status=no");
        document.viewUserContactForm.target = "userContactView_window";
        document.viewUserContactForm.submit()
    },
    viewRfi: function(d, c, a, b) {
        if (null == d) {
            alert("Please select an Rfi");
            return
        }
        Controller.loadPage(contextRoot + "/business/rfi.handle?methodName=getDoc&viewMode=true&rfiId=" + d + "&rfqCategoryId=" + b + "&rfiPartNo=" + c + "&" + a, null, null)
    },
    search: function(a) {
        var b = RfiController.validateSearch(a);
        if (b) {
            SearchController.searchWithForm("rfiSearch", ["lastId"], "searchResult")
        }
    },
    validateSearch: function(a) {
        var c = document.getElementById("rfiStartDateFrom").value;
        var e = document.getElementById("rfiStartDateTo").value;
        var d = document.getElementById("rfiDueDateFrom").value;
        var b = document.getElementById("rfiDueDateTo").value;
        if (c != "") {
            if (e == "") {
                alert("Please specify the Rfi Start Date To correctly");
                return false
            }
        } else {
            if (e != "") {
                if (c == "") {
                    alert("Please specify the Rfi Start Date From correctly");
                    return false
                }
            }
        }
        if ((e < c) || (b < d)) {
            alert("To Date should be greater than From Date ");
            return false
        }
        if (d != "") {
            if (b == "") {
                alert("Please specify the Rfi Due Date To correctly");
                return false
            }
        } else {
            if (b != "") {
                if (d == "") {
                    alert("Please specify the Rfi Due Date From correctly");
                    return false
                }
            }
        }
        return true
    },
    fetchAttribute: function(b, a) {
        document.rfiItemAddForm.selectedRfiItemId.value = b;
        RfiController.saveDocItemListWithCsrf("rfiItemAddForm", "saveDocItemList", "attr", a)
    },
    getDescOnLoad: function(a) {
        var e = document.getElementById("itemTab");
        var b = e.rows.length - 2;
        for (var c = 0; c < b; c++) {
            var d = document.getElementById("docItemList[" + c + "].code").value;
            var f = document.getElementById("docItemList[" + c + "].id").value;
            if (d == "" || f != 0) {
                return
            } else {
                RfiController.getItemDetail(c, document.getElementById("docItemList[" + c + "].code"), a)
            }
        }
    },
    getDescr: function(c) {
        if (!RfiController.validate(c)) {
            return
        }
        var b = document.rfiItemAddForm.csrfTokenName.value;
        var d = document.rfiItemAddForm.csrfTokenValue.value;
        var a = b + "=" + d;
        RfiController.getItemDetail(c, document.getElementById("docItemList[" + c + "].code"), a)
    },
    validate: function(a) {
        var b = document.getElementById("docItemList[" + a + "].code").value;
        if (b == "") {
            alert("Please specify the Code to get the Description");
            return false
        }
        return true
    },
    getItemDetail: function(e, c, a) {
        alert("hello");
        var d = $("form[id!='dummyForm']");
        var b = 0;
        $('input[id$=".code"]', d).each(function() {
            this.disabled = true
        });
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getItem&code=" + c.value + "&" + a, null, function(m) {
            $('input[id$=".code"]', d).each(function() {
                this.disabled = false
            });
            if (m._errors != null) {
                alert("i am here");
                Util.showMessage(m);
                document.getElementById("docItemList[" + e + "].code").value = "";
                return
            }
            Util.clearContent($("#_msgBox"));
            document.getElementById("docItemList[" + e + "].bigRfiItemLineDescription").value = Controller.unescapeHtml(m.item.description);
            var k = document.getElementById("docItemList[" + e + "].rfiItemQuantity").value;
            if (document.getElementById("buyerOrgId")) {
                b = document.getElementById("buyerOrgId").value
            }
            if (b == 2350) {
                if (m.item.isServiceItemYN == "Y") {
                    document.getElementById("docItemList[" + e + "].bigRfiItemLineDescription").readOnly = false;
                    document.getElementById("docItemList[" + e + "].bigRfiItemLineDescription").removeAttribute("readonly")
                } else {
                    document.getElementById("docItemList[" + e + "].bigRfiItemLineDescription").readOnly = true
                }
            }
            var l = new Array();
            var g = 0;
            if (m.length == 0) {
                return
            }
            var f = "item.action?popUp=Y&methodName=openItemAttachment&itemId=" + m.item.id + "&fileName=";
            for (var h = 0; h < m.item.attachments.length; h++) {
                l[g++] = '<div><input name="docItemList[';
                l[g++] = e;
                l[g++] = "].possibleAttachments[";
                l[g++] = h;
                l[g++] = "].selected";
                l[g++] = '" type="checkbox" value="true"/>';
                l[g++] = '<a target = "_new" href="';
                l[g++] = f + m.item.attachments[h].fileName + "&ext=" + m.item.attachments[h].extention + "&" + a;
                l[g++] = '">';
                l[g++] = m.item.attachments[h].label;
                l[g++] = "</a>";
                l[g++] = '<input name="docItemList[';
                l[g++] = e;
                l[g++] = "].possibleAttachments[";
                l[g++] = h;
                l[g++] = "].fileName";
                l[g++] = '" type="hidden" value="';
                l[g++] = m.item.attachments[h].fileName;
                l[g++] = '"/>';
                l[g++] = "</div>"
            }
            var n = document.getElementById("inItemTab" + e);
            n.rows[3].cells[1].innerHTML = l.join("")
        })
    },
    checkIfAllRowsFilledUp: function(e, d, a) {
        var c = null;
        for (var b = e; b >= 0; b--) {
            c = document.getElementById("docItemList[" + b + "].code").value;
            if (c == "") {
                alert(d);
                return false
            }
        }
        RfiController.saveDocItemListWithCsrf("rfiItemAddForm", "saveDocItemList", "next", a)
    },
    saveDocItemListWithCsrf: function(formName, methodname, buttonName, csrfToken) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodname, null, null)
    },
    viewDocItemListWithCsrf: function(formName, methodname, buttonName, csrfToken) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodname, null, null)
    },
    submitOnCategorySelection: function() {
        var c = document.rfiAddForm.rfqCategoryId.value;
        var b = document.rfiAddForm.viewMode.value;
        var a = document.rfiAddForm.OWASP_CSRFTOKEN.value;
        Controller.loadPage(contextRoot + "/business/rfi.handle?methodName=getDoc&rfqCategoryId=" + c + "&viewMode=" + b + "&OWASP_CSRFTOKEN=" + a, null, null)
    },
    fillOpenDate: function() {
        var a = document.getElementById("rfiDate.rfiEndDate").value;
        var g = a.substr(0, 4);
        var f = a.substr(5, 2);
        var h = a.substr(8, 2);
        var d = a.substr(11, 2);
        var e = a.substr(14, 2);
        var c = a.substr(17, 2);
        var j = new Date(g, (f - 1), h);
        j.setHours(d, e, c, 0);
        var b = new Date(j.getTime() + 15 * 60000);
        $("#rfiOpenDate").val(b.getYear() + "-" + (b.getMonth() + 1) + "-" + b.getDate() + " " + b.getHours() + ":" + b.getMinutes() + ":" + b.getSeconds())
    },
    signRfi: function(a, y, d, h, q, l, s, t) {
        if (h == 114) {
            RfiController.fillOpenDate()
        }
        var p = true;
        var r = "A";
        var m = document.getElementById("id").value;
        var b = document.getElementById("code").value;
        var g = document.getElementById("owner.id").value;
        var x = document.getElementById("actionFlag").value;
        var k = document.getElementById("partCount").value;
        var e = document.getElementById("rfiDate.rfiStartDate").value;
        var u = document.getElementById("rfiDate.rfiEndDate").value;
        var c = document.getElementById("rfiDate.rfiOpenDate").value;
        var w = "";
        var f = false;
        document.rfiAddForm.methodName.value = "saveDocAndShowItemList";
        document.rfiAddForm.buttonValue.value = s;
        var n = "1";
        if (b == "" && t != "true") {
            alert("Rfi Code is Required");
            p = false;
            return p
        }
        if (e == "") {
            alert("Rfi Start Date is Required");
            p = false;
            return p
        }
        if (u == "") {
            alert("Rfi End Date is Required");
            p = false;
            return p
        }
        if (c == "") {
            alert("Rfi Open Date is Required");
            p = false;
            return p
        }
        if (m == "0" && d) {
            f = true
        } else {
            if (m != "0" && q) {
                f = true
            }
        }
        if (y && d && f) {
            if (g == "0") {
                g = a
            }
            if (x == "" || x == "I") {
                var r = "W"
            }
            var v = b + "#|#" + rfqPartCount + "#|#" + g + "#|#" + r;
            var o = n + "#|#" + e + "#|#" + u + "#|#" + c;
            p = p && signDocument(v);
            p = p && signDocumentAndAsingnValue(o, "rfiDate.digitalCert.signHash")
        }
        if (p && RfiController.validateSubmit(l)) {
            var j = document.rfiAddForm.OWASP_CSRFTOKEN.value;
            Controller.onSubmitWithCsrf("rfiAddForm", "csrfToken", "saveDocAndShowItemList", null, null)
        }
    },
    validateSubmit: function(e) {
        var b = document.getElementById("actionFlag").value;
        var a = $("input[name='orgId']").val();
        var d = document.getElementById("id").value;
        if (null != b) {
            if (b == "A") {
                var c = false;
                if (a == e) {
                    c = confirm("Once Activated, the RFP details can not be changed. Do you want to activate?")
                } else {
                    c = confirm("Once Activated, the RfI details can not be changed. Do you want to activate?")
                }
                if (c == true) {
                    return true
                } else {
                    return false
                }
            } else {
                return true
            }
        } else {
            return true
        }
    },
    moreRow: function(d, g) {
        tbody = document.getElementById(d);
        var f = tbody.rows.length - 1;
        alert("index" + f);
        if (f < 0) {
            f = 0
        }
        if (f > 0) {
            var b = document.getElementById("rfiSpecialTerm[" + (f - 1) + "].bigRfiTermLineDescription")
        }
        var e = document.rfiAddForm.termCount.value;
        var c = document.getElementById("termTable");
        var j = c.getElementsByTagName("tr")[e].parentNode;
        var h = c.getElementsByTagName("tr")[e].cloneNode(true);
        h.setAttribute("id", "r" + e);
        var k = parseInt(e) + 1;
        var a = h.getElementsByTagName("input");
        j.appendChild(h);
        alert("Length:" + $("#termTable>tr:eq(" + k + ")").html());
        $("#termTable>tr:eq(" + k + ")").find("input").removeAttr("name").attr("name", "rfiSpecialTerm[" + e + "].rfiTermSerialNumber");
        $("#termTable>tr:eq(" + k + ")").find("input").attr("value", k);
        alert("NAME AFTER:" + $("#termTable>tr:eq(" + k + ")").find("input").attr("name"));
        var a = h.getElementsByTagName("select");
        a[0].setAttribute("name", "rfiSpecialTerm[" + e + "].rfiTermTerm.id");
        a[0].setAttribute("value", "-1");
        var a = h.getElementsByTagName("textarea");
        a[0].setAttribute("name", "rfiSpecialTerm[" + e + "].bigRfiTermLineDescription");
        a[0].setAttribute("value", e);
        var a = h.getElementsByTagName("a");
        a[0].setAttribute("href", "#");
        alert("prpindex" + e);
        a[0].setAttribute("onClick", "RfiController:deleteRow1('termTable'," + e + ",'" + g + "');");
        document.rfiAddForm.termCount.value = parseFloat(e) + 1
    },
    deleteRow: function(b, a, d) {
        alert("reference:::" + a);
        var c = document.getElementById("r" + a);
        tbody = document.getElementById(b);
        if (tbody.rows.length == 2) {
            alert("The first row cannot be removed.");
            return
        }
        if (confirm(d)) {
            tbody.deleteRow(a + 1)
        }
    },
    getRfiUserSearch: function(a) {
        Controller.onSubmit("rfiForm", null, "getDocumentUserSearch", null, null)
    },
    getRfiUserSearchResult: function(a) {
        $("input[name='methodName']").val("documentUserSearchResult");
        Controller.onSubmit("rfiForm", null, "documentUserSearchResult", null, null)
    },
    toggleUser: function(b) {
        var a = $("#" + b).attr("id").split("-");
        var d = a[0];
        var c = a[1];
        $("#" + d + " option:selected").each(function() {
            $("#" + c).append($(this).clone());
            $(this).remove()
        })
    },
    saveRfiUser: function(a) {
        var c = $("select[id='mapped'] option").map(function() {
            return $(this).val()
        }).get().join(",");
        $("input[name='mappedSellerIds']").val(c);
        var b = $("form[id='rfiForm']", "#_content");
        $("input[name='methodName']", b).val("saveDocumentUser");
        Controller.onSubmit("rfiForm", null, "saveDocumentUser", null, null)
    },
    viewSelectedTemplate: function() {
        $("input[name='methodName']").val("getDocumentConfigTemplate");
        Controller.onSubmit("rfiForm", null, "getDocumentConfigTemplate", null, null)
    },
    getRfiConfigTemplateList: function() {
        $("input[name='methodName']").val("getDocumentConfigTemplateList");
        Controller.onSubmit("rfiForm", null, "getDocumentConfigTemplateList", null, null)
    },
    attachTemplate: function() {
        var a = confirm("DO YOU WANT TO ATTACH THE QUESTIONNAIRE TEMPLATE");
        if (a == true) {
            $("input[name='methodName']").val("attachDocumentConfigTemplate");
            $("input[name='buttonValue']").val("ATTACH TEMPLATE AND GOTO R F I");
            Controller.onSubmit("rfiForm", null, "attachDocumentConfigTemplate", null, null)
        } else {
            return false
        }
    },
    downloadExcel: function(a) {
        document.documentItemExcelDownload.submit()
    },
    getRfiItemCatList: function() {
        $("input[name='methodName']").val("getDocumentItemCatList");
        Controller.onSubmit("rfiForm", null, "getDocumentItemCatList", null, null)
    },
    uploadExcel: function(a) {
        document.rfiItemUploadForm.submit()
    },
    saveLotWithDocument: function() {
        Controller.onSubmit("rfiItemCatAddForm", null, "saveDocumentItemCat", null, null)
    },
    getDescriptionByLotCode: function(b) {
        var d = $("form[id!='rfiItemCatAddForm']", "#_content");
        var c = $("#selectId option:selected", d).text();
        var a = $("#csrfToken").val();
        if ($("#selectId option:selected", d).val() == "0") {
            $("#selectDescription", d).html("");
            return
        }
        Controller.loadData(contextRoot + "/business/item.handle?methodName=getLotDescriptionByLotCode&itemCatCode=" + c + "&" + a, null, function(e) {
            if (e._errors != null) {
                log(e);
                Util.showMessage(e);
                return
            }
            Util.clearContent($("#_msgBox"));
            $("#selectDescriptionId", d).html("<textarea  name='rfiItemCatList[" + b + "].description' rows='3' cols='20'>" + Controller.unescapeHtml(e.lot.description) + "</textarea>");
            $("#lastPurchasedPriceId", d).html("<input type='text' name='rfiItemCatList[" + b + "].lastPurchasedPrice' value='0.0' />")
        })
    },
    getRfiConfigTemplate: function() {
        $("input[name='methodName']").val("getAttachDocumentConfigTemplate");
        Controller.onSubmit("rfiForm", null, "getAttachDocumentConfigTemplate", null, null)
    },
    deleteRfiSection: function(formName, csrfToken, methodName, entityId, entityValue, docSectionId, docTemplateId) {
        eval("document." + formName).entityId.value = entityId;
        eval("document." + formName).entityValue.value = entityValue;
        eval("document." + formName).documentSectionId.value = docSectionId;
        eval("document." + formName).documentConfigTemplateId.value = docTemplateId;
        eval("document." + formName).methodName.value = methodName;
        if (entityId == 100) {
            if (confirm("Delete the Section from the RFI?")) {
                Controller.onSubmit(formName, null, methodName, null, null)
            }
        }
    },
    retrieveRfiSection: function(formName, csrfToken, methodName, entityId, entityValue, docSectionId, docTemplateId) {
        eval("document." + formName).entityId.value = entityId;
        eval("document." + formName).entityValue.value = entityValue;
        eval("document." + formName).documentSectionId.value = docSectionId;
        eval("document." + formName).documentConfigTemplateId.value = docTemplateId;
        eval("document." + formName).methodName.value = methodName;
        Controller.onSubmit(formName, null, methodName, null, null)
    },
    submitDocumentSection: function(a) {
        $("input[name='methodName']").val("saveDocumentSection");
        $("input[name='buttonValue']").val(a);
        Controller.onSubmit("documetSectionModifyForm", null, "saveDocumentSection", null, null)
    },
    checkIfAllDocumentRowsFilledUp: function(d, c) {
        var b = null;
        for (var a = d; a >= 0; a--) {
            b = document.getElementById("docSection.docSecQuesRelList[" + a + "].docQuestion.code").value;
            if (b == "") {
                alert(c);
                return false
            }
        }
        document.getElementById("buttonValue").value = "next";
        Controller.onSubmit("documentQuestionAddForm", null, "saveDocumentQuestion", null, null)
    },
    saveDocumentSectionQuestionRelListWithCsrf: function(formName, methodname, buttonName, csrfToken) {
        eval("document." + formName).buttonValue.value = buttonName;
        Controller.onSubmit(formName, null, methodname, null, null)
    },
    goToRfi: function(formName, methodname, modifyType, csrfToken) {
        eval("document." + formName).modifyType.value = modifyType;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodname, null, null)
    },
    modifyRfiDetail: function(d, b, a, c) {
        Controller.onSubmitWithCsrf(b, a, c, null, null)
    },
    saveRfi: function(d, a, e, c, b) {
        if (d == "<%=IConstant.ORGANIZATION_ID_CORUS %>") {
            fillOpenDate()
        }
        document.getElementById("buttonValue").value = b;
        Controller.onSubmitWithCsrf(c, a, e, null, null)
    }
};
var HelpController = {
    openHelpPage: function(a, b) {
        window.open(contextRoot + "/html/help/organization" + a + "/help.html#" + b, "helpPopWinwod", "top=400, left=400, height=130, width=600, toolbar=no, status=no, scrollbars=no, location=no, resizable=no, menubar=no")
    },
    helpPage: function(a) {
        window.showModalDialog(contextRoot + "/html/help/organization" + a + "/help.html", "helpWindow", "dialogHeight: 400px; dialogWidth: 600px; dialogTop: 300px; dialogLeft: 300px; edge: Raised; center: Yes; resizable: Yes; status: Yes; ")
    },
    openHelpOnClick: function(b, a) {
        HelpController.showTip(document.getElementById(b), document.getElementById(a).innerHTML)
    },
    showTip: function(b, c) {
        if (document.all || document.getElementById) {
            thetitle = c.split("<br>");
            if (thetitle.length > 1) {
                thetitles = "";
                for (var a = 0; a < thetitle.length; a++) {
                    thetitles += thetitle[a]
                }
                b.title = thetitles
            } else {
                b.title = c
            }
        }
    }
};
var ReportController = {
    getReportInputs: function(formName, methodName) {
        eval("document." + formName).methodName.value = methodName;
        eval("document." + formName).action = contextRoot + "/business/search.action";
        eval("document." + formName).submit()
    },
    getReportInputDate: function(a) {
        rfqDatePeriod = +document.getElementById(a).rfqDatePeriod.value;
        document.getElementById(a).showDatePicker.value = rfqDatePeriod
    },
    submitForm: function(a) {
        document.getElementById(a).methodName.value = "showReportInput";
        document.getElementById(a).target = "_self";
        document.getElementById(a).submit()
    },
    showReport: function(a) {
        document.getElementById(a).methodName.value = "showReport";
        document.getElementById(a).target = "_new";
        document.getElementById(a).submit()
    },
    generateExcelReport: function(a) {
        document.getElementById(a).methodName.value = "reportDownload";
        document.getElementById(a).target = "_self";
        document.getElementById(a).submit()
    },
    generateExcelReportRfqApprover: function(c) {
        document.getElementById(c).methodName.value = "reportDownload";
        document.getElementById(c).target = "_self";
        var a = document.getElementById("startDateRfqApproverReport").value;
        var b = document.getElementById("endDateRfqApproverReport").value;
        a = a + " 00:00:00.0";
        b = b + " 23:59:59.0";
        document.getElementById("startDateRfqApproverReport").value = a;
        document.getElementById("endDateRfqApproverReport").value = b;
        document.getElementById(c).submit()
    },
    showReportPDF: function(a) {
        document.getElementById(a).methodName.value = "showReport";
        if (dateValidation()) {
            document.getElementById(a).target = "_blank"
        } else {
            document.getElementById(a).target = "_self"
        }
        document.getElementById(a).submit()
    },
    showExcelReportDownload: function(a) {
        document.getElementById(a).methodName.value = "showExcelReport";
        document.getElementById(a).target = "_self";
        document.getElementById(a).submit()
    },
    showExcelReport: function(a) {
        document.getElementById(a).methodName.value = "showExcelReport";
        document.getElementById(a).target = "searchResultPopupXls";
        window.open("", "searchResultPopupXls", "top=400, left=400, height=300, width=600, toolbar=no, status=no, scrollbars=yes, location=no, resizable=yes, menubar=yes");
        document.getElementById(a).submit()
    },
    showReportXLS: function(b, a) {
        document.getElementById(b).methodName.value = "showReport";
        document.getElementById(b).reportType.value = "XLS";
        document.getElementById(b).submit()
    },
    generateReport: function(formName, csrfToken, methodname, searchReportType) {
        eval("document." + formName).searchReportType.value = searchReportType;
        eval("document." + formName).methodName.value = methodname;
        eval("document." + formName).action = contextRoot + "/business/search.action";
        eval("document." + formName).target = "_self";
        eval("document." + formName).submit()
    },
    doSearch: function(formName, methodName, resultDiv, searchReportType) {
        $(".msgBox").html("").hide();
        eval("document." + formName).searchReportType.value = searchReportType;
        eval("document." + formName).methodName.value = methodName;
        eval("document." + formName).action = contextRoot + "/business/search.handle";
        eval("document." + formName).target = "_self";
        SearchController.searchWithForm(formName, ["lastId"], resultDiv)
    },
    initSearch: function(formName, methodName, csrfToken) {
        eval("document." + formName).action = contextRoot + "/business/search.handle";
        eval("document." + formName).methodName.value = methodName;
        Controller.onSubmitWithCsrf(formName, csrfToken, methodName, null, null)
    },
    modifySupplier: function(formName, userId) {
        eval("document." + formName).id.value = userId;
        eval("document." + formName).submit()
    },
    modifyBuyer: function(formName, userId) {
        eval("document." + formName).profileIdentity.value = userId;
        eval("document." + formName).action = contextRoot + "/administration/getUserModifyAction.do";
        eval("document." + formName).submit()
    },
    updateUserStatus: function(formName, authCode, authRole, authStatus, userId, buyerOrgId) {
        eval("document." + formName).authenticationUserCode.value = authCode;
        eval("document." + formName).authenticationRole.value = authRole;
        eval("document." + formName).authenticationStatus.value = authStatus;
        eval("document." + formName).userIdArray.value = userId;
        eval("document." + formName).userBuyerOrgId.value = buyerOrgId;
        eval("document." + formName).authenticationOrganization.value = buyerOrgId;
        Controller.onSubmitWithCsrf(formName, "<csrf:token-name/>=<csrf:token-value/>", "authenticationUpdateStatus", null, null)
    },
    resetPassword : function(/*String*/ formName, /*int*/ userId){
		eval("document."+formName).userBuyerOrgId.value = $('#buyerOrgName').val();
		eval("document."+formName).userIdArray.value = userId;
		Controller.onSubmitWithCsrf(formName,'<csrf:token-name/>=<csrf:token-value/>',"getAuthenticationPasswordReset",null,null);
	},
    
	generateVendorAndItemList :function(/*String*/ formName, /*String*/ csrfToken, /*String*/ searchReportType)
	{
		var today = new Date();
		var dd = today.getDate();
		var mm = today.getMonth()+1;
		if(mm<10)
			{
			mm = '0'+mm;
			}
		var yyyy = today.getFullYear();
		var dateVal = yyyy+'-'+mm+'-'+dd;
		startDate = eval("document."+formName).rfqStartDateFrom.value;
		endDate = eval("document."+formName).rfqStartDateTo.value;
		if(endDate<startDate){
			alert("RFQ START DATE TO date should be greater than From date ");
			return false;
		}
		if(endDate>dateVal){
			alert("RFQ START DATE TO date should be greater than Current Date ");
			return false;
		}
		eval("document."+formName).searchReportType.value = searchReportType;
		eval("document."+formName).submit();
	},
	resetValueVendor :function(/*String*/ formName)
	{
		eval("document."+formName).rfqStartDateFrom.value='';
		eval("document."+formName).rfqStartDateTo.value='';
	},
	validateItemHistory : function(/*String*/ formName){
		var today = new Date();
		var dd = today.getDate();
		var mm = today.getMonth()+1;
		if(mm<10)
			{
			mm = '0'+mm;
			}
		if(dd<10)
		{
		dd = '0'+dd;
		}
		var yyyy = today.getFullYear();
		var dateVal = yyyy+'-'+mm+'-'+dd;
		var startDate = eval("document."+formName).publishedDateFrom.value;
		var endDate = eval("document."+formName).publishedDateTo.value;
		var itemCode = eval("document."+formName).itemCode.value;
			if(itemCode==null || itemCode==''){
				alert('Enter Item Code');
				return false;
				}
			else if(endDate>dateVal){
				
				alert("RFQ PUBLISHED DATE TO date must be less than CURRENT DATE ");
				return false;
				
			}
			else if(startDate>dateVal){
				alert("RFQ PUBLISHED DATE FROM date must be less than CURRENT DATE ");
				return false;
			}
			else if(endDate<startDate){
				
				alert("RFQ PUBLISHED DATE TO date must be greater than RFQ PUBLISHED DATE FROM");
				return false;
				
			}
			else
			return true;
		},
		resetItemHistory : function (formName /*String*/)
		{
			eval("document."+formName).publishedDateFrom.value='';
			eval("document."+formName).publishedDateTo.value='';
			eval("document."+formName).itemCode.value='';
		}
};