/* Date.js ****************************************************************
 * Extends the native Date object.
 * @minify true
 * @author Joe Whetzel
 **************************************************************************** */

/* Returns the name of the day.
 */
Date.prototype.getDayString = function(){
  switch (this.getDay()) {
    case 0:
      return 'Sunday';
    case 1:
      return 'Monday';
    case 2:
      return 'Tuesday';
    case 3:
      return 'Wednesday';
    case 4:
      return 'Thursday';
    case 5:
      return 'Friday';
    case 6:
      return 'Saturday';
  }
};

/* Returns the name of the Month. By default the string is returned as a three
 * letter abbreviation. Providing the optional argument will return the full 
 * name of the month. The argument may be any value that equates to true.
 */
Date.prototype.getMonthString = function(full){
  switch (this.getMonth()) {
    case 0:
      return (full)?'January':'Jan';
    case 1:
      return (full)?'February':'Feb';
    case 2:
      return (full)?'March':'Mar';
    case 3:
      return (full)?'April':'Apr';
    case 4:
      return 'May';
    case 5:
      return (full)?'June':'Jun';
    case 6:
      return (full)?'July':'Jul';
    case 7:
      return (full)?'August':'Aug';
    case 8:
      return (full)?'September':'Sep';
    case 9:
      return (full)?'October':'Oct';
    case 10:
      return (full)?'November':'Nov';
    case 11:
      return (full)?'December':'Dec';
  }
};

/* Spanish equvalent to Date.getDayString, also available as Date.obtenerDia.
 */
Date.prototype.spanishDay = function(){
  switch (this.getDay()) {
    case 0:
      return 'domingo';
    case 1:
      return 'lunes';
    case 2:
      return 'martes';
    case 3:
      return 'mi&eacute;rcoles';
    case 4:
      return 'jueves';
    case 5:
      return 'viernes';
    case 6:
      return 's&aacute;bado';
  }
};
Date.prototype.obtenerDia = Date.prototype.spanishDay;

/* Spanish equvalent to Date.getMonthString, also available as Date.obtenerMes.
 */
Date.prototype.spanishMonth = function(full){
  switch (this.getMonth()) {
    case 0:
      return (full)?'enero':'ene';
    case 1:
      return (full)?'febrero':'feb';
    case 2:
      return (full)?'marzo':'mar';
    case 3:
      return (full)?'abril':'abr';
    case 4:
      return (full)?'mayo':'may';
    case 5:
      return (full)?'junio':'jun';
    case 6:
      return (full)?'julio':'jul';
    case 7:
      return (full)?'augusto':'aug';
    case 8:
      return (full)?'septiembre':'sep';
    case 9:
      return (full)?'octubre':'oct';
    case 10:
      return (full)?'noviembre':'nov';
    case 11:
      return (full)?'deciembre':'dec';
  }
};
Date.prototype.obtenerMes = Date.prototype.spanishMonth;

/* This method allows you to define the format of the date string returned.
 * The format string consists of zero or more conversion specifications and 
 * ordinary characters. All ordinary characters are copied directly into the 
 * returned string. A conversion specification consists of a percent sign "%" 
 * and one other character. The conversion specification is based on, but not a 
 * direct copy of, the conversion specification used by the unix date command.
 * %A full weekday name; i.e. "Monday"
 * %a abbreviated weekday name; i.e. "Mon"
 * %B full month name; i.e. "June"
 * %b abbreviated month name; i.e. "Jun"
 * %c time and date; i.e. "Mon Jun 18 09:46:17 2007"; same as "%aÊ%bÊ%dÊ%H:%M:%SÊ%Y"
 * %D month, day and year with leading zeros; i.e. "06/18/07"; same as "%m/%d/%y"
 * %d two digit day of the month, 01-31
 * %E day of the month, 1st-31st; i.e. "18th"
 * %e day of the month, 1-31
 * %F Year-Month-Day; i.e. "2007-06-18"; same as "%Y-%m/%d"
 * %H hour from 24-hour clock as two digit number, 00-23
 * %I hour from 12-hour clock as two digit number, 01-12
 * %k hour from 24-hour clock, 0-23
 * %l hour from 12-hour clock, 1-12
 * %M minutes as two digit number, 00-59
 * %m month as two digit number, 01-12
 * %O Spanish weekday name; i.e. "lunes"
 * %o abbreviated spanish weekday name; i.e. "lun"
 * %p "AM" or "PM"
 * %Q spanish month name; i.e. "junio"
 * %q abbreviated spanish month name; i.e. "jun"
 * %R hours and minutes separated by colon, uses leading zeros and 24 hour clock; i.e. "09:00" and "21:05"; same as "%H:%M"
 * %r hours:minutes:seconds AM/PM using 12-hour clock and leading zeros; i.e. "09:05:00 AM"; same as "%I:%M:%SÊ%p"
 * %S seconds with leading zeros, 00-59
 * %s seconds since epoch, unix time
 * %T hours:minutes:seconds using 24-hour clock; i.e. "13:04:07"; same as "%H:%M:%S"
 * %u day of the week as a number 1-7, Monday = 1
 * %v i.e. "18-Jun-2007"; same as "%d-%b-%Y"
 * %w day of the week as a number 0-6, Sunday = 0
 * %Y four digit year; i.e. "2007"
 * %y two digit year; i.e. "07"
 */
Date.prototype.toFormattedString = function (f) {
	var a,b;
	var d0 = (this.getDate() < 10) ? '0'+this.getDate() : this.getDate();
	var h0 = (this.getHours() < 10) ? '0'+this.getHours() : this.getHours();
	var m0 = (this.getMinutes() < 10) ? '0'+this.getMinutes() : this.getMinutes();
	var s0 = (this.getSeconds() < 10) ? '0'+this.getSeconds() : this.getSeconds();
	var mo0 = this.getMonth() +1;
	mo0 = (mo0 < 10) ? '0'+mo0 : mo0;
	f = f.replace(/%%/g,'%');
	f = f.replace(/%A/g,this.getDayString());
	f = f.replace(/%a/g,this.getDayString().substring(0,3));
	f = f.replace(/%B/g,this.getMonthString(true));
	f = f.replace(/%b/g,this.getMonthString());
	f = f.replace(/%c/g,this.getDayString().substring(0,3) + ' ' +
											this.getMonthString() + ' ' +
											d0 + ' ' + h0 + ':' + m0 + ':' + s0 + ' ' +
											this.getFullYear() );
	a = this.getFullYear()+'';
	a = a.substring(2);
	f = f.replace(/%D/g,mo0+'/'+d0+'/'+a);
	f = f.replace(/%d/g,d0);
	a = this.getDate();
	switch(a) {
		case 1 :
		case 21 :
		case 31 :
			a = a+'st';
			break;
		case 3 :
		case 23 :
			a = a+'rd';
			break;
		default :
			a = a+'th';
	}
	f = f.replace(/%E/g,a);
	f = f.replace(/%e/g,this.getDate());
	f = f.replace(/%F/g,this.getFullYear() +'-'+ mo0 +'-'+ d0);
	f = f.replace(/%H/g,h0);
	a = (this.getHours() > 12) ? this.getHours() -12 : this.getHours();
	f = f.replace(/%I/g,(a < 10) ? '0'+a : a);
	f = f.replace(/%k/g,this.getHours());
	f = f.replace(/%l/g,(this.getHours() > 12) ? this.getHours() -12 : this.getHours());
	f = f.replace(/%M/g,m0);
	f = f.replace(/%m/g,mo0);
	f = f.replace(/%O/g,this.spanishDay());
	f = f.replace(/%o/g,this.spanishDay().substring(0,3));
	f = f.replace(/%p/g,(this.getHours() > 11) ? 'PM' : 'AM');
	f = f.replace(/%Q/g,this.spanishMonth(true));
	f = f.replace(/%q/g,this.spanishMonth().substring(0,3));
	f = f.replace(/%R/g,h0+':'+m0);
	a = (this.getHours() > 12) ? this.getHours() -12 : this.getHours();
	a = (a < 10) ? '0'+a : a;
	b = (this.getHours() > 11) ? 'PM' : 'AM';
	f = f.replace(/%r/g,a +':'+ m0 +':'+ s0 +' '+ b);
	f = f.replace(/%S/g,s0);
	f = f.replace(/%s/g,Date.parse(this)/1000);
	f = f.replace(/%T/g,h0+':'+m0+':'+s0);
	f = f.replace(/%u/g,(this.getDay() === 0) ? 7 : this.getDay());
	f = f.replace(/%v/g,this.getDate()+'-'+this.getMonthString()+'-'+this.getFullYear());
	f = f.replace(/%w/g,this.getDay());
	f = f.replace(/%X/g,this.toLocaleTimeString());
	f = f.replace(/%Y/g,this.getFullYear());
	a = this.getFullYear()+'';
	f = f.replace(/%y/g,a.substring(2));
	return f;
};






/* Date.js ^ ---------------------------------------------------------------- */
