/**/ /*redirct url *act: URL * formName: which form to submit */ function gotoUrl(act, target, decoratorName, formName) ... { if (decoratorName != undefined && decoratorName != '') ...{//select sitemesh decorator if (act.indexOf('?') > 0) act = act + "&decorator=" + decoratorName; else act = act + "?decorator=" + decoratorName } var form = document.forms[0]; if (formName != undefined && formName != '') form = document.forms[formName]; form.method = "post"; form.action = act; if (target != undefined && target != null) ...{ form.target = target; } form.submit();} /**/ /*open new window *url: new window's URL *winName: new window name *decoratorName: sitemesh decorator name */ function openWin(url, winName, decoratorName) ... { if (url != '') ...{ if (decoratorName != undefined && decoratorName != '') ...{//select sitemesh decorator if (url.indexOf('?') > 0) url = url + "&decorator=" + decoratorName; else url = url + "?decorator=" + decoratorName; } else ...{ if (url.indexOf('?') > 0) url = url + "&decorator=openwin"; else url = url + "?decorator=openwin"; } } var win = window.open(url, winName, "top=100,left=100,height=400,width=800,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,fullscreen=no"); win.focus();} function scalePhoto(imgId, width, height) ... { var img = document.getElementById(imgId); if (img != null) ...{ var imgWidth = img.width; var imgHeight = img.height; if (imgWidth == 0) ...{ img.width = width; } if (imgHeight == 0) ...{ img.height = height; } if (imgWidth > width && imgHeight > height) ...{ //both image's width and height are larger than required one var widthRate = imgWidth / width; var heightRate = imgHeight / height; if (widthRate > heightRate) ...{ //use width to retrieve the image img.width = width; img.height = imgHeight * (width / imgWidth); } else ...{ img.height = height; img.width = imgWidth * (height / imgHeight); } } else if (imgWidth > width) ...{ //the image width lg than the required width img.width = width; img.height = imgHeight * (width / imgWidth); } else if (imgHeight > height) ...{ //the image height lg than the required img.height = height; img.width = imgWidth * (height / imgHeight); } }} /**/ /* * refresh win opener * formName: which form to submit */ function refreshOpener(act, formName) ... { var form = opener.document.forms[0]; if (formName != undefined && formName != '') form = opener.document.forms[formName]; if (act != undefined && act != '') form.action = act; else form.action = opener.document.location; form.method = 'post'; form.target = '_self'; form.submit();} /**/ /* * checkAll or unCheckAll checkbox */ function checkall(target, controller) ... { if (target != undefined && controller != undefined) ...{ if (target.length != undefined) ...{ for (var i = 0; i < target.length; i++) ...{ target[i].checked = controller.checked; } } else ...{ target.checked = controller.checked; } } else ...{ if (document.all.id != undefined) ...{ if (document.all.id.length != undefined) ...{ for (var i = 0; i < document.all.id.length; i++) ...{ document.all.id[i].checked = document.all.checkAll.checked; } } else ...{ document.all.id.checked = document.all.checkAll.checked; } } }} /**/ /* * get checked checkbox count */ function getCheckNum() ... { var count = 0; if (document.all.id != undefined) ...{ if (document.all.id.length != undefined) ...{ for (var i = 0; i < document.all.id.length; i++) ...{ if (document.all.id[i].checked) count++; } } else ...{ if (document.all.id.checked) count++; } } return count;} /**/ /* * submit delete action * act: url * msg: alert message * formName: which form to submit */ function doDelete(act, msg, formName) ... { if (getCheckNum() == 0) ...{ if (msg != undefined) alert(msg); else alert('Please select one or more item!'); return false; } if (confirm('Do you really want to delete the selected items?')) ...{ if (formName != undefined && formName != '') gotoUrl(act, null, null, formName); else gotoUrl(act); }} /**/ /* * submit ForMoreItem * act: url * msg: alert message * formName: which form to submit */ function doSubmitForMoreItem(act, msg, formName) ... { if (getCheckNum() == 0) ...{ if (msg != undefined) alert(msg); else alert('Please select one or more item!'); return false; } if (formName != undefined && formName != '') gotoUrl(act, null, null, formName); else gotoUrl(act);} /**/ /* * submit update action * act: url * msg: alert message * formName: which form to submit */ function doUpdate(act, msg, formName) ... { if (getCheckNum() != 1) ...{ if (msg != undefined) alert(msg); else alert('Please select one item to update!'); return false; } openWin("", 'updateWin'); if (formName != undefined && formName != '') ...{ gotoUrl(act, 'updateWin', 'openwin', formName); } else ...{ gotoUrl(act, 'updateWin', 'openwin'); }} function checkFieldNumber(id) ... { var field; try ...{ field = document.getElementById(id); } catch(t) ...{ try ...{ field = document.getElementByName(id); } catch(t) ...{ } } if (field == null) ...{ field = id; } if (!field.value)return false; //no such field,return false; var total = field.value; if (total == "") ...{ alert("请输入有效数字!"); field.focus(); field.select(); return false; } if (isNaN(total) == true) ...{ alert("请输入有效数字。"); field.select(); field.select(); return false; } if (total <= 0) ...{ alert("请输入正数"); field.select(); field.select(); return false; } return true;} /**/ /** * validate int */ function isInt(str) ... { var reg = /^[0-9]*[1-9][0-9]*$/g ; if (reg.test(str)) return true; else return false;} function isInteger(str) ... { var reg = /^-?d+$/g ; if (reg.test(str)) return true; else return false;} /**/ /** * validate date yyyy-mm-dd */ function isDate(time, format) ... { var reg = format; var reg = reg.replace(/yyyy/, "[0-9]{4}"); var reg = reg.replace(/yy/, "[0-9]{2}"); var reg = reg.replace(/MM/, "((0[1-9])|1[0-2])"); var reg = reg.replace(/M/, "(([1-9])|1[0-2])"); var reg = reg.replace(/dd/, "((0[1-9])|([1-2][0-9])|30|31)"); var reg = reg.replace(/d/, "([1-9]|[1-2][0-9]|30|31))"); var reg = reg.replace(/HH/, "(([0-1][0-9])|20|21|22|23)"); var reg = reg.replace(/H/, "([0-9]|1[0-9]|20|21|22|23)"); var reg = reg.replace(/mm/, "([0-5][0-9])"); var reg = reg.replace(/m/, "([0-9]|([1-5][0-9]))"); var reg = reg.replace(/ss/, "([0-5][0-9])"); var reg = reg.replace(/s/, "([0-9]|([1-5][0-9]))"); reg = new RegExp("^" + reg + "$"); if (reg.test(time)) return true; return false;} // ???????????????????????? function loaddefault(photoId) ... { var photo = document.getElementById(photoId); if (photo == null)return; photo.onerror = ""; photo.src = 'images/np_s1.jpg';} // Get an attribute from cookie function getCookie(c_name) ... { if (document.cookie.length > 0) ...{ c_start = document.cookie.indexOf(c_name + "=") if (c_start != -1) ...{ c_start = c_start + c_name.length + 1 c_end = document.cookie.indexOf(";", c_start) if (c_end == -1) c_end = document.cookie.length return unescape(document.cookie.substring(c_start, c_end)) } } return null} function initRequest(url) ... { if (window.XMLHttpRequest) ...{ return new XMLHttpRequest(); } else if (window.ActiveXObject) ...{ isIE = true; return new ActiveXObject("Microsoft.XMLHTTP"); }} // Put an attribute into the cookie function setCookie(c_name, value, expiredays) ... { var exdate = new Date() exdate.setDate(exdate.getDate() + expiredays) document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + exdate)} /**/ /*自定义javascript的Hashtable类*hashtabl的key是返回值,value是对应的提示信息*/ function Hashtable() ... { this._hash = new Object(); this.add = function(key, value) ...{ if (typeof(key) != "undefined") ...{ if (this.contains(key) == false) ...{ this._hash[key] = typeof(value) == "undefined"?null:value; return true; } else ...{ return false; } } else ...{ return false; } } this.remove = function(key) ...{ delete this._hash[key]; } this.count = function() ...{ var i = 0; for (var k in this._hash) ...{ i++; } return i; } this.items = function(key) ...{ return this._hash[key]; } this.contains = function(key) ...{ return typeof(this._hash[key]) != "undefined"; } this.clear = function() ...{ for (var k in this._hash) ...{ delete this._hash[k]; } }} /**/ /************************************* 检测邮箱地址正确性 author:jgnan **************************************/ function checkemail(email) ... { var rec = /(^(S+@).+((.com)|(.net)|(.org)|(.info)|(.edu)|(.mil)|(.gov)|(.biz)|(.ws)|(.us)|(.tv)|(.cc)|(.....{2,2}))$)/; return rec.test(email);} function DecodeCookie(str) ... { var strArr; var strRtn = ""; strArr = str.split(","); for (var i = 0; i <= strArr.length - 1; i++) ...{ strRtn += String.fromCharCode(eval(strArr[i])); } return strRtn;} /**/ /** * 检查字符串是否有效的日期. * 日期可以是以下格式,并且支持闰年: * 2006-08-02 2006.08.02 2006/8/2 * @param strValue 有效的时间时返回 true ,否则返回 false */ function validateDate(strValue) ... { var objRegExp = /^d...{4}(-|/|.)d...{1,2}1d...{1,2}$/ if (!objRegExp.test(strValue))...{ return false; } else ...{ var arrayDate = strValue.split(RegExp.$1); var intDay = parseInt(arrayDate[2], 10); var intYear = parseInt(arrayDate[0], 10); var intMonth = parseInt(arrayDate[1], 10); if (intMonth > 12 || intMonth < 1) ...{ return false; } var arrayLookup = ...{ '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31, '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31} if (arrayLookup[parseInt(arrayDate[1])] != null) ...{ if (intDay <= arrayLookup[parseInt(arrayDate[1])] && intDay != 0) return true; } if (intMonth - 2 == 0) ...{ var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0)); if (((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <= 28)) && intDay != 0) return true; } } return false;} /**/ /** * 用 cookie 信息简单判断当前用户是否已登录. */ function hasSignOn() ... { var myssoId = getCookie('mysso_id'); var myssoTicket = getCookie('mysso_ticket'); if(myssoId == null || myssoId == "")...{ return false; } if(myssoTicket == null || myssoTicket =="")...{ return false; } return true;} function signOn() ... { var url = document.URL; var sso = CONTEXT_URI_SSO + "/Login"; sso += "?entrance="; sso += encodeURIComponent(url); window.location = sso;} function isValidEmail(email) ... { var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]+)$" var reg = new RegExp(regu); return (email.search(reg) > -1);} function isValidPhone(phonenum) ... { phonenum = phonenum.replace(/ /g,"") //To Replace Spaces var regu = "^([0-9(]+)+([0-9-.()]*)+([0-9)]+)$" var reg = new RegExp(regu); return (phonenum.search(reg) > -1);}