Tools_client_window = function(objectname){
	this.objectname 	= objectname  // windowobject reference
	this.maxdimensions	= [screen.width-10,screen.height-40]
	this.dimensions		= [100,100] //w/h when opening
	this.position		= [0,0] // x/y when opening
	this.chrome 		= [1,1,1,1,1] // locationbar,scrollbars,statusbar,toolbar,menubar
	this.resizable 		= 0
	this.fullscreen 	= false
	this.opener			= self  // window that does the opening 
	this.target			= "target_"+objectname //simpler way to load into an existing window (like _blank)
	this.NewWindowObj	= "" // referrer for all direct window actions
	this.adjustV		= 0
	this.params			= ""
	if(typeof top._c_w_=="undefined"){top._c_w_=[]}
}
//Sluit alle windows
Tools_client_window.prototype.closeAll=function(){
	for (var i=0;i<top._c_w_.length;i++){
		if(this.windowPresence(top._c_w_[i])){top._c_w_[i].close();top._c_w_[i]=null}
	}top._c_w_=[]
}
Tools_client_window.prototype.addRef=function(a){top._c_w_[top._c_w_.length]=a}
// set the appearance of a window
// if the given sizes are bigger than the screen can handle they will be made smaller
Tools_client_window.prototype.setDimensions = function(width,height){
	this.dimensions[0]	 	= (width<this.maxdimensions[0] ) ? width  : this.maxdimensions[0]
	this.dimensions[1]		= (height<this.maxdimensions[1]) ? height : this.maxdimensions[1]
}
// Unvalidated version
Tools_client_window.prototype.setSize = function(width,height){this.dimensions[0]=width;this.dimensions[1]=height}
// Put a window of a known size centered on the screen.
// If parameters are supplied the x or y will not be centered but placed at that point
Tools_client_window.prototype.setPositionOrCentered = function(x,y){
	this.position[0] = (typeof x=="number") ? x : Math.floor((this.maxdimensions[0]-this.dimensions[0])/2)
	this.position[1] = (typeof y=="number") ? y : Math.floor((this.maxdimensions[1]-this.dimensions[1])/2)
}
Tools_client_window.prototype.setResizable = function(value){this.resizable = (value)?1:0}
Tools_client_window.prototype.setFullScreen = function(value){this.fullscreen = value}
Tools_client_window.prototype.setInterface = function(locationbar,scrollbars,statusbar,toolbar,menubar){
	this.chrome = [((locationbar)?1:0),((scrollbars)?1:0),((statusbar)?1:0),((toolbar)?1:0),((menubar)?1:0)]
	if(locationbar)this.adjustV -= 20
	if(statusbar) this.adjustV -= 20
	if(toolbar) this.adjustV -= 32
	if(menubar) this.adjustV -= 48
}
// If window is closed it wil be opened
// If window is opened a new document will be loaded into it
// If the document is already present in the window, no action will be taken
Tools_client_window.prototype.getParameters = function(){
	return  'location='		+	this.chrome[0] 		+ 
			',scrollbars='	+	this.chrome[1]		+
			',status='		+	this.chrome[2]		+
			',toolbar='		+	this.chrome[3]		+
			',menubar='		+	this.chrome[4]		+
			',resizable='	+	this.resizable		+
			',width='		+	this.dimensions[0]	+
			',height='		+	(this.dimensions[1]+this.adjustV)	+ 
			',left='		+	this.position[0]	+
			',top='			+	this.position[1]	+ 
			((this.fullscreen)?",fullscreen":"")
}
Tools_client_window.prototype.loadLocation = function(locationpath,reposition,target){
	if(!this.windowPresence()){
		this.NewWindowObj = this.opener.open(locationpath,this.target,this.getParameters())
		this.addRef(this.NewWindowObj)//referentie naar topframeset
	}
	else{//test of opgegeven link gelijk is aan huidige URL : test.htm?a=23 is NIET test.htm?a=200
		var loc = String(this.NewWindowObj.document.location)
		var docname	= loc.substring(loc.lastIndexOf("/")+1,loc.length)
		if(locationpath==docname){//dit document is al geladen :focus
			if(reposition){this.NewWindowObj.moveTo(this.position[0],this.position[1])}
			this.NewWindowObj.focus()	
		}
		else if(locationpath!=docname){//dit document kan in dit window worden geladen
			this.NewWindowObj.document.location = locationpath
			if(this.NewWindowObj&&reposition){this.NewWindowObj.moveTo(this.position[0],this.position[1])}
			this.NewWindowObj.focus()	
		}
	}
	if(this.windowPresence())this.NewWindowObj.focus()	
}

Tools_client_window.prototype.windowPresence = function(){
	var w=this.NewWindowObj
	if(typeof w=="undefined"){return false}
	if(w==""){return false}
	if(typeof w.document=="unknown"||typeof w.closed=="unknown"){return false}
	if(w.closed){ return false }
	return true
}
Tools_client_window.prototype.close = function(){
	if(this.windowPresence()){
		this.NewWindowObj.close()
		this.NewWindowObj=null
	}
}
Tools_client_window.prototype.LaadPaginaMetFoto = function(imgpath,title){
	this.closeAll()
	toonfoto	  = this
	this.winimage = new Image();this.winimage.src = unescape(imgpath)
	this.wintitle = title
	this.setInterface(0,0,0,0,0)
	this.timerId  = setTimeout(this.objectname+".timer()",200)
}
Tools_client_window.prototype.timer = function(){
	clearTimeout(this.timerId)
	if(this.winimage.complete){
		if(document.all){if(this.winimage.mimeType!=""){this.toon()}}	//ie
		else if(this.winimage.width!=0){this.toon()}					//ns
	}else{this.timerId = setTimeout(this.objectname+".timer()",200)}
}
Tools_client_window.prototype.toon = function(){
		this.setSize(this.winimage.width,this.winimage.height)
		this.setPositionOrCentered()
		this.NewWindowObj = this.opener.open("toonfoto.htm",this.target,this.getParameters())
		this.addRef(this.NewWindowObj)//referentie naar topframeset
}
