﻿function printPage() {
	var sUrl = location.href;
	sUrl += "?print=yes";
	openWindow(sUrl, "printWin", "width=800,height=600,resizable=yes,scrollbars=yes,toolbar=yes");
	return false;
}

function openWindow (strURL, strName, strOptions, bDoNotReturnWindow) {
	if (!strOptions) strOptions = "location=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,";
	else {
		//parse the strOptions variable to get width and height
		var arWidth = strOptions.match(/width=[0-9]+/i);
		var arHeight = strOptions.match(/height=[0-9]+/i);
		if (arWidth != null) {
			//Center window horizontally
			var intWidth = arWidth[0].substring(arWidth[0].lastIndexOf("=") + 1);
			var x = (screen.width - intWidth) / 2;
			x = (x<0) ? 0 : x
			strOptions += ",left=" + x;
		}
		if (arHeight != null) {
			//Center window vertically
			var intHeight = arHeight[0].substring(arHeight[0].lastIndexOf("=") + 1);
			var y = (screen.height - intHeight) / 2;
			y = (y<0) ? 0 : y
			strOptions += ",top=" + y;
		}
	}
	var popup = window.open(strURL,strName,strOptions);
	if (!bDoNotReturnWindow)
		return popup;
}



// ------------------------ sitemap ------------------------

function expListOpen(me) {
	var listBelow = me.parentNode.parentNode.getElementsByTagName('ul');
	if (me.className != 'expButton_open') {
		me.className = 'expButton_open';
		listBelow[0].style.display = 'none';
	} else {
		me.className = 'expButton_close';
		listBelow[0].style.display = 'block';
	}
}

function getObj (strLayer) {
	if(typeof(strLayer) == "object") return strLayer;
	var elmLayer = document.getElementById(strLayer);
	if (!elmLayer)
		elmLayer = document.getElementsByName(strLayer)[0];
	return elmLayer;
}

function setStyle(arElements, sProperty, sValue) {
	arElements = (arElements.length && typeof arElements != "string") ? arElements : [arElements];
	for (var i=0; i<arElements.length; i++) {
		var elm = getObj(arElements[i]);
		if (elm)
			elm.style[sProperty] = sValue;
	}
}

function getH (strLayer) {
	if (!(elmLayer=getObj(strLayer)))
		return false;
	if (window.getComputedStyle) {
		var style=getComputedStyle(elmLayer, null);
		return parseInt(style.getPropertyValue('height'));
	}
	else if (elmLayer.style.pixelHeight)
		return elmLayer.style.pixelHeight;
	else if(elmLayer.offsetHeight)
		return elmLayer.offsetHeight;
}

function getElementsByAttribute (strAttribute, strSearchValue, elmLayer, strTagName, bPartialMatch) {
	strTagName = strTagName || "*";
	elmLayer = getObj(elmLayer) || document;

	var arAllElements = elmLayer.getElementsByTagName(strTagName);
	var arElements = [];
	for (var i=0; i<arAllElements.length; i++) {
		var sAttrValue = arAllElements[i].getAttribute(strAttribute);
		if ((strAttribute == "class" && (arAllElements[i].className == strSearchValue || (bPartialMatch && arAllElements[i].className.indexOf(strSearchValue) > -1))) || 
			(strSearchValue && (sAttrValue == strSearchValue || (sAttrValue && sAttrValue.indexOf(strSearchValue) > -1))) ||
			(!strSearchValue && sAttrValue)) {
				arElements.push(arAllElements[i]);
		}
	}
	return arElements.slice(0);
}

// ------------------------ handler for expanding/contracting list items ------------------------
// Get an element by the class name
function getElementsByClassName(clsName, root) 
{
    var retVal = new Array();
    var elements = root.getElementsByTagName("*");
    for (var i = 0; i < elements.length; i++) 
    {
        if (elements[i].className.indexOf(" ") >= 0) 
        {
            var classes = elements[i].className.split(" ");
            for (var j = 0; j < classes.length; j++) 
            {
                if (classes[j] == clsName) 
                {
                    retVal.push(elements[i]);
                }
            }
        }
        else 
        {
            if (elements[i].className == clsName) 
            {
                retVal.push(elements[i]);
            }
        }
    }  
    return retVal;
}

// Elems flagged with class "show" will get class "hide"
// Elements with "hide" in current element will get "show"
function ExpandListItem(me) 
{
    if (getElementsByClassName("show", me).length > 0) 
    {
        // The item in question is already shown
        return;
    }
    
    // All sub items of the current item that are hidden should be shown
    var itemsToShowList = getElementsByClassName("hide", me);

    // Get a parent item that is the root of the items to hide
    var root = me.parentNode;
    // Find all visible items below the root
    var itemsToHideList = getElementsByClassName("show", root); 
    for (var i = 0; i < itemsToHideList.length; i++)
    {
        var itemToHide = itemsToHideList[i];
        itemToHide.className = itemToHide.className.replace("show", "hide");
    }
    
    for (var j = 0; j < itemsToShowList.length; j++)
    {
        var itemToShow = itemsToShowList[j];
        itemToShow.className = itemToShow.className.replace("hide", "show");
    }
}

