function openPopup(url, width, height) {
	window.open(url, 'ProSieben', 'width='+width+',height='+height);
}

function openPopUpWindow( side, width, height, top, left, scrollbars )
//function openPopUpWindow( side, width, height, top, left )
{
    if (side && side != null)
    {
        var newWindow = null;
        // newWindow = newWindow = document.open( side, "_blank", "width=" + width + ",height=" + height + ",top="+ top + ", left=" + left + ", toolbar=no, status=no, scrollbars=auto, location=no, menubar=no, directories=no, resizable=auto" );
        newWindow = 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=");
    }
    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';
    }
}

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;
}




/** 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();
    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('p7_community_login')) {
        hideElement(document.getElementById('community_box_login_link'));
        showElement(document.getElementById('community_box_logout_link'));
    }
}
