
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') {
            showElement(el);
        } else {
            hideElement(el);
        }
    }
}

function hideElement(el) {
    if (el) {
        el.style.display = 'none';
    }
}

function showElement(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
	hideElement(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')) {
        hideElement(document.getElementById('community_box_login_link'));
        showElement(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) showElement(content);
		}
		else {
			if (reiter) reiter.className = 'inactive';
			if (content) hideElement(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;
		}
	}
}

function writeFlashChannelNavi(swf, width, height, id)
{
	writeFlash(swf, '', width, height, id);
	if (!document.getElementById(id)) {
		var container = document.getElementById('channelnavi-outer');
		if (container) {
			var divs = container.getElementsByTagName('div');
			for (var i = 0; i < divs.length; i++) {
				if (divs[i].className == 'channelnavi') {
					divs[i].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: ATTENTION WHEN ALTERING ANYTHING BELOW THIS LINE
//*******************************************************************

function getObjectProperties(pObject, pDepth, pMaxDepth)
{
	var debugStrArray = new Array();
	if(pDepth > pMaxDepth) {
		return debugStrArray;
	}
	var tab = "";
	for(var i = 0; i < pDepth; i++) tab += "\t";
	for(property in pObject) {
		if(typeof(pObject[property]) == 'object') {
			var result = String(getObjectProperties(pObject[property], pDepth + 1, pMaxDepth).join("\n" + tab));
			debugStrArray.push(result);
		}
		else {
			var propertyValue = String(pObject[property]);
			if(propertyValue.substring(0, 'function'.length) == 'function') {
				continue;
			}
			debugStrArray.push(property + ' = ' + propertyValue);
			//document.getElementById('debug').innerHTML += "\n" + tab + property + ' = ' + propertyValue;
		}
	}
	return debugStrArray;
}



/**
 * Handles the click on a teaser element.
 */
function teaserclick(trackChannel,trackLink, teaserpfad, teaserlayout,teaserpos, teaserid, linktyp, pHtmlObject, pTargetUrl, pTargetWindowName)
{
	if (storedEvents&&storedEvents!='') sendOMTRData();

	var hasRedirection = typeof(pTargetUrl) != 'undefined';

	// tracking logic:
	// track now if there is no redirection,
	// track on unload if there is a redirection.
	var teaserclickStruct = new Object();
	
	if (trackChannel) {
		// fill tracking structure
		teaserclickStruct.trackChannel = trackChannel;
		teaserclickStruct.trackLink = trackLink;
		teaserclickStruct.teaserpfad = teaserpfad;
		teaserclickStruct.teaserlayout = teaserlayout;
		teaserclickStruct.teaserpos = teaserpos;
		teaserclickStruct.teaserid = teaserid;
		teaserclickStruct.linktyp = linktyp;
		teaserclickStruct.pHtmlObject = pHtmlObject;
		// do the tracking
		
		//try to track through onbeforeunload
		addEvent(window, 'beforeunload', function() {teaserclickMindlab(teaserclickStruct);}, false);
		
		if(!hasRedirection) {
			// track now
			teaserclickTracking(teaserclickStruct);
		}
		else {
			// set up unload handler for tracking
			addEvent(window, 'unload', function() {teaserclickTracking(teaserclickStruct);}, false);
		}
	}

	// follow target url if set
	if(typeof(pTargetUrl) != 'undefined') {
		var targetWindowName = (typeof(pTargetWindowName) != 'undefined') ? pTargetWindowName : '_self';
		window.open(pTargetUrl, targetWindowName);
	}
}

/**
 * Does the tracking using the global tracking structure.
 */
function teaserclickTracking(pTeaserclickStruct)
{
	var s=s_gi(s_account);
	s.linkTrackVars='events,products,eVar1';
	s.linkTrackEvents='event5';
	s.events='event5';
	s.products=';'+ pTeaserclickStruct.teaserpos +'|'+ pTeaserclickStruct.teaserid +'|'+ pTeaserclickStruct.teaserlayout +'|'+ pTeaserclickStruct.teaserpfad;
	if (pTeaserclickStruct.trackLink && pTeaserclickStruct.linktyp) s.products=s.products +'|'+ pTeaserclickStruct.linktyp;
	void(s.tl(typeof(pTeaserclickStruct.pHtmlObject) == 'undefined' ? document : pTeaserclickStruct.pHtmlObject,'o','Teaser Click - '+pTeaserclickStruct.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;
		}
	}
	
}

var aMindlabteaser = new Array();

function teasercountMindlab(teaserpfad, teaserlayout,teaserpos, teaserid, teaserlabel, teaserlink)
{
	
	var len= aMindlabteaser.length;
	aMindlabteaser[len]=  {
		 					"nm_teaserpfad" : teaserpfad,
		 					"nm_teaserlayout" : teaserlayout,
		 					"nm_teaserpos" : teaserpos, 
		 					"nm_teaserid" : teaserid,
		 					"nm_teaserlabel" : teaserlabel,
		 					"nm_teaserlink" : teaserlink
		 				  }
}

function teaserclickMindlab(pTeaserclickStruct)
{
/*
    oNMRemotePixel.setParameter("nm_teaserpfad", pTeaserclickStruct.teaserpfad);
	oNMRemotePixel.setParameter("nm_teaserlayout", pTeaserclickStruct.teaserlayout);
	oNMRemotePixel.setParameter("nm_teaserpos", pTeaserclickStruct.teaserpos);
	oNMRemotePixel.setParameter("nm_teaserid", pTeaserclickStruct.teaserid);
	oNMRemotePixel.setParameter("nm_teaserlinktyp", pTeaserclickStruct.linktyp);
	oNMRemotePixel.setParameter("nm_event", "Teaser Clicks");
	
	oNMRemotePixel.sendData(oNMRemoteSession );
	*/
}



/**
 * Crossbrowser function to add an event handler
 */
function addEvent(obj, eventType, callback, useCaption)
{
  if (obj.addEventListener) {
    obj.addEventListener(eventType, callback, useCaption);
    return true;
  } else if (obj.attachEvent) {
    var retVal = obj.attachEvent("on"+eventType, callback);
    return retVal;
  } else {
    return false;
  }
}

/*
	Mediacenter fallback
*/

function mcShowFallback(obj_id, info_id) {
	var movie = document.getElementById(obj_id);
	if (!movie) return;
	var tagname = movie.tagName.toLowerCase();
	if (tagname != 'object' && tagname != 'embed') {
		var mc_info = document.getElementById(info_id);
		if (!mc_info) return;
		mc_info.style.visibility = 'visible';
	}
}

s_browserInfo = {  
	_widthCategories : [800, 810, 820, 830, 840, 850, 860, 870, 880, 890,
						900, 910, 920, 930, 940, 950, 960, 970, 980, 990,
						1000, 1010, 1020, 1030, 1040, 1050, 1060, 1070, 1080, 1090,
						1100, 1110, 1120, 1130, 1140, 1150, 1160, 1170, 1180, 1190,
						1200, 1210, 1220, 1230, 1240, 1250, 1260, 1270, 1280, 1290,
						1300, 1310, 1320, 1330, 1340, 1350, 1360, 1370, 1380, 1390,
						1400, 1410, 1420, 1430, 1440, 1450, 1460, 1470, 1480, 1490,
						1500, 1510, 1520, 1530, 1540, 1550, 1560, 1570, 1580, 1590,
						1600, 1610, 1620, 1630, 1640, 1650, 1660, 1670, 1680, 1690,
						1700, 1710, 1720, 1730, 1740, 1750, 1760, 1770, 1780, 1790,
						1800],
	_heightCategories : [400, 500, 600, 700, 800, 900, 1000, 1100, 1200],
	_maxPopupWidth : 801, // filter all popups by excluding pages with a smaller viewport than this value
	_assumePopup : -1,
	viewportWidth : "",
	viewportHeight : "",
	flashVersion : "",
	
	getFlashVersion : function() {
		//returns the installed flash version, determined by SWFObject (if available)
		try {
			var fv = deconcept.SWFObjectUtil.getPlayerVersion();
			fv = fv.major + "." + fv.minor + "." + fv.rev;
			this.flashVersion = fv;
			return fv;
		} catch (err) {
			return "";
		}
	},
	
	getViewportWidth : function() {
		// returns the viewport width
		this._calculateSize();
		return this._matchCategories(this.viewportWidth, this._widthCategories);
	},
	
	getViewportHeight : function() {
		//returns the viewport height
		this._calculateSize();
		return this._matchCategories(this.viewportHeight, this._heightCategories);
	},
	
	_calculateSize : function() {
		// calculate the viewport width and height	
		try {			
			this.viewportWidth = window.top.document.documentElement.clientWidth;
			this.viewportHeight = window.top.document.documentElement.clientHeight;
			return true;
		} catch (err) {
			return false;
		}
	},
	
	_matchCategories : function(size, catArray) {
		//matches a calculated size against a given array
		var i = 0;
		var r = "";
		//detect if this is the first call (using viewport width) of this function
		if (this._assumePopup == -1) {
			//check if the current viewport has a smaller width than the estimated maxPopupWidth. 
			//if this is the case assume a popup (requires width categorization before height categorization)
			if (size < this._maxPopupWidth) {
				this._assumePopup = 1;
			} else {
				this._assumePopup = 0;
			}
		}
		if (this._assumePopup < 1) {
			if (typeof size == typeof 2) {
				r = "<= "+catArray[i]; //define the default (smallest) value, example: "<= "+catArray[i]
				while ((size > catArray[i]) && (i < catArray.length)) {
					i++;
				}
				if (i == catArray.length) {
					r = "> "+catArray[i-1];
				} else {
					if (i > 0) {
						r = catArray[i-1] + " - " + (catArray[i]-1);
					}
				}
			} else {
				r = "";
			}
		}
		return r;
	}
}