/**
  * Function print the remaining time or expired time, based on the compareData parameter
  *
  * @param compareDate
  *
  * @ return null
  */
function updateClock(compareDate){
		//incase date is '0' use user local time
		var delta = (compareDate.getYear() < new Date().getYear()) ?  new Date()- 1 + (checkTimeZone(true)*1000*60*60): new Date() - compareDate;
		
		//alert(delta .getHours() + ":"  + delta .getMinutes() + ":" + delta .getSeconds());
                                   
		if(delta<0){
			//document.getElementById("next").style.display = 'block';
			document.getElementById("clock").innerHTML = formatDate(delta) + " before start";
		}else{
			//document.getElementById("next").style.display = 'none';
			document.getElementById("clock").innerHTML = formatDate(delta);
		}
}//end updateClock function

/**
  * returns the time timezone and daylight saving of the browser
  *
  */
function checkTimeZone(withDts) {
   var rightNow = new Date();
   var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
   var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
   var temp = date1.toGMTString();
   var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
   var temp = date2.toGMTString();
   var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
   var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
   var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
   
   if(withDts){
		//check if dateTimeSaving is actvice
		if(dateTimeSaving()){
			return hoursDiffStdTime+1;	//during summertime!
		}
	}//end with dateTimeSaving
	return hoursDiffStdTime;
}

/**
  * Function that checks if there is a datetime saving at this moment
  *
  * @source: http://javascript.about.com/library/bltime4.htm
  * @date 28-10-2007
  *
  * @return, returns false if the daylightsaving is NOT active (during wintertime)
  */
function dateTimeSaving(){
	var gmt = new Date;
	var lsm = new Date;
	var lso = new Date;
	lsm.setMonth(2); // March
	lsm.setDate(31);
	var day = lsm.getDay();	// day of week of 31st
	lsm.setDate(31-day); 	// last Sunday
	lso.setMonth(9); 		// October
	lso.setDate(31);
	day = lso.getDay();
	lso.setDate(31-day);
	if (gmt < lsm || gmt >= lso){
		//daylight saving is NOT active
		return false;
	}
	return true;	//daylight saving is active (+1 hour, during summer time)
}//end function dateTimeSaving


/**
  * Formats date in miliseconds into a readable string
  *
  * @param date the needs to be formatted
  *
  * @return formatted date
  */
function formatDate(date){	
	var date = Math.abs(date);	//get time in miliseconds
	
	var days 	= 0;//Math.floor(date/1000/60/60/24%24);
	var hours 	= Math.floor(date/1000/60/60%24);
	var minutes = Math.floor(date/1000/60%60);
	var seconds = Math.floor(date/1000%60);	
	
	//add prefix zero's
	hours = hours < 10 ? "0" + hours : hours;
	minutes = minutes < 10 ? "0" + minutes : minutes;
	seconds = seconds < 10 ? "0" + seconds : seconds;
	
	return days > 0 ?  (days + " day(s) and " +hours + ":" + minutes + ":" + seconds) : (hours + ":" + minutes + ":" + seconds);
	
}//end formatDate function



