/*global de*/
de = this.de || {};
de.datev = de.datev || {};
de.datev.portal = de.datev.portal || {};
de.datev.portal.container = function () {
    var thisNamespace = de.datev.portal.container || {};


	// zentrale Variablen
	var anwUrlParams = {};
	var portalKontaktFormularUrl;
	var portalEmpfehlenFormularUrl;


	/////////////////////////////////////////////////////
	//(A) Daten (Url, Kontakt, Thema) aus der Anwendung
	/////////////////////////////////////////////////////
	var setAnwParameter = function (urlParam, themaParam, mailtoParam) {

		if(urlParam) {
			anwUrlParams.url = urlParam;
		}
		if(themaParam) {
			anwUrlParams.thema = themaParam;
		}
		if(mailtoParam) {
			anwUrlParams.mailto = mailtoParam;
		}
		//vorerst aus den Anwendungen fix die Position contentfooter festlegen
		anwUrlParams.linkpos = "contentfooter";
	};

	var getAnwParameter = function() {
		return anwUrlParams;
	};


	/////////////////////////////////////////
	//(B) Daten (FormularUrls) aus dem Portal
	/////////////////////////////////////////

	//(B.1) Portal-Url zum Kontaktformular
	//obligatorisch: url, thema, mailto

	//z.B: (http://www2.datev.de/dpiforms/ShowForm.do?formid=2002
	//&country=DE
	//&linkpos=contentfooter|rechtespalte
	//&zg=zielgruppe
	//&thema=[noch zu ersetzen (Default aus JSP: Titel der Ressource)]
	//&url=[noch zu ersetzen (Default aus JSP: Url der Ressource)]
	//&mailto=[noch zu ersetzen (Default aus JSP: info@datev.de)])
	var setKontaktFormularUrl = function (kontaktFormularUrl) {

		//Dummy
		//kontaktFormularUrl = "http://www2.datev.de/dpiforms/ShowForm.do?formid=2002&country=DE&thema=Anwendung&url=DefaultUrl&mailto=info@datev.de&linkpos=";
		portalKontaktFormularUrl = kontaktFormularUrl;
	};

	var getKontaktFormularUrl = function () {
		return portalKontaktFormularUrl;
	};


	//(B.2) Portal-Url zum Empfehlenformular
	//obligatorisch: url, thema

	//z.B: (http://www2.datev.de/dpiforms/ShowForm.do?formid=2001
	//&country=DE
	//&linkpos=contentfooter|rechtespalte
	//&zg=zielgruppe
	//&thema=[noch zu ersetzen, Default: Ressourcetitel]
	//&url=[noch zu ersetzen, Default: contentUrl bzw. NavKnotenUrl])
	var setEmpfehlenFormularUrl = function (empfehlenFormularUrl) {
		//Dummy
		//empfehlenFormularUrl = "http://www2.datev.de/dpiforms/ShowForm.do?formid=2001&country=DE&linkpos=&thema=Anwendung&url==DefaultUrl";
		portalEmpfehlenFormularUrl = empfehlenFormularUrl;
	};

	var getEmpfehlenFormularUrl = function () {
		return portalEmpfehlenFormularUrl;
	};


	//////////////////////////////////////
	//(B) Anweisung fuer die Anwendung
	//////////////////////////////////////

	//(B.1) aktuelle Schrift im Portal
	var anwendungBekommtSchrift = function () {
		return de.datev.portal.fontsize.getFontSize();
	};

	/////////////////////////////////////
	//(C) Anweisungen fuer das Portal
	////////////////////////////////////

	//(C.1) aktuelle Hoehe der Anwendung
	var portalBekommtHoehe = function (hoehe) {
		var iframe = document.getElementById("anwendung");

		if (iframe && hoehe) {

			iframe.style.height = parseInt(hoehe) + "px";

			//Fallback-Scrollverhalten ("auto") abschalten
			iframe.scrolling = "no";

			//Background-Dummy fuer Anwendungen ausschalten (wenn Anwendung eigenen Footer verwendet)
			/*var contentfooter= document.getElementById("contentFooter");
			if(!contentfooter) {
				var background= document.getElementById("contentAndRightColumn");
				background.style.backgroundImage = "none";
			}*/
		}
	};

	//(C.2) aktuelle Schriftgroesse der Anwendung
	var portalBekommtSchrift = function (schrift) {
		de.datev.portal.fontsize.setFontSize(schrift);
	};

	//(C.3) AdserverId der Anwendung
	var portalBekommtAdserverId = function () {
		//vorerst zurueckgestellt
	};


	//(C.4) Wunsch der Anwendung, das portaleigene Kontaktformular aufzurufen
	//obligatorisch: mailto, url
	//optional: thema, url, linkpos
	var openPortalKontaktFormular = function(url, thema, mailto) {

		var kontaktFormularUrl = getKontaktFormularUrl();

		// Parameter aktualisieren, wenn welche mit der Methode mitgekommen sind
		if(url || thema || mailto ) {
			setAnwParameter(url, thema, mailto);
		}

		//Default-Url auf jeden Fall aktualisieren und Formular aufrufen
		kontaktFormularUrl = de.datev.replaceUrlParameter(kontaktFormularUrl, getAnwParameter());
		return de.datev.portal.popup.openWindowKontakt(kontaktFormularUrl);
	};


	//(C.5) Wunsch der Anwendung, das portaleigene Empfehlenformular aufzurufen
	//obligatorisch: url
	//optional: thema, linkpos
	var openPortalEmpfehlenFormular = function(url, thema) {

		var empfehlenFormularUrl = getEmpfehlenFormularUrl();

		//Parameter aktualisieren, wenn welche mit der Methode mitgekommen sind
		if(url || thema ) {
			setAnwParameter(url, thema);
		}

		//Default-Url auf jeden Fall aktualisieren und Formular aufrufen
		empfehlenFormularUrl = de.datev.replaceUrlParameter(empfehlenFormularUrl, getAnwParameter());
		return de.datev.portal.popup.openWindowRecommendation(empfehlenFormularUrl);
	};

	///////////////////////////////////////////////////////
	// Ausfuehrung
	///////////////////////////////////////////////////////
	var init = function() {

		//DATEN
		window.top.setAnwParameter = setAnwParameter;
		window.top.getAnwParameter = getAnwParameter;

		window.top.setKontaktFormularUrl = setKontaktFormularUrl;
		window.top.getKontaktFormularUrl = getKontaktFormularUrl;
		window.top.setEmpfehlenFormularUrl = setEmpfehlenFormularUrl;
		window.top.getEmpfehlenFormularUrl = getEmpfehlenFormularUrl;

		//AKTIONEN
		window.top.anwendungBekommtSchrift = anwendungBekommtSchrift;

		window.top.portalBekommtHoehe = portalBekommtHoehe;
		window.top.portalBekommtSchrift = portalBekommtSchrift;
		window.top.portalBekommtAdserverId = portalBekommtAdserverId;

		window.top.openPortalKontaktFormular = openPortalKontaktFormular;
		window.top.openPortalEmpfehlenFormular = openPortalEmpfehlenFormular
	}();


    //////////////////////////////////////////////////////
    // PUBLIC
    //////////////////////////////////////////////////////
    thisNamespace.getAnwParameter = getAnwParameter;

	thisNamespace.setKontaktFormularUrl = setKontaktFormularUrl;
	thisNamespace.getKontaktFormularUrl = getKontaktFormularUrl;
	thisNamespace.setEmpfehlenFormularUrl = setEmpfehlenFormularUrl;
	thisNamespace.getEmpfehlenFormularUrl = getEmpfehlenFormularUrl;

    return thisNamespace;
}(); // de.datev.portal.container



