/* 常用正则表达式 */ var PATTERN_EMAIL="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"; var PATTERN_CHINESE_CHAR="[\u4e00-\u9fa5]"; var PATTERN_DOUBLEBYTE_CHAR="[^\x00-\xff]"; var PATTERN_UNSIGNED_INTEGER="^\\d+$"; String.prototype.vbtrim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } /* 字节长度 */ String.prototype.len=function(){ return this.replace(/[^\x00-\xff]/g,"aa").length; } function lTrim(sString) { var i; if (sString.length < 1) return ""; for (i = 0; i < sString.length; i++) if (sString.charAt(i) != " ") break; if (i >= sString.length) return(""); else return(sString.substring(i, sString.length)); } function rTrim(sString) { var i; if (sString.length < 1) return ""; for (i = (sString.length - 1); i >= 0; i--) if (sString.charAt(i) != " ") break; if (i < 0) return(""); else return(sString.substring(0, i + 1)); } function allTrim(sString) { if (sString.length < 1) return ""; var dString = lTrim(sString); dString = rTrim(dString); return dString; } function isEmpty(sString) { var s = allTrim(sString); if (s.length < 1) return true; else return false; } function getLength(sString) { var s = allTrim(sString); return s.length; } function getByteLength(sString){ if(sString==null) return 0; if(sString.length==0) return 0; var sEscape = escape(sString); var iLen = sString.length; var iUnicodeCount = getInStringCount(sEscape,"%u"); return iLen+iUnicodeCount; } function getInStringCount(src,patten){ var pos1 = src.indexOf(patten); if(pos1<0) return 0; var sSplits = src.split(patten); return sSplits.length-1; } function replace(sSource, sFind, sReplace) { var pos1 = sSource.indexOf(sFind); while (pos1 >= 0) { if ((pos1 + sFind.length) >= sSource.length) { sSource = sSource.substring(0, pos1) + sReplace; } else { sSource = sSource.substring(0, pos1) + sReplace + sSource.substring(pos1 + sFind.length, sSource.length); } pos1 = sSource.indexOf(sFind,pos1); } return sSource; } function isNumberPatten(src,sPatten){ var arr; arr = sPatten.split("."); if(arr.length==1){ return isNumber(src,arr[0].length,0); }else{ return isNumber(src,arr[0].length+arr[1].length,arr[1].length); } } function isNumber(src,precision,scale){ var integer_part = precision - scale; if (integer_part < 0 || precision < 0 || scale < 0) return false; var patten; if (scale > 0) { patten = "^-?\\d{1," + integer_part + "}(\\.\\d{1," + scale + "})?$"; } else { patten = "^-?\\d{1," + integer_part + "}$"; } return Matchs(src, patten); } function Matchs(src,patten){ var re; // 声明变量。 re = new RegExp(patten,"g"); // 创建正则表达式对象。 return re.test(src); } function UnsignedIntergetTextInput(input){ input.onkeypress=function(){ if (!((window.event.keyCode >= 48) && (window.event.keyCode <= 57))){ window.event.keyCode = 0 ; } } input.onbeforepaste=function(){ var str=window.clipboardData.getData("Text"); if(str){ if(!Matchs(str,PATTERN_UNSIGNED_INTEGER)){ window.clipboardData.setData("Text",""); } }else{ window.clipboardData.setData("Text",""); } } } function isNumeric(sString) { var s = allTrim(sString); if (isNaN(s) == true) return false; else return true; } function isInt(sString) { var s = allTrim(sString); if (isNumeric(s) == false) return false; if ((s % 1) == 0) return true; else return false; } function getFormatDateFormSfzhm(strSfzhm,delimiter){ return FormatDate8T11(getDateFromSfzhm(strSfzhm),delimiter); } function getDateFromSfzhm(strSfzhm){ return strSfzhm.substr(6,8); } function FormatDate8T11(strDate,delimiter){ return strDate.substr(0,4) + delimiter + strDate.substr(4,2) + delimiter + strDate.substr(6,2); } function ValidateNull(form){ var prop; for(var i=0;i< form.elements.length;i++){ prop = form.elements[i]; if(prop.name!=""){ if(prop["className"]=="required"){ if(isEmpty(prop["value"])){ if(typeof prop["alt"]!='undefined') alert("\""+prop["alt"]+"\""+"必填!"); else alert("\""+prop["title"]+"\""+"必填!"); if(typeof(prop.focus)!='undefined'){ prop.focus(); } return false; } if(prop["type"].toLowerCase()=="checkbox" && prop["checked"]==false){ alert("\""+prop["alt"]+"\""+"必选!"); return false; } } } } return ValidateLength(form); } function ValidateLength(form){ var prop; var comment = null; var maxlength = null; for(var i=0;i< form.elements.length;i++){ prop = form.elements[i]; if(prop.type=="text"){ if(prop.alt==null || prop.alt.length!=0){ comment = prop.alt; } if(prop.title==null || prop.title.length!=0){ comment = prop.title; } if(comment==null){ comment=''; } /*if(typeof prop.maxlength == "undefined"){*/ maxlength = prop.maxLength; /*}else{ maxlength = prop.maxlength; }*/ if(maxlength!=null){ if(getByteLength(prop.value)>maxlength){ if(comment.length==0){ alert("未知名字段长度不能大于"+maxlength + "位(中文字算2位)"); prop.focus(); prop.select(); return false; }else{ alert('"'+comment+'"长度不能大于'+maxlength + "位(中文字算2位)"); prop.focus(); prop.select(); return false; } } } } } return true; } /* 除了excludeNames数组外的form字段如果所有为空 */ function ValidateAllNull(form,excludeNames){ var prop; if(arguments.length<2){ excludeNames=new Array(); } var needCheck=true; var checkCount=0; for(var i=0;i< form.elements.length;i++){ prop = form.elements[i]; if(prop.name!=""){ for(var j=0;j 0) return null; return IDT18(strSfzhm); } /* 将object转换为数组,如果object是数组则直接返回 */ function asArray(object){ var array; if(typeof object=='undefined'){ return new Array(); }else if(typeof object["length"]=='undefined'){ //array = new Array(object); array=new Array(); array[0]=object; }else{ array = object; } return array; } /** * 根据元素获取其所在元素组的索引 * 参数: * element:元素 * id:元素的标识 */ function getElementIndex(element,id){ var elements = asArray(document.all[id]); for(var i = 0; i < elements.length; i++){ if(elements[i] == element){ return i; } } return -1; } /** * 根据某个元素获取与其处在相同索引的元素 * 参数: * element:元素 * id:元素的标识 * otherElementIds...:其他元素的标识,动态参数 * 返回:{id1:element1,id2:element2,...} */ function getSameIndexElements(element,id,otherElementIds){ var index=getElementIndex(element,id); var result={}; for(var i=2;i=srcTab.rows.length) return; if(to>=desTab.rows.length) to=desTab.rows.length; if(to<0) to=desTab.rows.length; var toIndex=to; var newrow; for(var i=0;i=table.rows.length) from=table.rows.length-1; if(size<0) size = table.rows.length-from; if(table.rows.length-from=0;i--){ table.deleteRow(from+i); } } /* 删除table标签的index行,table至少应该有minrows行 */ function deleteRow(table,index,minrows){ if(arguments.length<3) minrows=0; if(arguments.length<2) index=-1; if(index==-1) index = table.rows.length-1; if(minrows<0) minrows=0; if(index<0) return; if(table.rows.length<=minrows) return; table.deleteRow(index); } /** * 删除当前行,参数: * obj:行内对象 * marchLevel:父亲级别,默认为1,即第一个包含的TR */ function deleteCurrentRow(obj,marchLevel){ var parent=obj; var level=1; if(marchLevel){ level=marchLevel; } var hit=0; for(;true;){ parent = parent.parentElement; if(parent==document.body){ break; } if(parent.tagName.toLowerCase()=='tr'){ hit=hit+1; if(hit==level){ parent.removeNode(true); break; } } } } /** * 获取元素的左边位置 */ function getClientLeft(ctrl){ if(ctrl==document.body||ctrl==undefined){ return 0; } return ctrl.offsetLeft+ctrl.offsetParent.clientLeft+getClientLeft(ctrl.offsetParent); } /** * 获取元素的顶部位置 */ function getClientTop(ctrl){ if(ctrl==document.body||ctrl==undefined){ return 0; } return ctrl.offsetTop+ctrl.offsetParent.clientTop+getClientTop(ctrl.offsetParent); } /** * 获取元素的右边位置 */ function getClientRight(ctrl){ if(ctrl==undefined) return 0; if(ctrl==document.body){ return document.body.scrollWidth; } return getClientLeft(ctrl)+ctrl.clientWidth; } /** * 获取元素的底部位置 */ function getClientBottom(ctrl){ if(ctrl==undefined) return 0; if(ctrl==document.body){ return document.body.scrollHeight; } return getClientTop(ctrl)+ctrl.offsetHeight; } /** * 获取元素的宽度 */ function getClientWidth(ctrl){ if(ctrl==undefined){ return 0; } if(ctrl==document.body){ return document.body.scrollWidth>document.body.clientWidth?document.body.scrollWidth:document.body.clientWidth; } return ctrl.clientWidth; } /** * 获取元素的高度 */ function getClientHeight(ctrl){ if(ctrl==undefined){ return 0; } if(ctrl==document.body){ return document.body.scrollHeight>document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight; } return ctrl.clientHeight; } /** * 放置遮罩 */ function placeMask(element,mask){ mask.style.left=getClientLeft(element); mask.style.top=getClientTop(element); mask.style.width=''+getClientWidth(element)+'px'; mask.style.height=''+getClientHeight(element)+'px'; } var INDICATOR_IMG='/wsbs/resource/scripts/js/loading.gif'; function showIndicator(params){ if(typeof(params)=='undefined'){ params={}; } if(typeof(params.element)=='undefined'){ params.element=document.body; } if(typeof(params.msg)=='undefined'){ params.msg='正在处理中,请稍候...'; } if(typeof(params.img)=='undefined'){ params.img=INDICATOR_IMG; } var indicator = document.getElementById("indicator"); if(indicator==null){ document.body.insertAdjacentHTML('beforeEnd','
'); document.body.insertAdjacentHTML('beforeEnd','
'+params.msg+'
'); indicator = document.getElementById("indicator"); var indicatorContent = document.getElementById("indicatorContent"); indicator.style.left=''+getClientLeft(params.element)+'px'; indicator.style.top=''+getClientTop(params.element)+'px'; indicator.style.width=''+getClientWidth(params.element)+'px'; indicator.style.height=''+getClientHeight(params.element)+'px'; indicatorContent.style.left=''+(getClientLeft(indicator)+(getClientWidth(indicator)-getClientWidth(indicatorContent))/2)+'px'; indicatorContent.style.top=''+(getClientTop(indicator)+(getClientHeight(indicator)-getClientHeight(indicatorContent))/2)+'px'; } } function hideIndicator(){ var indicator = document.getElementById("indicator"); var indicatorContent = document.getElementById("indicatorContent"); if(indicator!=null){ indicator.removeNode(true); indicatorContent.removeNode(true); } } // JavaScript Document function __SectionMaxMin(oBtn, sContentID) { var oContent = document.getElementById(sContentID); if (oContent != null) { var sMaxIcon = oBtn.getAttribute('max_icon'); var sMinIcon = oBtn.getAttribute('min_icon'); if (oContent.style.display == 'none') { oBtn.src = sMinIcon; oContent.style.display = ''; } else { oBtn.src = sMaxIcon; oContent.style.display = 'none'; } return true; //cancel postback } return false; //failed so do postback } function __Help_OnClick(sHelpID) { var oHelp = document.getElementById(sHelpID); if (oHelp != null) { if (oHelp.style.display == 'none') oHelp.style.display = ''; else oHelp.style.display = 'none'; return true; //cancel postback } return false; //failed so do postback } function __SetSpan(id,title,memo){ document.write(""+title+" "); document.write(""); document.write("点击查看材料说明 "); document.write("
"); document.write(""); } //function window.onhelp(){return false} //屏蔽F1帮助 var forbidRC=true; function KeyDown(){ //屏蔽鼠标右键、Ctrl+n、shift+F10、F5刷新、退格键 //alert("ASCII代码是:"+event.keyCode); if ((window.event.altKey)&& ((window.event.keyCode==37)|| //屏蔽 Alt+ 方向键 ← (window.event.keyCode==39))){ //屏蔽 Alt+ 方向键 → alert("不准你使用ALT+方向键前进或后退网页!"); event.returnValue=false; } if((event.keyCode == 8) && (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password")){ event.keyCode=0; event.returnValue=false; } if ( (event.ctrlKey && event.keyCode==82)){ //Ctrl + R event.keyCode=0; event.returnValue=false; } if ((event.ctrlKey)&&(event.keyCode==78)){ //屏蔽 Ctrl+n event.returnValue=false; } if (window.event.srcElement.tagName == "A" && (window.event.shiftKey||window.event.ctrlKey)){ window.event.returnValue = false; //屏蔽 shift 加鼠标左键新开一网页 } if ((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4 window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px"); return false; } if (window.event.keyCode>=112 && window.event.keyCode<=123){ //屏蔽Fn window.event.keyCode=0; window.event.returnValue=false; } if(window.event.keyCode==70&&window.event.shiftKey&&event.ctrlKey){ forbidRC=!forbidRC; } } function lclick(){ if (window.event.shiftKey){ window.event.returnValue = false; //屏蔽 shift 加鼠标左键新开一网页 } } function Help(){ return false; } document.onkeydown=KeyDown; document.onclick=lclick; /* document.oncontextmenu=function(){ if(forbidRC){ return false; } };*/ window.onhelp=Help; function findSubmit(form){ var result=[]; if(form.elements.length>0){ for(var i=0;i= n2) { s += '1'; n1 = n1 - n2; } else s += '0'; } return s; } function Dig2Dec(s) { var retV = 0; if(s.length == 4) { for(var i = 0; i < 4; i ++) { retV += eval(s.charAt(i)) * Math.pow(2, 3 - i); } return retV; } return -1; } function Hex2Utf8(s) { var retS = ""; var tempS = ""; var ss = ""; if(s.length == 16) { tempS = "1110" + s.substring(0, 4); tempS += "10" + s.substring(4, 10); tempS += "10" + s.substring(10,16); var sss = "0123456789ABCDEF"; for(var i = 0; i < 3; i ++) { retS += "%"; ss = tempS.substring(i * 8, (eval(i)+1)*8); retS += sss.charAt(Dig2Dec(ss.substring(0,4))); retS += sss.charAt(Dig2Dec(ss.substring(4,8))); } return retS; } return ""; }