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

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, tag1) {
	magicdropdownButtonHandled = true;
	// TODO: hide other dropdowns

	// show requested dropdown
	el = magicdropdowns[tag];
	el1 = magicdropdowns[tag1];
	toggleElementVisibility(el);
	el1.style.display = 'none';
}

function magicdropdownOptionClick(tag, optionValue, optionText) {
	// change text
	var textEl = document.getElementById('magicdropdown-text-'+tag);
	if (textEl) {
        
        if (optionValue == '') {
        	textEl.style.color = '#FFFFFF';
        	textEl.style.fontWeight = 'bold';
        	if (optionText.length > 18) {
        		optionText = optionText.substr(0, 18);
        	}
        	textEl.innerHTML = optionText;
        } else {
        	textEl.style.fontWeight = 'normal';
        	textEl.style.color = '#000000';
        	textEl.innerHTML = optionText;
        }
    }

	// change hidden form value to optionValue
    var valueEl = document.getElementById('magicdropdown-value-'+tag);
    if (valueEl) {
        valueEl.value = optionValue;
    }

	// hide dropdown
	hideElement(magicdropdowns[tag]);
	
	if (optionValue == '') {
		if (textEl) {
	        textEl.innerHTML = optionText;
	        textEl.style.backgroundColor = '#ff0033';
    	}
		return;
	} else {
		textEl.style.backgroundColor = '#FFFFFF';
	}
	
	document.location.href = optionValue;
}


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('p7_community_login')) {
        hideElement(document.getElementById('community_box_login_link'));
        showElement(document.getElementById('community_box_logout_link'));
    }
}
