// Octopus Phoenix System Common Javascript // Create Date: 11 Jun 2003 function emailCheck (emailStr) { /* The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known TLD. 1 means check it, 0 means don't. */ var checkTLD=1; /* The following is the list of known TLDs that an e-mail address must end with. */ var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; /* The following pattern is used to check if the entered e-mail address fits the user@domain format. It also is used to separate the username from the domain. */ var emailPat=/^(.+)@(.+)$/; /* The following string represents the pattern for matching all special characters. We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */ var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* The following string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/ var validChars="\[^\\s" + specialChars + "\]"; /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes). E.g. "jiminy cricket"@disney.com is a legal e-mail address. */ var quotedUser="(\"[^\"]*\")"; /* The following pattern applies for domains that are IP addresses, rather than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */ var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; /* The following string represents an atom (basically a series of non-special characters.) */ var atom=validChars + '+'; /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */ var word="(" + atom + "|" + quotedUser + ")"; // The following pattern describes the structure of the user var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */ var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); /* Finally, let's start trying to figure out if the supplied address is valid. */ /* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */ var matchArray=emailStr.match(emailPat); if (matchArray==null) { /* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */ alert("Email address seems incorrect (check @ and .'s)"); return false; } var user=matchArray[1]; var domain=matchArray[2]; // Start by checking that only basic ASCII characters are in the strings (0-127). for (i=0; i127) { alert("Ths username contains invalid characters."); return false; } } for (i=0; i127) { alert("Ths domain name contains invalid characters."); return false; } } // See if "user" is valid if (user.match(userPat)==null) { // user is not valid alert("The username doesn't seem to be valid."); return false; } /* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */ var IPArray=domain.match(ipDomainPat); if (IPArray!=null) { // this is an IP address for (var i=1;i<=4;i++) { if (IPArray[i]>255) { alert("Destination IP address is invalid!"); return false; } } return true; } // Domain is symbolic name. Check if it's valid. var atomPat=new RegExp("^" + atom + "$"); var domArr=domain.split("."); var len=domArr.length; for (i=0;i= 'a' && fieldValue.charAt(i) <= 'z')) { valid = false; break; } } return valid; } //check if number is within a valid range function CheckRange(fieldValue, fromRange, toRange, type){ if (type == "1") { return (parseInt(fieldValue, 10) >= fromRange); } if (type == "2") { return (parseInt(fieldValue, 10) <= toRange); } if (type == "3") { return (parseInt(fieldValue, 10) > fromRange && parseInt(fieldValue, 10) < toRange); } } //check if number starts with "0" //if yes return false function CheckZeroStart(fieldValue){ var i; var zeroCnt=0; var nonZeroCnt=0; for(i=0; i 1){ strRem[k] = number % 2; if(strRem[k] == 1){ quo = number / 2 - 0.5; }else{ quo = number / 2; } k = k + 1; number = quo; } strRem[k] = number; for( ; k >= 0; k--){ strTemp = strTemp + strRem[k]; } return strTemp; }else if (number == 0){ strTemp = "0"; return strTemp; } } //check for valid date format (yyyy-mm-dd) function isDateorNull(theElement) { var CorrectDate; var SplitDate; var thisDay; var thisMonth; var thisYear; var inpDate = theElement.value; var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31); // var MonthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12"); var CockUp = 0; // kill if nothing there if (inpDate.length == 0 ){ alert("Please enter date"); return false; } // numerical dates first for DDMMYYYY OR DDMMYY /* if (/^[0-9]{3}$/.test(inpDate.substr(1,3))) { if (/^[0-9]{8}/.test(inpDate)) { thisDay = inpDate.substr(0,2); thisMonth = inpDate.substr(2,2); thisYear = inpDate.substr(4,4); }else if (/^[0-9]{6}/.test(inpDate)) { thisDay = inpDate.substr(0,2); thisMonth = inpDate.substr(2,2); thisYear = inpDate.substr(4,2); }else{ CockUp = 1; } } // now alpha numeric dates for DDMONYYYY, DMONYYYY, DDMONYY, DMONYY, DDMONY, DMONY or MONYY else if (/^[a-zA-Z|0-9]{3}$/.test(inpDate.substr(1,3))) { if (/^[0-9|a-zA-Z]{9}/.test(inpDate)){ thisDay = inpDate.substr(0,2); thisMonth = inpDate.substr(2,3).toUpperCase(); thisYear = inpDate.substr(5,4); }else if (/^[0-9|a-zA-Z]{8}/.test(inpDate)){ thisDay = inpDate.substr(0,1); thisMonth = inpDate.substr(1,3).toUpperCase(); thisYear = inpDate.substr(4,4); }else if (/^[0-9|a-zA-Z]{7}/.test(inpDate)){ thisDay = inpDate.substr(0,2); thisMonth = inpDate.substr(2,3).toUpperCase(); thisYear = inpDate.substr(5,2); }else if (/^[0-9|a-zA-Z]{6}/.test(inpDate)){ if (/^[a-zA-Z]{1}/.test(inpDate.substr(1,1))){ thisDay = inpDate.substr(0,1); thisMonth = inpDate.substr(1,3).toUpperCase(); thisYear = inpDate.substr(4,2); }else { thisDay = inpDate.substr(0,2); thisMonth = inpDate.substr(2,3).toUpperCase(); thisYear = inpDate.substr(3,2);} } else{ CockUp = 1; } } // lastly pick up every conceivable special character or kick out with error else { */ if(inpDate.indexOf("-") == -1){ CockUp = 1; }else{ if(/-/.test(inpDate)) {SplitDate = inpDate.split("-");} // else if (/\//.test(inpDate)) {SplitDate = inpDate.split("/");} // else if (/\./.test(inpDate)) {SplitDate = inpDate.split(".");} // else if (/,/.test(inpDate)) {SplitDate = inpDate.split(",");} // else if (/\;/.test(inpDate)) {SplitDate = inpDate.split(";");} // else if (/\:/.test(inpDate)) {SplitDate = inpDate.split(":");} // else if (/\*/.test(inpDate)) {SplitDate = inpDate.split("*");} // else if (/_/.test(inpDate)) {SplitDate = inpDate.split("_");} // else if (/%/.test(inpDate)) {SplitDate = inpDate.split("%");} else{ CockUp = 1;} // thisDay = SplitDate[0]; // thisMonth = SplitDate[1].substr(0,1).toUpperCase() + SplitDate[1].substr(1,2).toLowerCase(); // thisYear = SplitDate[2]; thisYear = SplitDate[0]; thisMonth = SplitDate[1].substr(0,1).toUpperCase() + SplitDate[1].substr(1,2).toLowerCase(); thisDay = SplitDate[2]; } /* } */ // request reinput data if nonexistent if(!thisYear) {CockUp = 1;} if(!thisMonth) {CockUp = 1;} if(!thisDay) {CockUp = 1;} // kick out any errors before we do any formatting etc if(CockUp == 1){ alert("Input date format is incorrect - please try again using YYYY-MM-DD"); theElement.focus(); return false; } // change from numeric to alpha-numeric if(/^[0-9]{1}$/.test(thisMonth.substr(0,1))){ switch (thisMonth) { /* case "01" : case "1" : thisMonth = 'Jan'; break; case "02" : case "2" : thisMonth = 'Feb'; break; case "03" : case "3" : thisMonth = 'Mar'; break; case "04" : case "4" : thisMonth = 'Apr'; break; case "05" : case "5" : thisMonth = 'May'; break; case "06" : case "6" : thisMonth = 'Jun'; break; case "07" : case "7" : thisMonth = 'Jul'; break; case "08" : case "8" : thisMonth = 'Aug'; break; case "09" : case "9" : thisMonth = 'Sep'; break; case "10" : thisMonth = 'Oct'; break; case "11" : thisMonth = 'Nov'; break; case "12" : thisMonth = 'Dec'; break; */ case "01" : case "1" : thisMonth = '01'; break; case "02" : case "2" : thisMonth = '02'; break; case "03" : case "3" : thisMonth = '03'; break; case "04" : case "4" : thisMonth = '04'; break; case "05" : case "5" : thisMonth = '05'; break; case "06" : case "6" : thisMonth = '06'; break; case "07" : case "7" : thisMonth = '07'; break; case "08" : case "8" : thisMonth = '08'; break; case "09" : case "9" : thisMonth = '09'; break; case "10" : thisMonth = '10'; break; case "11" : thisMonth = '11'; break; case "12" : thisMonth = '12'; break; default : alert("Please enter a correct month."); theElement.focus(); return false; } }else{ alert("Month should be integers."); return false; } // check for "+" sign if(/^[+]{1}$/.test(thisYear.substr(0,1))){ alert("Incorrect Year."); return false; } if(/^[+]{1}$/.test(thisDay.substr(0,1))){ alert("Incorrect Day."); return false; } // sort variable lengths out and build date if(thisDay.length == 1) {thisDay = "0" + thisDay;} if(thisDay.length >= 3) { alert("Incorrect Day."); theElement.focus(); return false; } if(thisMonth.length >= 3) { alert("Incorrect Month."); theElement.focus(); return false; } // if (thisYear.length == 1) {thisYear = "200" + thisYear;} // if (thisYear.length == 2) {thisYear = "20" + thisYear;} if(thisYear.length != 4) { alert("Year must be entered as 4 digits."); theElement.focus(); return false; } if(isNaN(thisYear)){ alert("Year must be integers."); theElement.focus(); return false; } CorrectDate = thisYear + "-" + thisMonth + "-" + thisDay; // Check alpha-numeric Valid Month // var filter=/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/; // if(!filter.test(thisMonth)){ // alert("Please enter a correct month~~~~."); // theElement.focus(); // return false; // } // Check For Leap Year N = thisYear; if((N%4 == 0 && N%100 != 0) || (N%400 == 0 )){ DayArray[1]=29; } // check for correct days in month for(var ctr=0; ctr<=11; ctr++){ if(MonthArray[ctr] == thisMonth){ if(thisDay <= DayArray[ctr] && thisDay > 0 ){ CockUp = 0; }else{ alert("Input day is incorrect for the input month."); theElement.focus(); CockUp = 1; return false; } } } if(CockUp == 0){ theElement.value = CorrectDate; return true; } } //check the day difference between 2 days //date pass in must follow this format dd-mm-yyyy function CheckDateDiff(date1, date2) { var fromDateYYYY = date1.substr(6,4); var fromDateMM = date1.substr(3,2)-1; var fromDateDD = date1.substr(0,2); var toDateYYYY = date2.substr(6,4); var toDateMM = date2.substr(3,2)-1; var toDateDD = date2.substr(0,2); var fromDate = new Date(fromDateYYYY, fromDateMM, fromDateDD); var toDate = new Date(toDateYYYY, toDateMM, toDateDD); var difference = toDate.getTime() - fromDate.getTime(); var daysDifference = Math.floor(difference/1000/60/60/24); return daysDifference; } function ChangeColor(type, theElement){ if(type == "black"){ theElement.style.color = 'black'; }else if(type == "red"){ theElement.style.color = 'red'; } return true; } // =================================================================== // Author: Matt Kruse // WWW: http://www.mattkruse.com/ // // NOTICE: You may use this code for any purpose, commercial or // private, without any further permission from the author. You may // remove this notice from your final code if you wish, however it is // appreciated by the author if at least my web site address is kept. // // You may *NOT* re-distribute this code in any way except through its // use. That means, you can include it in your product, or your web // site, or any other form where the code is actually being used. You // may not put the plain javascript up on your site for download or // include it in your javascript libraries for download. // If you wish to share this code with others, please just point them // to the URL instead. // Please DO NOT link directly to my .js files from your site. Copy // the files to your server and use them there. Thank you. // =================================================================== // HISTORY // ------------------------------------------------------------------ // May 17, 2003: Fixed bug in parseDate() for dates <1970 // March 11, 2003: Added parseDate() function // March 11, 2003: Added "NNN" formatting option. Doesn't match up // perfectly with SimpleDateFormat formats, but // backwards-compatability was required. // ------------------------------------------------------------------ // These functions use the same 'format' strings as the // java.text.SimpleDateFormat class, with minor exceptions. // The format string consists of the following abbreviations: // // Field | Full Form | Short Form // -------------+--------------------+----------------------- // Year | yyyy (4 digits) | yy (2 digits), y (2 or 4 digits) // Month | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits) // | NNN (abbr.) | // Day of Month | dd (2 digits) | d (1 or 2 digits) // Day of Week | EE (name) | E (abbr) // Hour (1-12) | hh (2 digits) | h (1 or 2 digits) // Hour (0-23) | HH (2 digits) | H (1 or 2 digits) // Hour (0-11) | KK (2 digits) | K (1 or 2 digits) // Hour (1-24) | kk (2 digits) | k (1 or 2 digits) // Minute | mm (2 digits) | m (1 or 2 digits) // Second | ss (2 digits) | s (1 or 2 digits) // AM/PM | a | // // NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm! // Examples: // "MMM d, y" matches: January 01, 2000 // Dec 1, 1900 // Nov 20, 00 // "M/d/yy" matches: 01/20/00 // 9/2/00 // "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM" // ------------------------------------------------------------------ var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat'); function LZ(x) {return(x<0||x>9?"":"0")+x} // ------------------------------------------------------------------ // isDate ( date_string, format_string ) // Returns true if date string matches format of format string and // is a valid date. Else returns false. // It is recommended that you trim whitespace around the value before // passing it to this function, as whitespace is NOT ignored! // ------------------------------------------------------------------ function isDate(val,format) { var date=getDateFromFormat(val,format); if (date==0) { return false; } return true; } // ------------------------------------------------------------------- // compareDates(date1,date1format,date2,date2format) // Compare two date strings to see which is greater. // Returns: // 1 if date1 is greater than date2 // 0 if date2 is greater than date1 of if they are the same // -1 if either of the dates is in an invalid format // ------------------------------------------------------------------- function compareDates(date1,dateformat1,date2,dateformat2) { var d1=getDateFromFormat(date1,dateformat1); var d2=getDateFromFormat(date2,dateformat2); if (d1==0 || d2==0) { return -1; } else if (d1 > d2) { return 1; } return 0; } // ------------------------------------------------------------------ // formatDate (date_object, format) // Returns a date in the output format specified. // The format string uses the same abbreviations as in getDateFromFormat() // ------------------------------------------------------------------ function formatDate(date,format) { format=format+""; var result=""; var i_format=0; var c=""; var token=""; var y=date.getYear()+""; var M=date.getMonth()+1; var d=date.getDate(); var E=date.getDay(); var H=date.getHours(); var m=date.getMinutes(); var s=date.getSeconds(); var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k; // Convert real date parts into formatted versions var value=new Object(); if (y.length < 4) {y=""+(y-0+1900);} value["y"]=""+y; value["yyyy"]=y; value["yy"]=y.substring(2,4); value["M"]=M; value["MM"]=LZ(M); value["MMM"]=MONTH_NAMES[M-1]; value["NNN"]=MONTH_NAMES[M+11]; value["d"]=d; value["dd"]=LZ(d); value["E"]=DAY_NAMES[E+7]; value["EE"]=DAY_NAMES[E]; value["H"]=H; value["HH"]=LZ(H); if (H==0){value["h"]=12;} else if (H>12){value["h"]=H-12;} else {value["h"]=H;} value["hh"]=LZ(value["h"]); if (H>11){value["K"]=H-12;} else {value["K"]=H;} value["k"]=H+1; value["KK"]=LZ(value["K"]); value["kk"]=LZ(value["k"]); if (H > 11) { value["a"]="PM"; } else { value["a"]="AM"; } value["m"]=m; value["mm"]=LZ(m); value["s"]=s; value["ss"]=LZ(s); while (i_format < format.length) { c=format.charAt(i_format); token=""; while ((format.charAt(i_format)==c) && (i_format < format.length)) { token += format.charAt(i_format++); } if (value[token] != null) { result=result + value[token]; } else { result=result + token; } } return result; } // ------------------------------------------------------------------ // Utility functions for parsing in getDateFromFormat() // ------------------------------------------------------------------ function _isInteger(val) { var digits="1234567890"; for (var i=0; i < val.length; i++) { if (digits.indexOf(val.charAt(i))==-1) { return false; } } return true; } function _getInt(str,i,minlength,maxlength) { for (var x=maxlength; x>=minlength; x--) { var token=str.substring(i,i+x); if (token.length < minlength) { return null; } if (_isInteger(token)) { return token; } } return null; } // ------------------------------------------------------------------ // getDateFromFormat( date_string , format_string ) // // This function takes a date string and a format string. It matches // If the date string matches the format string, it returns the // getTime() of the date. If it does not match, it returns 0. // ------------------------------------------------------------------ function getDateFromFormat(val,format) { val=val+""; format=format+""; var i_val=0; var i_format=0; var c=""; var token=""; var token2=""; var x,y; var now=new Date(); var year=now.getYear(); var month=now.getMonth()+1; var date=now.getDate(); var hh=now.getHours(); var mm=now.getMinutes(); var ss=now.getSeconds(); var ampm=""; while (i_format < format.length) { // Get next token from format string c=format.charAt(i_format); token=""; while ((format.charAt(i_format)==c) && (i_format < format.length)) { token += format.charAt(i_format++); } // Extract contents of value based on format token if (token=="yyyy" || token=="yy" || token=="y") { if (token=="yyyy") { x=4;y=4; } if (token=="yy") { x=2;y=2; } if (token=="y") { x=2;y=4; } year=_getInt(val,i_val,x,y); if (year==null) { return 0; } i_val += year.length; if (year.length==2) { if (year > 70) { year=1900+(year-0); } else { year=2000+(year-0); } } } else if (token=="MMM"||token=="NNN"){ month=0; for (var i=0; i11)) { month=i+1; if (month>12) { month -= 12; } i_val += month_name.length; break; } } } if ((month < 1)||(month>12)){return 0;} } else if (token=="EE"||token=="E"){ for (var i=0; i12)){return 0;} i_val+=month.length;} else if (token=="dd"||token=="d") { date=_getInt(val,i_val,token.length,2); if(date==null||(date<1)||(date>31)){return 0;} i_val+=date.length;} else if (token=="hh"||token=="h") { hh=_getInt(val,i_val,token.length,2); if(hh==null||(hh<1)||(hh>12)){return 0;} i_val+=hh.length;} else if (token=="HH"||token=="H") { hh=_getInt(val,i_val,token.length,2); if(hh==null||(hh<0)||(hh>23)){return 0;} i_val+=hh.length;} else if (token=="KK"||token=="K") { hh=_getInt(val,i_val,token.length,2); if(hh==null||(hh<0)||(hh>11)){return 0;} i_val+=hh.length;} else if (token=="kk"||token=="k") { hh=_getInt(val,i_val,token.length,2); if(hh==null||(hh<1)||(hh>24)){return 0;} i_val+=hh.length;hh--;} else if (token=="mm"||token=="m") { mm=_getInt(val,i_val,token.length,2); if(mm==null||(mm<0)||(mm>59)){return 0;} i_val+=mm.length;} else if (token=="ss"||token=="s") { ss=_getInt(val,i_val,token.length,2); if(ss==null||(ss<0)||(ss>59)){return 0;} i_val+=ss.length;} else if (token=="a") { if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";} else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";} else {return 0;} i_val+=2;} else { if (val.substring(i_val,i_val+token.length)!=token) {return 0;} else {i_val+=token.length;} } } // If there are any trailing characters left in the value, it doesn't match if (i_val != val.length) { return 0; } // Is date valid for month? if (month==2) { // Check for leap year if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year if (date > 29){ return 0; } } else { if (date > 28) { return 0; } } } if ((month==4)||(month==6)||(month==9)||(month==11)) { if (date > 30) { return 0; } } // Correct hours value if (hh<12 && ampm=="PM") { hh=hh-0+12; } else if (hh>11 && ampm=="AM") { hh-=12; } var newdate=new Date(year,month-1,date,hh,mm,ss); return newdate.getTime(); } // ------------------------------------------------------------------ // parseDate( date_string [, prefer_euro_format] ) // // This function takes a date string and tries to match it to a // number of possible date formats to get the value. It will try to // match against the following international formats, in this order: // y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d // M/d/y M-d-y M.d.y MMM-d M/d M-d // d/M/y d-M-y d.M.y d-MMM d/M d-M // A second argument may be passed to instruct the method to search // for formats like d/M/y (european format) before M/d/y (American). // Returns a Date object or null if no patterns match. // // ------------------------------------------------------------------ // function parseDate(val) { // return parseDateEx(val, 'yyyy-MM-dd HH:mm:ss'); // } // ------------------------------------------------------------------ // parseDate(date_string, date_format_number) // // This function takes a date string and tries to match it to a // number of possible date formats to get the value. // d-M-y d-M-y H:m:s // ------------------------------------------------------------------ function parseDate(val, dateFormat) { var yearIndex = val.lastIndexOf('-')+1; if(dateFormat==1) { if(trim(val).substring(yearIndex).length==2 || trim(val).substring(yearIndex).length==4) { return parseDateEx(trim(val), 'dd-MM-yyyy'); } else { return null; } } else if(dateFormat==2) { if(trim(val).substring(yearIndex).length==4) { return parseDateEx(trim(val), 'dd-MM-yyyy'); } else { return null; } } else if(dateFormat==3) { var hourIndex = val.indexOf(' ',yearIndex); if(hourIndex==-1) { val=trim(val)+' 00:00:00'; hourIndex = val.indexOf(' ',yearIndex); } else { var timePart = val.substring(hourIndex); var minuteIndex = timePart.indexOf(':'); var timePart1 = timePart.substring(minuteIndex+1); var secondIndex = timePart1.indexOf(':'); if(secondIndex==-1) { val=trim(val)+':00'; } } if(trim(val).substring(yearIndex,hourIndex).length==2 || trim(val).substring(yearIndex,hourIndex).length==4) { return parseDateEx(trim(val), 'dd-MM-yyyy HH:mm:ss'); } else { return null; } } else if(dateFormat==4) { var hourIndex = val.indexOf(' ',yearIndex); if(hourIndex==-1) { val=trim(val)+' 00:00:00'; hourIndex = val.indexOf(' ',yearIndex); } else { var timePart = val.substring(hourIndex); var minuteIndex = timePart.indexOf(':'); var timePart1 = timePart.substring(minuteIndex+1); var secondIndex = timePart1.indexOf(':'); if(secondIndex==-1) { val=trim(val)+':00'; } } if(trim(val).substring(yearIndex,hourIndex).length==4) { return parseDateEx(trim(val), 'dd-MM-yyyy HH:mm:ss'); } else { return null; } } else { if(trim(val).substring(yearIndex).length==2 || trim(val).substring(yearIndex).length==4) { return parseDateEx(trim(val), 'dd-MM-yyyy'); } else { return null; } } } // ------------------------------------------------------------------ // parseDate( date_string [, prefer_euro_format] ) // // This function takes a date string and tries to match it to a // number of possible date formats to get the value. It will try to // match against the following international formats, in this order: // y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d // M/d/y M-d-y M.d.y MMM-d M/d M-d // d/M/y d-M-y d.M.y d-MMM d/M d-M // A second argument may be passed to instruct the method to search // for formats like d/M/y (european format) before M/d/y (American). // Returns a Date object or null if no patterns match. // ------------------------------------------------------------------ function parseDateEx(val, format) { // var preferEuro=(arguments.length==2)?arguments[1]:false; // generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d', // 'y-M-d H:m','MMM d, y H:m','MMM d,y H:m','y-MMM-d H:m','d-MMM-y H:m','MMM d H:m', // 'y-M-d H:m:s','MMM d, y H:m:s','MMM d,y H:m:s','y-MMM-d H:m:s','d-MMM-y H:m:s','MMM d H:m:s', 'HH:mm:ss'); // generalFormats2=new Array('y/M/d','MMM d, y','MMM d,y','y/MMM/d','d/MMM/y','MMM d', // 'y/M/d H:m','MMM d, y H:m','MMM d,y H:m','y/MMM/d H:m','d/MMM/y H:m','MMM d H:m', // 'y/M/d H:m:s','MMM d, y H:m:s','MMM d,y H:m:s','y/MMM/d H:m:s','d/MMM/y H:m:s','MMM d H:m:s', 'HH:mm:ss'); // monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d', // 'M/d/y H:m','M-d-y H:m','M.d.y H:m','MMM-d H:m','M/d H:m','M-d H:m', // 'M/d/y H:m:s','M-d-y H:m:s','M.d.y H:m:s','MMM-d H:m:s','M/d H:m:s','M-d H:m:s'); // dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M', // 'd/M/y H:m','d-M-y H:m','d.M.y H:m','d-MMM H:m','d/M H:m','d-M H:m', // 'd/M/y H:m:s','d-M-y H:m:s','d.M.y H:m:s','d-MMM H:m:s','d/M H:m:s','d-M H:m:s'); // var checkList=new Array('generalFormats','generalFormats2',preferEuro?'monthFirst':'dateFirst',preferEuro?'dateFirst':'monthFirst'); allowableFormat=new Array('d-M-y','d-M-y H:m:s'); var checkList=new Array('allowableFormat'); var d=null; for (var i=0; i= 48 && event.keyCode <= 57); } function getEvent(event) { return (event) ? event : ((window.event) ? window.event : ""); } //Check whether the value is hex number function CheckHexNumber(fieldValue){ var thechar; var index = 0; // var hexPattern=new RegExp("[0-9A-F]"); while (index < fieldValue.length) { thechar = fieldValue.substr(index,1); // TODO change it to regex // if (thechar.match(hexPattern) == null) { // return false; // } if ((thechar != "0") && (thechar != "1") && (thechar != "2") && (thechar != "3") && (thechar != "4") && (thechar != "5") && (thechar != "6") && (thechar != "7") && (thechar != "8") && (thechar != "9") && (thechar != "A") && (thechar != "B") && (thechar != "C") && (thechar != "D") && (thechar != "E") && (thechar != "F")) { return false; } index = index + 1; } return true; } //Check muilt email address of imput box which emails are seperated by comma function multiEmailCheck(elm) { var email = elm.value.split(",") var isError = false; var i = -1; for (i = 0; i < email.length; i ++) { if(!emailCheck(trim(email[i]))){ isError = true; break; } } if(isError){ ChangeColor("red", elm); elm.focus(); return false; }else{ ChangeColor("black", elm); return true; } } function setImage(event) { var event = getEvent(event); var image = ''; if (event.type == 'mouseover' || event.type == 'focus') { image = '/common/image/' + event.srcElement.name + '_btn_down.gif'; } else if (event.type == 'mouseout' || event.type == 'blur') { image = '/common/image/' + event.srcElement.name + '_btn_up.gif'; } event.srcElement.src = image; } function clearForm(form) { for (var i = 0; i < form.elements.length; i++) { if (form.elements[i].type == "text") { form.elements[i].value = ""; } else if (form.elements[i].type == "password") { form.elements[i].value = ""; } } } function formatMessage(string, parameter) { var s = new String(string); for (var i = 0; i < parameter.length; i++) { var p = "\{" + i + "\}"; while(s.indexOf(p)>=0) { s = s.replace(p,parameter[i]); } } return s; } function round(number,X) { // rounds number to X decimal places, defaults to 2 X = (!X ? 2 : X); // return Math.round(number*Math.pow(10,X))/Math.pow(10,X); return number.toFixed(X); } function checkDecmialFormat(fieldValue,fieldName,totalNumber,decimalPlace,alloweNegative){ if(!isValidDecimalFormat(fieldValue,totalNumber,decimalPlace,alloweNegative)){ alert(getDecmialFormatErrorMessage(fieldName,totalNumber,decimalPlace,alloweNegative)); return false; }else{ return true; } } function getDecmialFormatErrorMessage(fieldName,totalNumber,decimalPlace,alloweNegative){ formatErrMsg=""; decimalFormat=""; if(alloweNegative){ decimalFormat="(+/-)"; }else{ decimalFormat="(+)"; } for(var i=0;i0 && (totalNumber-i)==decimalPlace) decimalFormat+="."; decimalFormat+="9"; } return formatMessage(formatErrMsg,[fieldName,decimalFormat]); } //------------------------------------------------------------------- // isValidDecimalFormat(fieldValue,totalNumber,decimalPlace) { // e.g. 9999.99 -> isValidDecimalFormat(fieldValue,6,2,false) // Returns true if value contains a correct format //------------------------------------------------------------------- function isValidDecimalFormat(fieldValue,totalNumber,decimalPlace,alloweNegative) { if(fieldValue.substring(0,1)=='-'){ if(alloweNegative){ fieldValue=fieldValue.substring(1); }else{ return false; } } if( fieldValue.length-1>totalNumber || !isDecimal(fieldValue) ){ return false; } if(decimalPlace>0){ if (fieldValue.indexOf('.') >= 0) { if ((fieldValue.substring(fieldValue.indexOf(".")+1,fieldValue.length)).length > decimalPlace){ return false; } if ((fieldValue.substring(0,fieldValue.indexOf("."))).length > totalNumber-decimalPlace){ return false; } } if (fieldValue.indexOf('.') == -1) { if (fieldValue.length > totalNumber-decimalPlace){ return false; } } }else{ if (fieldValue.indexOf('.') >= 0) { return false; } } return true; } function isDecimal(val) { var digits="1234567890."; for (var i=0; i < val.length; i++) { if (digits.indexOf(val.charAt(i))==-1) { return false; } } return true; } function checkPhoneNumber(textbox, fieldName){ var pattern = "[^0-9\(\)-]"; var result = textbox.value.match(pattern); if(result == null){ return true; } else { formatErrMsg=""; alert(formatMessage(formatErrMsg,[fieldName,"0-9,'(',')' and '-' only"])); textbox.focus(); return false; } } function limitText(limitField, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } } function capitalize(event) { var event = getEvent(event); var key = event.keyCode; if ((key > 96) && (key < 123)) { event.keyCode = key-32; } } function upperCase(field) { field.value=field.value.toUpperCase(); }