// neues Fenster zeigt die Seite mit print.css 
var printWindow;

function openPrintWindow(url, target) {
    var windowUrl = url ? url : window.location.href;
    var windowName = target ? target : "_blank";
    var windowWidth = getWinWidth(730);
    var windowHeight = getWinHeight(600);
    printWindow = window.open(windowUrl, windowName, "width=" + windowWidth + ",height=" + windowHeight + ",scrollbars,resizable,menubar,toolbar,left=0,top=0");
    printWindow.focus();    
}

function getWinWidth(favWidth) {
	var sh;
	if (!favWidth) { favWidth = 600 } // assume a window that fits in smallest common screen
    if (screen.width) {
        sw = screen.width;
    } else {
		sw = 640; // assume smallest common screen resolution
	}
	if (favWidth < sw) { // if window fits in screen
		return favWidth; // return the preferred width
					 					 } else {
		return sw - 50; // return screen width minus a padding to screen border
					 						 			}
}

function getWinHeight(favHeight) {
	var sh;
	if (!favHeight) { favHeight = 400 } // assume a window that fits in smallest common screen
    if (screen.height) {
        sh = screen.height;
    			 	 						} else {
		sh = 480; // assume smallest common screen resolution
	}
	if (favHeight < sh) { // if window fits in screen
		return favHeight; // return the preferred height
					 						} else {
		return sh - 50; // return screen height minus a padding for windows taskbar etc.
	}
}

/* Switch actual stylesheet to print and trigger print dialog if supported */
function setupPrint() {
    // hide whole body to avoid flickering while disabling and enabling the stylesheets
    document.body.style.display = "none";
    if (document.getElementsByTagName) {
        var elem;
        for(var i = 0; (elem = document.getElementsByTagName("link")[i]); i++) {
            if (elem.getAttribute("rel").indexOf("style") != -1 && elem.getAttribute("media") != "screen") {
                elem.disabled = true;
                // if link is an alternate stylesheet and has both screen and print media type
                if (elem.getAttribute("rel").indexOf("alt") != -1 && elem.getAttribute("title").indexOf("Druckvorschau") != -1) {
                    // enable stylesheet
                    elem.disabled = false;
                }
            }
        }
    }
    // show body again
    document.body.style.display = "block";
    if (window.print) {
        window.setTimeout("window.print()", 1000);
    }
}

function validateChoice(elem) {
    var isValid = true;
    if (elem && elem.type == "select-one") {
        if (elem.options[elem.selectedIndex].value == "") {
            isValid = false;
        }
    }
    return isValid;
}
