Date.prototype.days_en=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sun","Mon","Tue","Wed","Thu","Fri","Sat"];Date.prototype.months_en=["January","February","March","April","May","June","July","August","September","October","November","December","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];Date.prototype.days_it=["Domenica","Luned&iacute;","Marted&iacute;","Mercoled&iacute;","Gioved&iacute;","Venerd&iacute;","Sabato","Dom","Lun","Mar","Mer","Gio","Ven","Sab"];Date.prototype.months_it=["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre","Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic"];Date.prototype.oneMinute=60*1000;Date.prototype.oneHour=60*1000*60;Date.prototype.oneDay=60*1000*60*24;Date.prototype.pad0=function(b){return(b<0||b>9?"":"0")+b};Date.prototype.compare=function(b){if(b===0){return-1}else{if(this>b){return 1}}return 0};Date.prototype.addDays=function(b){this.setDate(this.getDate()+b);return this};Date.prototype.addMonths=function(b){this.setMonth(this.getMonth()+b);return this};Date.prototype.addYears=function(b){this.setFullYear(this.getFullYear()+b);return this};Date.prototype.isLeap=function(){var b=this.getFullYear();return((b%4===0&&b%100!==0)||b%400===0)};Date.prototype.daysBefore=function(){var c=new Date();var b=this.getTime()-c.getTime();return Math.floor(b/this.oneDay)};Date.prototype.daysBetween=function(b){var d=0;this.setHours(0);this.setMinutes(0);this.setSeconds(0);b.setHours(0);b.setMinutes(0);b.setSeconds(0);if(b>this){d=(b.getTimezoneOffset()-this.getTimezoneOffset())*this.oneMinute}else{d=(this.getTimezoneOffset()-b.getTimezoneOffset())*this.oneMinute}var c=Math.abs(b.getTime()-this.getTime())-d;return Math.ceil(c/this.oneDay)};Date.prototype.toFormat=function(n,f){var i;var F;if(f===undefined){i=this.days_en;F=this.months_en}else{if(f===""||f==="en"){i=this.days_en;F=this.months_en}else{if(f==="it"){i=this.days_it;F=this.months_it}}}n=n+"";var G="";var t=0;var e="";var L="";var O=this.getYear()+"";var A=this.getMonth()+1;var g=this.getDate();var l=this.getDay();var p=this.getHours();var z=this.getMinutes();var I=this.getSeconds();var Q,P,D,C,j,q,o,B,J,b,r,x,v,w,u;if(O.length<4){O=""+(O-0+1900)}if(p===0){p=12}else{if(p>12){p=p-12}}q=this.pad0(o);if(p>11){v=p-12}else{v=p}u=p+1;x=this.pad0(v);w=this.pad0(u);if(p>11){a="PM"}else{a="AM"}B=this.pad0(z);I=I;J=this.pad0(I);var N={y:""+O,yy:O.substring(2,4),yyyy:O,M:A,MM:this.pad0(A),MMM:F[A-1],NNN:F[A+11],d:g,dd:this.pad0(g),E:i[l+7],EE:i[l],H:p,HH:this.pad0(p),K:v,hh:q,k:u,KK:x,kk:w,a:a,m:z,mm:B,s:I,ss:J};while(t<n.length){e=n.charAt(t);L="";while((n.charAt(t)==e)&&(t<n.length)){L+=n.charAt(t++)}if(N[L]!==null&&N[L]!==undefined){G=G+N[L]}else{G=G+L}}return G};Date.prototype.isInteger=function(d){var b="1234567890";for(var c=0;c<d.length;c++){if(b.indexOf(d.charAt(c))==-1){return false}}return true};Date.prototype.getInt=function(e,b,d,c){for(var g=c;g>=d;g--){var f=e.substring(b,b+g);if(f.length<d){return null}if(this.isInteger(f)){return f}}return null};String.prototype.toDate=function(h,e){if(e===undefined){day_names=this.days_en;month_names=this.months_en}else{if(e===""||e==="en"){day_names=this.days_en;month_names=this.months_en}else{if(e==="it"){day_names=this.days_it;month_names=this.months_it}}}h=h+"";var n=0;var m=0;var d="";var u="";var v="";var w,z;var s=new Date();var A=s.getYear();var q=s.getMonth()+1;var f=1;var k=s.getHours();var p=s.getMinutes();var t=s.getSeconds();var b="";while(m<h.length){d=h.charAt(m);u="";while((h.charAt(m)==d)&&(m<h.length)){u+=h.charAt(m++)}if(u=="yyyy"||u=="yy"||u=="y"){if(u=="yyyy"){w=4;z=4}if(u=="yy"){w=2;z=2}if(u=="y"){w=2;z=4}A=s.getInt(this,n,w,z);if(A===null){return 0}n+=A.length;if(A.length==2){if(A>70){A=1900+(A-0)}else{A=2000+(A-0)}}}else{if(u=="MMM"||u=="NNN"){q=0;for(var l=0;l<month_names.length;l++){var r=month_names[l];if(this.substring(n,n+r.length).toLowerCase()==r.toLowerCase()){if(u=="MMM"||(u=="NNN"&&l>11)){q=l+1;if(q>12){q-=12}n+=r.length;break}}}if((q<1)||(q>12)){return 0}}else{if(u=="EE"||u=="E"){for(var o=0;o<day_names.length;o++){var g=day_names[o];if(this.substring(n,n+g.length).toLowerCase()==g.toLowerCase()){n+=g.length;break}}}else{if(u=="MM"||u=="M"){q=s.getInt(this,n,u.length,2);if(q===null||(q<1)||(q>12)){return 0}n+=q.length}else{if(u=="dd"||u=="d"){f=s.getInt(this,n,u.length,2);if(f===null||(f<1)||(f>31)){return 0}n+=f.length}else{if(u=="hh"||u=="h"){k=s.getInt(this,n,u.length,2);if(k===null||(k<1)||(k>12)){return 0}n+=k.length}else{if(u=="HH"||u=="H"){k=s.getInt(this,n,u.length,2);if(k===null||(k<0)||(k>23)){return 0}n+=k.length}else{if(u=="KK"||u=="K"){k=s.getInt(this,n,u.length,2);if(k===null||(k<0)||(k>11)){return 0}n+=k.length}else{if(u=="kk"||u=="k"){k=s.getInt(this,n,u.length,2);if(k===null||(k<1)||(k>24)){return 0}n+=k.length;k--}else{if(u=="mm"||u=="m"){p=s.getInt(this,n,u.length,2);if(p===null||(p<0)||(p>59)){return 0}n+=p.length}else{if(u=="ss"||u=="s"){t=s.getInt(this,n,u.length,2);if(t===null||(t<0)||(t>59)){return 0}n+=t.length}else{if(u=="a"){if(this.substring(n,n+2).toLowerCase()=="am"){b="AM"}else{if(this.substring(n,n+2).toLowerCase()=="pm"){b="PM"}else{return 0}}n+=2}else{if(this.substring(n,n+u.length)!=u){return 0}else{n+=u.length}}}}}}}}}}}}}}if(n!=this.length){return 0}if(q==2){if(((A%4===0)&&(A%100!==0))||(A%400===0)){if(f>29){return 0}}else{if(f>28){return 0}}}if((q==4)||(q==6)||(q==9)||(q==11)){if(f>30){return 0}}if(k<12&&b=="PM"){k=k-0+12}else{if(k>11&&b=="AM"){k-=12}}return new Date(A,q-1,f,k,p,t)};
