/**
 *	Javascript file with common functions
 */


/**
 * Javascript function to display a dialog
 *
 * @return void
 *
 * @author Henk Erik van der Hoek (mail@henkerikvanderhoek.nl)
 * @since  1.0.0
 */

function Dialog (sUrl, iWidth, iHeight)
{
    var posX = (screen.width / 2) - (iWidth/2);
    var posY = (screen.height / 2) - (iHeight/2);

    dialog = window.open (sUrl, "dialog", "width="+iWidth+"px, height="+iHeight+"px, resizable=no, scrollbars=yes");

    dialog.moveTo (posX, posY);
    dialog.name = 'popup';
    dialog.focus ();
}


function initialzePNGSupportForIE ()
{
    if (navigator.appName == "Microsoft Internet Explorer") {

        var imageCollection = document.getElementsByTagName ('img');
        var len = imageCollection.length;

        for (var i = 0; i < len; i++) {

            var image = imageCollection[i];
            var div = document.createElement ('div');

            //alert (image.nodeName);

            div.style.height = image.height;
            div.style.width = image.width;
            div.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + image.getAttribute ('src'); + '", sizingMethod="scale")';

            image.style.display = 'none';

            var parent = image.parentNode;
            parent.insertBefore (div, image);




        }
    }

}

function initFolding()
{
	var div = document.getElementsByTagName('div'), i = 0, length = div.length;
	for (i = 0; i < length; i++) {
		if (div[i].className == 'caption' && div[i].parentNode.className == 'fold') {
			div[i].onclick = function () {
				var child = this.parentNode.firstChild;
				//alert(this.isOpen);
				if (typeof this.isOpen != 'undefined' && this.isOpen == true) {
					this.isOpen = false;
					while (child) {
						if (child.className == 'caption') { child.firstChild.innerHTML = 'Zoek criteria tonen'; child.firstChild.className = 'plus'; }
						if (child.className == 'content') { child.style.display = 'none'; }
						child = child.nextSibling;
					}
				} else {
					this.isOpen = true;
					while (child) {
						if (child.className == 'caption') { child.firstChild.innerHTML = 'Zoek criteria verbergen'; child.firstChild.className = 'minus'; }
						if (child.className == 'content') { child.style.display = 'block'; }
						child = child.nextSibling;
					}
				}
				//document.focus();
			}
		}
	}
}

EventManager.add (window, 'load', initFolding);
