/** VALIDATOR.JS by Steven on 2007-4-2 version:1.0.0 */ function login(){ if(validateRequired("loginForm","loginName,loginPassword",'Username,Password')==false) return false; dojo.io.bind({ url:'foreLogin!login.shtml', handle:function(type,data,evt){ if(type=="load"){ dojo.byId("loginTD").innerHTML=data.trim(); writeCookie("is_chemical",dojo.byId("loginCookie").value,0.5); writeCookie("is_chemical_id",dojo.byId("loginIdCookie").value,0.5); if(dojo.byId("loginError")) alert(dojo.byId("loginError").value); }else{ //alert(data.message); alert('Invalid login name or password'); } }, formNode:dojo.byId("loginForm") }); } function delCookie(name){ var date = new Date(); date.setTime(date.getTime() - 10000); document.cookie = name + "="+name+"; expires=" + date.toGMTString()+";domain=.ispharm.com"; } function exitSys(){ delCookie("is_chemical"); delCookie("is_chemical_id"); dojo.io.bind({ url:'foreLogin!exitLogin.shtml', handle:function(type,data,evt){ if(type=="load"){ dojo.byId("loginTD").innerHTML=data.trim(); } } }); } /** * 为String添加trim(),ltrim(),rtrim()方法 */ function selectSingleMulti(o,id,type){ var chS ; if(type=="1"){ chS = document.getElementsByName(id); }else chS = document.getElementsByName(o.name); if(type=="1"){ if(o.checked){ if(chS!=null && chS.length>0){ for(i=0;i0){ for(i=0;i0){ for(m=0;m0){ dojo.byId("pageList.currentPage").value = parseInt(pcount)-1; nextPage(); }else firstPage(); } String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }; function trim(val) { val=ltrim(val); val=rtrim(val); return val; } function ltrim(val) { for(var l=0;l0;r--) { if(val.charAt(r)==' ') val=val.substring(0,val.length-1); else break; } return val; } function len(str) { var len=str.length; var arr=str.match(/[^\x00-\x80]/ig); if(arr!=null) len += arr.length; return len; }; /** * 得到字符串的长度(增强了对汉字的识别,一个汉字的长度为2) * Steve Add at 2007-04-02 */ function getStringLength(val) { num=val.length var arr=val.match(/[^\x00-\x80]/ig) if(arr!=null) num += arr.length return num; }; /** PUBLIC check and get a FORM object 2007-04-02 by Steven */ function checkFormArg(form) { var obj; if(typeof(form)=="object") obj=form; else if(isNaN(form)) obj=document.forms[form]; else obj=document.forms[form]; if(typeof(obj)!="object") alert("error form!"); else return obj }; /** END */ /** PUBLIC check and get a FORM object 2007-04-02 by Steven */ function checkReturn() { if(errorMsg!="") { alert(errorMsg); errorMsg=""; return false; } }; /** END */ /** PUBLIC set focus To Element 2007-04-02 by Steven */ function focusToElement(obj) { if(errorMsg!="") { obj.select(); obj.focus(); } focusElement==null; }; /** END */ /** PUBLIC return Function is checkVal is Empty 2007-04-02 by Steven */ function checkEmpty(objVal) { checkVal=trim(objVal); if(checkVal=="") return true; }; /** END */ function validateCharacter(form,element,argName) { with(checkFormArg(form)) { if(checkCharacter(document.getElementById(element).value)) return; if(parseInt(checkVal)!=checkVal) { errorMsg+=argName+" must be characters or numbers."; focusToElement(document.getElementById(element)); } } return checkReturn(); }; function validateRequired(form,element,argName) { with(checkFormArg(form)) { element = element.split(","); argName = argName.split(","); if(element.length!=argName.length) { alert("error arg!"); return; } for(var i=0;imaxLength) { alert("error arg!"); return; } if(checkEmpty(document.getElementById(element).value)) return; if(minLength!=-1) { if(getStringLength(checkVal)maxLength) errorMsg+=argName+" length cant maore than "+maxLength+".\n"; } if(minLength!=-1 && maxLength!=-1) { if(errorMsg!="") errorMsg=argName+" length between "+minLength+" to "+maxLength+" .\n"; } focusToElement(document.getElementById(element)); } return checkReturn(); }; function validateValRange(form,element,argName,minValue,maxValue) { with(checkFormArg(form)) { if(checkEmpty(document.getElementById(element).value)) return; if(isNaN(checkVal)) errorMsg+=argName+" is not valid numbers.\n"; else { if(minValue!=-1) { if(parseFloat(checkVal)parseFloat(maxValue)) errorMsg+=argName+" cant more than "+maxValue+".\n"; } if(minValue!=-1 && maxValue!=-1) { if(errorMsg!="") errorMsg=argName+" must between "+minValue+" to "+maxValue+" .\n"; } } focusToElement(document.getElementById(element)); } return checkReturn(); }; function validateEmail(form,element,argName) { with(checkFormArg(form)) { if(checkEmpty(document.getElementById(element).value)) return; var emailPat=/([\-\_\w]+@[\-\_\w]+\.\w+)(\.{0,1}\w*)(\.{0,1}\w*)/i; if(checkVal.match(emailPat)==null) { errorMsg+=argName+" is not a valid email."; focusToElement(document.getElementById(element)); } } return checkReturn(); }; function validateDate(form,element,argName) { with(checkFormArg(form)) { var isDate=true; if(checkEmpty(document.getElementById(element).value)) return; checkVal=checkVal.replace('/',''); checkVal=checkVal.replace('-','/'); checkVal=checkVal.replace('-','/'); if(new Date(checkVal)=="NaN") isDate=false; else { var newDate=new Date(checkVal); var y=newDate.getFullYear(); var m=newDate.getMonth()+1; var d=newDate.getDate(); var dateMatch = eval(element+".value"); dateMatch = dateMatch.split(/\D/); if(parseInt(y)!=dateMatch[0] || parseInt(m)!=dateMatch[1] || parseInt(d)!=dateMatch[2]) isDate=false; } if(isDate==false) { errorMsg+=argName+" is not a valid date,\n date format is yyyy-mm-dd ."; focusToElement(document.getElementById(element)); } } return checkReturn(); }; function validateCheckBox(form,element,argName,minSele,maxSele) { with(checkFormArg(form)) { var seleCount=0; element=document.getElementsByName(element); if(typeof(element.length)=="undefined") { if(element.checked==true) seleCount++; } else { for(var i=0;imaxSele) errorMsg+=argName+" 不能选择多于 "+maxSele+" 项.\n"; } if(minSele!=-1 && maxSele!=-1) { if(errorMsg!="") errorMsg=argName+" 必须选择 "+minSele+" 到 "+maxSele+" 之间." } } return checkReturn(); }; function validateRadio(form,element,argName) { with(checkFormArg(form)) { var selected=false; element=document.getElementsByName(element); if(typeof(element.length)=="undefined") { if(element.checked==true) { selected=true; return selected; } } else { for(var i=0;i