if (typeof locale != 'object') { locale = {}; } validator._messages = { '_default':'Invalid value.' ,'min_length':'Message is too short.' ,'max_length':'Message is too long.' ,'min_value':'Value is too small.' ,'max_value':'Value is too large' ,'required':'This field is required.' ,'thesame':'Fields are not the same.' ,'float':'Put a number here.' ,'date':'Invalid date.' ,'date_new':'Invalid date.' ,'sum':'Sum of values is invalid.' ,'sum_max':'Sum of values is exceeded.' ,'email':'This e-mail address is invalid.' }; if (typeof locale != 'object') { locale = {}; }; if (typeof locale.date != 'object') { locale.date = {}; }; locale.date.format = 'y-MM-dd'; locale.date.ms_per_minute = 60 * 1000; locale.date.ms_per_hour = 60 * locale.date.ms_per_minute; locale.date.ms_per_day = 24 * locale.date.ms_per_hour; locale.date.sec_per_beat = 24*60*60/1000; locale.date.placeholder_tag = '*%'; locale.date.regexpSeparators = '[\\-_,:\\.\\/\\\\]'; locale.date.weekname = 'T'; locale.date.monthname = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; locale.date.dayname = { 0:'Sunday', 1:'Monday', 2:'Tuesday', 3:'Wednesday', 4:'Thursday', 5:'Friday', 6:'Saturday'}; locale.date.dayname_short = { 0:'Sun.', 1:'Mon.', 2:'Tue.', 3:'Wed.', 4:'Thu.', 5:'Fri.', 6:'Sat.'}; // Convert date from a human readable string to a Date object // params: string - string holding date // format - date format // retuns: Date() object locale.date.fromString = function(string,format) { try { if (!format) { format = this.format; }; var rx = new RegExp(this.regexpSeparators,'g'); string = string.replace(rx,' ').replace(/\ {2,}/g,' ').split(' '); format = format.replace(rx,' ').replace(/\ {2,}/g,' ').split(' '); var date = { year:0,month:0,day:1,hours:0,minutes:0,seconds:0,milliseconds:0,pm:0 }; for (var i in format) { switch(format[i]) { case 'y': case 'yy': case 'Y': case 'YY': date.year = string[i]; break; case 'MM': case 'M': date.month = parseInt(string[i],10)-1; break; case 'MMMM': date.month = this.monthname.indexOf(String(string[i])); break; case 'MMM': date.month = this.monthname.indexOf(String(string[i]).substr(0,3)); break; case 'dd': case 'd': date.day = string[i]; break; case 'HH': case 'H': case 'hh': case 'h': date.hours = string[i]; break; case 'a': date.pm = (string[i] == 'AM') ? 0 : 1; break; case 'mm': case 'm': date.minutes = string[i]; break; case 'ss': case 's': date.seconds = string[i]; break; case 'S': date.milliseconds = string[i]; break; }; }; if (date.pm == 1) { date.hours = parseInt(date.hours,10) + 12; }; // alert(string+'\n'+'y:'+date.year+' m:'+date.month+' d:'+date.day+' h:'+date.hours+' m:'+date.minutes+' s:'+date.seconds+' ms:'+date.milliseconds); date = new Date(date.year,date.month,date.day,date.hours,date.minutes,date.seconds,date.milliseconds); return date; } catch(e) { return date; }; }; // fromString() // add padding to a string // params: s - string // size - desired length // char - character/string to padd with // returns: padded string locale.date.fillChar = function(s,size,char) { if (char != undefined) { while (String(s).length < size) { s = char+s; }; }; return s; }; // fillChar() // get counting suffixes // language specific function // params: dayno - day number (0-6) // returns: string with suffix locale.date.getCountSuffix = function(dayno) { switch(dayno % 10) { case 1 : return 'st'; case 2 : return 'nd'; case 3 : return 'rd'; default: return 'th'; }}; // Convert date to a human readable string // params: date - Date object holding date to use // format - date format // retuns: formatted string locale.date.toString = function(date,format) { try { if (typeof format == 'undefined') { format = this.format; }; var rep = {}; // replacements table var pc = {}; //precalculated values pc.year = date.getFullYear(); pc.month = date.getMonth()+1; pc.day = date.getDate(); pc.dow = date.getDay(); pc.hours = date.getHours(); pc.minutes = date.getMinutes(); pc.seconds = date.getSeconds(); pc.milliseconds = date.getMilliseconds(); pc.hours2 = this.fillChar(pc.hours,2,'0'); pc.minutes2 = this.fillChar(pc.minutes,2,'0'); pc.seconds2 = this.fillChar(pc.seconds,2,'0'); pc.day2 = this.fillChar(pc.day,2,'0'); pc.month2 = this.fillChar(pc.month,2,'0'); pc.year2 = this.fillChar(String(pc.year).substr(-2),2,'0'); pc.year4 = this.fillChar(pc.year,4,'0'); pc.hoursPM = (pc.hours % 12 == 0) ? 12 : (pc.hours % 12); pc.month_end = new Date(date.getFullYear(),date.getMonth()+1,0); pc.now = new Date(); pc.year_begin = new Date(0,0,1); pc.year_begin.setFullYear(pc.now.getFullYear()); pc.day_begin = new Date(date); pc.day_begin.setHours(0); pc.day_begin.setMinutes(0); pc.day_begin.setSeconds(0); pc.is_leap_year = (pc.year % 400 == 0) || ( (pc.year % 100 != 0) && (pc.year % 4 == 0) ) ? 1 : 0; pc.is_am_pm = (pc.hours < 12) ? 'AM' : 'PM'; pc.timezone_diff = this.fillChar(-1*parseInt(date.getTimezoneOffset()/60,10),2,'0')+':'+this.fillChar(parseInt(date.getTimezoneOffset() % 60,10),2,'0'); if (date.getTimezoneOffset() < 0) { pc.timezone_diff = '+'+pc.timezone_diff; } pc.timezone_diff2 = pc.timezone_diff.replace(':',''); pc.timezone = 'UTC '+pc.timezone_diff; pc.timezone_name = pc.timezone; pc.monthname = this.monthname[pc.month-1]; pc.monthname3 = String(pc.monthname).substr(0,3); pc.monthname2 = String(pc.monthname).substr(0,2); pc.monthname1 = String(pc.monthname).substr(0,1); pc.dayname = this.dayname[pc.dow]; pc.dayname_short = this.dayname_short[pc.dow]; pc.dayname3 = String(pc.dayname).substr(0,3); pc.dayname2 = pc.dayname_short; pc.dayname1 = String(pc.dayname).substr(0,1); pc.week_number = Math.ceil((date.getTime() - pc.year_begin.getTime()) / this.ms_per_day / 7); pc.dst = '?'; rep['ddd'] = pc.month_end.getDate(); rep['dd'] = pc.day2; rep['d'] = pc.day; rep['SS'] = this.getCountSuffix(date.getDate()); rep['D'] = Math.floor((date.getTime() - pc.year_begin.getTime()) / this.ms_per_day); rep['ww'] = pc.week_number; rep['EEEE'] = pc.dayname; rep['EEE'] = pc.dayname3; rep['EE'] = pc.dayname3; rep['E'] = pc.dayname1; rep['eee'] = pc.dow; rep['e'] = pc.dow; rep['MMMMM'] = String(pc.monthname1); rep['MMMM'] = String(pc.monthname); rep['MM'] = pc.month2; rep['M'] = pc.month; rep['MMM'] = String(pc.monthname3); rep['yy'] = (pc.year % 100); rep['y'] = pc.year; rep['YY'] = (pc.year % 100); rep['Y'] = pc.year; rep['l'] = pc.is_leap_year; rep['a'] = pc.is_am_pm; rep['B'] = Math.ceil((date.getSeconds()+(date.getMinutes()*60)+((date.getHours()+1)*60*60)) / this.sec_per_beat); rep['HH'] = pc.hours2; rep['H'] = pc.hours; rep['hh'] = this.fillChar(pc.hoursPM,2,'0'); rep['h'] = pc.hoursPM; rep['mm'] = pc.minutes2; rep['m'] = pc.minutes; rep['ss'] = pc.seconds2; rep['s'] = pc.seconds; rep['S'] = pc.milliseconds; rep['I'] = pc.dst; rep['ZZZZ'] = pc.timezone_diff; rep['Z'] = pc.timezone_diff2 rep['zzzz'] = pc.timezone_name; rep['z'] = pc.timezone; rep['X'] = -1*date.getTimezoneOffset()*60; rep['c'] = pc.year+'-'+pc.month2+'-'+pc.day2+'T'+ pc.hours2+':'+ pc.minutes2+':'+pc.seconds2+pc.timezone_diff; rep['r'] = pc.dayname3+', '+pc.day2+' '+pc.monthname3+' '+pc.year+' '+pc.hours2+':'+pc.minutes2+':'+pc.seconds2+' '+pc.timezone_diff2; rep['U'] = parseInt(date.getTime()/1000,10); rep['GGGGG'] = ''; rep['GGGG'] = ''; rep['G'] = ''; rep['FFFFF'] = pc.dayname+', '+pc.monthname+' '+pc.day+', '+pc.year; rep['FFFF'] = pc.monthname+' '+pc.day+', '+pc.year; rep['FFF'] = pc.monthname3+' '+pc.day+', '+pc.year; rep['FF'] = pc.month+'/'+pc.day+'/'+pc.year2; rep['F'] = pc.monthname3+' '+pc.day+', '+pc.year4; rep['TTTTT'] = pc.hoursPM+':'+pc.minutes2+':'+pc.seconds2+' '+pc.is_am_pm+' '+rep['zzzz']; rep['TTTT'] = pc.hoursPM+':'+pc.minutes2+':'+pc.seconds2+' '+pc.is_am_pm+' '+pc.timezone; rep['TTT'] = pc.hoursPM+':'+pc.minutes2+':'+pc.seconds2+' '+pc.is_am_pm; rep['TT'] = pc.hoursPM+':'+pc.minutes2+' '+pc.is_am_pm; rep['KKKKK'] = pc.dayname+', '+pc.monthname+' '+pc.day+', '+pc.year4+' '+pc.hoursPM+':'+pc.minutes2+':'+pc.seconds2+' '+pc.is_am_pm + ' '+pc.timezone_name; rep['KKKK'] = pc.monthname+' '+pc.day+', '+pc.year4+' '+pc.hoursPM+':'+pc.minutes2+':'+pc.seconds2+' '+pc.is_am_pm + ' '+pc.timezone; rep['KKK'] = pc.monthname3+' '+pc.day+', '+pc.year4+' '+rep['TTT']; rep['KK'] = rep['FF']+' '+rep['TT']; rep['K'] = pc.monthname3+' '+pc.day+', '+pc.year4+' '+pc.hoursPM+':'+pc.minutes2+':'+pc.seconds2+' '+pc.is_am_pm; rep['OOO'] = String(rep['c']).replace(' ',''); rep['CCC'] = pc.dayname+', '+pc.day2+'-'+pc.monthname3+'-'+pc.year2+' '+pc.hours2+':'+pc.minutes2+':'+pc.seconds2+' '+pc.timezone_name; rep['RRRRR'] = rep['OOO']; rep['RRRR'] = pc.dayname3+', '+pc.day2+' '+pc.monthname3+' '+pc.year+' '+pc.hours2+':'+pc.minutes2+':'+pc.seconds2+' '+pc.timezone_diff2; rep['RRR'] = pc.dayname3+', '+pc.day2+' '+pc.monthname3+' '+pc.year2+' '+pc.hours2+':'+pc.minutes2+':'+pc.seconds2+' '+pc.timezone_diff2; rep['RR'] = pc.dayname+', '+pc.day2+'-'+pc.monthname3+'-'+pc.year2+' '+pc.hours2+':'+pc.minutes2+':'+pc.seconds2+' '+pc.timezone_name; rep['R'] = pc.dayname3+', '+pc.day2+' '+pc.monthname3+' '+pc.year2+' '+pc.hours2+':'+pc.minutes2+':'+pc.seconds2+' '+pc.timezone_diff2; rep['SSS'] = pc.dayname3+', '+pc.day2+' '+pc.monthname3+' '+pc.year+' '+pc.hours2+':'+pc.minutes2+':'+pc.seconds2+' '+pc.timezone_diff2; rep['WWW'] = pc.year+'-'+pc.month2+'-'+pc.day2+'T'+pc.hours2+':'+pc.minutes2+':'+pc.seconds2+pc.timezone_diff; rep['WW'] = pc.hoursPM+':'+pc.minutes2+':'+pc.seconds2+' '+pc.is_am_pm; var ph = {};phc = 0; // placeholders for (var r in rep) { format = format.replace(r,this.placeholder_tag+phc+this.placeholder_tag); ph[phc] = rep[r]; phc++; } for (var phc in ph) { format = format.replace(this.placeholder_tag+phc+this.placeholder_tag,ph[phc]); } return format; } catch(e) { return format; } } //toString() // Check if date is valid // params: datestr - string holding date // format - date format // returns: true/false if datestr is formatted accordingly to format and is valid date locale.date.isValid = function(datestr,format) { if (typeof format == 'undefined') { format = this.format; } var rx = new RegExp(this.regexpSeparators,'g'); var datestrArray = datestr.replace(rx,' ').replace(/\ {2,}/g,' ').split(' '); formatArray = format.replace(rx,' ').replace(/\ {2,}/g,' ').split(' '); if (datestrArray.length != formatArray.length) { return false; } var date = this.fromString(datestr,format); if (isNaN(date.getTime())) { return false; } return (date.getTime() == this.fromString(datestr,format).getTime()); } //isValid() // Compare two dates // params: date - base date // sdate - date to compare (substract) // format - date format // returns: - difference (in ms) - if two valid dates are given // - NaN otherwise locale.date.compare = function(date,sdate,format) { date = this.fromString(date,format); sdate = this.fromString(sdate,format); if (isNaN(date.getTime()) || isNaN(sdate.getTime())) { return NaN; }; return date.getTime() - sdate.getTime(); } //compare() if (typeof locale != 'object') { locale = {}; }; if (typeof locale.popup != 'object') { locale.popup = {}; }; if (typeof locale.popup.error != 'object') { locale.popup.error = {}; }; if (typeof locale.popup.error.internal != 'object') { locale.popup.error.internal = {}; }; locale.popup.error.internal.msg = 'Internal Error.'; locale.popup.error.internal.title = 'Error'; if (typeof locale.popup.warning != 'object') { locale.popup.warning = {}; }; if (typeof locale.popup.warning.not_found != 'object') { locale.popup.warning.not_found = {}; }; locale.popup.warning.not_found.msg = 'Requested object doesn\'t exist.'; locale.popup.warning.not_found.title = 'NO DATA'; if (typeof locale.popup.button != 'object') { locale.popup.button = {}; }; locale.popup.button.ok = 'Ok'; locale.popup.button.yes = 'Yes'; locale.popup.button.no = 'No'; locale.popup.button.cancel = 'Cancel'; locale.popup.button.close = 'Close'; if (typeof locale != 'object') { locale = {}; }; if (typeof locale.number != 'object') { locale.number = {}; }; if (typeof locale.number.separator != 'object') { locale.number.separator = {}; }; locale.number.separator.decimal = ',';