﻿function getX() {
    var x;
    if (self.innerHeight) // all except Explorer
    { x = self.innerWidth; }
    else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
    { x = document.documentElement.clientWidth; }
    else if (document.body) // other Explorers
    { x = document.body.clientWidth; }

    return x;
}

function getY() {
    var y;
    if (self.innerHeight) // all except Explorer
    { y = self.innerHeight; }
    else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
    { y = document.documentElement.clientHeight; }
    else if (document.body) // other Explorers
    { y = document.body.clientHeight; }

    return y;
}

function getWidth() {
    var x;
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) // all but Explorer Mac
    { x = document.body.scrollWidth; }
    else // Explorer Mac; //would also work in Explorer 6 Strict, Mozilla and Safari 
    { x = document.body.offsetWidth; }

    return x;
}

function getHeight() {
    var y;
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) // all but Explorer Mac
    { y = document.body.scrollHeight; }
    else // Explorer Mac;		 //would also work in Explorer 6 Strict, Mozilla and Safari
    { y = document.body.offsetHeight; }

    return y;
}


document.getElementsByClassName = function(c) {

    var r = new Array();
    var j = 0;
    var o = document.getElementsByTagName("*");
    for (i = 0; i < o.length; i++) {
        if (o[i].className == c) {
            r[j] = o[i];
            j++;
        }
    }
    return r;
}

function hideSifrElements() {
    var obj = document.getElementsByClassName('sIFR-flash');
    for (i = 0; i < obj.length; i++)
    { obj[i].style.display = 'none'; }
}

function showSifrElements() {
    var obj = document.getElementsByClassName('sIFR-flash');
    for (i = 0; i < obj.length; i++) {
        if (obj[i].className == 'loginText')
        { obj[i].style.display = 'inline'; }
        else
        { obj[i].style.display = ''; }
    }
}

function openPopupDiv(width, height, url, className) {

	hideSifrElements();
	var origIframe = document.getElementById('overlayIframe');

	var container = document.getElementById('overlayContainer');
	// reset container height
	//container.style.height = 202 + 'px';

	var iframe = document.createElement('iframe');

	//var winLeft = (getX() - container.offsetWidth) / 2;
	//var winTop = ((getY() - container.offsetHeight) / 2) - 120;

	//var url = 'Login.aspx';

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	iframe.setAttribute("src", url);
	//iframe.setAttribute('width', 350);
	//iframe.setAttribute('height', 200);
	iframe.setAttribute("scrolling", "auto");
	iframe.setAttribute("frameBorder", "0");
	iframe.setAttribute('id', 'overlayIframe');
	//iframe.setAttribute('class', className);
	iframe.className = className;

	//container.style.top = winTop + 'px';
	//container.style.left = winLeft + 'px';

	document.getElementById('overlayContainer').style.visibility = "visible";
	// document.getElementById('overlayContainerImg').style.height = arrayPageSize[1] + 'px';
	//document.getElementById('overlayContainerImg').style.width = getWidth() + 'px';


	//iframe.style.width = width + 'px';
	//iframe.style.height = height + 'px';
	//container.style.width = width + 'px';
	//container.style.height = height + 'px';

	if (origIframe) {
		container.replaceChild(iframe, origIframe);
	}
	else {
		container.appendChild(iframe);
	}
}

function closePopupDiv() {
    showSifrElements();
    document.getElementById('overlayContainer').removeChild(document.getElementById('overlayIframe'));
    document.getElementById('overlayContainer').style.visibility = "hidden";
}

function resizePopup() {
    var container = document.getElementById('overlayContainerContent');
    if (container != null) {
        var winLeft = (getX() - container.offsetWidth) / 2;
        var winTop = 0;
        if (getY() >= 450) {
            winTop = ((getY() - container.offsetHeight) / 2 - 120);
        }
        else {
            winTop = ((getY() - container.offsetHeight) / 2);
        }

        container.style.top = winTop + 'px';
        container.style.left = winLeft + 'px';
    }
}

//function upgrade() {
//    this.location.href = '/verkoop.html';
//}

//function openPage(url)
//{ this.location.href = url; }

//function openPageNewWindow(url)
//{ window.open(url, 'subscribePanel'); }

//function openPopup(url, width, height) {
//    //window.open(url, 'vacature', 'width=' + width + ', height=' + height +'scrollbars=yes,toolbar=no,location=no, resizable=yes');
//    window.open(url, 'vacature', 'width=' + width + ',scrollbars=yes,toolbar=no,location=no, resizable=yes');
//}

//function resizeMe(width, height) {
//    var container   = document.getElementById('overlayContainerContent');
//    var iframe = document.getElementById('overlayIframe');
//    
//    container.style.width = width + 'px';
//    container.style.height = height + 'px';
//    
//    iframe.style.width = width + 'px';
//    iframe.style.height = height + 'px';

//}

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}

function getPageScroll() {

    var yScroll;

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }

    arrayPageScroll = new Array('', yScroll)
    return arrayPageScroll;
}

