/* Main Function List: Cstr(string) :change the string into int;return string; Rep1(string) :change the string 's "'",""" into "`" and change "<>" into "()" ;return string; Trim(string) :Trim the string's " " before and after the string;return string; */ //*************************************** string function ************************* //Avoid error when no validate function found. function validate(form){ return true; } function Cstr(inp) { return(""+inp+""); } function cstr(inp) { return(""+inp+""); } function Trim(inString) { var l,i,g,t,r; inString=Cstr(inString); l=inString.length; t=inString; for(i=0;i0;i--) { g=t.substring(i,i-1); if(g==" ") { r=t.substring(i-1,0); } else { break; } } return(r); } function trim(inString) { var l,i,g,t,r; inString=Cstr(inString); l=inString.length; t=inString; for(i=0;i0;i--) { g=t.substring(i,i-1); if(g==" ") { r=t.substring(i-1,0); } else { break; } } return(r); } function doDelete(action,overlay){ if(!validateDelete()) return; if(overlay == null){ origAction = document.forms[0].action; if(null != action){ destAction = origAction + "?" + action; }else{ destAction = origAction; } } else { destAction = action; } //alert(destAction); document.forms[0].action = destAction; document.forms[0].submit(); } function doSearch(id,type,value,path){ var op_tool = 0 ; var op_loc_box = 0; var op_dir = 0; var op_stat = 0; var op_menu = 0; var op_scroll =1; var op_resize = 1; var op_wid = 700; var op_heigh = 300; //find the relative dir var dest = path + "/search?id="+id +"&type="+UrlEncode(type); //alert(dest); //alert(trim(replace(value,"|","",false,false))); if(value!=null&&value!=""&&(trim(replace(value,"|","",false,false))!="")){ dest = dest + "&value=" + value; } else{ dest = dest + "&page=1"; } //alert(dest); var option = "toolbar="+ op_tool +",location="+ op_loc_box +",directories=" + op_dir +",status="+ op_stat +",menubar="+ op_menu +",scrollbars=" + op_scroll +",resizable=" + op_resize +",width=" + op_wid +",height="+ op_heigh; window.open(dest, "what_I_want", option); } //for calendar control function openCal(id,path){ var op_tool = 0 ; var op_loc_box = 0; var op_dir = 0; var op_stat = 0; var op_menu = 0; var op_scroll =0; var op_resize = 0; var op_wid = 220; var op_heigh = 220; //find the relative dir if(path == null) { dest = "calendar?config="+id; } else { dest = path + "/calendar?config="+id; } var option = "toolbar="+ op_tool +",location="+ op_loc_box +",directories=" + op_dir +",status="+ op_stat +",menubar="+ op_menu +",scrollbars=" + op_scroll +",resizable=" + op_resize +",width=" + op_wid +",height="+ op_heigh; window.open(dest, "calendar", option); } function doChangeId(){ with(document.forms[0]){ //rrn=fldRrn.value; //id=fldId.value; //objecttype="FIELD"; //window.open("changeid.jsp?rrn="+rrn+"&&id="+id+"&objecttype="+objecttype); } } function doCopy(type){ var op_tool = 0 ; var op_loc_box = 0; var op_dir = 0; var op_stat = 0; var op_menu = 0; var op_scroll =1; var op_resize = 1; var op_wid = 700; var op_heigh = 300; var dest = "copyfunction.jsp?type="+type +"&page=1"; var option = "toolbar="+ op_tool +",location="+ op_loc_box +",directories=" + op_dir +",status="+ op_stat +",menubar="+ op_menu +",scrollbars=" + op_scroll +",resizable=" + op_resize +",width=" + op_wid +",height="+ op_heigh; window.open(dest, "what_I_want", option); } function doOpenWindow(destination) { window.open(destination); } function doPopup(destination,menu) { window.open(destination,"ebiz", "top=140,left=100,width=820,height=420,title=,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar="+menu+",resizable=1," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doPopupPsw(destination,menu) { window.open(destination,"ebiz", "top=140,left=100,width=820,height=220,title=,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar="+menu+",resizable=1," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doPopup1(destination) { window.open(destination,"ebiz", "top=140,left=100,width=820,height=420,title=,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=1," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doPopupMaintain(destination) { window.open(destination,"ebiz", "top=140,left=100,width=500,height=250,title=,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=0," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function displayChart(destination) { window.open(destination,"ebiz", "top=190,left=250,width=525,height=360,title=,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=0," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doOpenSelect(destination) { window.open(destination,"ebiz", "top=380,left=360,width=300,height=240,title=Select Option,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=0," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doOpen(destination,name) { var i = destination.indexOf("?"); if ( i > 0 && destination.indexOf(i,"%") == -1) { var a = destination.substring(0,i); var b = destination.substring(i+1,destination.length); b = b.split("&"); var c = "?"; for ( var i = 0; i < b.length; i++ ) { var d = b[i].split("="); if ( i > 0 ) { c+="&"; } c+=encodeURIComponent(d[0])+"="+encodeURIComponent(d[1]); } destination = a + c; } window.open(destination,name||"ebiz", "top=50,left=50,width=870,height=600,title=,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=0," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doOpenUpload(destination,name) { window.open(destination,name, "top=150,left=50,width=800,height=200,title=,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=0," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doDownload(destination) { window.open(destination,"download", "top=100,left=100,width=300,height=150,title=Download File,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=0," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doOpenErrorPage(destination) { window.open(destination,"errorpage", "top=100,left=100,width=350,height=200,title=Error File,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=1," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } function doOpenContent(destination) { window.open(destination,"content", "top=100,left=100,width=820,height=550,title=,channelmode=0," + "directories=0,fullscreen=0,location=0,menubar=0,resizable=0," + "scrollbars=1,status=1,titlebar=0,toolbar=no"); } // check whether id is proper function isProper(string) { if (!string) return false; var iChars = "*|!,\":<>[]{}`\';()@&$#%"; for (var i = 0; i < string.length; i++) { if (iChars.indexOf(string.charAt(i)) != -1) return false; } return true; } //------------------------------------------------------------- check numeric //this function is used to tell whether str is numeric. function IsNumeric(str){ if (str.search(/^[+|-]?[0-9]+[.]?[0-9]*$/) != -1) return true; else return false; } // function IsFloat(str) { var loctionpoint=Trim(str).lastIndexOf("."); if (loctionpoint!=-1) { if(IsNumeric(str)) { return true; } } else return false; } function IsInt(str) { //is integer and natural number var bflag=true var nLen=str.length for(i=0;i'9') bflag=false } return bflag } //------------------------------------------------------------- check length //to get the string(unicode including GBK)'s real length, //a chinese char means a three chars length function getLength(str){ var _str_code=""; var i=0; var j=0; //avoid the null pointer exception; if(str==null) return; str = Trim(str); while(true){ _str_code=str.charCodeAt(i); i++; if(_str_code>=0&&_str_code<=255){ j++; }else if(_str_code>255){ j=j+3; }else{ break; } } return j; } //------------------------------------------------------------- check date format function IsDate(str){ bValid = true; //DD/MM/YYYY dateRegexp = new RegExp("^(\\d{2})[/-](\\d{2})[/-](\\d{4})$"); var matched = dateRegexp.exec(str); if(matched != null) { if (!isValidDate(matched[1], matched[2], matched[3])) { bValid = false; } } else { bValid = false; } return bValid; } function IsDate(str, format){ bValid = true; //default date format is "DD/MM/YYYY" exp = "^(\\d{2})[/-](\\d{2})[/-](\\d{4})$"; if (format=="DD/MM/YYYY" || format == "DD-MM-YYYY") { exp = "^(\\d{2})[/-](\\d{2})[/-](\\d{4})$"; } else if(format == "DD/MM/YY" || format == "DD-MM-YY") { exp = "^(\\d{2})[/-](\\d{2})[/-](\\d{2})$"; } else if(format == "MM/DD/YYYY" || format == "MM-DD-YYYY") { exp = "^(\\d{2})[/-](\\d{2})[/-](\\d{4})$"; } else if(format == "YYYY/MM/DD" || format == "YYYY-MM-DD") { exp = "^(\\d{4})[/-](\\d{2})[/-](\\d{2})$"; } //DD/MM/YYYY dateRegexp = new RegExp(exp); var matched = dateRegexp.exec(str); if(matched != null) { day = matched[1]; month = matched[2]; year = matched[3]; if (format=="DD/MM/YYYY" || format == "DD-MM-YYYY" || format == "DD/MM/YY" || format == "DD-MM-YY") { day = matched[1]; month = matched[2]; year = matched[3]; } else if(format == "MM/DD/YYYY" || format == "MM-DD-YYYY") { day = matched[2]; month = matched[1]; year = matched[3]; } else if(format == "YYYY/MM/DD" || format == "YYYY-MM-DD") { day = matched[3]; month = matched[2]; year = matched[1]; } if (!isValidDate(day, month, year)) { bValid = false; } } else { bValid = false; } return bValid; } function isValidDate(day,month,year) { if (month < 1 || month > 12) return false; if (day < 1 || day > 31) return false; if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) return false; if (month == 2) { var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day == 29 && !leap)) return false; } return true; } //------------------------------------------------------------- check time function IsTime(str){ if (str.search(/^[0-9]?[0-9]:[0-5][0-9]:[0-5][0-9]$/) != -1) return validtime(str); else return false; } /* Hours must be between 0 and 24, since minutes and seconds have been filtered by regular expression. */ function validtime(obj) { retval = false; i = obj.indexOf(":"); hours=obj.substring(0,i); if (parseInt(hours) >= 0 && parseInt(hours) < 24) retval = true; return retval; } //------------------------------------------------------------- check email function IsEmail(str){ if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true; else return false; } function goToURL() { var i, args=goToURL.arguments; document.returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'"); } //--------------------------------------------------------------- replace for validate_adhoc function replace(target,oldTerm,newTerm,caseSens,wordOnly){ var wk ; var ind = 0; var next = 0; wk=Cstr(target); if (!caseSens) { oldTerm = oldTerm.toLowerCase(); wk = target.toLowerCase(); } while ((ind = wk.indexOf(oldTerm,next)) >= 0) { if (wordOnly) { var before = ind - 1; var after = ind + oldTerm.length; if (!(space(wk.charAt(before)) && space(wk.charAt(after)))) { next = ind + oldTerm.length; continue; } } target = target.substring(0,ind) + newTerm + target.substring(ind+oldTerm.length,target.length); wk = wk.substring(0,ind) + newTerm + wk.substring(ind+oldTerm.length,wk.length); next = ind + newTerm.length; if (next >= wk.length) { break; } } return target; } //avoid double post transaction function transaction(obj,validated){ if(validated==null) { sType='validate'; }else { sType='novalidate'; } //validate method bug, it should return true instead of undefined if(sType=='novalidate' || validate(document.forms[0])){ document.forms[0].action=document.forms[0].action+'?'+obj.name+'=1'; document.body.style.cursor='wait'; document.forms[0].submit(); obj.disabled=true; } } function UrlEncode(str){ var i,c,ret="",strSpecial="!\"#$%&'()*+,/:;<=>?@[\]^`{|}~%"; for(i=0;i=0x4e00){ c=qswhU2GB[str.charCodeAt(i)-0x4e00]; ret+="%"+c.slice(0,2)+"%"+c.slice(-2); } else{ c=str.charAt(i); if(c==" ") ret+="+"; else if(strSpecial.indexOf(c)!=-1) ret+="%"+str.charCodeAt(i).toString(16); else ret+=c; } } return ret; } function selectOption(url, customer, textBox, type){ var URLTo = url + "customer="; URLTo = URLTo + customer; URLTo = URLTo + "&textbox="; URLTo = URLTo + textBox; URLTo = URLTo + "&type="; URLTo = URLTo + type; doOpenSelect(URLTo); } function linktoftp(url){ var URLTo = url doLinkToFTP(URLTo); } function doLinkToFTP(destination) { window.open(destination,"FTPService", "top=10,left=10,width=1000,height=700,title=,channelmode=0," + "directories=1,fullscreen=0,location=1,menubar=1,resizable=1," + "scrollbars=1,status=1,titlebar=1,toolbar=1"); } function printWindow() { bV = parseInt(navigator.appVersion) if (bV >= 4) window.print() else alert("IE Version >=4.0 is needed") }