// JavaScript Document String.prototype.subBytesStr = function(pos, n) { var totLen = 0; for (var i = pos; i < this.length; i++) { totLen += getCharLength(this.charCodeAt(i)); if (totLen > n) { return this.substr(pos, i - pos); } else if (totLen == n) { return this.substr(pos, i - pos + 1); } } return this.substr(pos, i - pos + 1); } String.prototype.jsonEncode = function() { return this.replace(/([,\'\"\[\]\{\}\r\n\\])/g, "\\$1"); } function getCookie(cookieName) { var cookieString = document.cookie; var start = cookieString.indexOf(cookieName + '='); if (start == -1) return null; start += cookieName.length + 1; var end = cookieString.indexOf(';', start); if (end == -1) return unescape(cookieString.substring(start)); return unescape(cookieString.substring(start, end)); } function getSelectedOptionText(obj){ if(obj==null || obj.options == null) return null; var options = obj.options; var index = options.selectedIndex; return options[index].text; } function addSelectOptions(idSel) { var strOpts = ""; for (var i=1; i'+arguments[i][j][1]+''; } } $("#"+idSel).append(strOpts); } function escapeHTMLChar(str){ if(str!=null && str!=''){ str = str.replace(/&/g,"&"); str = str.replace(//g, ">"); str = str.replace(/\'/g, "\'"); str = str.replace(/\"/g, """); } return str; } function unEscapeHTMLChar(str){ if(str!=null && str!=''){ str = str.replace(/</g, "<"); str = str.replace(/>/g, ">"); str = str.replace(/\'/g, "'"); str = str.replace(/\"/g, "\""); str = str.replace(/&/g,"&"); } return str; } function jsonEncode(str) { return (typeof(str) == "string") ? str.jsonEncode() : str; } function jsonHtmlEncode(str, isTextArea) { var strHtml=""; for (var i=0; i"; break; case '<': case '>': case '&': strHtml += "&#" + str.charCodeAt(i) + ";"; break; default: strHtml += str.charAt(i); break; } } return strHtml; } // the returned value muste quoted by double quotes function valEncode(str) { var val = ""; for (var i=0; i 0) ? rows : 1; offset = (offset > 0) ? (rows - (offset % rows)) : 0; var objTrs = $("#"+idTab+">tbody>tr"); for (var i=0; itbody>tr"); for (var i=0; i"); if(pos==-1){ pos = old_html.indexOf(""); } if(pos!=-1){ old_html = old_html.substring(0, pos); } data_grid_table_div.innerHTML = old_html + tbodyStart + tBody + tbodyEnd + tableEnd; } function deleteTableRowData(rowId){ if(confirm(glbMessages.confirmForDelete)==false){ return; } var idNode = document.getElementById("ID_Hidden_Id"); if(idNode!=null) idNode.value = rowId.substring(5); var commandNode = document.getElementById("ID_Hidden_Command"); if(commandNode!=null) commandNode.value = "delete"; document.getElementById("ID_BtnSubmitListData").click(); } function batchDeleteTableRowData(){ var ids = getSelectedCheckBoxIds(); if(ids==null){ alert(glbMessages.warningForNoRecordSelected); return; } if(confirm(glbMessages.confirmForDelete)==false){ return; } var idNode = document.getElementById("ID_Hidden_Id"); if(idNode!=null) idNode.value = ids; var commandNode = document.getElementById("ID_Hidden_Command"); if(commandNode!=null) commandNode.value = "delete"; document.getElementById("ID_BtnSubmitListData").click(); } function deleteTableRowDataWithSuffix(rowId, suffix){ if(confirm(glbMessages.confirmForDelete)==false){ return; } var idNode = document.getElementById("ID_Hidden_Id"+suffix); if(idNode!=null) idNode.value = rowId.substring(5+suffix.length); var commandNode = document.getElementById("ID_Hidden_Command"+suffix); if(commandNode!=null) commandNode.value = "delete"; document.getElementById("ID_BtnSubmitListData"+suffix).click(); } function batchDeleteTableRowDataWithSuffix(suffix){ var ids = getSelectedCheckBoxIdsByName('rowChkBox'+suffix); if(ids==null){ alert(glbMessages.warningForNoRecordSelected); return; } if(confirm(glbMessages.confirmForDelete)==false){ return; } var idNode = document.getElementById("ID_Hidden_Id"+suffix); if(idNode!=null) idNode.value = ids; var commandNode = document.getElementById("ID_Hidden_Command"+suffix); if(commandNode!=null) commandNode.value = "delete"; document.getElementById("ID_BtnSubmitListData"+suffix).click(); } // Reserved function beforeSubmitListData(){ return true; } function setCommand(cmd){ var cmdNode = document.getElementById("ID_Hidden_Command"); if(cmdNode!=null){ cmdNode.value = cmd; } } function hideNodeOnCheckBoxObjClick(nodeId, nodeCheckBox) { var nodeToBeHidden = document.getElementById(nodeId); if (nodeToBeHidden!=null){ if (nodeCheckBox.checked) { nodeToBeHidden.style.display = (nodeToBeHidden.tagName != "TR" && nodeToBeHidden.tagName != "TBODY") ? "block" : ""; } else { nodeToBeHidden.style.display = "none"; } } } function hideNodeBySelectObjValue(nodeId, nodeSelect, strDispVal) { var nodeToBeHidden = document.getElementById(nodeId); if (strDispVal == null) { strDispVal = "1"; } if (nodeToBeHidden!=null){ if (nodeSelect.value == strDispVal) { nodeToBeHidden.style.display = (nodeToBeHidden.tagName != "TR" && nodeToBeHidden.tagName != "TBODY") ? "block" : ""; } else { nodeToBeHidden.style.display = "none"; } } } function hideNodeOnCheckBoxClick(nodeId, checkBoxId) { var nodeCheckBox = document.getElementById(checkBoxId); if (nodeCheckBox != null) { hideNodeOnCheckBoxObjClick(nodeId, nodeCheckBox); } } function hideNodeBySelectValue(nodeId, selectId, strDispVal) { var nodeSelect = document.getElementById(selectId); if (nodeSelect != null) { hideNodeBySelectObjValue(nodeId, nodeSelect, strDispVal); } } // the function fpTrContructor like this function(i, []){ return trStr; } function loadListData(idTable, strData, fpTrContructor) { var objTable = $("#"+idTable); var strTabHtm = objTable.html(); var objListData = eval('('+strData+')'); if (fpTrContructor != null) { for (var i=0; i"; } strTabHtm += ""; } } objTable.html(strTabHtm); return objListData; } function TrStr() { this.tds = ""; this.add = function() { for (var i=0; i'; } return this; }; this.addTd = function() { for (var i=0; i'+this.tds+''; }; this.getTds = function () { return this.tds; }; for (var i=0; ioption[value='"+value+"']").attr("selected", "true"); } function addPortOptions(idSelect, iPortNum, iSelectedPort) { var objSelect = $("#"+idSelect); var strHtml = objSelect.html(); for (var i=1; i<=iPortNum; i++) { if (i == iSelectedPort) { strHtml += ''; } else { strHtml += ''; } } objSelect.html(strHtml); } function addSlotOptions(idSelect, iSlotNum, iSelectedSlot) { var objSelect = $("#"+idSelect); var strHtml = objSelect.html(); for (var i=1; i<=iSlotNum; i++) { if (i == iSelectedSlot) { strHtml += ''; } else { strHtml += ''; } } objSelect.html(strHtml); } function setTextAreaHeight(objText, height) { if (height > 0) { if (parseInt(objText.style.height) != height) { objText.style.height = height+"px"; } } else { if (objText.scrollHeight - parseInt(objText.style.height) > 10) { objText.style.height = (objText.scrollHeight)+"px"; } } } function getDocScrollTop() { if (document.compatMode == "\"BackCompat\"") { sTop = document.body.scrollTop; } else { //document.compatMode == \"CSS1Compat\" sTop = document.documentElement.scrollTop == 0 ? document.body.scrollTop : document.documentElement.scrollTop; } return sTop; } function setDocScrollTop(sTop) { document.body.scrollTop = sTop; if (document.compatMode != "\"BackCompat\"") { document.documentElement.scrollTop = sTop; } } function drawPortCheckBoxes(iPortNum, selectedPorts, strPrompts, idChkBox) { if (idChkBox == null) idChkBox = "__ID_PortChkBoxes"; var idChkBoxAll = idChkBox + "All"; var idChkBoxParent = idChkBox + "Parent"; var strHtml = ""; strHtml += ''; strHtml += ''; strHtml += '"; } } $("#"+strTabId).append(strTabHtm); } function displayEnabledBySelect(idSelect, idNode) { displayBySelect(idSelect, [idNode], [1]); } function displayBySelect(idSelect, arrNodeIds, arrVals) { var objSelect = __G(idSelect); if (undefined == objSelect.arrValObjMaps) { objSelect.arrValObjMaps = new Array(); } if (undefined == objSelect.lastVal) { objSelect.lastVal = objSelect.value; } if (null == arrVals) { arrVals = new Array(); for (var i=0; i'+arrColNames[i]+''; } var strBodyHtml = ""; var listData = eval('('+strData+')').data; for(var i=0; i'; if (funcOnTrDraw != null) { trStr += funcOnTrDraw(listData[i]); } else { for (var j=1; j'; } } trStr += ''; strBodyHtml += trStr; } if (strBodyHtml == "") { strBodyHtml = '' + ''; } var strTblHtml = '' + ''; strTblHtml += '
' + '
'+glbListSkins.dataList+'
' + '
' + '' + '' + '
' + '
' + '
' + '
'+strPrompts[0]+''; strHtml += ''; for (var i=1, j=0; i<=iPortNum; i++) { var id = idChkBox + i; var val = ((i < 10) ? "0" : "") + i; strHtml += '' + val + '  '; if (i%8 == 0 && iinput").attr("checked", this.checked); }); return { getChecked:function() { var strPorts = ""; $("#"+idChkBoxParent+">input:checked").each(function(i, item){ strPorts += (i > 0) ? (","+item.value) : item.value; }); return strPorts; }, sizeOfChecked:function() { return $("#"+idChkBoxParent+">input:checked").length; }, isChecked:function(i) { return ($("#"+idChkBoxParent+">input[value="+i+"]:checked").length > 0); } }; } function addCurPageOptions(maxPages, curPage, pageStr) { var strHtml = ""; for (var i=1; i<=maxPages; i++) { if (i == curPage) { strHtml += ''; } else { strHtml += ''; } } return strHtml; } function addPerPageOptions(itemsPerPages, pageStr) { var strHtml = ""; for (var i=1; i'+itemsPerPages[i]+'/'+pageStr+''; } else { strHtml += ''; } } return strHtml; } function drawPageFoot(totItems, curPage, itemsPerPages, onPageChange, style) { var maxPages = Math.ceil(totItems/itemsPerPages[0]); var pages = style[0]; var page = style[1]; var width = style[2]; var strHtml = ""; if (curPage > maxPages) curPage = 0; strHtml += 'Total:'+' '+totItems+'    '; strHtml += ''+curPage+'/'; strHtml += ''+maxPages+''+pages+'  '; strHtml += '    '; if (itemsPerPages.length > 1) { strHtml += ''; } else { strHtml += ''; } document.write(strHtml); $("#ID_SelCurPage").change(function() { onPageChange(totItems, this.value, $("#ID_SelPerPage>option:selected").attr("value")); }); $("#ID_SelPerPage").change(function() { onPageChange(totItems, $("#ID_SelCurPage>option:selected").attr("value"), this.value); }); } function drawPageFootCn(totItems, curPage, itemsPerPages, onPageChange) { drawPageFoot(totItems, curPage, itemsPerPages, onPageChange, ["页", "页", "65px"]); } function drawPageFootEn(totItems, curPage, itemsPerPages, onPageChange) { drawPageFoot(totItems, curPage, itemsPerPages, onPageChange, [" Pages", "Page", "85px"]); } function changeAllRecords(objChkBoxAll, idTab) { $("#"+idTab+">tbody>tr>td:first-child>input[type=checkbox]:enabled").attr("checked", objChkBoxAll.checked); } function changeAllRecordsTdRow(objChkBoxAll, idTab, tdRow) { $("#"+idTab+">tbody>tr>td:nth-child("+tdRow+")>input[type=checkbox]:enabled").attr("checked", objChkBoxAll.checked); } function changeAllRecordsTdRowIpt(objChkBoxAll, idTab, tdRow ,iptRow) { $("#"+idTab+">tbody>tr>td:nth-child("+tdRow+")>input:nth-child("+iptRow+")[type=checkbox]:enabled").attr("checked", objChkBoxAll.checked); } function initSelectAll(idCbx, idTab, index) { var nChecked = 0; var nNotChecked = 0; $("#"+idTab+">tbody>tr").each(function(i, tr) { $(" input:checkbox:eq("+index+"):enabled", $(tr)).each(function(j, cbx) { nChecked += (cbx.checked ? 1 : 0); nNotChecked += (cbx.checked ? 0 : 1); }); }); $("#"+idCbx).prop("checked", nChecked > nNotChecked).click(function(e) { onSelectAllClick(this, idTab, index); }); } function onSelectAllClick(cbx, idTab, index) { $("#"+idTab+">tbody>tr").each(function(i, e) { $(" input[type=checkbox]:eq("+index+"):enabled", $(e)).each(function(j, ele) { this.checked = cbx.checked; if (this.onclick != null) { this.onclick(); } }); }); } function getSelectedRecords(idTab) { var strRecs = ""; $("#"+idTab+">tbody>tr>td:first-child>input[type=checkbox]:checked").each(function(i, item){ strRecs += (i > 0) ? (","+item.value) : item.value; }); return strRecs; } function deleteRecords(strRecs, funcDeleteRecords) { if (!confirm(glbMessages.confirmForDelete)) { return false; } funcDeleteRecords(strRecs); } function batchDeleteRecords(idTab, funcDeleteRecords) { var strRecs = getSelectedRecords(idTab); if (strRecs == "") { alert(glbMessages.warningForNoRecordSelected); return false; } if (!confirm(glbMessages.confirmForDelete)) { return false; } funcDeleteRecords(strRecs); } function checkRadio(idArr, value){ if(idArr==null) return; var arrLen = idArr.length; for(var i=0; icolArrLen) len = colArrLen; var dataArr = new Array(len); for(var i=0; i
' + '['+glbListSkins.opDel+'] ' + '['+glbListSkins.opEdit+']
'+glbListSkins.noData+'
' + '' + '' + strThHtml + '' + '' + '' + strBodyHtml + '
' + ''+glbListSkins.operation+'
'; document.write(strTblHtml); var strDtaStaHtml = '' + '' + '' + '
'+glbListSkins.dataStatus+'
'; // draw the data status tr $(strDtaStaHtml).insertBefore("#"+idDetails+" table:first"); var objDetails = $("#"+idDetails); var objStatus = objDetails.find("select:first"); var objInputs = objDetails.find("input[type=text], select:gt(0), textarea"); var objSubmit = objDetails.find("input[type=submit]"); var objCmd = $("#ID_Hidden_Cmd_"+idTable); var objId = $("#ID_Hidden_Id_"+idTable); var dispStatus = function(status) { objDetails.attr("style", "display:block"); objStatus.val(status); } var setCommand = function(cmd, id) { objCmd.val(cmd); objId.val(id); } $("#ID_BtnAdd_"+idTable).click(function(){ objInputs.val(""); if (funcOnAdd != null) { funcOnAdd(); } dispStatus("2"); setCommand("add", "-1"); }); $("#ID_BtnDelAll_"+idTable).click(function(){ var ids = getSelectedRecords(idTable); if(ids==""){ alert(glbMessages.warningForNoRecordSelected); return false; } if(confirm(glbMessages.confirmForDelete)==false){ return false; } setCommand("delete", ids); objSubmit.click(); }); $("#"+idTable+">tbody>tr").each(function(index, element) { $(element).find("a:first").click(function() { if(confirm(glbMessages.confirmForDelete)==false){ return false; } setCommand("delete", this.name); objSubmit.click(); }); $(element).find("a:last").click(function() { var objTds = $(element).find("td:gt(0):lt("+(arrColNames.length+1)+")"); if (funcOnEdit != null) { var arrCols = Array(); for (var i=0; itextarea"); arrCols.push((objTxa.length > 0) ? objTxa.val() : $(objTds[i]).html()); } funcOnEdit(arrCols); } else { objInputs.each(function(i, element) { var objTxa = $(objTds[i]).find(">textarea"); element.value = (objTxa.length > 0) ? objTxa.val() : $(objTds[i]).html(); }); } dispStatus("1"); setCommand("edit", this.name); }); }); } function htmlEncode(str, isTextArea) { var strHtml=""; for (var i=0; i"; break; case '<': case '>': case '&': case '"': strHtml += "&#" + str.charCodeAt(i) + ";"; break; default: strHtml += str.charAt(i); break; } } return strHtml; } function displayNode(objNode, bDisplay) { if (bDisplay) { objNode.style.display = (objNode.tagName != "TR" && objNode.tagName != "TBODY") ? "block" : ""; } else { objNode.style.display = "none"; } } function checkMaxLength(objInput, maxChars, maxBytes) { if (maxBytes != null && maxBytes > 0) { objInput.value = objInput.value.substr(0, maxChars).subBytesStr(0, maxBytes); } else { objInput.value = objInput.value.substr(0, maxChars); } } function getCharLength(charCode) { if (charCode <= 0x007f) { return 1; } else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) { return 2; } else if ((0x0800 <= charCode) && (charCode <= 0xffff)) { return 3; } else{ return 4; } } function colInputsClear(input) { var td = $(input).parents("td:first"); var tr = td.parents("tr:first"); tr.find("td").each(function(index, element) { element.index = index; }); tr.siblings().find("td:nth-child("+(td[0].index+1)+")").find("input,textarea").val(""); } function rowInputsClear(input) { $(input).parents("td:first").siblings("").find("input,textarea").val(""); } function colInputsCopy(input){ var td = $(input).parents("td:first"); var tr = td.parents("tr:first"); tr.find("td").each(function(index, element) { element.index = index; }); inputsCopy(tr.siblings().find("td:nth-child("+(td[0].index+1)+")").find("input,textarea")); } function rowInputsCopy(input){ inputsCopy($(input).parents("td:first").siblings("").find("input,textarea")); } function inputsCopy(ipts){ var step = null; var val1 = null; var val2 = ""; for (var i = 0; i < ipts.length; i++) { var $_ipt = $(ipts[i]); if ($_ipt.val() != "") { /* the input value is not zero, set it as val2 */ val2 = $_ipt.val(); if (/^[0-9]+$/.test(val2)) { /* the input value is number */ if (val1 != null) { step = val2 - val1; } val1 = val2; } else { val1 = null; } } else { /* the input value is zero, clear the val1 */ val1 = null; if (step != null) { $_ipt.val(parseInt(val2) + step); val2 = $_ipt.val(); } else { $_ipt.val(val2); } } } }