﻿function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++)
	{
		var anchor = anchors[i];
		if
		(
			anchor.getAttribute("href")
			&&
			(
				anchor.getAttribute("rel") == "external" ||
				anchor.getAttribute("rel") == "external nofollow" ||
				anchor.getAttribute("rel") == "nofollow external"
			)
		)
		{ anchor.target = "_blank"; }
	}
}

function internalInfo() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if
		(anchor.getAttribute("href") && (anchor.getAttribute("rel") == "info" || anchor.getAttribute("rel") == "info nofollow" || anchor.getAttribute("rel") == "nofollow info")) 
        {
            var url = anchor.getAttribute("href");
		    var title = anchor.getAttribute("title");

		    anchor.onclick = function () { var a = window.open(this.getAttribute("href"), "Informatie", "width=860,height=500,status=no,resizable=yes,scrollbars=yes"); a.focus(); return false; }
		}
		else if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "popup follow"))
		{
		    anchor.onclick = function () { var a = window.open(this.getAttribute("href") + "?popup=1&follow=1", "Informatie", "width=860,height=500,status=no,resizable=yes,scrollbars=yes"); a.focus(); return false; }
		}
	}
}

window.onload = function() {
    externalLinks();
    internalInfo();
}

function getLnk(src, lnk, txt, cssClass, external, popup, onClickFunction) {
    
    // defaults
    popup = typeof (popup) != 'undefined' ? popup : false;
    var blank = " t" + "arget=\"" + "_blank" + "\"";
    external = external == true ? blank : '';
    var style = " c" + "lass=\"" + cssClass + "\"";
    cssClass = ((typeof (cssClass) != 'undefined') && (cssClass != '')) ? style : '';
    var funct = " o" + "nclick=\"" + onClickFunction + "\"";
    clickFunction = ((typeof (onClickFunction) != 'undefined') && (onClickFunction != '')) ? funct : '';

    // genereren href
    var href = lnk;

    if (popup) {
        if (href.toLowerCase().indexOf("?popup=1") == -1) {
            href = href + "?popup=1";
        }
    }

    // controleren popup
    if (popup) {
        var a = "<a on" + "click=\"" + "window.open('" + href + "', 'informatie', 'width=860,height=500,status=no,resizable=yes,scrollbars=yes'); return false;\"" + cssClass + " >" + txt + "</a>";
    } else {
        var a = "<a h" + "ref=\"" + href + "\"" + cssClass + "" + external + "" + clickFunction + " >" + txt + "</a>";
    }

    // wegschrijven link
    $(src).html(a);
}


function goLnk(element) {
    var url = $(element).find('.url').text();
    var popup = $(element).find('.popup').text();
    var external = $(element).find('.external').text();

    if (popup == 'True') {
        if (url.toLowerCase().indexOf("?popup=1") == -1) {
            url = url + '?popup=1';
        }
        window.open(url, 'informatie', 'width=860,height=500,status=no,resizable=yes,scrollbars=yes');
    } else if (external == 'True') {
        var urlLink = unescape(url);
        window.open(urlLink);
    } else {
        var urlLink = unescape(url);
        location.href = urlLink;
    }
}

function getGashUrl(url) {
    var newUrl = url + location.hash;
    document.location.href = newUrl;
}

function bigInfoPopup (identity, objectIdentity, shop) {
    overlay = document.createElement('div');

    $(overlay).addClass('voordelenPopupOverlay')
                .css('position', 'absolute')
                .css('top', '0px')
                .css('left', '0px')
                .css('width', $(document).width())
                .css('height', $(document).height())
                .css('background', '#04236a')
                .css('z-index', '200')
                .css('opacity', '0.7')
                .click(function () {
                    destroyPopup();
                });
    $(overlay).appendTo($('body'));
    popup = document.createElement('div');
    text = getPaginaBlokHtmlPerShop(identity, objectIdentity, shop);
    $(popup).html('<div class="section-top"><a href="javascript:destroyPopup();"></a></div><div class="section">' + text + '</div><div class="section-bottom"><a href="javascript:destroyPopup();"></a></div>');
    $(popup).addClass('voordelenPopup')
            .css('position', 'absolute')
            .css('z-index','201');
            $(popup).appendTo($('body'));
            var offestTop = $(window).scrollTop() > 0 ? $(window).scrollTop() : 0;
            var top = ($(window).height() - $(popup).outerHeight()) / 2 + offestTop;
            var left = ($(window).width() - $(popup).outerWidth()) / 2;
            $(popup).css({ position: 'absolute', margin: 0, top: (top > 0 ? top : 0) + 'px', left: (left > 0 ? left : 0) + 'px' });

}

function destroyPopup() {
    $('.voordelenPopupOverlay').remove();
    $('.voordelenPopup').remove();
}

