//*********************************************************************************
// DOJO REQUIRE
//*********************************************************************************
dojo.require("dojo.parser");
dojo.require("dijit.Dialog");
dojo.require("dijit.form.Form");
dojo.require("dijit.form.Button");

dojo.addOnLoad(function() {
		
});

//*********************************************************************************
/** Call a Dialog with message*/	
//*********************************************************************************
function popMessage (titel,msg) {
	diag = new dijit.Dialog;
	diag.titleNode.innerHTML = titel;
	//voeg een sluit button toe aan bericht
	msg += '<br /><br /><div align="center"><a href=javascript:diag.hide()>venster sluiten</a> of <a href=javascript:location.reload();>pagina herladen</a></div>' ;
	diag.attr('content', msg);
	diag.show();
}

/** Call a Dialog with URL	*/
function popPage (titel,url, idname, onLoadHandler) {
	diag = new dijit.Dialog({href: url, title: titel, id: idname, autofocus: false});
	//pas de positie aan.
	diag._endDrag = function(e){
	if(e && e.node && e.node === this.domNode){
	   var p = e._leftTop || dojo.coords(e.node,true);
	   this._relativePosition = { //we don't want our dialog to scroll.
	    t: p.t,
	    l: p.l
	   }   
	   this._firstRun = false;  
	  }
	 }
	  
	 diag._position = function(){
	  if(!dojo.hasClass(dojo.body(),"dojoMove")){
	    
	   var node = this.domNode;
	   if (!this._relativePosition || this._firstRun  ) { 
	    this._firstRun = this._firstRun ? false: true;
	    var viewport = dijit.getViewport();
	    var mb = dojo.marginBox(node);
		//console.log("vp.w="+viewport.w+" mb.w="+mb.w);
	    this._relativePosition = {
	      l: Math.floor(viewport.l + ((((viewport.w - mb.w) / 2) < 0) ? 10 : ((viewport.w - mb.w) / 2))),
	      t: Math.floor(viewport.t + ((((viewport.h - mb.h) / 2) < 0) ? 10 : ((viewport.h - mb.h) / 2)))
	    }  
	   }
	   
	   var p = this._relativePosition;
	   dojo.style(node,{
	    left: p.l + "px",
	    top: p.t + "px"
	   });
	  }
	 }

	 
	//diag.connect(diag, "hide", dojo.hitch(diag, function() {this.destroy();}));
	diag.connect(diag, "hide", dojo.hitch(diag, function() {this.destroyRecursive();}));
	
	if (onLoadHandler) {
		diag.connect(diag, "onLoad", onLoadHandler); 
	};	
	
	
	diag.show();
	//console.dir(diag);
}

