/*
 * This file is part of a larger software package. Please read the License file 
 * in the root of this installation for terms of usage and distribution.
 * 
 * @author The Web Pro Miami, Inc. <info@thewebpro.com>
 * @copyright The Web Pro Miami, Inc. <info@thewebpro.com>, http://www.thewebpro.com/
 * 
 * CORE: manage/assets/scripts/jquery.dataTables.datetime.js - version 1.0
*/

function getTimeValue(x) {
	x = x.replace("Today",nGetTodayDate());
	x = x.replace("Yesterday",nGetYesterdayDate());
	var time = x.match(/(\d+)(?::(\d\d))?\s*(P?)/);
	var h = parseInt(time[1]) + (time[3] ? 12 : 0);
	if(!time[3] && parseInt(time[1])==12) h = 0;
	if(time[3] && parseInt(time[1])==12) h = 12;
	return h * 60 + ( parseInt(time[2]) || 0 );
}
/* Define two custom functions (asc and desc) for string sorting */
$.fn.dataTableExt.oSort['datetime-asc']  = function(x,y) {
	var x = getTimeValue(x);
	var y = getTimeValue(y);
	return ((x < y) ? -1 : ((x > y) ?  1 : 0));
};

$.fn.dataTableExt.oSort['datetime-desc'] = function(x,y) {
	x = getTimeValue(x);
	y = getTimeValue(y);
	return ((x < y) ?  1 : ((x > y) ? -1 : 0));
};

function nGetTodayDate(){
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth()+1;
	var yyyy = today.getFullYear();
	if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} today = mm+'/'+dd+'/'+yyyy;
	return today;
}

function nGetYesterdayDate(){
	var yesterday = new Date();
	yesterday.setDate(yesterday.getDate() - 1);
	var dd = yesterday.getDate();
	var mm = yesterday.getMonth()+1;
	var yyyy = yesterday.getFullYear();
	if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} yesterday = mm+'/'+dd+'/'+yyyy;
	return yesterday;
}