/* 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 doSearch(id,type,value){ 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 = "/mycim2/search?id="+id +"&type="+type; if(value!=""&&value!=null){ dest = dest +"&value="+value; } else{ dest = dest + "&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 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 = 500; 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 doOpen(url){ 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 = url; 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); } //------------------------------------------------------------- check numeric //this function is used to tell whether str is numeric. function IsNumeric(str) { var chrC; var intC; var intLen; var intI; var token=0;//tag the number of "." var token1=0;//tag the number of "e" or "E" str=Cstr(str); str=Trim(str); intLen=str.length; intI=0; chrC=str.substring(intI,intI+1);//get the first char if ((chrC.indexOf("+")!=-1)||(chrC.indexOf("-")!=-1)) intI++; chrC=str.substring(intI,intI+1);//remorve first + or - if (isNaN(parseInt(chrC)) && (chrC.indexOf(".")==-1) && (chrC.indexOf("E")==-1) && (chrC.indexOf("e")==-1)) return false; //first char is E or e if ((chrC.indexOf("e")!=-1) || (chrC.indexOf("E")!=-1)) { return false; intI++; if (intI=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; dateRegexp = new RegExp("^(\\d{4})[/-](\\d{2})[/-](\\d{2})$"); var matched = dateRegexp.exec(str); if(matched != null) { if (!isValidDate(matched[1], matched[2], matched[3])) { bValid = false; } } else { bValid = false; } return bValid; } function isValidDate(year, month, day) { 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-9]+$/) != -1) return true; else return false; } //------------------------------------------------------------- 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; } //------------------------------------------------------------- Check IP address function isIP(str) { if (str.search(/^/) != -1) return ture; 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; } function replace(source, oldStr, newStr) { var i; var chr; var str = "~"; for (i = 0; i < source.length; i++) { chr = source.charAt(i); if (chr == oldStr) { source = source.replace(chr, str); } } for (i = 0; i < source.length; i++) { chr = source.charAt(i); if (chr == "~") { source = source.replace(chr, newStr); } } return source; } function hasSpecialChar(str) { //Counter var i; //a char in the string var chrCode; for(i=0;i0&&chrCode<9) || (chrCode>10&&chrCode<12) || (chrCode>14&&chrCode<32) || (chrCode>32&&chrCode<41) || (chrCode>46&&chrCode<48) || (chrCode>57&&chrCode<64) || (chrCode>90&&chrCode<95) || (chrCode>95&&chrCode<97) || (chrCode>122)) { return true; } } return false; } function hasSpecialCharOrSpace(str) { //Counter var i; //a char in the string var chrCode; for(i=0;i0&&chrCode<45) || (chrCode>46&&chrCode<48) || (chrCode>57&&chrCode<64) || (chrCode>90&&chrCode<95) || (chrCode>95&&chrCode<97) || (chrCode>122)) { return true; } } return false; } function hasSpecialCharExceptChinese(str) { //Counter var i; //a char in the string var chrCode; for(i=0;i0&&chrCode<9) || (chrCode>10&&chrCode<12) || (chrCode>14&&chrCode<32) || (chrCode>32&&chrCode<41) || (chrCode>46&&chrCode<48) || (chrCode>57&&chrCode<64) || (chrCode>90&&chrCode<95) || (chrCode>95&&chrCode<97)) { return true; } } return false; } function hasDoubleQuotationMarks(str) { //Counter var i; //a char in the string var chrCode; for(i=0;i