/*  Pup Settings Object
 *  (c) 2008 Polder Knowledge
 *--------------------------------------------------------------------------*/
var pup = {
	settings:{
		ajax_index_location: "ajax/index_ajax.php",
		language:"nl"
	},
	scriptsonload:{
		windowonloadevents:new Array(),
		execute:function(){
			for(var i = 0;i < pup.scriptsonload.windowonloadevents.length;i++){
				eval(pup.scriptsonload.windowonloadevents[i]);
			}
		},
		add:function(p_oFunction){
			pup.scriptsonload.windowonloadevents[pup.scriptsonload.windowonloadevents.length] = p_oFunction;
		}
	},
	scriptsunload:{
		windowunloadevents:new Array(),
		execute:function(){
			for(var i = 0;i < pup.scriptsunload.windowunloadevents.length;i++){
				eval(pup.scriptsunload.windowunloadevents[i]);
			}
		},
		add:function(p_oFunction){
			pup.scriptsunload.windowunloadevents[pup.scriptsunload.windowunloadevents.length] = p_oFunction;
		}
	}
}

var viewport = {
	setiframeheightmax:function(p_sIframeId){
		iframe = $(p_sIframeId);

		// Check DOM or IE
		if(iframe.contentDocument){
			iframe_content = iframe.contentDocument;
		}else if(iframe.contentWindow){
			iframe_content = iframe.contentWindow.document;
		}
		//alert(iframe_content.body.scrollHeight);
		iframe.style.height = iframe_content.body.scrollHeight+'px';
	},
	seteditor:function(p_sTextAreaId){
		oFCKeditor = new FCKeditor(p_sTextAreaId);
		oFCKeditor.BasePath = "libraries/fckeditor/";
		oFCKeditor.Config["SmileyPath"]="/userfiles/smiley/msn/";
		oFCKeditor.ToolbarSet = "Default";
		oFCKeditor.Height = '250';
		oFCKeditor.Width = "100%";
		oFCKeditor.Skin = "silver";
		oFCKeditor.ReplaceTextarea();
	},
	dialog:{
		create:function(p_sDialogSource){
			var sizes = viewport.getPageSize();
			docheight = sizes[1];
			docwidth = sizes[0];
			
			transparant_layer = document.createElement("div");
			transparant_layer.id = "transparant_layer";
			transparant_layer.style.position = "absolute";
			transparant_layer.style.top = 0;
			transparant_layer.style.left = 0;
			transparant_layer.style.height = docheight +"px";
			transparant_layer.style.width = docwidth+"px";
			transparant_layer.className = "transparant_layer";
			document.body.appendChild(transparant_layer);
	
			popup_dialog = document.createElement("div");
			popup_dialog.id = "popup_dialog";
			popup_dialog.name = "popup_dialog";
			popup_dialog.className = "popup_dialog";
 			popup_dialog.style.position = "absolute";
 			popup_dialog.style.zIndex = "10001";
 			popup_dialog.style.height = this.winheight+"px";
 			popup_dialog.style.width = this.winwidth+"px";
 			popup_dialog.style.top = (sizes[3]/2-this.winheight/2) + "px";
			popup_dialog.style.left = (sizes[2]/2-this.winwidth/2) + "px";
			popup_dialog.innerHTML = '<div id="popup_dialog_header" class="box_header">Title</div><div id="popup_dialog_content"><iframe name="popup_dialog_iframe" id="popup_dialog_iframe" src="'+p_sDialogSource+'" frameborder="0" scrolling="no"></iframe></div><div id="popup_dialog_bottom"></div>';
			document.body.appendChild(popup_dialog);
			$('popup_dialog_iframe').height = (this.winheight - 54)+"px";
			viewport.button.create('popup_dialog_bottom', 'popup_button_cancel', 'Annuleren', 'buttons', 'viewport.dialog.destroy();');
// 			popup_dialog = document.createElement("iframe");
// 			popup_dialog.id = "popup_dialog";
// 			popup_dialog.name = "popup_dialog";
// 			popup_dialog.style.position = "absolute";
// 			popup_dialog.style.zIndex = "10001";
// 			popup_dialog.style.height = this.winheight+"px";
// 			popup_dialog.style.width = this.winwidth+"px";
// 			popup_dialog.style.top = ( sizes[3]/2-this.winheight/2) + "px";
// 			popup_dialog.style.left = ( sizes[2]/2-this.winwidth/2) + "px";
// 			popup_dialog.style.border ="0px";
// 			popup_dialog.frameBorder= "0px";
// 			popup_dialog.src = p_sDialogSource;
// 			document.body.appendChild(popup_dialog);
		},
		add_button:function(){
			
		},
		destroy:function(){
			document.body.removeChild($("popup_dialog"));
			document.body.removeChild($("transparant_layer"));
		},
		winwidth: 400,
		winheight: 400
	},
	tabs:{ // add and remove tabs from menu.
		containerids: new Array(),
		add:function(p_sMenuId, p_ContainerId, p_sTabId, p_sTabTitle, p_sTabUrl, p_sLoadScripts, p_sClickScripts){
			l_oTabContainer = ($(p_sMenuId).getElementsByTagName("ul")[0]!=undefined)?($(p_sMenuId).getElementsByTagName("ul")[0]):(document.createElement("ul"));
			l_oTab = document.createElement("li");
			l_oTab.id = p_sTabId;
			l_oTab.className= ($(p_sMenuId).getElementsByTagName("li").length==0)?("selected"):("");
			l_oTabAction = document.createElement("a");
			l_oTabAction.href = p_sTabUrl;

			l_oTabAction.onclick = function(){viewport.tabs.show(p_sTabId, this.href, p_ContainerId); return false;};
			l_oTabAction.innerHTML = p_sTabTitle;

			l_oTab.appendChild(l_oTabAction);
			l_oTabContainer.appendChild(l_oTab);
			$(p_sMenuId).appendChild(l_oTabContainer);
			if($(p_sMenuId).getElementsByTagName("li").length == 1){
				this.show(p_sTabId, p_sTabUrl, p_ContainerId);
			}
			if(p_sLoadScripts != ''){
				this.ontabloaded.add(p_sTabId, p_sLoadScripts);
			}
			if(p_sClickScripts != ''){
				this.ontabclicked.add(p_sTabId, p_sClickScripts);
			}
		},
		remove:function(p_sId){
			if($(p_sId) != null){
				$(p_sId).parentNode.removeChild($(p_sId));
				if(viewport.tabs.containerids.in_array(p_sId+"_container_div")){
					$(p_sId+"_container_div").parentNode.removeChild($(p_sId+"_container_div"));
					viewport.tabs.containerids.remove(p_sId+"_container_div");
				}
			}
		},
		remove_all:function(p_sId){
			if($(p_sId) != null){
				menu_tabs = $(p_sId).getElementsByTagName("li");
				for(var n=menu_tabs.length;n>0;n--){
					this.remove(menu_tabs[menu_tabs.length-1].id);
				}
			}
		},
		show:function(p_sId, p_sUrl, p_sTarget){
			var l_oMenuitems = $(p_sId).parentNode;
			var l_oMenutabs = l_oMenuitems.getElementsByTagName("li");
			for(var i = 0;i < l_oMenutabs.length; i++){
				l_oMenutabs[i].className = (l_oMenutabs[i].id == p_sId)?("selected"):("");
			}
			if(!viewport.tabs.containerids.in_array(p_sId+"_container_div")){
				l_oTabContent = document.createElement("div");
				l_oTabContent.id = p_sId+"_container_div";
				$(p_sTarget).appendChild(l_oTabContent);
				new Ajax.Updater(p_sId+"_container_div", p_sUrl, {
					method: "post", 
					onComplete:function(t){
						viewport.tabs.containerids.push(p_sId+"_container_div");
						viewport.tabs.ontabloaded.execute(p_sId);
						viewport.tabs.ontabclicked.execute(p_sId);
						viewport.tabs.changetab(p_sId, p_sUrl, p_sTarget);
					}
				});
			}else{
				
				this.ontabclicked.execute(p_sId);
				this.changetab(p_sId, p_sUrl, p_sTarget);
			}
			
			
		},
		changetab:function(p_sId, p_sUrl, p_sTarget){
			for(var i = 0;i < $(p_sTarget).childNodes.length;i++){
				$(p_sTarget).childNodes[i].className = ($(p_sTarget).childNodes[i].id == p_sId+"_container_div")?("show"):("noshow");
			}
		},
		ontabloaded:{
			tabloaded_array:{},
			execute:function(p_sTabId){
				if(this.tabloaded_array[p_sTabId] != undefined){
					eval(this.tabloaded_array[p_sTabId]);
				}
			},
			add:function(p_sTabId, p_sScripts){
				this.tabloaded_array[p_sTabId] = p_sScripts;
			}
		},
		ontabclicked:{
			tabclicked_array:{},
			execute:function(p_sTabId){
				if(this.tabclicked_array[p_sTabId] != undefined){
					eval(this.tabclicked_array[p_sTabId]);
				}
			},
			add:function(p_sTabId, p_sScripts){
				this.tabclicked_array[p_sTabId] = p_sScripts;
			}
		}
	},
	button:{
		create:function(p_sContaierId, p_sButtonId, p_sButtonText, p_sButtonClass, p_oAction){
			new_button = document.createElement("input");
			new_button.type = 'submit';
			new_button.id = p_sButtonId;
			new_button.value = p_sButtonText;
			new_button.className = p_sButtonClass;
			new_button.onclick = function(){eval(p_oAction); return false;};
			$(p_sContaierId).appendChild(new_button);
		},
		remove:function(p_sButtonId){
			if($(p_sButtonId) != null){
				$(p_sButtonId).parentNode.removeChild($(p_sButtonId));
			}
		},
		remove_all:function(p_sButtonsContainerId){
			var bar_buttons = $(p_sButtonsContainerId).getElementsByTagName("input");
			for(var i=bar_buttons.length;i>0;i--){
				if(bar_buttons[bar_buttons.length-1].type =="submit")
				this.remove(bar_buttons[bar_buttons.length-1].id);
			}
		}
	},
	setstatusmenu:function(p_iObjectId,p_sMessage,p_iTimeout, p_bIsError){
		if(p_bIsError){
			$(p_iObjectId).innerHTML = '<div class="error_message">'+p_sMessage+'</div>';
		}else{
			$(p_iObjectId).innerHTML = '<div class="message">'+p_sMessage+'</div>';
		}
		obj = $(p_iObjectId);
		setTimeout('obj.innerHTML=""',(p_iTimeout)?(p_iTimeout):(1000));
	},
	block:{
		blocked_block:new Array(),
		findPos:function(obj){
			var curleft = curtop = 0;
			if (obj.offsetParent) {
				do {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
				} while (obj = obj.offsetParent);
				return [curtop,curleft];
			}
		},
		enable_all:function(){
			for(i=0;i<this.blocked_block.length;i++){
				$(this.blocked_block[i]).parentNode.removeChild($(this.blocked_block[i]));
				this.blocked_block.shift();
			}
		},
		disable:function(p_sBlockId){
			var left = this.findPos($(p_sBlockId))[1];
			var top = this.findPos($(p_sBlockId))[0];
			transparant_layer = document.createElement("div");
			transparant_layer.id = p_sBlockId+"_disable_layer";
			transparant_layer.style.position = "absolute";
			transparant_layer.style.top = top+"px";
			transparant_layer.style.left= left+"px";
			transparant_layer.style.height = ($(p_sBlockId).clientHeight != 0 ? $(p_sBlockId).clientHeight : $(p_sBlockId).offsetHeight )+"px";
			transparant_layer.style.width = ($(p_sBlockId).clientWidth !=0? $(p_sBlockId).clientWidth : $(p_sBlockId).offsetWidth) +"px";
			transparant_layer.className = "transparant_layer";
			this.blocked_block.push(p_sBlockId+"_disable_layer");
			document.body.appendChild(transparant_layer);
		}
	},
	getPageSize:function(){
	
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
	
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}
}

window.onload = pup.scriptsonload.execute;
window.onbeforeunload = pup.scriptsunload.execute;