function setSidebar(){
	var p_description = "Sidebar";
	var p_title = "Sidebar";
	var p_url = "http://www.heute.de/ZDFheute/sidebar/0,3662,,00.html";

	if (document.all && !window.opera){ //IE5+
		void(_search=open(p_url ,'_search'));
	}
	else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')){ //Gecko
		window.sidebar.addPanel (p_title, p_url, '');
	}
	else { //anything else
		window.open (p_url,p_title,'width=157,height=600');
	}
}


function redirto(id) {
	if (isNaN(id)) {
		//if the id is not numeric - handle it as it where an url - needed eg. for the heute link
		document.location.href=id;
	} else {
		if (id!='1000000') document.location.href='http://www.zdf.de/ZDFde/inhalt/' + id % 32 + '/0,1872,' + id + ',00.html';
	}
}

function testIsValidObject(objToTest) {
	if (null == objToTest) {
		return false;
	}
	if ("undefined" == typeof(objToTest) ) {
		return false;
	}
	return true;
}

function changeZappelImageVisibility(whichSheet) {
	var zappelImage = document.getElementById("zappel-image");
	if (whichSheet == 'main') {
		if (testIsValidObject(zappelImage)) zappelImage.style.display = "none";
	} else {
		if (testIsValidObject(zappelImage)) zappelImage.style.display = "block";
	}
}

function changeWahlImageVisibility(whichSheet) {
	var wahlImage = document.getElementById("wahl-image");
	if (whichSheet == 'main') {
		if (testIsValidObject(wahlImage)) wahlImage.style.display = "none";
	} else {
		if (testIsValidObject(wahlImage)) wahlImage.style.display = "block";
	}
}


function getTimePadding(timeStr) {
	var timeStr2 = "" + timeStr;
	if (timeStr2.length == 1) {
		var ret = '0' + timeStr2;
		return ret;	
	} else {
		return timeStr2;
	}
}

function CEDateFormat2JSDateFormat(wholeDate) {
	var dateOnly = wholeDate.split(" ")[0];
	var timeOnly = wholeDate.split(" ")[1];
	
	var js_year = dateOnly.split(".")[2];
	var js_month = dateOnly.split(".")[1] - 1;
	var js_day = dateOnly.split(".")[0];
	var js_hours = timeOnly.split(":")[0];
	var js_minutes = timeOnly.split(":")[1];
	
	return new Date(js_year, js_month, js_day, js_hours, js_minutes, 0);
}

function isTomorrow(currentDate, refDate) {
	var startOfCurrentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
	var startOfRefDate = new Date(refDate.getFullYear(), refDate.getMonth(), refDate.getDate(), 0, 0, 0);
	var oneDayInMillis = 1000 * 3600 * 24;
	
	if (startOfCurrentDate.getTime() + oneDayInMillis == startOfRefDate.getTime()) {
		return true;
	} else {
		return false;
	}
}

function isToday(currentDate, refDate) {
	var startOfCurrentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
	var startOfRefDate = new Date(refDate.getFullYear(), refDate.getMonth(), refDate.getDate(), 0, 0, 0);
	
	if (startOfCurrentDate.getTime() == startOfRefDate.getTime()) {
		return true;
	} else {
		return false;
	}
}
function getCETimeDisplay(startDate, endDate, defaultDate) {
	var currentDate = new Date();
	
	var changedTimeDisplay = defaultDate;
	if (isTomorrow(currentDate, startDate)) {
		changedTimeDisplay = "morgen um " + getTimePadding(startDate.getHours()) + "." + getTimePadding(startDate.getMinutes()) + " Uhr";
	} else if (isToday(currentDate, startDate)) {
		var fifteenMinutes = 1000 * 60 * 15;
		if (currentDate.getTime() + fifteenMinutes <= startDate.getTime()) {
			changedTimeDisplay = "heute um " + getTimePadding(startDate.getHours()) + "." + getTimePadding(startDate.getMinutes()) + " Uhr";
		} else if (currentDate.getTime() + fifteenMinutes > startDate.getTime() && currentDate.getTime() <= startDate.getTime()) {
			changedTimeDisplay = "gleich um " + getTimePadding(startDate.getHours()) + "." + getTimePadding(startDate.getMinutes()) + " Uhr";
		} else if (currentDate.getTime() > startDate.getTime() && currentDate.getTime() < endDate.getTime()) {
			changedTimeDisplay = "jetzt";
		}
	}
	return changedTimeDisplay;
}

function changeCETimeDisplay(startDate, endDate, defaultDate, elementName) {
	var changedTimeDisplay = getCETimeDisplay(startDate, endDate, defaultDate)
	if (changedTimeDisplay != defaultDate) {
		if (document.getElementById(elementName)) document.getElementById(elementName).innerHTML = changedTimeDisplay;
	}
}

