﻿/*
* author: Ryan Grauer - ryanATmodusdev.net
*  company: Modus Development
*/

$.extend({
	datediff: function(start, end){
		
		if(!end) end = Date.parse("now").toString("MM/dd/yyyy HH:mm:ss");
		
		this.start = Date.parse(start);
		this.end = Date.parse(end);
		this.difference = this.end.getTime() - this.start.getTime();
		this.days = Math.floor( this.difference / 1000/60/60/24 );
		this.hours = Math.floor( (this.difference / 1000/60/60) - (used_day_in_hours = this.days*24) );
		this.minutes = Math.floor( (this.difference / 1000/60) - ( used_hours_in_minutes = (this.hours + used_day_in_hours)*60 ) );
		this.seconds = Math.floor( (this.difference / 1000) - ( used_minutes_in_seconds = (this.minutes + used_hours_in_minutes)*60 ) );
		this.milliseconds = this.difference - ( used_minutes_in_seconds*1000 ) - (this.seconds*1000);
		
		return this;
	}
});

Number.prototype.format = function(format){
	if( (format == "nn") && this < 10) return "0" + this.toString();
	else if( (format == "nnn") && this < 10) return "00" + this.toString();
	else if( (format == "nnn") && this < 100) return "0" + this.toString();
	return this.toString();
}