/*******************************************************************************\
Countdown Timer JavaScript Module
Version 2.3.5 (kept in step with fergcorp_countdownTimer.php)
Copyright (c) 2007-2009 Andrew Ferguson
---------------------------------------------------------------------------------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\*******************************************************************************/

function rtrim(stringToTrim) {
	return stringToTrim.replace(/..$/,"");
}

function fergcorp_countdownTimer_js ()
{
    var r = 0;
    for (var i=0; i < fergcorp_countdownTimer_js_events.length; i++) {
		
		var nowDate = new Date();
		var targetDate = new Date(fergcorp_countdownTimer_js_events[i]["targetDate"]*1000);
		//alert(document.getElementById(fergcorp_countdownTimer_js_events[i]["id"]).innerHTML);
		if((targetDate - nowDate) < 0){
			document.getElementById(fergcorp_countdownTimer_js_events[i]["id"]).innerHTML = sprintf(fergcorp_countdownTimer_js_language['ago'], fergcorp_countdownTimer_fuzzyDate(nowDate, targetDate, getOptions));			
		}
		else if((targetDate - nowDate) >= 0 ){
			document.getElementById(fergcorp_countdownTimer_js_events[i]["id"]).innerHTML = sprintf(fergcorp_countdownTimer_js_language['in'],fergcorp_countdownTimer_fuzzyDate(targetDate, nowDate, getOptions));
		}
	}
	
    window.setTimeout('fergcorp_countdownTimer_js()', 1000);
}

function fergcorp_countdownTimer_fuzzyDate(targetTime, nowTime, getOptions){
	var rollover = 0;
	var vars = '';
	var sigNumHit = false;
	var totalTime = 0;

	var nowDate = nowTime;
	var targetDate = targetTime;
	
	var s = '';
	
	var nowYear = nowDate.getFullYear();
	var nowMonth = nowDate.getMonth() + 1;
	var nowDay = nowDate.getDate();
	var nowHour = nowDate.getHours();
	var nowMinute = nowDate.getMinutes();
	var nowSecond = nowDate.getSeconds();
	
	var targetYear = targetDate.getFullYear();
	var targetMonth = targetDate.getMonth() + 1;
	var targetDay = targetDate.getDate();
	var targetHour = targetDate.getHours();
	var targetMinute = targetDate.getMinutes();
	var targetSecond = targetDate.getSeconds();
	
	var resultantYear = targetYear - nowYear;
	var resultantMonth = targetMonth - nowMonth;
	var resultantDay