/**
 * @author    Adrian Meyer
 * @copyright FWP Systems GmbH
 */
var showAjaxForm = function(id, overlay) {
    var pageSize = getPageSize();
    var objBody = document.getElementsByTagName("body").item(0);
    var objForm = document.getElementById(id).cloneNode(true);

    if (!overlay) {
        objBody.insertBefore(objForm, objBody.firstChild);
    } else {
        var objOverlay = new Element('div', {
            'id' : 'overlay',
            'styles' : {
    			'display' : 'block',
    			'position' : 'absolute',
    			'top' : 0,
    			'left' : 0,
    			'z-index' : 90,
    			'width' : '100%',
    			'height' : (pageSize[1] + 'px')
    		}
        });

        objOverlay.insertBefore(objForm, objOverlay.firstChild);
        objBody.insertBefore(objOverlay, objBody.firstChild);
    }

    objForm.style.display = 'block';
    objForm.style.zIndex = '99';
}

/**
 * @author    Adrian Meyer
 * @copyright FWP Systems GmbH
 */
var removeOverlay = function() {
    try {
        var overlayNode = document.getElementsByTagName("body")[0].firstChild;
        document.getElementsByTagName("body")[0].removeChild(overlayNode);
    } catch(e) {}
}

/**
 * @author    Adrian Meyer
 * @copyright FWP Systems GmbH
 */
var getPageSize = function() {
	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) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if (yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if (xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	pageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
	return pageSize;
}

/**
 * @author    Adrian Meyer
 * @copyright FWP Systems GmbH
 */
var ask = function(question, location, onFalse) {
    var check = confirm(question);

	if (!check) {
	    if (typeof onFalse == 'function') {
	        onFalse();
	    }

	    return false;
	} else {
	    window.location = location;
	}
}