function printAGOF()
{
	try {var sPrintagof=IVW.substring(IVW.indexOf("/CP/")+4,IVW.length-2);} catch(err) {}
	if ((sPrintagof==undefined) || (sPrintagof==""))
	{
		sPrintagof="- Keine AGOF-ID gefunden! -";
		alert(sPrintagof);
	} else
	{
		alert("AGOF-ID: "+sPrintagof);
		//window.document.title+=printagof;
	}
}

function openPopup(url, width, height) {
	var win = window.open(url, 'Kabel1', 'width='+width+',height='+height);
	if (win) win.focus();
}

function openPopUpWindow( side, width, height, top, left, scrollbars )
{
    if (side && side != null)
    {
        var win = document.open(side, "_blank", "width=" + width + ",height=" + height + ",top="+ top + ",left=" + left + ",toolbar=no,status=no,location=no,menubar=no,directories=no,resizable=yes,scrollbars=" + scrollbars + ",scrolling=");
		if (win) win.focus();
    }
    return;
}

function openPopUpWindowInside( side, width, height, top, left, scrollbars )
{
    if (side && side != null)
    {
        var win = window.open(side, "Detail", "width=" + width + ",height=" + height + ",top="+ top + ",left=" + left + ",toolbar=no,status=no,location=no,menubar=no,directories=no,resizable=yes,scrollbars=" + scrollbars + ",scrolling=");
		if (win) win.focus();
    }
    return;
}

function openerLocation(url)
{
	if (window.opener) {
		window.opener.parent.location.href = url;
	}
	else {
		window.open(url);
		window.focus();
	}
	return void(0);
}

function toggleElementVisibility(el) {
	if (el) {
        if (el.style.display != 'block') {
            showElementKabeleine(el);
        } else {
            hideElementKabeleine(el);
        }
    }
}

function hideElementKabeleine(el) {
    if (el) {
        el.style.display = 'none';
    }
}

function showElementKabeleine(el) {
    if (el) {
        el.style.display = 'block';
        el.style.visibility = 'visible';
    }
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

// attrib_name may be
// id|class|readOnly
// or a style property name like 'display'
function setAttributeForElement(id, attrib_name, attrib_value)
{
	var element = document.getElementById(id);
	if (!element) return;
	
	if (attrib_name == 'class') {
		element.className = attrib_value;
	}
	else if (attrib_name == 'id') {
		element.id = attrib_value;
	}
	else if (attrib_name == 'readOnly') {
		element.readOnly = attrib_value;
	}
	else {
		element.style[attrib_name] = attrib_value;
	}
	return 1;
}


/** Magic Dropdowns **/

var magicdropdowns = new Array();
var magicdropdownButtonHandled = false;

function magicdropdownButtonClick(tag) {
	magicdropdownButtonHandled = true;
	// TODO: hide other dropdowns

	// show requested dropdown
	el = magicdropdowns[tag];
	toggleElementVisibility(el);
}

function magicdropdownOptionClick(tag, optionValue, optionText) {
	// change text
	var textEl = document.getElementById('magicdropdown-text-'+tag);
	if (textEl) {
        textEl.innerHTML = optionText;
        textEl.style.color = '#000000';
    }

	// change hidden form value to optionValue
    var valueEl = document.getElementById('magicdropdown-value-'+tag);
    if (valueEl) {
        valueEl.value = optionValue;
    }

	// hide dropdown
	hideElementKabeleine(magicdropdowns[tag]);
}


function magicdropdownClickHandler(event) {
	if (!magicdropdownButtonHandled) {
		// TODO: hide all dropdowns
	}

	magicdropdownButtonHandled = false;
}

function magicdropdownInit() {
	document.onclick = magicdropdownClickHandler;
	magicdropdowns = new Array();
}

function magicdropdownRegister(tag) {
	magicdropdowns[tag] = document.getElementById('magicdropdown-dropdown-'+tag);
}



/* musicload */

function musicloadAlert() {
    //alert('Willkommen in der ProSieben-Filiale von musicload.\nLeider kann unser umfangreiches Download-Angebot nur\nin Deutschland genutzt werden. User aus Österreich und der Schweiz\ngreifen bitte auf andere nationale Anbieter zurück.');
    openPopUpWindow('/shop_more/partner/musicload/popup_musicload.php', 400, 300, 50, 50, 'yes');
}




var bikky = document.cookie;

function getCookie(name) { // use: getCookie("name");
    var index = bikky.indexOf(name + "=");
    if (index == -1) return null;
    index = bikky.indexOf("=", index) + 1;
    var endstr = bikky.indexOf(";", index);
    if (endstr == -1) endstr = bikky.length;
    return unescape(bikky.substring(index, endstr));
}

var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days

function setCookie(name, value) { // use: setCookie("name", value);
    if (value != null && value != "")
      document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString()+"; path=/";
    bikky= document.cookie; // update bikky
}

function testCookie() {
    var yourName = getCookie ("yourName");
    if (yourName == null) yourName = prompt ("What is your name?", "");
    alert ("Hello, " + yourName + "\nWelcome to my Website");
    setCookie ("yourName", yourName);
}


function checkCommunityBoxLinks() {
    if (getCookie('k1_community_login')) {
        hideElementKabeleine(document.getElementById('community_box_login_link'));
        showElementKabeleine(document.getElementById('community_box_logout_link'));
    }
}

function doTeatri(directory)
{
	if (directory && window.teatri != '') {
		document.write('<img src="http://ps.kabeleins.de/cgi-bin/k1ps.cgi?pfad=' + directory
			+ window.teatri + '" width="1" height="1" align="right">');
	}
}

/* Dynabox and Combox */

function dynaboxToggle(id, max_id, reiter_raw_id, content_raw_id, module_id) {
	var reiter_buttons = document.getElementById(reiter_raw_id + '-' + module_id);
	if (reiter_buttons) {
		reiter_buttons.className = reiter_raw_id + ' ebene' + id;
	}

	for (var i = 1; i <= max_id; i++) {
		var reiter  = document.getElementById(reiter_raw_id  + i + '-' + module_id);
		var content = document.getElementById(content_raw_id + i + '-' + module_id);
		
		if (i == id) {
			if (reiter) reiter.className = 'active';
			if (content) showElementKabeleine(content);
		}
		else {
			if (reiter) reiter.className = 'inactive';
			if (content) hideElementKabeleine(content);
		}
	}
	
	return void(0);
}

/* Channel Navi Highlighting */

// Make sure that all compared paths end on a slash.
// It does not cause a problem here if a slash is appended to a filename.
function channelNaviHighlight(urls, ids, aufklapp)
{
	var pathname = window.location.pathname;
	if (! pathname.match('/$')) pathname += '/';

	for (var i = 0; i < urls.length; i++) {
		var url = urls[i];
		if (! url.match('/$')) url += '/';

		if (url && new RegExp('^' + url).test(pathname)) {
			var anchor = document.getElementById('c' + ids[i]);
			if (anchor) anchor.className = 'highlighted';
			var aufklapp = aufklapp[i];
			if (aufklapp) {
				var ul = document.getElementById('channel-more' + aufklapp);
				if (ul) ul.style.display = 'block';
			}
			break;
		}
	}
}

/* Format Navi Highlighting */

function formatNaviHighlight(urls, ids)
{
	var pathname = window.location.pathname;
	if (! pathname.match('/$')) pathname += '/';

	for (var i = 0; i < urls.length; i++) {
		var url = urls[i];
		if (! url.match('/$')) url += '/';

		if (url && new RegExp('^' + url).test(pathname)) {
			var anchor = document.getElementById('f' + ids[i]);
			if (anchor) anchor.className = 'highlighted';
			break;
		}
	}
}

/* Fix gallery layout problem for images with height > 390 */
function adjustStylesForGalleryImage()
{
	var divs = document.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++) {
		if (divs[i].className == 'snippet-middle') {
			var images = divs[i].getElementsByTagName('img');
			for (var j = 0; j < images.length; j++) {
				var move_up = 20;
				if (parseInt(images[j].height) > 404 - move_up) {
					divs[i].style.width     = '500px';
					divs[i].style.position  = 'relative';
					divs[i].style.marginTop = '-' + move_up + 'px';
					break;
				}
			}
			break;
		}
	}
}

/* */
function mar1515(id)
{
	var element = document.getElementById('id_mar1515_' + id);
	if (element) {
		var height = parseInt(element.style.height);
		if (height < 165) element.style.height = '165px';
		element.style.paddingRight = '250px';
		element.style.backgroundPosition="bottom right";
		element.style.backgroundImage='url('+ '/images/auto/mar1515.jpg' + ')';
	}
}

// Funktion zum Löschen von vorbefüllten Input-Feldern
// Aufruf: 
function ClearInput(id) {
	var element = document.getElementById(id);
	if (element) {
		element.value = '';
	}
}


//USERTRACKING: DO NOT ALTER BELOW THIS LINE

function teaserclick(trackChannel,trackLink, teaserpfad, teaserlayout,teaserpos, teaserid, linktyp)
{
	if (trackChannel){
		var s=s_gi(s_account);
		s.linkTrackVars='events,products,eVar1,eVar12';
		s.linkTrackEvents='event5';
		s.events='event5';
		s.products=';'+ teaserpos +'|'+ teaserid +'|'+ teaserlayout +'|'+ teaserpfad;
		if (trackLink && linktyp) 
		{
			s.products=s.products +'|'+ linktyp;
			s.eVar12=linktyp;
		}	
		void(s.tl(this,'o','Teaser Click - '+teaserid) );
	}
}

var productstring;
function teasercount(teaserpfad, teaserlayout,teaserpos, teaserid)
{
	if (trackChannel){
		if (productstring) {
			productstring=productstring + ',;'+ teaserpos +'|'+ teaserid +'|'+ teaserlayout +'|'+ teaserpfad;
		} else {
			productstring=';'+ teaserpos +'|'+ teaserid +'|'+ teaserlayout +'|'+ teaserpfad;
		}
	}
}

/* Gewinnspielname, Newslettername deklarieren*/
var NLName;
var GSName;