/**
 * Copyright (c) 2009 Chris Leonello
 * jqPlot is currently available for use in all personal or commercial projects 
 * under both the MIT and GPL version 2.0 licenses. This means that you can 
 * choose the license that best suits your project and use it accordingly. 
 *
 * Although not required, the author would appreciate an email letting him 
 * know of any substantial use of jqPlot.  You can reach the author at: 
 * chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
 *
 * If you are feeling kind and generous, consider supporting the project by
 * making a donation at: http://www.jqplot.com/donate.php .
 */
(function(d){d.jqplot.DateAxisRenderer=function(){d.jqplot.LinearAxisRenderer.call(this)};d.jqplot.DateAxisRenderer.prototype=new d.jqplot.LinearAxisRenderer();d.jqplot.DateAxisRenderer.prototype.constructor=d.jqplot.DateAxisRenderer;d.jqplot.DateTickFormatter=function(j,k){if(!j){j="%Y/%m/%d"}return Date.create(k).strftime(j)};d.jqplot.DateAxisRenderer.prototype.init=function(n){this.tickOptions.formatter=d.jqplot.DateTickFormatter;this.daTickInterval=null;this._daTickInterval=null;d.extend(true,this,n);var l=this._dataBounds;for(var o=0;o<this._series.length;o++){var p=this._series[o];var r=p.data;var k=p._plotData;var q=p._stackData;for(var m=0;m<r.length;m++){if(this.name=="xaxis"||this.name=="x2axis"){r[m][0]=Date.create(r[m][0]).getTime();k[m][0]=Date.create(r[m][0]).getTime();q[m][0]=Date.create(r[m][0]).getTime();if(r[m][0]<l.min||l.min==null){l.min=r[m][0]}if(r[m][0]>l.max||l.max==null){l.max=r[m][0]}}else{r[m][1]=Date.create(r[m][1]).getTime();k[m][1]=Date.create(r[m][1]).getTime();q[m][1]=Date.create(r[m][1]).getTime();if(r[m][1]<l.min||l.min==null){l.min=r[m][1]}if(r[m][1]>l.max||l.max==null){l.max=r[m][1]}}}}};d.jqplot.DateAxisRenderer.prototype.reset=function(){this.min=this._min;this.max=this._max;this.tickInterval=this._tickInterval;this.numberTicks=this._numberTicks;this.daTickInterval=this._daTickInterval};d.jqplot.DateAxisRenderer.prototype.createTicks=function(){var C=this._ticks;var z=this.ticks;var D=this.name;var B=this._dataBounds;var w,A;var u,x;var l,k;var j,y;if(z.length){for(y=0;y<z.length;y++){var n=z[y];var p=new this.tickRenderer(this.tickOptions);if(n.constructor==Array){p.value=Date.create(n[0]).getTime();p.label=n[1];if(!this.showTicks){p.showLabel=false;p.showMark=false}else{if(!this.showTickMarks){p.showMark=false}}p.setTick(p.value,this.name);this._ticks.push(p)}else{p.value=Date.create(n).getTime();if(!this.showTicks){p.showLabel=false;p.showMark=false}else{if(!this.showTickMarks){p.showMark=false}}p.setTick(p.value,this.name);this._ticks.push(p)}}this.numberTicks=z.length;this.min=this._ticks[0].value;this.max=this._ticks[this.numberTicks-1].value;this.daTickInterval=[(this.max-this.min)/(this.numberTicks-1)/1000,"seconds"]}else{if(D=="xaxis"||D=="x2axis"){w=this._plotDimensions.width}else{w=this._plotDimensions.height}if(this.min!=null&&this.max!=null&&this.numberTicks!=null){this.tickInterval=null}if(this.tickInterval!=null){if(Number(this.tickInterval)){this.daTickInterval=[Number(this.tickInterval),"seconds"]}else{if(typeof this.tickInterval=="string"){var r=this.tickInterval.split(" ");if(r.length==1){this.daTickInterval=[1,r[0]]}else{if(r.length==2){this.daTickInterval=[r[0],r[1]]}}}}}u=((this.min!=null)?Date.create(this.min).getTime():B.min);x=((this.max!=null)?Date.create(this.max).getTime():B.max);if(u==x){var o=24*60*60*500;u-=o;x+=o}var q=x-u;var s,v;s=(this.min!=null)?Date.create(this.min).getTime():u-q/2*(this.padMin-1);v=(this.max!=null)?Date.create(this.max).getTime():x+q/2*(this.padMax-1);this.min=s;this.max=v;q=this.max-this.min;if(this.numberTicks==null){if(this.daTickInterval!=null){var m=Date.create(this.max).diff(this.min,this.daTickInterval[1],true);this.numberTicks=Math.ceil(m/this.daTickInterval[0])+1;this.max=Date.create(this.min).add((this.numberTicks-1)*this.daTickInterval[0],this.daTickInterval[1]).getTime()}else{if(w>200){this.numberTicks=parseInt(3+(w-200)/100,10)}else{this.numberTicks=2}}}if(this.daTickInterval==null){this.daTickInterval=[q/(this.numberTicks-1)/1000,"seconds"]}for(var y=0;y<this.numberTicks;y++){var u=Date.create(this.min);j=u.add(y*this.daTickInterval[0],this.daTickInterval[1]).getTime();var p=new this.tickRenderer(this.tickOptions);if(!this.showTicks){p.showLabel=false;p.showMark=false}else{if(!this.showTickMarks){p.showMark=false}}p.setTick(j,this.name);this._ticks.push(p)}}if(this._daTickInterval==null){this._daTickInterval=this.daTickInterval}};var g=24*60*60*1000;var e=function(j,k){j=String(j);while(j.length<k){j="0"+j}return j};var c={millisecond:1,second:1000,minute:60*1000,hour:60*60*1000,day:g,week:7*g,month:{add:function(l,j){c.year.add(l,Math[j>0?"floor":"ceil"](j/12));var k=l.getMonth()+(j%12);if(k==12){k=0;l.setYear(l.getFullYear()+1)}else{if(k==-1){k=11;l.setYear(l.getFullYear()-1)}}l.setMonth(k)},diff:function(n,l){var j=n.getFullYear()-l.getFullYear();var k=n.getMonth()-l.getMonth()+(j*12);var m=n.getDate()-l.getDate();return k+(m/30)}},year:{add:function(k,j){k.setYear(k.getFullYear()+Math[j>0?"floor":"ceil"](j))},diff:function(k,j){return c.month.diff(k,j)/12}}};for(var i in c){if(i.substring(i.length-1)!="s"){c[i+"s"]=c[i]}}var h=function(m,l){if(Date.prototype.strftime.formatShortcuts[l]){return m.strftime(Date.prototype.strftime.formatShortcuts[l])}else{var j=(Date.prototype.strftime.formatCodes[l]||"").split(".");var k=m["get"+j[0]]?m["get"+j[0]]():"";if(j[1]){k=e(k,j[1])}return k}};var f={succ:function(j){return this.clone().add(1,j)},add:function(l,k){var j=c[k]||c.day;if(typeof j=="number"){this.setTime(this.getTime()+(j*l))}else{j.add(this,l)}return this},diff:function(k,n,j){k=Date.create(k);if(k===null){return null}var l=c[n]||c.day;if(typeof l=="number"){var m=(this.getTime()-k.getTime())/l}else{var m=l.diff(this,k)}return(j?m:Math[m>0?"floor":"ceil"](m))},strftime:function(k){var m=k||"%Y-%m-%d",j="",l;while(m.length>0){if(l=m.match(Date.prototype.strftime.formatCodes.matcher)){j+=m.slice(0,l.index);j+=(l[1]||"")+h(this,l[2]);m=m.slice(l.index+l[0].length)}else{j+=m;m=""}}return j},getShortYear:function(){return this.getYear()%100},getMonthNumber:function(){return this.getMonth()+1},getMonthName:function(){return Date.MONTHNAMES[this.getMonth()]},getAbbrMonthName:function(){return Date.ABBR_MONTHNAMES[this.getMonth()]},getDayName:function(){return Date.DAYNAMES[this.getDay()]},getAbbrDayName:function(){return Date.ABBR_DAYNAMES[this.getDay()]},getDayOrdinal:function(){return Date.ORDINALNAMES[this.getDate()%10]},getHours12:function(){var j=this.getHours();return j>12?j-12:(j==0?12:j)},getAmPm:function(){return this.getHours()>=12?"PM":"AM"},getUnix:function(){return Math.round(this.getTime()/1000,0)},getGmtOffset:function(){var j=this.getTimezoneOffset()/60;var k=j<0?"+":"-";j=Math.abs(j);return k+e(Math.floor(j),2)+":"+e((j%1)*60,2)},getTimezoneName:function(){var j=/(?:\((.+)\)$| ([A-Z]{3}) )/.exec(this.toString());return j[1]||j[2]||"GMT"+this.getGmtOffset()},toYmdInt:function(){return(this.getFullYear()*10000)+(this.getMonthNumber()*100)+this.getDate()},clone:function(){return new Date(this.getTime())}};for(var a in f){Date.prototype[a]=f[a]}var b={create:function(j){if(j instanceof Date){return j}if(typeof j=="number"){return new Date(j)}var o=String(j).replace(/^\s*(.+)\s*$/,"$1"),k=0,l=Date.create.patterns.length,m;var n=o;while(k<l){ms=Date.parse(n);if(!isNaN(ms)){return new Date(ms)}m=Date.create.patterns[k];if(typeof m=="function"){obj=m(n);if(obj instanceof Date){return obj}}else{n=o.replace(m[0],m[1])}k++}return NaN},MONTHNAMES:"January February March April May June July August September October November December".split(" "),ABBR_MONTHNAMES:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),DAYNAMES:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),ABBR_DAYNAMES:"Sun Mon Tue Wed Thu Fri Sat".split(" "),ORDINALNAMES:"th st nd rd th th th th th th".split(" "),ISO:"%Y-%m-%dT%H:%M:%S.%N%G",SQL:"%Y-%m-%d %H:%M:%S",daysInMonth:function(j,k){if(k==2){return new Date(j,1,29).getDate()==29?29:28}return[undefined,31,undefined,31,30,31,30,31,31,30,31,30,31][k]}};for(var a in b){Date[a]=b[a]}Date.prototype.strftime.formatCodes={matcher:/()%(#?(%|[a-z]))/i,Y:"FullYear",y:"ShortYear.2",m:"MonthNumber.2","#m":"MonthNumber",B:"MonthName",b:"AbbrMonthName",d:"Date.2","#d":"Date",e:"Date",A:"DayName",a:"AbbrDayName",w:"Day",o:"DayOrdinal",H:"Hours.2","#H":"Hours",I:"Hours12.2","#I":"Hours12",p:"AmPm",M:"Minutes.2","#M":"Minutes",S:"Seconds.2","#S":"Seconds",s:"Unix",N:"Milliseconds.3","#N":"Milliseconds",O:"TimezoneOffset",Z:"TimezoneName",G:"GmtOffset"};Date.prototype.strftime.formatShortcuts={F:"%Y-%m-%d",T:"%H:%M:%S",X:"%H:%M:%S",x:"%m/%d/%y",D:"%m/%d/%y","#c":"%a %b %e %H:%M:%S %Y",v:"%e-%b-%Y",R:"%H:%M",r:"%I:%M:%S %p",t:"\t",n:"\n","%":"%"};Date.create.patterns=[[/-/g,"/"],[/st|nd|rd|th/g,""],[/(3[01]|[0-2]\d)\s*\.\s*(1[0-2]|0\d)\s*\.\s*([1-9]\d{3})/,"$2/$1/$3"],[/([1-9]\d{3})\s*-\s*(1[0-2]|0\d)\s*-\s*(3[01]|[0-2]\d)/,"$2/$3/$1"],function(m){var k=m.match(/^(?:(.+)\s+)?([012]?\d)(?:\s*\:\s*(\d\d))?(?:\s*\:\s*(\d\d(\.\d*)?))?\s*(am|pm)?\s*$/i);if(k){if(k[1]){var l=Date.create(k[1]);if(isNaN(l)){return}}else{var l=new Date();l.setMilliseconds(0)}var j=parseFloat(k[2]);if(k[6]){j=k[6].toLowerCase()=="am"?(j==12?0:j):(j==12?12:j+12)}l.setHours(j,parseInt(k[3]||0,10),parseInt(k[4]||0,10),((parseFloat(k[5]||0))||0)*1000);return l}else{return m}},function(m){var k=m.match(/^(?:(.+))[T|\s+]([012]\d)(?:\:(\d\d))(?:\:(\d\d))(?:\.\d+)([\+\-]\d\d\:\d\d)$/i);if(k){if(k[1]){var l=Date.create(k[1]);if(isNaN(l)){return}}else{var l=new Date();l.setMilliseconds(0)}var j=parseFloat(k[2]);l.setHours(j,parseInt(k[3],10),parseInt(k[4],10),parseFloat(k[5])*1000);return l}else{return m}},function(n){var l=n.match(/^([0-3]?\d)\s*[-\/.\s]{1}\s*([a-zA-Z]{3,9})\s*[-\/.\s]{1}\s*([0-3]?\d)$/);if(l){var m=new Date();var o=parseFloat(String(m.getFullYear()).slice(2,4));var p=parseInt(String(m.getFullYear())/100,10)*100;var r=1;var s=parseFloat(l[1]);var q=parseFloat(l[3]);var k,j,t;if(s>31){j=l[3];if(s<o+r){k=p+s}else{k=p-100+s}}else{j=l[1];if(q<o+r){k=p+q}else{k=p-100+q}}var t=d.inArray(l[2],Date.ABBR_MONTHNAMES);if(t==-1){t=d.inArray(l[2],Date.MONTHNAMES)}m.setFullYear(k,t,j);m.setHours(0,0,0,0);return m}else{return n}}];if(d.jqplot.config.debug){d.date=Date.create}})(jQuery);
