function openWindow(inURL, inWindowName, inAttributes) {
    var theWindowName = inWindowName ? inWindowName : 'Popup';
    var theAttributes = inAttributes;

    if(!theAttributes) {
        theAttributes =
        'left=50,top=50,width=800,height=600,menubar=yes,status=yes,scrollbars=yes,resizable=yes';
    }
    theWindow = open(inURL, theWindowName, theAttributes);
    theWindow.focus();
    return false;
}

function openDefaultPopup(inURL, inWidth, inHeight) {
    var theWindowName = 'Popup';
    var theWidth = inWidth ? inWidth : '608';
    var theHeight = inHeight ? inHeight : '635';

    theAttributes = 'left=50,top=50,width=' + theWidth + ',height=' + theHeight + ',menubar=yes,status=yes,scrollbars=yes,resizable=yes';
    theWindow = open(inURL, theWindowName, theAttributes);
    theWindow.focus();
    return false;
}

// reference to the popup window
var winId	

//vgl Core JSF Chapter 13

// This function calls a popup window, parameteres are the hidden form 
// and the hidden command element of the hidden form.
function showPopup(form, target) {
	if (winId){
		winId.close();
	}
	features="height=470,width=425,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('','popup',features); // open an empty window
    winId.focus();

	//This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}

function openPopup(url) {
	if (winId){
		winId.close();
	}
    features="height=635,width=590,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";
	winId=window.open(url,'popup',features);
    winId.focus();
    return false;
}



// This function calls a bigger popup window, paramteres are the hidden form
// and the hidden command element of the hidden form.
function showBigPopup(form, target) {
	if (winId) winId.close();

	var action = $("#printProductDetailsHiddenForm").attr("action").split("?")[0];
	var query = "quantity=" + $(".select_quantity").val() + "&" + "article=" + $(".article").html() + "&" + "price=" + $(".price").html() + "&" + "wbVariantAttribute1=" + $(".wbVariantAttribute1").val() + "&" + "wbVariantAttribute2=" + $(".wbVariantAttribute2").val() + "&" + "wbVariantAttribute3=" + $(".wbVariantAttribute3").val() + "&" + "selected=" + $(".selected").val()
	
	$("#printProductDetailsHiddenForm").attr("action", action + "?" + escape(query));

	features="height=635,width=590,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('','popup',features); // open an empty window
    winId.focus();    

    //This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}

function showCustomPopup(form, target, popupSizeX, popupSizeY) {
	if (winId){
		winId.close();
	}
	features="height="+popupSizeY+",width="+popupSizeX+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('','popup',features); // open an empty window
    winId.focus();

    //This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}
		
function showCustomScrollbarPopup(form, target, popupSizeX, popupSizeY) {
	if (winId){
		winId.close();
	}
	features="height="+popupSizeY+",width="+popupSizeX+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes, resizable=yes";			
	winId=window.open('','popup',features); // open an empty window
    winId.focus();

	//This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}
		

function showPopupProduct(form, target) {
	if (winId){
		winId.close();
	}
	features="height=500,width=570,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('','popup',features); // open an empty window
    winId.focus();

	//This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}

function showPopupOrder(form, target) {
	if (winId){
		winId.close();
	}
	features="height=750,width=650,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes, resizable=yes";			
	winId=window.open('','popup',features); // open an empty window
    winId.focus();

	//This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}

	
function showCatalogPopup1(url) {
	if (winId){
		winId.close();
	}
	features="height=805,width=1024,status=no,toolbar=no,menubar=no,location=no,scrollbars=no, resizable=no";			
	winId=window.open(url,'popupCat',features); // open an empty window
    winId.focus();
}

function getCatalogURL(catid,pn) {
	var pn1;
	if (!catid){
		alert("katid darf nicht Null sein!");
	}
	if (!pn){
		pn1 = 1;
	}
	else{
		pn1 = pn;
	}
	var url = "/walbusch-de/onlineCatalogues/" + catid + "/index.html?onlinekatpage=" + pn1;
	return url;
}

function showCatalogPopup(id,catid,pn){
	var url = getCatalogURL(catid,pn);
	showCatalogPopup1(url);
}

function showCatalogPopupForTeaser(catid,pn){
	var url = getCatalogURL(catid,pn);
	showCatalogPopup1(url);
}
		
		



// This function calls a popup window, parameteres are the hidden form,  the hidden command element 
// of the hidden form and a multiplier which specifies how many vantageIcons shall be displayed.
function showVantageIconPopup(form, target, multiplier) {
	if (winId){
		winId.close();
	}
	if (multiplier>4) {
		multiplier=5;
	}
	var height=100+(multiplier*55);
	features="height="+height+",width=425,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('','popup',features); // open an empty window
    winId.focus();

    //This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}


function sendForm(form, target) {
	//This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}

function showCustomNamedPopup(name, form, target, popupSizeX, popupSizeY) {
	if (winId){
		winId.close();
	}
	features="height="+popupSizeY+",width="+popupSizeX+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('',name ,features); // open an empty window
    winId.focus();    

    //This is an emulation of the action link on the hidden form being clicked and submitted.
	document.getElementById(form+':'+target).onclick(null);
}


function openDetailsPopup(url, element) {
    var WINDOW_NAME = "detailPopup";
    var FEATURES = "menubar=no,scrollbars=yes,toolbar=no,resizable=yes,location=no,directories=no,status=no,width=625,height=650";

    var form = $(element).parents().map(function () {if ($(this).hasClass("product")) return this;});
    var quantity = form.find(".select_quantity").val();
    if (quantity == null || quantity == "")
        quantity = 1;
    var query = "quantity=" + quantity + "&" + "article=" + form.find(".article").html() + "&" + "price=" + form.find(".price").html() + "&" + "wbVariantAttribute1=" + form.find(".wbVariantAttribute1").val() + "&" + "wbVariantAttribute2=" + form.find(".wbVariantAttribute2").val() + "&" + "wbVariantAttribute3=" + form.find(".wbVariantAttribute3").val() + "&" + "selected=" + form.find(".selected").val();
    query = escape(query);
    url +=  "&" + query;

    var win = window.open(url, WINDOW_NAME , FEATURES);
    win.focus();
    return false;
}
function openColorViewPopup(url){
    var WINDOW_NAME = "colorViewDetail";
    var FEATURES = "menubar=no,scrollbars=yes,toolbar=no,resizable=yes,location=no,directories=no,status=no,width=394,height=470";

    var win = window.open(url, WINDOW_NAME , FEATURES);
    win.focus();
    return false;
}

function open_popup_onlinekat(url) {
    var WINDOW_NAME = "_onlinekat";
    var FEATURES = "'menubar=no,scrollbars=no,toolbar=no,resizable=yes,location=no,directories=no,status=no,width=780,height=600";

    var win = window.open(url, WINDOW_NAME , FEATURES);
    win.focus();
}

function openCalendarPopup(pageid) {
    var WIDTH       = '980';
    var HEIGHT      = '700';
    //    var WINDOW_NAME = 'CALENDAR';
    //    var FEATURES    = 'left=50,top=50,width=' + WIDTH + ',height=' + HEIGHT + ',menubar=no,scrollbars=no,toolbar=no,resizable=yes,location=no,directories=no,status=no';
    var url = 'pages/adventCalendar.jsf?pageid=' + pageid;
//    var win  = window.open(url, WINDOW_NAME, FEATURES);
//    win.focus();
    openLayer(url, WIDTH, HEIGHT);
}


function getNonLayerRootElements(){
    return $('#content');
//    return $('#header, #wrapper, #promo, #suche, #service, .clLevel0border');
}

function openLayer(url, width, height, left, top){
    getNonLayerRootElements().fadeTo("slow", ".2").bind('click', function(){
       closeLayer();
    });
    if ($('#layer').length == 0){
        var aTop = (typeof top != 'undefined') ? top : 95;
        var aLeft = (typeof left != 'undefined') ? left : 210;
        $('body').append('<iframe id="layer" style="z-index:100000000; position:absolute; top: ' + aTop + 'px; left: ' + aLeft + 'px" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" border="0" />');
    }
    $('#layer').attr('width', width);
    $('#layer').attr('height', height);
    var layer = $('#layer');
    if (layer.attr("src") != url)
        layer.attr("src", url);
    layer.fadeIn('slow');
    scrollIntoView(layer, 10);

}

function closeLayerImmediately(url){
    if(url)
        window.location.href = url;
    getNonLayerRootElements().unbind('click').fadeTo("1");
    $('#layer').fadeOut();
}

function closeLayer(url){
    if(url)
        window.location.href = url;
    getNonLayerRootElements().unbind('click').fadeTo('slow', "1");

    $('#layer').fadeOut('slow');
}

function scrollIntoView(obj, minTopSpace){
    var scrollTop = getScrollTop();
    var offsetTop = obj.offset().top;
    if (scrollTop > offsetTop){
        window.scrollTo(getScrollLeft(), offsetTop - minTopSpace);
    }
}

function getScrollTop(){
    if (window.pageYOffset) {
        return window.pageYOffset;
    } else if (document.body && document.body.scrollTop) {
        return document.body.scrollTop;
    }else if (document.documentElement.scrollTop){
        return document.documentElement.scrollTop;
    }
    return 0;
}

function getScrollLeft(){
    if (window.pageXOffset) {
        return window.pageXOffset;
    } else if (document.body && document.body.scrollLeft) {
        return document.body.scrollLeft;
    }else if (document.documentElement.scrollLeft){
        return document.documentElement.scrollLeft;
    }
    return 0;
}
