function callEntry(args) {
    process();

    if (args == null) {
        return;
    }

    var url = contextpath + "?";

    if (args.length > 0) {
        url += "_M=" + args[0];
        element.modulecode = args[0];
    }

    if (args.length > 1) {
        url += "&_F=" + args[1];
    }

    if (workspace) {
        top.workspace.document.location = url;
    }
}

/****
 **======================================================
 **/
//filter  code and description of city by country code on data.js file
function filter(arraylist, key1, val1, retCode, retDesc) {
    var idx1, idxCode, idxDesc, len = 0;
    var retlist = new Array(), idxlist = arraylist[0];

    for (i = 0; i < idxlist.length; i++) {
        if (key1 == idxlist[i]) {
            idx1 = i;
        }

        if (retCode == idxlist[i]) {
            idxCode = i;
        }

        if (retDesc == idxlist[i]) {
            idxDesc = i;
        }
    }

    for (j = 1; j < arraylist.length; j++) {
        idxlist = arraylist[j];

        if (idxlist[idx1] == val1) {
            retlist[len] = new Array();
            retlist[len][0] = idxlist[idxCode];
            retlist[len][1] = idxlist[idxDesc];
            len++;
        }
    }

    return retlist;
}

/**
 * relate combox country by  key1,orig,dest,retcode,retdesc
 **/
function relatedCombox(arraylist, key1, orig, dest, retCode, retDesc) {
    if (dest.options != null) {
        for (i = dest.options.length - 1; i >= 0; i--) {
            dest.options.remove(i);
        }
    }

    dest.value = "";

    //create blank country option
    var oOption = document.createElement("OPTION");

    dest.options.add(oOption);

    oOption.value = "";
    oOption.innerText = "";

    //get country options
    var result = filter(arraylist, key1, orig.value, retCode, retDesc);

    if (result == null) {
        return;
    }

    //create country options
    for (i = 0; i < result.length; i++) {
        oOption = document.createElement("OPTION");

        dest.options.add(oOption);

        oOption.value = result[i][0];
        oOption.innerText = result[i][1];
    }
    dest.fireEvent("onchange");
}

function getPropertyObject(propName) {
    if ('null' == propName) {
        return "NULL";
    } else {
        return document.all(propName).value;
    }
}

function setPropertyObject(propName, value) {
    if ('null' != propName) {
        document.all(propName).value = value;
    }
}

function readOnlySelect(selectObj, confirmValue) {
    var tmp;

    for (i = 0; i < selectObj.options.length; i++) {
        tmp = selectObj.options[i].value;

        if (tmp == confirmValue) {
            selectObj.selectedIndex = i;
        }
    }
}

function changeCheckbox(srcObj) {
    if (srcObj.checked) {
        srcObj.nextSibling.value = srcObj.value;
    } else {
        srcObj.nextSibling.value = "";
    }
}

function ondb_click(pk) {
    setpk(pk);
    modifyRecord();
}

function setpk() {
    var oTr = getParentByTagName(event.srcElement, "TR");

    if (oTr != null) {
        oTable = getParentByTagName(oTr, "TABLE");

        if (typeof(oTable.currTr) != "undefined" && oTable.currTr != null) {
            for (var i = 0; i < oTable.currTr.cells.length; i++) {
                oTable.currTr.cells[i].style.backgroundColor = "WHITE";
            }
        }

        var oTds = oTr.cells;

        for (var i = 0; i < oTds.length; i++) {
            oTds[i].style.backgroundColor = "#C4E7E7";
        }

        oTable.currTr = oTr;
    }

    if (document.forms[0].elements['_PRIMARYKEY_0'] != null) {
        var numargs = arguments.length;

        for (i = 0; i < numargs; i++) {
            document.forms[0].elements['_PRIMARYKEY_' + i].value = arguments[i];
        }
    }
}

function logout() {
    window.top.document.location.href = "logoff.do";
}

function checkSelected(obj) {
    if (typeof(obj) != "undefined") {
        if (typeof(obj.length) == "undefined") {
            return obj.checked ? 1 : 0;
        } else {
            var i = 0;

            for (j = 0; j < obj.length; j++) {
                if (obj[j].checked) {
                    i++;
                }
            }

            return i;
        }
    } else {
        return 0;
    }
}

function changeCaption(_caption) {
    window.top.document.title = _caption;
}

function selectAll(elementId, value) {
    var objects = document.getElementsByName(elementId);

    for (var i = 0; i < objects.length; i++) {
        if (objects[i].type == 'checkbox') {
            objects[i].checked = value;
        }
    }
}

function checkPriamryKey(form) {
    if (typeof(form.elements['selectall']) != "undefined" && form.elements['selectall'].checked) {
        return true;
    }

    if (typeof(form.elements['_PRIMARYKEY_0']) != "undefined") {
        var i = 0;

        while (typeof(form.elements['_PRIMARYKEY_' + i]) != "undefined") {
            if (typeof(form.elements['_PRIMARYKEY_' + i].value) == "undefined" || form.elements['_PRIMARYKEY_'
                + i].value == '')
            {
                return false;
            }

            i++;
        }
    }

    return true;
}

function call_command(m, f) {
    if ("COMMAND_MODIFY" == f || "COMMAND_DELETE" == f || "COMMAND_RETRIVE" == f) {
        return;
    }

    document.form['_EntryForm']._M.value = m;
    document.form['_EntryForm']._F.value = f;

    document.form['_EntryForm'].submit();
}

//function to control the page index
function gopage(num) {
    document.forms[0].curr_page.value = num;

    document.forms[0].submit();
}

function gopageByEnter(event) {
    if (event.keyCode == 13 && event.srcElement.type == "text" && event.srcElement.name == "curr_page") {
        document.forms[0].submit();
    }
}

function viewDoc() {
    if (typeof(window.getRefType) != "undefined") {
        var refUnid = window.document.all("_PRIMARYKEY_0") == null
            ? null
            : window.document.all("_PRIMARYKEY_0").value;

        if (refUnid != null && refUnid != "") {
            var refType = window.getRefType();

            window.top.setTimeout("showPopup('edoc', 700, 450, '/portal/addins/edoc/edoc.do?reftype=" + refType
                + "&refunid=" +
                                  refUnid + "');", 100);
        }
    }
}

function doWindowScroll() {
    var oCoolBar = document.getElementById("idCoolBar");

    if (oCoolBar != null) {
        oCoolBar.style.top = document.body.scrollTop;
    }
}

function doWindowResize()
{
    var oCoolBar = document.getElementById("idCoolBar");

    if (oCoolBar != null) {
        oCoolBar.style.top = document.body.scrollTop;
    }
}

//remove blanks before or after a string
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}


/*
* prepare for searching
* return true if ready
* call by searchForm's onSubmit event
*/
function searchPrepare() {
    var searchCriterias = document.all("searchCriteria");
    var hasCriteria = false;
    for (var i = 0; i < searchCriterias.length; i++) {
        searchCriterias[i].value = searchCriterias[i].value.trim();
        if (searchCriterias[i].value != "") {
            hasCriteria = true;
        }
    }
    if (hasCriteria) {
        return true;
    } else {
        alert(MSG_NoSearchCondition);
        return false;
    }
}

function searchFormValidation(formname, documentform) {
    formnamefunc = "validate" + formname + "(" + documentform + ")";
    return eval(formnamefunc) && searchPrepare();
}

function dateCheck(str) {
    //            var reg = /^(\d{1,4})(-|\/)(0?)(\d{1,2})\2(\d{1,2})$/;
    var dateReg = /^((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1])-(0[1-9]|[1-9]|1[0-2])-[0-9]{4}$/;
    var r = str.match(dateReg);
    if (r == null) {
        return   false;
    }
    return true;
}

function maxInputCheck(obj, max) {
    var maxLen = max;
    var m = obj.value.length;
    var n = m;
    var j = 0;

    for (var i = 0; i < m; i++) {
        if (obj.value.charCodeAt(i) < 0 || obj.value.charCodeAt(i) > 161) {
            n = n + 1;
            if (i < 100) {
                j = j + 1;
            }
        }
    }

    if (n > maxLen) {
        obj.value = obj.value.substring(0, maxLen - j);
    }
}