/*///////////////////////////////////////////////////////////////////////
//Dialog.js
//Written by Electric Solutions GbR
//Copyright 2002-2009 by Electric Solutions GbR
//Author: R. Grosseck
//support@electric-solutions.de
//www.electric-solutions.de
///////////////////////////////////////////////////////////////////////*/

(function Dialog(){
	var isactive;					//Screen aktiv
	var dialogobj;							//HauptScreen Objekt
	var updatedivcontent;	//Bool um dialog_content auch bei resize anzupassen
}

(Dialog = {

	Init : function() {		
		this.dialogobj=this.getObj('screen');		
		this.isactive=false;
		this.updatedivcontent=false;
	},
	
	getObj : function (name) {
		if(browser.isIE && browser.version == 4)
		return document.all[name];
		else if(browser.isNS && browser.version == 4)
		return document.layers[name];
		else
		return document.getElementById(name);
	},

	ShowDialog : function(){		
		if (browser.isNS && browser.version == 4)
		this.dialogobj.visibility="show";
		else
		this.dialogobj.style.visibility="visible";		
		this.isactive=true;
	},

	HideDialog : function(){
		/*
		if(browser.isNS && browser.version == 4)
		this.dialogobj.visibility="hide";
		else
		this.dialogobj.style.visibility="hidden";
		
		this.isactive=false;
		this.dialogobj.innerHTML="";
		*/
		this.SlideHideDialog(this.dialogobj, 10);
	},
	
	SlideHideDialog : function(obj, s){
		if(s <= 0){
			if(browser.isNS && browser.version == 4)
			this.dialogobj.visibility="hide";
			else
			this.dialogobj.style.visibility="hidden";
			
			this.isactive=false;
			this.dialogobj.innerHTML="";
			Windows._setOpacity(this.dialogobj, 10);
		}
		else	{
			Windows._setOpacity(this.dialogobj, s);
			s--;
			window.setTimeout("Dialog.SlideHideDialog('"+this.dialogobj+"',"+s+")", 25);
		}
	},

	getWinHeight : function(){
	  var winheight = 0;
	  if (window.innerHeight) winheight = window.innerHeight;
		else if (document.documentElement && document.documentElement.clientHeight) 
			winheight = document.documentElement.clientHeight;
		else if (document.body && document.body.clientHeight) 
			winheight = document.body.clientHeight;		
		return winheight;
	},
	
	getWinWidth : function(){
	  var winwidth = 0;
	  if (window.innerWidth)
	  	winwidth = window.innerWidth;
		else if (document.documentElement && document.documentElement.clientWidth) 
			winwidth = document.documentElement.clientWidth;
		else if (document.body && document.body.offsetWidth) 
			winwidth = document.body.offsetWidth;		
		return winwidth;
	},
	
	getDivHeight : function(obj){
	  var divheight =obj.offsetHeight;
		return divheight;
	},
	
	getDivWidth : function(obj){
	  var divwidth =obj.offsetWidth;
		return divwidth;
	},
	
	SetDivWidth : function(div, x){
		this.getObj(div).style.width=x+'px';
	},
	
	SetDivHeight : function(div, x){
		this.getObj(div).style.height=x+'px';
	},
	
	CenterDialogWindow : function(obj){
		var a=Math.round(this.getWinHeight()/2);
		var b=Math.round(parseInt(this.getDivHeight(obj))/2);;
		var c=a-b;
		obj.style.top=c+"px";
		if(browser.isIE && browser.version < 7){
			a=Math.round(this.getWinWidth()/2);
			b=Math.round(parseInt(this.getDivWidth(obj))/2);
			c=a-b;		
			obj.style.left=c+"px";
		}
	},
	
	SetDialogWidth : function(x){
		this.getObj('dialog').style.width=x;
	},
	
	SetDialogHeight : function(x){
		this.getObj('dialog').style.Height=x;
	},
	
	DialogTemplate : function(title){
		var output;
		output="<div id=\"dialog\">";
		output+="<div id=\"dialog_header\">";
		output+="<div id=\"dialog_header_title\">" + title + "</div>";
		output+="<div id=\"dialog_header_close\"><a href=\"javascript:void(0)\" onclick=\"Dialog.HideDialog()\" title=\""+LOCAL_LANG[language]['button_close']+"\"><img src=\"images/button_close.png\" border=\"0\"></a></div>";		
		output+="<div style=\"clear:both\"></div>";
		output+="</div>";		
		output+="<div id=\"dialog_content\">";	
		output+="placeholder";
		output+="</div>";
		output+="</div>";
		return output;
	},
	
	Dialog : function(title,text,width,height){
		this.dialogobj.innerHTML=this.DialogTemplate(title).replace(/placeholder/g, text);
		if(width)
		this.SetDialogWidth(width);
		if(height)
		this.SetDialogHeight(height);		
		this.CenterDialogWindow(this.getObj('dialog'));
		//this.SetDivHeight('dialog_content', this.getDivHeight(this.getObj('dialog'))-this.getDivHeight(this.getObj('dialog_header'))-10);
		this.ShowDialog();
	},

	ShowDialogError : function(error){
		var output, odiv;
		output="<div id=\"dialog\">";
		output+="<div id=\"dialog_header_error\">";
		output+="<div id=\"dialog_header_title\">"+LOCAL_LANG[language]['error']+"</div>";
		output+="<div id=\"dialog_header_close\"><a href=\"javascript:void(0)\" onclick=\"Dialog.HideDialog()\"><img src=\"images/button_close.png\" border=\"0\"></a></div>";		
		output+="<div style=\"clear:both\"></div>";
		output+="</div>";		
		output+="<div id=\"dialog_content\">";	
		output+="<div id=\"dialog_image\"><img src=\"images/icon_stop.png\" width=\"48\" height=\"48\"></div>";
		output+="<div id=\"dialog_text\">";
		output+="<p>" + error + "</p>";		
		output+="</div>";
		output+="<div style=\"clear:both\"></div>";
		output+="</div>";
		output+="<div id=\"dialog_button\"><input type=\"button\" name=\"close\" value=\"" + LOCAL_LANG[language]['button_close'] + "\" class=\"button\" onclick=\"Dialog.HideDialog()\"></div>";
		output+="</div>";		
		this.dialogobj.innerHTML=output;
		this.CenterDialogWindow(Dialog.getObj('dialog'));
		this.ShowDialog();		
	},
	
	setUpdateDivContent : function(bool){
		this.updatedivcontent=bool;	
	},
	
	UpdateDialog : function(){
		if(this.isactive == true){
			this.dialogobj.style.width=this.getWinWidth()+"px";
			this.dialogobj.style.height=this.getWinHeight()+"px";
			this.CenterDialogWindow(this.getObj('dialog'));
		}
		if(this.updatedivcontent == true){
			this.SetDivHeight('dialog_content', this.getDivHeight(this.getObj('dialog'))-this.getDivHeight(this.getObj('dialog_header'))-10);
		}
	}
}));

/*////////////////////////////////////////////////////////////////////////////////////////////////////
//Fenster ohne Screen
////////////////////////////////////////////////////////////////////////////////////////////////////*/
var	zindex = 1100;
var WCPWindowDefault = window.WCPWindowDefault || {};
function setDefaults(object, defaults) {
  for (var option in defaults) {  	
    if (!object.hasOwnProperty(option))
      object[option] = defaults[option];
  }
}
//Default Options
setDefaults(WCPWindowDefault, {
  width : '50%',
	height : '50%',
	minwidth : '25%',
	minheight : '25%',
	forwarding : true,
	maximize : true,
	resize : true
});

function WCPWindow(properties){

}

WCPWindow.prototype.Create = function(properties) {
	this.windowobj = winid =(new Date()).getTime();
	this.properties = properties;
	setDefaults(properties, WCPWindowDefault);
	var is_saved=0;
	for(var x=0; x<WCPWindowInstances.length; x++){
		if(WCPWindowInstances[x]['windowobj'] == this.windowobj)	
		is_saved=1;
	}
	if(is_saved == 0){
		WCPWindowInstances[WCPWindowInstances.length]={'windowobj' : this.windowobj, 'properties' : this.properties, 'position' : ''};
	}	
	return winid;
};
	
WCPWindow.prototype.getObj = function (name) {
	if(browser.isIE && browser.version == 4)
	return document.all[name];
	else if(browser.isNS && browser.version == 4)
	return document.layers[name];
	else
	return document.getElementById(name);
};

WCPWindow.prototype.ShowWindow = function(obj){		
	if (browser.isNS && browser.version == 4)
	obj.visibility="show";
	else
	obj.style.visibility="visible";		
};

WCPWindow.prototype.HideWindow = function(obj){	
	if(browser.isNS && browser.version == 4)
	obj.visibility="hide";
	else
	obj.style.visibility="hidden";
	//obj.innerHTML="";
};

WCPWindow.prototype.getWinHeight = function(){
  var winheight = 0;
  if (window.innerHeight) winheight = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) 
		winheight = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		winheight = document.body.clientHeight;		
	return winheight;
};
	
WCPWindow.prototype.getWinWidth = function(){
  var winwidth = 0;
  if (window.innerWidth)
  	winwidth = window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth) 
		winwidth = document.documentElement.clientWidth;
	else if (document.body && document.body.offsetWidth) 
		winwidth = document.body.offsetWidth;		
	return winwidth;
};
	
WCPWindow.prototype.getDivHeight = function(obj){
  var divheight =obj.offsetHeight;
	return divheight;
};
	
WCPWindow.prototype.getDivWidth = function(obj){
  var divwidth =obj.offsetWidth;
	return divwidth;
};
	
WCPWindow.prototype.SetDivWidth = function(div, x){
	this.getObj(div).style.width=x+'px';
};
	
WCPWindow.prototype.SetDivHeight = function(div, x){
	this.getObj(div).style.height=x+'px';
};

WCPWindow.prototype.SetDivContentHeight = function(obj){
	this.SetDivHeight('window_content_'+obj, this.getDivHeight(this.getObj('window_'+obj))-this.getDivHeight(this.getObj('window_header_'+obj))-10);		
};

//Padding vom Hauptcontent Div setzen (default ist 4px)
WCPWindow.prototype.SetDivContentPadding = function(obj, value){
	var wobj=this.getObj('window_content_'+obj);
	wobj.style.padding = value +"px";
};

//HIntergrundfarbe vom Hauptcontent Div setzen (default ist 4px)
WCPWindow.prototype.SetDivContentColor = function(obj, value){
	var wobj=this.getObj('window_content_'+obj);
	wobj.style.backgroundColor = value;
};

//Richtet Fenster mittig aus
WCPWindow.prototype.CenterWindow = function(obj){
	var a=Math.round(this.getWinHeight()/2);
	var b=Math.round(parseInt(this.getDivHeight(obj))/2);;
	var c=a-b;
	obj.style.top=c+"px";
	//if(browser.isIE && browser.version < 7){
		a=Math.round(this.getWinWidth()/2);
		b=Math.round(parseInt(this.getDivWidth(obj))/2);		
		c=a-b;
		obj.style.left=c+"px";
	//}
};

//Korregiert Fenster bei Browser Resize
WCPWindow.prototype.RedrawWindow = function(obj){
	var winheight=this.getWinHeight();
	var divheight=this.getDivHeight(obj);
	var divtop=parseInt(obj.style.top);	
	if(divheight+divtop > winheight){
		var newpos=(winheight-divheight-(divheight+divtop-winheight));
		if(newpos < 0)
		obj.style.top=0+"px";
		else
		obj.style.top=(winheight-divheight-(divheight+divtop-winheight))+"px";
	}
	
	var winwidth=this.getWinWidth();
	var divwidth=this.getDivWidth(obj);	
	var divleft=parseInt(obj.style.left);	
	if(divwidth+divleft > winwidth){
		var newpos=(winwidth-divwidth-(divwidth+divleft-winwidth));
		if(newpos < 0)
		obj.style.left=0+"px";
		else
		obj.style.left=newpos+"px";
	}
}

WCPWindow.prototype.SetWindowWidth = function(obj,x){
	if(x.indexOf("%") == -1)
	obj.style.width=x+"px";	
	else
	obj.style.width=x;	
};

WCPWindow.prototype.SetWindowHeight = function(obj,y){
	if(y.indexOf("%") == -1)
	obj.style.height=y+"px";
	else
	obj.style.height=y;
};

WCPWindow.prototype.SetWindowTop = function(obj,t){
	if(t.indexOf("%") == -1)
	obj.style.top=t+"px";	
	else
	obj.style.top=t;	
};

WCPWindow.prototype.SetWindowLeft = function(obj,l){
	if(l.indexOf("%") == -1)
	obj.style.left=l+"px";
	else
	obj.style.left=l;
};

//fenster Titel Setzen
WCPWindow.prototype.SetWindowTitle = function(obj, title){
	var wobj=this.getObj('window_header_title_' + obj);
	wobj.innerHTML=title;
};

//Vergrößert Fenster auf angegebene Größe
WCPWindow.prototype.ResizeWindow = function(obj, top, left, x, y){
	if(typeof(obj) == "object")
	var wobj= obj;
	else
	var wobj=this.getObj(obj);
	
	if(top)
	this.SetWindowTop(wobj,top);
	if(left)
	this.SetWindowLeft(wobj,left);
	if(x)
	this.SetWindowWidth(wobj,x);
	if(y)
	this.SetWindowHeight(wobj,y);	
	this.UpdateWindow();
};

//Vergrößert Fenster auf Maximale Größe
WCPWindow.prototype.Maximize = function(obj){
	//Entferne Drag
	var wobj_header=this.getObj('window_header_' + obj);	
	wobj_header.onmouseover=function (){this.style.cursor='default';}
	wobj_header.onmousedown=function (){};
	wobj_header.onmouseup=function (){};
	wobj_header.ondblclick=function (){Windows.Minimize(obj);}
	//Entferne Resize Event	
	document.onmousemove =  null;	
	
	//Ersetze Button
	var wobj_button_maximinimize=this.getObj('window_button_maximinimize_' + obj);
	wobj_button_maximinimize.firstChild.setAttribute("onclick", "Windows.Minimize('"+obj+"')");
	wobj_button_maximinimize.firstChild.setAttribute("title", LOCAL_LANG[language]['button_minimize']);
	var pic=wobj_button_maximinimize.firstChild.firstChild.getAttribute("src");
	wobj_button_maximinimize.firstChild.firstChild.setAttribute("src", pic.replace(/button_maximize.png/g, "button_minimize.png"));	

	var wobj=this.getObj(obj);
	
	//Speichere aktuelle Position
	this._updateWindowData(obj, 'position', {'top':parseInt(wobj.style.top),'left':parseInt(wobj.style.left),'width':this.getDivWidth(wobj),'height':this.getDivHeight(wobj)});
	
	//Resize Window
	wobj.style.top=0+"px";
	wobj.style.left=0+"px";
	var x=this.getWinWidth();
	var y=this.getWinHeight()-4;
	this.ResizeWindow(wobj, 0, 0, x.toString(), y.toString());
};

//Verkleinert Fenster auf Anfangsgröße
WCPWindow.prototype.Minimize = function(obj){
	//Aktiviere Drag
	var wobj_header=this.getObj('window_header_' + obj);
	var wobj = this._getWindowData(obj);
	wobj_header.onmouseover=function (){this.style.cursor='move';}
	wobj_header.onmousedown=function (){
		Windows._ActivateWindow(obj);
		if(wobj['properties']['forwarding'] == true)		
		Windows._ForwardWindow(obj);
		DragResize.activate();
	};
	wobj_header.onmouseup=function (){DragResize.activate();};
	if(wobj['properties']['maximize'] == true)
	wobj_header.ondblclick=function (){Windows.Maximize(obj);}
	//Aktiviere Resize
	document.onmousemove =  function(e){
		if(wobj['properties']['resize'] == true)
		DragResize.mouseMove(e, Windows.getObj(obj)); 
		DragResize.drag(e);
	};
	
	//Ersetze Button
	var wobj_button_maximinimize=this.getObj('window_button_maximinimize_' + obj);
	wobj_button_maximinimize.firstChild.setAttribute("onclick", "Windows.Maximize('"+obj+"')");
	wobj_button_maximinimize.firstChild.setAttribute("title", LOCAL_LANG[language]['button_maximize']);
	var pic=wobj_button_maximinimize.firstChild.firstChild.getAttribute("src");
	wobj_button_maximinimize.firstChild.firstChild.setAttribute("src", pic.replace(/button_minimize.png/g, "button_maximize.png"));	
	
	//Resize Window
	var woobj=this.getObj(obj);	
	this.ResizeWindow(woobj, wobj['position']['top'].toString(), wobj['position']['left'].toString(), wobj['position']['width'].toString(), wobj['position']['height'].toString());
};

//Fenster Template
WCPWindow.prototype.WindowTemplate = function(title){
	var output;	
	output="<div class=\"window\" id=\"window_"+this.windowobj+"\">";
	output+="<div class=\"window_header\" id=\"window_header_"+this.windowobj+"\" onmouseover=\"this.style.cursor='move'\"";
	output+=" onmousedown=\"Windows._ActivateWindow('"+this.windowobj+"');";
	if(this.properties['forwarding'] == true)
	output+="Windows._ForwardWindow('"+this.windowobj+"');";
	output+="DragResize.activate()\" onmouseup=\"DragResize.activate()\"";
	if(this.properties['maximize'] == true)
	output+=" ondblclick=\"Windows.Maximize('"+this.windowobj+"')\"";
	output+=">";
	output+="<div class=\"window_header_title\" id=\"window_header_title_"+this.windowobj+"\">" + title + "</div>";
	output+="<div class=\"window_header_close\">";
	if(this.properties['maximize'] == true)
	output+="<span id=\"window_button_maximinimize_"+this.windowobj+"\"><a href=\"javascript:void(0)\" onclick=\"Windows.Maximize('"+this.windowobj+"')\" onFocus=\"this.blur()\" title=\""+LOCAL_LANG[language]['button_maximize']+"\"><img src=\"images/button_maximize.png\" border=\"0\"></a></span> ";
	output+="<a href=\"javascript:void(0)\" onclick=\"Windows.Close('"+this.windowobj+"')\" onFocus=\"this.blur()\" title=\""+LOCAL_LANG[language]['button_close']+"\"><img src=\"images/button_close.png\" border=\"0\"></a></div>";		
	output+="<div style=\"clear:both\"></div>";
	output+="</div>";		
	output+="<div class=\"window_content\" id=\"window_content_"+this.windowobj+"\" onclick=\"Windows._ActivateWindow('"+this.windowobj+"');";
	if(this.properties['forwarding'] == true)
	output+="Windows._ForwardWindow('"+this.windowobj+"')";
	output+="\">placeholder</div>";
	output+="</div>";
	return output;
};

//Erstellt Fenster Instanz
WCPWindow.prototype.Open = function(title,text){
	//var obj=this.getObj(this.windowobj);	
	var win = document.createElement("div");
	win.setAttribute("id",this.windowobj);  
	win.style.position="absolute";
	win.style.zIndex=zindex++; 
	if(this.properties['width'])
	this.SetWindowWidth(win,this.properties['width']);
	if(this.properties['height'])
	this.SetWindowHeight(win,this.properties['height']);
	if(this.properties['minwidth'])
	win.style.minWidth=this.properties['minwidth']+"px";
	if(this.properties['minheight'])
	win.style.minHeight=this.properties['minheight']+"px";
	win.innerHTML = this.WindowTemplate(title).replace(/placeholder/g, text);
	document.body.appendChild(win);	
	this._ForwardWindow(this.windowobj);
	this._ActivateWindow(this.windowobj);
	this.CenterWindow(win);
	//DragResize.init(this.windowobj,0,this.getWinWidth(),0,this.getWinHeight()-9);
	//DragResize.init(this);
	//Setze Content Div auf Hoehe des Fensters
	this.SetDivContentHeight(this.windowobj);
};

//Löscht Fenster Instance
WCPWindow.prototype.Close = function(obj){
	//Lösche geschlossene Fenster Instanz
	var newwcpwindos=new Array();
	var i=0;
	for(var x=0; x<WCPWindowInstances.length; x++){
		if(WCPWindowInstances[x]['windowobj'] != obj)
		newwcpwindos[i++]=WCPWindowInstances[x];
	}
	WCPWindowInstances=newwcpwindos;
	
	this._SlideCloseWindow(obj, 10)
	
	if(DragResize.obj != null)
	DragResize.obj = null;	
};

//Schließt alle Fenster z.B. bei Session OUT
WCPWindow.prototype.CloseWindows = function(){	
	for(var x=0; x<WCPWindowInstances.length; x++){
		document.body.removeChild(this.getObj(WCPWindowInstances[x]['windowobj']));
	}
	WCPWindowInstances=new Array();
};

//Slided Fenster aus
WCPWindow.prototype._SlideCloseWindow = function(obj, s){
	if(s <= 0)
	document.body.removeChild(this.getObj(obj));
	else	{
		this._setOpacity(this.getObj(obj), s);
		s--;
		window.setTimeout("Windows._SlideCloseWindow('"+obj+"',"+s+")", 10);
	}
};

//Aktualisiert größe bei Browser Resize
WCPWindow.prototype.UpdateWindow = function(){
	var obj;
	for(var x=0; x<WCPWindowInstances.length; x++){
		obj=this.getObj(WCPWindowInstances[x]['windowobj'])
		if(obj != null){
			this.RedrawWindow(obj);
			this.SetDivContentHeight(WCPWindowInstances[x]['windowobj']);
		}
	}	
};

//zIndex um Fenster in vordergrund zu bringen ändern
WCPWindow.prototype._ForwardWindow = function(winid){
	var obj;
	var zindex=1100;
	for(var x=0; x<WCPWindowInstances.length; x++){
		if(winid == WCPWindowInstances[x]['windowobj']){
			obj=this.getObj(WCPWindowInstances[x]['windowobj'])
			if(obj != null){			
				obj.style.zIndex=zindex--;
			}
		}
	}
	for(var x=0; x<WCPWindowInstances.length; x++){
		if(winid != WCPWindowInstances[x]['windowobj']){
			obj=this.getObj(WCPWindowInstances[x]['windowobj'])
			if(obj != null){				
				obj.style.zIndex=zindex--;				
			}
		}
	}
}

//zIndex um Fenster in vordergrund zu bringen ändern
WCPWindow.prototype._ActivateWindow = function(winid){
	var obj;
	for(var x=0; x<WCPWindowInstances.length; x++){
		if(winid == WCPWindowInstances[x]['windowobj']){
			obj=this.getObj(WCPWindowInstances[x]['windowobj'])
			if(obj != null){				
				this.getObj("window_header_"+WCPWindowInstances[x]['windowobj']).className="window_header";
				DragResize.init(WCPWindowInstances[x], this.getWinWidth(), this.getWinHeight()-9);
			}
		}
	}
	for(var x=0; x<WCPWindowInstances.length; x++){
		if(winid != WCPWindowInstances[x]['windowobj']){
			obj=this.getObj(WCPWindowInstances[x]['windowobj'])
			if(obj != null){
				this.getObj("window_header_"+WCPWindowInstances[x]['windowobj']).className="window_header_off";				
			}
		}
	}
}

//Disable Forwarding Window, wenn Fenster durch Fenster initialisiert wird
WCPWindow.prototype.DisableForwardWindow = function(){
	this.deactivate_forwarding = true;
}

WCPWindow.prototype._setOpacity = function(obj, value){
	obj.style.opacity = value/10;
	obj.style.filter = 'alpha(opacity=' + value*10 + ')';
}

WCPWindow.prototype._getWindowData = function(win){
	for(var x=0; x<WCPWindowInstances.length; x++){
		if(win == WCPWindowInstances[x]['windowobj']){
			return WCPWindowInstances[x];
		}
	}
}

WCPWindow.prototype._updateWindowData = function(win, key, value){
	for(var x=0; x<WCPWindowInstances.length; x++){
		if(win == WCPWindowInstances[x]['windowobj']){
			WCPWindowInstances[x][key] = value;
		}
	}
}
/*////////////////////////////////////////////////////////////////////////////////////////////////////
//Fenster verschieben + Fenstergröße ändern
////////////////////////////////////////////////////////////////////////////////////////////////////*/
var DragResize = {

	obj : null,
	isaktiv : false,
	isresize : false,	
	
	init : function(wobj, maxX, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{		
		o=document.getElementById(wobj['windowobj']);
		o.onmousedown	= DragResize.start;
		o.wobj=wobj;
		o.hmode	= bSwapHorzRef ? false : true ;
		o.vmode	= bSwapVertRef ? false : true ;

		o.root = o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= 0;
		o.minY	= 0;
		o.maxX	= maxX;
		o.maxY	= maxY;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;		
		
		o.root.onDragResizeStart	= new Function();		
		o.root.onDragResizeEnd	= new Function();
		o.root.onDragResize		= new Function();
		document.onmousemove =  function(e){
			if(wobj['properties']['resize'] == true)
			DragResize.mouseMove(e, o); 
			DragResize.drag(e);
		};
	},

	start : function(e)
	{
		if(DragResize.isaktiv == true){
			var o = DragResize.obj = this;
			e = DragResize.fixE(e);		
			
			var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
			var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
			o.root.onDragResizeStart(x, y);
	
			o.lastMouseX	= e.clientX;
			o.lastMouseY	= e.clientY;
	
			if (o.hmode) {
				if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
				if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX - o.offsetWidth;
			} else {
				if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
				if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x  - o.offsetWidth;
			}
	
			if (o.vmode) {
				if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
				if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY - o.offsetHeight;
			} else {
				if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
				if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y - o.offsetHeight;
			}
			
			document.onmouseup		= DragResize.end;
			return false;
		}
		else {
			var o = DragResize.obj = this;
			if(o.root.wobj['properties']['resize'] == true){
				e = DragResize.fixE(e);
				
				var dir = DragResize.getDirection(e);
				if (dir == "") return;
				
				o.el =  DragResize.obj;
				o.direction = dir;
				o.grabx = e.pageX || e.clientX + document.documentElement.scrollLeft;
				o.graby = e.pageY || e.clientY + document.documentElement.scrollTop;
				o.width = DragResize.obj.offsetWidth;
				o.height =  DragResize.obj.offsetHeight;
				o.left =  DragResize.obj.offsetLeft;
				o.top =  DragResize.obj.offsetTop;
				DragResize.activate_resize();
				
				document.onmouseup		= DragResize.end;
			}
			return false;
			e.returnValue = false;
		}
	},

	drag : function(e)
	{
		if(DragResize.isaktiv == true){
			e = DragResize.fixE(e);
			var o = DragResize.obj;
	
			var ey	= e.clientY;
			var ex	= e.clientX;
			var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
			var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
			var nx, ny;
	
			if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
			if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
			if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
			if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
	
			
	
			nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
			ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
	
			if (o.xMapper)		nx = o.xMapper(y)
			else if (o.yMapper)	ny = o.yMapper(x)
	
			DragResize.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
			DragResize.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
			DragResize.obj.lastMouseX	= ex;
			DragResize.obj.lastMouseY	= ey;
	
			DragResize.obj.root.onDragResize(nx, ny);		
		}
		else if(DragResize.isresize == true) {
			e = DragResize.fixE(e);
			var o = DragResize.obj;
			
			var xPos, yPos, str, xMin, yMin;
			xMin = 30; //The smallest width possible
			yMin = 10; //             height
			
			xPos = e.pageX || e.clientX + document.documentElement.scrollLeft;
 			yPos = e.pageY || e.clientY + document.documentElement.scrollTop;
			if (o.direction.indexOf("e") != -1){
				if(DragResize.obj.offsetLeft+Math.max(xMin, o.width + xPos - o.grabx) < Windows.getWinWidth())
				DragResize.obj.style.width = Math.max(xMin, o.width + xPos - o.grabx) + "px";
			}
		
			if (o.direction.indexOf("s") != -1){
				if(DragResize.obj.offsetTop+7+Math.max(yMin, o.height + yPos - o.graby) <= (Windows.getWinHeight()+4))
				DragResize.obj.style.height = Math.max(yMin, o.height + yPos - o.graby) + "px";
			}
	
			if (o.direction.indexOf("w") != -1) {				
				//if((o.left + xPos - o.grabx) < o.left)
				DragResize.obj.style.left = Math.min(o.left + xPos - o.grabx, o.left + o.width - xMin) + "px";
				//if((Resize.obj.offsetLeft+Resize.obj.offsetWidth) < Windows.getWinWidth())
				DragResize.obj.style.width = Math.max(xMin, o.width - xPos + o.grabx) + "px";
			}
			if (o.direction.indexOf("n") != -1) {
				if((o.top + yPos - o.graby) < o.top)
				DragResize.obj.style.top = Math.min(o.top + yPos - o.graby, o.top + o.height - yMin) + "px";
				DragResize.obj.style.height = Math.max(yMin, o.height - yPos + o.graby) + "px";
			}
			Windows.SetDivContentHeight(DragResize.obj.id);
		}
		return false;
	},

	end : function()
	{
		if(DragResize.isresize == true)
		DragResize.activate_resize();
		document.onmouseup   = null;
		DragResize.obj.root.onDragResizeEnd(	parseInt(DragResize.obj.root.style[DragResize.obj.hmode ? "left" : "right"]), 
									parseInt(DragResize.obj.root.style[DragResize.obj.vmode ? "top" : "bottom"]));
		DragResize.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	},
	
	activate : function(){
		DragResize.isaktiv=DragResize.isaktiv == false ? true : false;		
	},
	
	activate_resize : function(){
		DragResize.isresize=DragResize.isresize == false ? true : false;
	},
	
	mouseMove : function(e,o) {
		if(DragResize.isresize == false){
			DragResize.obj = o;
			if(o == null)
			return;
			
			var xPos, yPos, str, xMin, yMin;
			xMin = 30; //The smallest width possible
			yMin = 10; //             height
				
			str = DragResize.getDirection(e);	
			if (str == "") str = "default";
			else str += "-resize";
			o.style.cursor = str;
		}
	},
	
	getDirection : function(e) {

		var xPos, yPos, offset, dir;
		dir = "";
		
		 // We always record the current mouse position.
 		xPos = e.pageX-DragResize.obj.root.offsetLeft || e.clientX + document.documentElement.scrollLeft;
 		yPos = e.pageY-DragResize.obj.root.offsetTop || e.clientY + document.documentElement.scrollTop;
		offset = 8; //The distance from the edge in pixels
	
		if (yPos<offset) dir += "n";
		else if (yPos > DragResize.obj.root.offsetHeight-offset) dir += "s";
		if (xPos<offset) dir += "w";
		else if (xPos > DragResize.obj.root.offsetWidth-offset) dir += "e";
		return dir;
	}
};
