/*
	ZKS $Id: scripts.js 1066 2008-04-14 09:24:01Z silvan.thiele@de.ibm.com $
	JavaScripts fuer ZKS
*/

// START: global ZKS package ==================================================
if(typeof zks == "undefined"){
	if(typeof this["zks"] == "undefined"){
		this.zks = {};
	}
	zks.global = this;
}
// END: global ZKS package


/* START: Flyout Menue */
zks.topnav = {
	navhor: "zks_mnnav_list", // id of main navigation top ul element
	active: "zks_act", // class for active tab
	leftClass: "zks_iehover", // class for internet explorer, li:hover substitution class for left aligned flyout
	rightClass: "zks_prf", // class for right aligned flyout menu for internet explorer 
	navheight: "2.3em", // top position for iframe to be placed
	
	/**
	 * adds an invisible iframe under the flyout ul of the main navigation to cover windowed elements in IE 
	 * @param {Node} navelement   - container element of main navigation
	 * @param {String} posleft - left position to place iframe
	 * @param {String} posright   - right position to place iframe
	 */
	addIframe: function(navelement,posleft,posright) {
		if (navelement.getElementsByTagName("ul").length) {
			var icover = navelement.lastChild;
	
			if (!(icover) || (icover.tagName != "IFRAME")) {
				navelement.lastChild.insertAdjacentHTML("afterEnd","<iframe src='javascript:false' longdesc='no content' scrolling='no' frameborder='0' style='display:none;'></iframe>");
				icover = navelement.lastChild;
			}
			var icstyle = icover.style;
			icstyle.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
			icstyle.position = "absolute";
			icstyle.top = this.navheight;
			icstyle.right = posright;
			icstyle.left = posleft;
			var ul = navelement.getElementsByTagName("UL");
			icstyle.width = ul[0].clientWidth +2;
			icstyle.height = ul[0].clientHeight;
			icstyle.zIndex = "499";
			icstyle.display = "block";
		}
	},
	
	/**
	 * hides invisible iframe under the flyout ul of the main navigation
	 * @param {Node} obj - element containing the iframe, usually the LI main element containing the protected UL 
	 */
	killIframe: function(obj) {
		var icover = obj.lastChild;
		if (icover && icover.tagName == "IFRAME") {
			icover.style.display = "none";
		}
	},
	
	/**
	 * appends menu functionality on all menu items, substitutes the li:hover effect for IE
	 */
	sfHover: function() {
		var navHorElem = dojo.byId(this.navhor);
		if (!navHorElem) return;
		var sfEls = navHorElem.childNodes;
		dojo.forEach(sfEls, function(navEl) {
			navEl.onmouseenter=function() {
				dojo.addClass(this, zks.topnav.leftClass);
				dojo.hasClass(this,zks.topnav.rightClass) ? zks.topnav.addIframe(this, "auto", "-1px") : zks.topnav.addIframe(this, "0", "auto");
			}
			navEl.onmouseleave=function() {
				dojo.removeClass(this, zks.topnav.leftClass);
				zks.topnav.killIframe(this);
			}
		});
	},
	
	/**
	 * menu initialization
	 */
	initMenu: function () {
		if (dojo.isIE && dojo.isIE<7) {
			this.sfHover();
		}
		
		// verhindert click auf 1st level, da dahinter keine Seiten liegen
		dojo.query("ul#zks_mnnav_list > li > a").onclick(function(evt){
		    dojo.stopEvent(evt);
		});
		
		/* Entfernt die open Klasse, die beim IE6 (ohne js) dafür sorgt, das ein SubMenue erscheint */
		var openTag = dojo.query(".zks_open", dojo.byId("zks_mnav"));
		dojo.forEach(openTag, 
					function(openTagItem) {
						dojo.removeClass(openTagItem, "zks_open");
					});
		/* Entfernt die zks_mnav_drp Klasse, die beim IE6 (ohne js) dafür sorgt, das ein SubMenue erscheint */
		var mnavTag = dojo.query(".zks_mnav_drp", dojo.byId("zks_mnav"));
		dojo.forEach(mnavTag, 
					function(mnavTagItem) {
						dojo.removeClass(mnavTagItem, "zks_mnav_drp");
					});
		var noscriptTag = dojo.query(".zks_mnav_noscript", document);
		dojo.forEach(noscriptTag, 
					function(noscriptTagItem) {
						dojo.removeClass(noscriptTagItem, "zks_mnav_noscript");
					});
	}
};
/* END: Flyout Menue */

// START: Font Size Settings ==================================================
zks.fontset = {
	cookieName: "zks_fontsize",
	pref: 77, // size preference default
	defPc: 1.1, // scale parameter
	bigObj: new Object(), // "+" button
	smallObj: new Object(), // "-" button
	cookieProps: {expires:365, path:"/", domain:""},
	
	/* init the font size buttons */
	init: function(obj) {
		//console.info("cookie1=" + this.getPref());
		if(this._getPref()!=null) this.pref=this._getPref(); // if a cookie value exists, then read the value
		this._setPref(this.pref);
		
		if(!obj) return; // head2 has no "+","-" buttons
		if(!obj.bigId || !obj.smallId) return; // "+","-" buttons have wrong ID
		this.bigObj = dojo.byId(obj.bigId);
		this.smallObj = dojo.byId(obj.smallId);
		dojo.connect(this.bigObj, 'onclick', this, "_setBig");
		dojo.connect(this.smallObj, 'onclick', this, "_setSmall");
	},
	
	_setBig: function(evt) {
		this.pref = Math.round(this.pref * this.defPc);
		this._setPref(this.pref);
	},
	
	_setSmall: function(evt) {
		this.pref = Math.round(this.pref / this.defPc);
		this._setPref(this.pref);
	},
	
	_setPref: function(val) {
		dojo.cookie(this.cookieName, val, this.cookieProps);
		dojo.style(dojo.body(), "fontSize", val+"%");
		console.info("FontSize cookie=" + this._getPref() + "%");
	},
	
	_getPref: function() {
		return dojo.cookie(this.cookieName);
	}
};
// END: Font Size Settings

// START: ZKS Popups ==================================================
dojo.declare("zks.popup", null, {
	wObj: null,
	h: 500,
	w: 400,
	t: 50,
	l: 50,
	
	// initialization function
	constructor: function(obj){
		 this.w = obj.w;
		 this.h = obj.h;
		 this.t = obj.t;
		 this.l = obj.l;
	},
	
	open: function(src) {
		if (this.wObj!=null && !this.wObj.closed) {
			this.wObj.location.href = src;
			this.wObj.focus();
		} else {
			this.wObj = window.open(src, "_blank", "width=" +this.w+ ",height=" +this.h+ ",top=" +this.t+ ",left=" +this.l+ ",toolbar=no,scrollbars=yes,resizable=yes,menubar=no,location=no,dependent=no");
			this.wObj.focus();
		}
	}
});

// only 3 types of popup windows
zks.popPrint = new zks.popup({w:960, h:600, t:50, l:50});
zks.popHelp = new zks.popup({w:730, h:500, t:50, l:50});
zks.popHelp2 = new zks.popup({w:990, h:600, t:50, l:50});

// END: ZKS Popups

// START: Button confirm dialogs ==================================================
zks.btnaction = {
	btnEl: new Array(), // all the buttons in an assoziative array, counter is buttonID
	dialogTxt: new Array(), // all the wordings in an assoziative array, counter is buttonID
	
	init: function(obj) {
		if(!obj) return;
		if(!dojo.byId(obj.btnid)) return; // button exists?
		if(!obj.dialogAct || obj.dialogAct!=1) return; // dialog enabled?
		
		this.btnEl[obj.btnid] = dojo.byId(obj.btnid);
		this.dialogTxt[obj.btnid] = obj.dialogTxt;
		dojo.connect(this.btnEl[obj.btnid], 'onclick', this, "_confirm");
	},
	
	_confirm: function(evt) {
		//console.info("evt.target.id=" + evt.target.id);
		var agree = confirm(this.dialogTxt[evt.target.id]);
		if(agree) return true;
		else dojo.stopEvent(evt); // stop the click event
	},
	
	initEpost: function(obj) {
		if(!obj) return;
		if(!dojo.byId(obj.tblid)) return; // table exists?
		if(!obj.dialogAct || obj.dialogAct!=1) return; // dialog enabled?
		this.dialogTxt['tblEl'] = obj.dialogTxt;
		
		dojo.query("a.zks_cntlnk_downl").forEach(
			function(lnkEl) {
				//console.info("lnkEl=" + lnkEl);
				dojo.connect(lnkEl, 'onclick', zks.btnaction, "_confirmEpost");
			}
		);
	},
	
	_confirmEpost: function(evt) {
		var agree = confirm(this.dialogTxt['tblEl']);
		if(agree) return true;
		else dojo.stopEvent(evt); // stop the click event
	}
}
// END: Button confirm dialogs

// === init pageonload behaviours ===================================================

/* START: IE-Hover for Form Tabs et al. */
/* More Information on the Dojo-Stunts:
 * 		http://redesign.dojotoolkit.org/?q=jsdoc/dojo/HEAD/object/dojo.query
 * 		http://redesign.dojotoolkit.org/?q=jsdoc/dojo/HEAD/object/dojo.forEach
 */
dojo.addOnLoad(
    function(){
		if (dojo.isIE && dojo.isIE<7) { // class "zks_tabs" is only used for js-funtions
			var inputTag = dojo.query(".zks_tabs input[type='submit']", document);
			dojo.forEach(inputTag, function(inputTagItem) {
				inputTagItem.onmouseenter=function() {
					dojo.addClass(this, "zks_formtabs_ie_hover");
				};
				inputTagItem.onmouseleave=function() {
					dojo.removeClass(this, "zks_formtabs_ie_hover");
				};
			});
		}
    }
);
/* END: IE-Hover for Form Tabs et al. */

/* START: IE-Hover for Buttons et al. */
dojo.addOnLoad(
    function(){
		if (dojo.isIE && dojo.isIE<7) {
			var inputTag1 = dojo.query("input.zks_btn1", document);
			var inputTag2 = dojo.query("input.zks_btn2", document);
			var inputTag = inputTag1.concat(inputTag2);
			dojo.forEach(inputTag, function(inputTagItem) {
				inputTagItem.onmouseenter=function() {
					dojo.addClass(this, "zks_btn_hover");
				};
				inputTagItem.onmouseleave=function() {
					dojo.removeClass(this, "zks_btn_hover");
				};
			});
			
			inputTag1 = dojo.query("input.zks_btn1_arrow", document);
			inputTag2 = dojo.query("input.zks_btn2_arrow", document);
			inputTag = inputTag1.concat(inputTag2);
			dojo.forEach(inputTag, function(inputTagItem) {
				inputTagItem.onmouseenter=function() {
					dojo.addClass(this, "zks_btn_arrow_hover");
				};
				inputTagItem.onmouseleave=function() {
					dojo.removeClass(this, "zks_btn_arrow_hover");
				};
			});
			
			inputTag1 = dojo.query("input.zks_btn1_tick", document);
			inputTag2 = dojo.query("input.zks_btn2_tick", document);
			inputTag = inputTag1.concat(inputTag2);
			dojo.forEach(inputTag, function(inputTagItem) {
				inputTagItem.onmouseenter=function() {
					dojo.addClass(this, "zks_btn_tick_hover");
				};
				inputTagItem.onmouseleave=function() {
					dojo.removeClass(this, "zks_btn_tick_hover");
				};
			});
			
			inputTag1 = dojo.query("input.zks_btn1_no_tick", document);
			inputTag2 = dojo.query("input.zks_btn2_no_tick", document);
			inputTag = inputTag1.concat(inputTag2);
			dojo.forEach(inputTag, function(inputTagItem) {
				inputTagItem.onmouseenter=function() {
					dojo.addClass(this, "zks_btn_no_tick_hover");
				};
				inputTagItem.onmouseleave=function() {
					dojo.removeClass(this, "zks_btn_no_tick_hover");
				};
			});

			inputTag = dojo.query("input.zks_btn3", document);
			dojo.forEach(inputTag, function(inputTagItem) {
				inputTagItem.onmouseenter=function() {
					dojo.addClass(this, "zks_btn3_hover");
				};
				inputTagItem.onmouseleave=function() {
					dojo.removeClass(this, "zks_btn3_hover");
				};
			});
		}
		/* Fuegt den kleinen Teasern vor Login einen onmouseover und onclick hinzu. */
		teavlTag = dojo.query(".zks_tea_kl_vlog", document);
		dojo.forEach(teavlTag, function(teavlTagItem) {
			teavlTagItem.onmouseover=function() {
				dojo.addClass(this,"zks_tea_onclick");
			};
			teavlTagItem.onmouseout=function() {
				dojo.removeClass(this,"zks_tea_onclick");
			};
			teavlTagItem.onclick=function() {
				window.location.href = dojo.query("a.zks_lnk_arr_1",this);
			}
		});
    }
);
/* END: IE-Hover for Form Tabs et al. */
