

// 
/**
 * Opent mp3player.php met get argumenten.
 *
 * Bij meerdere argumenten worden deze samengevoegd zodat bijvoorbeeld een bepaalde artiest en een aantal
 * aparte files wordt afgespeeld.
 *
 * @param  mixed   artistIds	 Ids van artiest(en) (array van ints, string van kommagescheiden ints of int)
 * @param  int     playId	     Id van als eerste af te spelen bestand
 * @param  bool    defaultFiles  Slechts 1 nummer per artiest, namelijk alleen de als default ingestelde file
 * @param  mixed   fileIds 	     Ids van de file(s) (array van ints, string van kommagescheiden ints of int)
 * @param  object  extraOptions	 Extra opties: Nu nog alleen sort
 * @return void
 */
function openMusicPlayer(artistIds, playId, defaultFiles, fileIds, extraOptions)
{
    var reqString;

    if (typeof artistIds == 'array') {
        artistIds = artistIds.join(',');
    }
    if (typeof fileIds == 'array') {
        fileIds = artistIds.join(',');
    }

    if (defaultFiles) {
        reqString = 'default=1';
    } else {
        reqString = 'default=0';
    }

    if (artistIds) {
        reqString += '&artistIds=' + artistIds;
    }
    if (fileIds) {
        reqString += '&fileIds=' + fileIds;
    }
    if (playId) {
        reqString += '&playId=' + playId;
    }
	if (extraOptions) {
        if (extraOptions.sort) {
			reqString += '&sort=' + extraOptions.sort;
		}
	}

    playId = parseInt(playId);
    window.open('/player/mp3player.php?' + reqString, 'mfMusicPlayer', 'width=590,height=500,scrollbars=0,resizable=0,status=0');
}


function openRecommend(sectionId, elementId, url, noSection, noSectionTitle)
{
	if (!noSection) {
		noSection = '';
	}
	if (!noSectionTitle) {
		noSectionTitle = '';
	}
    window.open('/shared/recommend.php?sectionId=' + sectionId + '&elementId=' + elementId + '&url=' + escape(url) + '&noSection=' + noSection + '&noSectionTitle=' + noSectionTitle , '', 'width=500,height=550,location=0,status=0,resizable=1,scrollbars=0');
}


function hideFormElements(form, els)
{
		var el;

		for (var i = 0; i < els.length; i++) {
				var el = document.getElementById('fieldRow' + form + els[i]);
				if (el) {
						el.style.display = 'none';
				}
		}
}

function showFormElements(form, els)
{
		var el;

		for (var i = 0; i < els.length; i++) {
				var el = document.getElementById('fieldRow' + form + els[i]);
				if (el) {
						el.style.display = '';
				}
		}
}


// http://www.quirksmode.org/blog/archives/2005/08/addevent_consid.html
// addEvent(obj,"mouseover",doSomething)
function addEvent(obj, evType, fn, useCapture) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, useCapture);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        // alert("Handler could not be attached");
    }
}


function mfReplaceMouseOvers() {
    els = document.getElementsByTagName('div');
    for (var i = 0; i < els.length; i++) {
        if (els[i].className == 'contentblock') {
            els[i].onmouseover = new Function("this.className = 'contentblock contentblock_hover';");
            els[i].onmouseout  = new Function("this.className = 'contentblock';");
        } else if (els[i].className == 'resultblock') {
            els[i].onmouseover = new Function("this.className = 'resultblock contentblock_hover';");
            els[i].onmouseout  = new Function("this.className = 'resultblock';");
        } else if (els[i].className == 'listblock') {
            els[i].onmouseover = new Function("this.className = 'listblock listblock_hover';");
            els[i].onmouseout  = new Function("this.className = 'listblock';");
        }
    }
}

function doWriteEmail(name, domain) {

    document.write('<a href="mail' + 'to:' + name + '@' + domain + '">' + name + '@' + domain + '</a>');
}

/*
function getFaqLinkArticle(text, article) {
    return "<a href=\"/faq/index.php?article=" + article + "\" onclick=\"window.open(this.href, '', 'width=750,height=500,scrollbars=1'); return false;\">" + text + "</a>";
}
*/
function getFaqLinkArticle(text, article) {
	if (isNaN(article)) {
		return "<a href=\"/faq/index.php?" + article + "\" onclick=\"window.open(this.href, '', 'width=750,height=500,scrollbars=1'); return false;\">" + text + "</a>";
	} else {
		return "<a href=\"/faq/index.php?article=" + article + "\" onclick=\"window.open(this.href, '', 'width=750,height=500,scrollbars=1'); return false;\">" + text + "</a>";
	}
}
function getFaqLinkCategory(text, category) {
    return "<a href=\"/faq/index.php?category=" + category + "\" onclick=\"window.open(this.href, '', 'width=750,height=500,scrollbars=1'); return false;\">" + text + "</a>";
}

function getFaqLink(text) {
    return "<a href=\"/faq/\" onclick=\"window.open(this.href, '', 'width=750,height=500,scrollbars=1'); return false;\">" + text + "</a>";
}

function clearSelectOptions(selectObject)
{
    if (selectObject && selectObject.options) {
        var tiltCount = 0;
        while (selectObject.options.length > 0) {
            if (tiltCount++ > 10000) {
                break;
            }
            selectObject.options[0] = null;
        }
    }
}


var srcs = new Array();
function replaceImgSrc(obj, src)
{
    srcs[obj] = obj.src;
    obj.src = src;
}

function restoreImgSrc(obj)
{
    if (srcs[obj]) {
        obj.src = srcs[obj];
    }
}



/* MENU-FUNCTIES */ 
function showMenu(id)
{
    var el;
    if (id) {
        el = document.getElementById('dropdown-' + id);
        if (el) {
            el.style.display = '';
        }
    }

    var els = document.getElementsByTagName('DIV');
    for (var i = 0; i < els.length; i++) {
        if (els[i].id.substr(0, 9) == 'dropdown-') {
            if (!el || els[i] != el) {
                els[i].style.display = 'none';
            }
        }
    }

    var menuLeft   = getLeftPx(el);
    var menuTop    = getTopPx(el);
    var menuWidth  = el.clientWidth;
    var menuHeight = el.clientHeight;

    if (navigator.userAgent.indexOf('MSIE 6') > 1) {
        // verberg alle SELECT-elementen die zich onder het menu bevinden (MSIE 6-bug)
        var els = document.getElementsByTagName('SELECT');
        if (els) {
            for (var i = 0; i < els.length; i++) {
                if (getLeftPx(els[i]) > menuLeft && getLeftPx(els[i]) < (menuLeft + menuWidth) || 
                    (getLeftPx(els[i]) + els[i].clientWidth) > menuLeft && (getLeftPx(els[i]) + els[i].clientWidth) < (menuLeft + menuWidth)) {
                    if (getTopPx(els[i]) > menuTop && getTopPx(els[i]) < (menuTop + menuHeight)) {
                        els[i].style.visibility = 'hidden';
                    }
                }
            }
        }
    }
}

function isChild(p, c) 
{
    if (p == c) {
        // een element is geen child van zichzelf!
        // Opera en Konqueror vinden standaard van wel
        return false;
    }
    if (p && c) {
        if (p.contains) {
            // waarschijnlijk MSIE
            if (p.contains(c)) {
                return true;
            } else {
                return false;
            }
        }
        if (p.childNodes && p.childNodes.length) {
            // waarschijnlijk Mozilla
            for (var i=0; i<p.childNodes.length; i++) {
                ac = p.childNodes[i];
                if (ac == c)  return true;
                if (ac.childNodes.length && isChild (ac, c))  return true;
            }
        }
    }
    return false;
}


function condHide(e, el) 
{
    var relTarg;
    var targ;
    if (!e) var e = window.event;
    
    if (e.relatedTarget) {
        relTarg = e.relatedTarget;
    } else if (e.toElement) {
        relTarg = e.toElement;
    }
    if (e.target) {
        targ = e.target;
    } else if (e.srcElement) {
        targ = e.srcElement;
    }

    if (document.getElementById && document.getElementById('dropdown-' + el)) {
        obj = document.getElementById('dropdown-' + el);
    }

    if (!isChild(obj, relTarg)) {
        obj.style.display = 'none';

        if (navigator.userAgent.indexOf('MSIE 6') > 1) {
            // toon alle SELECT-elementen weer die eerder verborgen waren
            var els = document.getElementsByTagName('SELECT');
            for (var i = 0; i < els.length; i++) {
                els[i].style.visibility = '';
            }
        }
    }
}
/* einde MENU-FUNCTIES */ 


function getTopPx(obj) {
  var result = obj.offsetTop;
  while (obj.offsetParent) {
    obj = obj.offsetParent;
    result += obj.offsetTop;
  }
  return result;
}


function getLeftPx(obj) {
  var result = obj.offsetLeft;
  while (obj.offsetParent) {
    obj = obj.offsetParent;
    result += obj.offsetLeft;
  }
  return result;
}

addEvent(window, 'load', new Function('mfReplaceMouseOvers()'));
