/*dependency:de.datev.events*/

/*global de*/
de = this.de || {};
de.datev = de.datev || {};
de.datev.portal = de.datev.portal || {};
de.datev.portal.popup = function () {
    var thisNamespace = de.datev.portal.popup || {};

	///////////////////////////////////////////////////////
	// Funktionen
	///////////////////////////////////////////////////////

	var openWindow = function(url, name, properties)
	{
		properties = properties || "width=385,height=335,scrollbars=yes,resizable=yes";
		var datevpop = window.open(url, name, properties);
		return datevpop;
	};

	var openWindowKontakt = function(url)
	{
		var properties = "width=810,height=620,scrollbars=yes,resizable=yes,top=100,left=100";
		var datevpop = window.open(url, 'Kontakt', properties);
		return datevpop;
	};

	var openKontaktInfoPage = function(url)
	{
		var properties = "width=780,height=640,scrollbars=yes,resizable=no,status=no,toolbar=no,top=100,left=100";
		var datevpop = window.open(url, 'Kontakt', properties);
		return datevpop;
	};

	var openWindowRecommendation = function(url)
	{
		var properties = "width=790,height=620,scrollbars=no,resizable=yes,top=100,left=100";
		var datevpop = window.open(url, 'datevpop', properties);
		return datevpop;
	};

	var openWindowPrintPreview = function(url)
	{
		var properties = "width=650,height=681,scrollbars=yes,resizable=yes";
		var datevpop = window.open(url, 'datevpop', properties);
		return datevpop;
	};

	var openWindowSearch = function(url)
	{
		var properties = "width=950,height=870,scrollbars=yes,resizable=yes";
		var datevpop = window.open(url, 'popsearch', properties);
		return datevpop;
	};


	var openWindowBasket = function()
	{
		var properties = "width=600,height=456,scrollbars=yes,resizable=yes";
		var datevpop = window.open('best_wk_popup.html', 'popbasket', properties);
		return datevpop;
	};

	var openWindowNotepad = function()
	{
		var properties = "width=600,height=456,scrollbars=yes,resizable=yes";
		var datevpop = window.open('best_wk_popup.html', 'popnotepad', properties);
		return datevpop;
	};

	var openWindowPriceinfo = function(url)
	{
		var properties = "width=600,height=456,scrollbars=yes,resizable=yes";
		var datevpop = window.open(url, 'poppriceinfo', properties);
		return datevpop;
	};

	var openWindowSiteMap = function (url) {
		var properties = "width=1200,height=1000,scrollbars=yes,resizable=no";
		var datevpop = window.open(url, 'SiteMap', properties);
		return datevpop;
	};

	/*@AP20100420*/
	var openWindowIntranetImpressum = function (url) {
		var properties = "width=650,height=500,scrollbars=yes,resizable=no";
		var datevpop = window.open(url, 'Impressum', properties);
		return datevpop;
	};


	/*Flash-Demo (fuer Portal-Relaunch)*/
	var popup1 = function (url) {
		var properties = "height=500,left=100,width=780,top=100,dependent=yes,resizable=yes,location=no,menubar=no,scrollbars=no,toolbar=no,status=no";
		var datevpop1 = window.open(url, 'Popup1', properties);
		return datevpop1;
	};

	/*Internet-Lexikon*/
	var popup2 = function (url) {
		var properties = "height=500,left=100,width=780,top=100,dependent=yes,resizable=yes,location=no,menubar=no,scrollbars=no,toolbar=no,status=no";
		var datevpop2 = window.open(url, 'Popup2', properties);
		return datevpop2;
	};

	/*FAQ im Produkte-Bereich*/
	var popup3 = function (url) {
		var properties = "height=600,left=100,width=800,top=100,dependent=yes,resizable=yes,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no";
		var datevpop3 = window.open(url, 'Popup3', properties);
		return datevpop3;
	};

	/*Anmeldung zu einer Veranstaltung*/
	var popup4 = function (url) {
		var properties = "height=600,left=100,width=780,top=100,dependent=yes,resizable=yes,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no";
		var datevpop4 = window.open(url, 'Popup4', properties);
		return datevpop4;
	};

	/*Flash-Demo (fuer CeBIT 2006)*/
	var popup5 = function (url) {
		var properties = "height=600,left=100,width=800,top=100,dependent=yes,resizable=yes,location=no,menubar=no,scrollbars=no,toolbar=no,status=no";
		var datevpop5 = window.open(url, 'Popup5', properties);
		return datevpop5;
	};

	/*Screenshots 800 x 600*/
	var popup6 = function (url) {
		var properties = "height=600,left=100,width=800,top=100,dependent=yes,resizable=no,location=no,menubar=no,scrollbars=no,toolbar=no,status=no";
		var datevpop6 = window.open(url, 'Popup6', properties);
		return datevpop6;
	};
/*
  <DEPENDENT>yes</DEPENDENT>
  <HEIGHT>640</HEIGHT>
  <LEFT>100</LEFT>
  <LOCATION>no</LOCATION>
  <MENUBAR>no</MENUBAR>
  <RESIZABLE>no</RESIZABLE>
  <SCROLLBARS>yes</SCROLLBARS>
  <STATUS>no</STATUS>
  <TOOLBAR>no</TOOLBAR>
  <TOP>100</TOP>
  <WIDTH>780</WIDTH>
*/
	/*Formulare (Kontakt / E-Mail / Empfehlen)*/
	var popup7 = function (url) {
		var properties = "height=640,left=100,width=780,top=100,dependent=yes,resizable=no,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no";
		var datevpop7 = window.open(url, 'Popup7', properties);
		return datevpop7;
	};

	/*Mehrwert-CD*/
	var popup8 = function (url) {
			var properties = "height=700,left=100,width=1009,top=100,dependent=yes,resizable=yes,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no";
			var datevpop8 = window.open(url, 'Popup8', properties);
			return datevpop8;
	};

	/*Produktfinder*/
	var popup9 = function (url) {
			var properties = "height=649,left=50,width=934,top=50,dependent=yes,resizable=yes,location=no,menubar=no,scrollbars=no,toolbar=no,status=no";
			var datevpop9 = window.open(url, 'Produktfinder', properties);
			return datevpop9;
	};


	/*Popup mit flexibler Breite*/
	var popup10 = function (url) {

		var bildschirmbreite= screen.height.toString();
		var bildschirmhoehe= screen.width.toString();

		//(1) Popup Bildschirmbreite geben
		var bildPopup=window.open("","bildPopup","left=50,top=50,width="+bildschirmbreite+",height="+bildschirmhoehe+",location=no,toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes");
		bildPopup.document.writeln("<html><head><title><\/title><\/head>");
		bildPopup.document.writeln("<body>");
		bildPopup.document.writeln("<p style=\"text-align:center;\"><img src=\""+url+"\"><\/p>");
		bildPopup.document.writeln("<\/body><\/html>");

		//(2) Popup auf Bildgroesse setzen
		var bild = bildPopup.document.getElementsByTagName("img")[0];
			de.datev.events.addEvent(bild, "load", function(evt) {
			var bildLoaded = de.datev.events.getSrcElement(evt);
			de.datev.portal.popup.check(bildPopup, bildLoaded);
		});
	};
	var check = function(bildPopup, bild) {

		if (bild) {

			var hoehe = bild.height + 120;
			var breite = bild.width + 50;

			bildPopup.resizeTo(breite, hoehe);
		}
		bildPopup.document.close();
		bildPopup.focus();

		return bildPopup;
	};

	/*secure-Preisinfos (ehem. openWindowPriceinfo())*/
	var popup11 = function (url) {
			var properties = "height=456,width=600,resizable=yes,scrollbars=yes";
			var popup11 = window.open(url, 'poppriceinfo', properties);
			return popup11;
	};

	/*FAQ-Popup in den Produktbeschreibungen (ehem. openKontaktInfoPage())*/
	var popup12 = function (url) {
			var properties = "width=780,height=640,scrollbars=yes,resizable=no,status=no,toolbar=no,top=100,left=100";
			var popup12 = window.open(url, 'faq', properties);
			return popup12;
	};

	/*Popup-Typen für Formulare [START]*/
	var popup13 = function (url) {
		var properties = "width=870,height=750,scrollbars=yes,resizable=yes,status=no,toolbar=no,top=100,left=100";
		var popup13 = window.open(url, 'test', properties);
		return popup13;
	};
	var popup14 = function (url) {
			var properties = "width=820,height=660,scrollbars=yes,resizable=yes,status=no,toolbar=no,top=100,left=100";
			var popup14 = window.open(url, 'test', properties);
			return popup14;
	};
	var popup15 = function (url) {
			var properties = "width=810,height=570,scrollbars=yes,resizable=yes,status=no,toolbar=no,top=100,left=100";
			var popup15 = window.open(url, 'test', properties);
			return popup15;
	};
	/*Popup-Typen für Formulare [ENDE]*/

	var init = function() {
		var events = de.datev.events;

		// popup-Attribut-Suche nur im relevanten Contentbereich (#contentAndRightColumn)
		var coAndRc = ((document.getElementById("contentAndRightColumn")) != null) ? document.getElementById("contentAndRightColumn") : window.document;
		//Popup-Behandlung der Anchor
		var allAnchor = coAndRc.getElementsByTagName("a");
		if (allAnchor && allAnchor.length > 0) for(var j = 0; j < allAnchor.length; j++) {

			var anchor = allAnchor[j];

			var url = anchor.attributes.href.value.trim();
			var popup = anchor.getAttribute("popup");

			if (url && url.length > 0 && popup && popup.length > 0) {

				var popupId = "id"+j;
				anchor.id = popupId;
				popup = eval(popup);
				setPopupHandler(popupId, popup, url, true);

			}/*end - if (url && popup)*/
		}/*end - if (allAnchor)*/


		//ToDo: mit Anchor konsolidieren
		//Popup-Behandlung der Areas
		var allAreas = coAndRc.getElementsByTagName("area");
		if (allAreas && allAreas.length > 0) for(var j = 0; j < allAreas.length; j++) {

			var area = allAreas[j];

			if(area.attributes.href) {

				var areaUrl = area.attributes.href.value.trim();
				var areaPopup = area.getAttribute("popup");

				if (areaUrl && areaUrl.length > 0 && areaPopup && areaPopup.length > 0) {

					var areaPopupId = "id"+j;
					area.id = areaPopupId;
					areaPopup = eval(areaPopup);
					setPopupHandler(areaPopupId, areaPopup, areaUrl, true);

				}/*end - if (areaUrl && areaPopup)*/
			}/*end - if (area.attributes.href)*/
		}/*end - if (allAreas)*/


		/*Hilfeportal-Fallback*/

		//nur im Hilfeportal
		if (JS_GLOBAL_VAR_Portal && JS_GLOBAL_VAR_Portal == "dhp_de") {

			//nur im Firefox (Im IE bekommt der body aus der JSP direkt das Attribut scroll="auto")
			if(window.scrollbars && window.scrollbars.visible == false) {

				//Erneuten Aufruf des Fensters verhindern
				if(window.name != "Hilfeportal"){

					var wi = (window.innerWidth != null) ? window.innerWidth : document.documentElement.clientWidth;
					var he = (window.innerHeight != null) ? window.innerHeight : document.documentElement.clientHeight;

					var posX = window.screenX ? window.screenX : window.screenLeft;
					var posY = window.screenY ? window.screenY : window.screenTop;

					var properties = "height="+ he +
									" ,width=" + wi +
									" ,left=" + posX +
									" ,top=" + posY +
									" ,scrollbars=yes";

					var url = document.location.href;
					window.close();
					window.open(url, "Hilfeportal" , properties);

				}//end - if(!Hilfeportal)
			}//end - if(scrollbars)
		}//end - if(JS_GLOBAL_VAR_Portal)
	};


	var setPopupHandler = function(elemId, popupFunc, urlSuffix, replace) {
		var events = de.datev.events;

		var elem = document.getElementById(elemId);
		if (elem) {
			events.addEvent(elem, "click", function(evt) {
				events.preventDefault(evt);
				var url = elem.getAttribute("href");
				if (urlSuffix) {

					//urspruengliche Url ersetzen
					if(replace) {
						url = urlSuffix;
						//href-Attribut entfernen
						elem.removeAttribute("href");
					}

					else {
						url += urlSuffix;
					}

				}
				popupFunc(url);
			});
		}
	};


	var setClassPopupHandler = function(elemClass, popupFunc, urlSuffix, replace) {
		var dom = de.datev.dom;
		var events = de.datev.events;

		//vorerst nur fuer anchor-Elemente
		elems = dom.getElementsByTagAndClassName("a", elemClass);

		if(elems) for(var i=0; i<elems.length; i++) {

			var elem = elems[i];
			events.addEvent(elem, "click", function(evt) {
				events.preventDefault(evt);
				var url = elem.getAttribute("href");
				if (urlSuffix) {

					//urspruengliche Url ersetzen und...
					if(replace) {
						url = urlSuffix;
						//...href-Attribut entfernen
						elem.removeAttribute("href");
					}

					else {
						url += urlSuffix;
					}
				}
				popupFunc(url);
			});
		}
	};

    //////////////////////////////////////////////////////
    // PUBLIC
    //////////////////////////////////////////////////////
    thisNamespace.init = init;
    thisNamespace.check = check;
    thisNamespace.setPopupHandler = setPopupHandler;
    thisNamespace.setClassPopupHandler = setClassPopupHandler;

    thisNamespace.openWindow = openWindow;
    thisNamespace.openWindowKontakt = openWindowKontakt;
    thisNamespace.openKontaktInfoPage = openKontaktInfoPage;
    thisNamespace.openWindowRecommendation = openWindowRecommendation;
    thisNamespace.openWindowPrintPreview = openWindowPrintPreview;
    thisNamespace.openWindowSearch = openWindowSearch;
    thisNamespace.openWindowBasket = openWindowBasket;
    thisNamespace.openWindowNotepad = openWindowNotepad;
    thisNamespace.openWindowPriceinfo = openWindowPriceinfo;
    thisNamespace.openWindowSiteMap = openWindowSiteMap;
    thisNamespace.openWindowIntranetImpressum = openWindowIntranetImpressum; /*@AP20100420*/

    thisNamespace.popup1 = popup1;
    thisNamespace.popup2 = popup2;
    thisNamespace.popup3 = popup3;
    thisNamespace.popup4 = popup4;
    thisNamespace.popup5 = popup5;
    thisNamespace.popup5 = popup5;
    thisNamespace.popup6 = popup6;
    thisNamespace.popup7 = popup7;
    thisNamespace.popup8 = popup8;
    thisNamespace.popup9 = popup9;
    thisNamespace.popup10 = popup10;
    thisNamespace.popup11 = popup11;
    thisNamespace.popup12 = popup12;
    thisNamespace.popup13 = popup13;
    thisNamespace.popup14 = popup14;
    thisNamespace.popup15 = popup15;

    return thisNamespace;
}(); // de.datev.portal.popup

////////////////////////////////////////////////////////////////
// Ausfuehrung
////////////////////////////////////////////////////////////////
de.datev.events.addEvent(window, "load", de.datev.portal.popup.init);