
/**
 * Parse date and time with the format:
 * dd/mm/yyyy hh:mm:ss
 * to JS format
 */
Date.prototype["parseDateTime"] = function(str, onlyDate) {
	var elements = str.split(" ");
	
	//Date
	elements[0] = elements[0].split("/");
	
	if (onlyDate)
		return Date.parse(elements[0][2] + "/" + elements[0][1] + "/" + elements[0][0]);
	
	return Date.parse(elements[0][2] + "/" + elements[0][1] + "/" + elements[0][0] + " " + elements[1]);
};

/**
 * Parses and sets the date/time in the date object
 * dd/mm/yyyy hh:mm:ss
 */
Date.prototype["setDateTime"] = function(str, onlyDate) {
	this.setTime(this.parseDateTime(str, onlyDate));
};

/**
 * Adds years, months, days, hours, minutes or seconds to a date object
 */
Date.prototype["addDateTime"] = function(what, value) {
	switch(what) {
		case "years":
			this.addYears(value);
			break;
		case "months":
			this.addMonths(value);
			break;
		case "days":
			this.addDays(value);
			break;
		case "hours":
			this.addHours(value);
			break;
		case "minutes":
			this.addMinutes(value);
			break;
		case "seconds":
		 this.addSeconds(value);
		 break;
	}
};

/**
 * Format and return the current date as string
 * dd/mm/yyyy hh:mm:ss
 */
Date.prototype["getDateTime"] = function(onlyDate) {
	var day = this.getDate();
	var month = this.getMonth() + 1;
	var hours = this.getHours();
	var minutes = this.getMinutes();
	var seconds = this.getSeconds();
	
	//padding
	if (day < 10) day = "0" + day;
	if (month < 10) month = "0" + month;
	if (hours < 10) hours = "0" + hours;
	if (minutes < 10) minutes = "0" + minutes;
	if (seconds < 10) seconds = "0" + seconds;
	
	if (onlyDate)
		return day + "/" + month + "/" + this.getFullYear();
		
	return day + "/" + month + "/" + this.getFullYear() + " " + hours + ":" + minutes + ":" + seconds;
};

/**
 * compare to another date objects
 * return:
 * 0 - date is equal
 * 1 - date is later
 * -1 - date is earlier
 */
Date.prototype["compareDate"] = function(date) {
	var ts1 = this.getTime();
	var ts2 = date.getTime();
	
	if (ts1 == ts2)
		return 0;
	
	if (ts1 < ts2)
		return 1
	
	if (ts1 > ts2)
		return -1
};