function openPopup(url, width, height) {
	var win = window.open(url, 'Sat1', 'width='+width+',height='+height);
	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=");
		win.focus();
    }
    return;
}

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('s7_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.sat1.de/cgi-bin/s1ps.cgi?pfad=' + directory
			+ window.teatri + '" width="1" height="1" align="right">');
	}
}

/* Combox*/

function eshowcom(name) {
	var container = document.getElementById(name);
	if (container) container.style.display = "block";
	var button = document.getElementById(name+"_button");
	if (button) button.className = "combox_active_"+ name +"_button";
}

function ehidecom(name) {
	var container = document.getElementById(name);
	if (container) container.style.display = "none";
	var button = document.getElementById(name+"_button");
	if (button) button.className = "combox_inactive_"+ name +"_button";
}

function rollovercom(a, b, c) {
	eshowcom(a);
	ehidecom(b);
	ehidecom(c);
}


function comActive(reiter){
	if(reiter == 1) {
		rollovercom('combox_reiterebene1' , 'combox_reiterebene2', 'combox_reiterebene3')
	}
	if(reiter == 2) {
		rollovercom('combox_reiterebene2' , 'combox_reiterebene1', 'combox_reiterebene3')
	}
	if(reiter == 3) {
		rollovercom('combox_reiterebene3' , 'combox_reiterebene2', 'combox_reiterebene1')
	}
}

/* End Combox*/

/*Dynabox*/

function eshowdyna(name) {
	var container = document.getElementById(name);
	if (container) container.style.display = "block";
	var button = document.getElementById(name+"_button")
	if (button) button.className = "dynabox_active_"+ name +"_button";
}

function ehidedyna(name) {
	var container = document.getElementById(name);
	if (container) container.style.display = "none";
	var button = document.getElementById(name+"_button");
	if (button) button.className = "dynabox_inactive_"+ name +"_button";
}

function rolloverdyna(a, b, c) {
	eshowdyna(a);
	ehidedyna(b);
	ehidedyna(c);
}

function dynaActive(reiter){
	if(reiter == 1) {
	rolloverdyna('dynabox_reiterebene1' , 'dynabox_reiterebene2', 'dynabox_reiterebene3')
	}
	if(reiter == 2) {
	rolloverdyna('dynabox_reiterebene2' , 'dynabox_reiterebene1', 'dynabox_reiterebene3')
	}
	if(reiter == 3) {
	rolloverdyna('dynabox_reiterebene3' , 'dynabox_reiterebene2', 'dynabox_reiterebene1')
	}
}
/*Dynabox*/

/* 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 item = document.getElementById('c' + ids[i]);
			if (item) {
				var classname = item.className;
				if (classname && ! classname.match('-hl\$')) {
					item.className = classname + '-hl';
				}
			}
			
			var aufklapp = aufklapp[i];
			if (aufklapp != null) {
				var ul = document.getElementById('weiterenavi' + aufklapp);
				if (ul) ul.style.display = 'block';
			}
			break;
		}
	}
}

/*DHTML Übersicht*/
function swapAttributeForElement(id, id1, maxvalue)
{
	maxvalue = maxvalue + 1;
	for (var i=0; i<=maxvalue; i++)
	{
		var id2 = id1 + i;
		setAttributeForElement(id2, 'display', 'none');
	}
	

	setAttributeForElement(id, 'display', 'block');
		
}

/* ViB header teaser */
function flitTeaser(source_id, target_id) {
	var target_teaser = document.getElementById(target_id);

	if (target_teaser) {
		var source_teaser = document.getElementById(source_id);
		if (source_teaser) {
			target_teaser.innerHTML = source_teaser.innerHTML;
		}
	}
}

function eshowdhtml(name) {
if(document.getElementById(name).style.display != "block"){
	document.getElementById(name).style.display = "block";
	var stand = document.getElementById(name+"_button").className;
	document.getElementById(name+"_button").className = stand + "_hover";
}
}

function ehidedhtml(name) {
document.getElementById(name).style.display = "none";
var stand = document.getElementById(name+"_button").className;
stand = stand.split("_");
document.getElementById(name+"_button").className = stand[0];
}

function rolloverdhtml(a, b) {
eshowdhtml(a);
ehidedhtml(b);
}
/*DHTML Übersicht*/

function swapLayer(module, count, firstAttrib, firstValue, secondAtrrib, secondValue)
{
	var reg = /(\w.+)_\d/;
  	reg.exec(module);
		
	for (var i = 0; i <= count; i++) {
		var module1 = RegExp.$1 + '_' + i;

		setAttributeForElement(module1, firstAttrib, firstValue);
	}
	setAttributeForElement(module, secondAtrrib, secondValue);
	
}

/*A-Z Modul*/
function toggleiframe(elem, frame_src)
{
	var iframe = document.getElementById('iframe_az');

	if (!iframe) {
		return;
	}
	
	var item = document.getElementById(elem);
	if (item) {
		if (!is_loaded) {
			iframe.style.height = '0px';
			iframe.src = frame_src;
			is_loaded = 1;
			
		}
		else if (is_loaded == -1) {
			iframe.style.display = 'block';
			is_loaded = 1;
		}
		else if (is_loaded == 1) {
			iframe.style.display = 'none';
			is_loaded = -1;
		}
	}
}

function onloadiframe(iframe, container_id)
{
	var container = document.getElementById(container_id);
	var frame_id = parent.document.getElementById(iframe);
	if (container && frame_id) {
		var height = container.offsetHeight || 620;
		frame_id.style.height = height + 'px';
	}
}

function insertaznavigation()
{
	var item = document.getElementById('azisin');
	if (!item) {
		var insert_point = document.getElementById('naviOuter');
		var insert_point1 = document.getElementsByName('slot1');
		if(insert_point || insert_point1)
		{
			var newiframediv = document.createElement("div");
			newiframediv.style.position = "relative";
			newiframediv.style.width = "572px";
			newiframediv.style.left = "8px";
			var newiframe = document.createElement("iframe");
			newiframe.style.height = "0px";
			newiframe.style.width = "100%";
			newiframe.id = "iframe_az";
			newiframe.name ="iframe_az";
			newiframe.className = "iframe";
			newiframe.allowTransparency = "true";
			newiframe.scrolling = "no";
			newiframe.frameBorder = "0";

			//Den Link als Kindelement in das "menu" Element hängen
			newiframediv.appendChild(newiframe);
			
			var isFormat = document.getElementById("naviOuter");
			var isTop = document.getElementById("naviTop");
			if(isFormat)
			{
				if(isTop)
				{
					document.getElementById("mitte").insertBefore(newiframediv, document.getElementById("naviTop"));
				}
				else
				{
					document.getElementById("mitte").insertBefore(newiframediv, document.getElementById("naviOuter"));
				}
					
			}
			else 
			{
				// FIXME: insert_point1 does not necessarily exist.
				if (insert_point1 && insert_point1[0])
					insert_point1[0].appendChild(newiframediv);
			}
		}
	}
}

function closeiframe(elem)
{
	var iframe = parent.document.getElementById('iframe_az');

	if (!iframe) {
		return;
	}
	
	var item = parent.document.getElementById(elem);
	
	if (item) {
		if (parent.is_loaded == -1) {
			iframe.style.display = 'block';
			parent.is_loaded = 1;
		}
		else if (parent.is_loaded == 1) {
			iframe.style.display = 'none';
			parent.is_loaded = -1;
		}
	}
}

/** Flash Newsletter Box**/

function setNewsletterBoxState(state)
{
	if (!state) state = 'closed';
	setAttributeForElement('newsletterbox-inner','class','newsletterbox-inner-' + state);
	return void(0);
}

/* Only IE >= 5.5 and Mozilla can do correct CSS clipping */
function canNewsletterBox() {
	if (window.isType
		&& (isType('popup1', 'tandem')
			|| isType('popup1', 'xxl')
			|| isType('popup1', 'wallpaper'))) return;
	
	var ua = window.navigator.userAgent;

	if (ua.indexOf('Opera') > -1) return;
	if (ua.indexOf('Netscape') > -1) return;

	var found = ua.match(/MSIE ([0-9.]+)/);
	if (found) {
		if (parseFloat(found[1]) < 5.5) return;
		return 1;
	}

	found = ua.match(/Mozilla\/([0-9.]+)/);
	if (found) {
		if (parseFloat(found[1]) < 5.0) return;
		return 1;
	}
	
	return;
}

