function AWindow (){		
this.width=0;
this.height=0;
this.top=0;
this.left=0;
this.index=0;
// Minimized or maximized
this.state=false; 
this.id="";
this.src="";
this.name="";
this.root=null;
this.staticid=null;
}

function FloatWindow (){		
	this.readSizeFromCookie = false;	// Determines if size and position of windows should be set/retreved by use of cookie
	this.windowMinSize = [100,100];	// Mininum width and height of windows.
	this.moveCounter = -1;	
	this.startEventPos = new Array();
	this.startPosWindow = new Array();
	this.startWindowSize = new Array();
	this.initResizeCounter = -1;	
	this.activeWindow = false;
	this.activeWindowContent = false;	
	this.windowArray = new Array();
	this.currentZIndex = 10000;	
	this.activeWindowIframe = false;
	this.divCounter = 0;
	this.zIndexSet = false;
	this.imagesrc= "/img/floatwindow/";
	this.MSIEWIN = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Win')>=0 && navigator.userAgent.toLowerCase().indexOf('opera')<0)?true:false;
	this.opera = navigator.userAgent.toLowerCase().indexOf('opera')>=0?true:false;
	this.ajaxObjects = new Array();
}
var floatWindow=new  FloatWindow();
		
 AWindow.prototype.close=function(itselfref)
{
floatWindow.hideWindowParam(itselfref.id);
floatWindow.hideBack();
floatWindow.windowArray.remove(itselfref);
};

 AWindow.prototype.min=function(itselfref)
{
floatWindow.hideWindowParam(itselfref.id);
};
 AWindow.prototype.reload=function(winObj)
{
publishIFrame2(winObj.name,winObj.src,winObj.width,winObj.height);
};

 FloatWindow.prototype.hideAllWindow=function(){
    var array =	document.getElementsByTagName("div");
    for(var i=0 ;i<array.length;i+=1){
    var div = array[i];
    if(tool.startWith(div.id,"dhtml_goodies_id") ===true){
   document.body.removeChild(div);
    }
    	}
    	floatWindow.hideBack();
    	};
	FloatWindow.prototype.hideWindowParam=function(id){
	var element = document.getElementById(id);
	if(element){
	floatWindow.hideWindowElement(element);
	}else{
	// alert("id not found = " +idfull );
	floatWindow.hideAllWindow();
	}
	
	};
	FloatWindow.prototype.hideWindow=function()
	{
	var element = document.getElementById('dhtml_goodies_id' +  this.id.replace(/[^\d]/g,''));
	floatWindow.hideWindowElement(element);
	
	};
	FloatWindow.prototype.hideWindowElement=function(element){
	// floatWindow.switchElement(false,element);
	var parent =document.body;
	if(parent){
	try{
	parent.removeChild(element);
	}
	catch(e){
	alert("Error hideWindowElement = " + e);
	}
	}
		floatWindow.hideBack();
	};
	FloatWindow.prototype.minimizeWindow=function(e,inputObj)
	{
	//alert("minimizeWindow");
		if(!inputObj){inputObj = this;}
		var numericID = inputObj.id.replace(/[^0-9]/g,'');
		floatWindow.switchElement(false,document.getElementById('dhtml_goodies_id' + numericID));
		var state;	
		var winObj = floatWindow.windowArray[numericID];
		if(inputObj.src.indexOf('minimize')>=0){
			floatWindow.activeWindowContent.style.display='none';
			document.getElementById('resizeImage'+numericID).style.display='none';
			inputObj.src = inputObj.src.replace('minimize','maximize');	
			if(winObj){
			winObj.state = false;
			}
			state = '0';		
		}else{			
			floatWindow.activeWindowContent.style.display='block';
			document.getElementById('resizeImage'+numericID).style.display='';
			inputObj.src = inputObj.src.replace('maximize','minimize');
			if(winObj){
			winObj.state = true;
			}
			state = '1';
		}
	};
	
	FloatWindow.prototype.createNewWindow=function(winObj)
	{
	var d = domUtil;
	var index = floatWindow.windowArray.length;
		winObj.index=index;
		winObj.id="floatwin_window_id"+index;
		var ret = d.createDIV(winObj.id,"floatwin_window_main");
		winObj.root=ret;
		
		floatWindow.windowArray[index] = winObj;
		ret.style.width=winObj.width+"px";
		ret.style.height=winObj.height+"px";
	    ret.style.top=winObj.top+"px";
		ret.style.left=winObj.left+"px";
		
		
		document.body.appendChild(ret);
		
		return ret;
	};
	

	
	/* floatWindow function illustrates how you can create a new custom window dynamically */
	
	FloatWindow.prototype.customFunctionCreateWindow=function(urlToExternalFile)
	{		
		var divId = floatWindow.createNewWindow(200,200,300,300);
		document.getElementById('windowContent' + divId).innerHTML = 'Content of new window';
		if(urlToExternalFile){addContentFromUrl(urlToExternalFile,divId);}	// Add content from external file
	};
	
		FloatWindow.prototype.customFunctionCreateWindowIframe=function(name,urlToExternalFile,width,height,staticid)
	{		
	   var win = new AWindow();
	   win.width=width;
	    win.name=name;
	    win.height=height;
	     win.top=50;
	      win.left=250;
	      win.src =urlToExternalFile;
	      win.staticid=staticid;
		var el = floatWindow.createNewWindow(win);

	 var iframe = document.createElement("iframe");
	 var add ="&"
	  var src = urlToExternalFile;
	  var c = new Date();
	  var time =c.getTime();
	  var sep="?";
	 if(src.indexOf(".jsp?")>-1){
	   sep="&";
	 }
	 src+=sep +"ts="+time ;
	 iframe.src= src  ;
	 iframe.frameborder="0";
	  iframe.border="0";
	 	 iframe.width="100%";
	 	  iframe.height="100%";
	 el.appendChild(iframe);
	// floatWindow.activeWindow.style.display='visible';
	};
FloatWindow.prototype.createBack=function(){
		var d = domUtil;
	var el =d.getById("windowback");
	if(el ==null){
	//alert("create windowback");
	var body = document.getElementsByTagName("body")[0];
	var divel= document.createElement("div");
	 var id = document.createAttribute('id');
  id.value = 'windowback';
  
  divel.setAttributeNode(id);
  d.addAttribute(divel,"onclick","floatWindow.hideOnclick()");
d.setClass(divel,"windowback");
	body.appendChild(divel);
	}
	};
	FloatWindow.prototype.hideBack=function(){
	var el =document.getElementById("windowback");
	if(el!==null){
	var body = document.getElementsByTagName("body")[0];
	body.removeChild(el);
	}
	};
	//window.onload = floatWindow.initWindows;
	
FloatWindow.prototype.hideOnclick=function(){
//alert("hideOnclick");
if(w2mconf.browser.isIE6up===false){
floatWindow.hideBack();
}
};

FloatWindow.prototype.refresh=function(){
//alert("hideOnclick");
	var d = domUtil;
	//alert("refresh 1");
if(w2mconf.browser.isIE6up===false){

	var array = floatWindow.windowArray;
	var winObj=	array[array.length-1] ;
	winObj.reload(winObj);

//alert("refresh 4");

}
};
	FloatWindow.prototype.containsStaticid=function(staticid){
	var ret =false;
	var array = floatWindow.windowArray;
	var end=array.length;
	for(i=0;i<end;i+=1){
	var w = array[i];
	if(w!==null){
	var v = w.staticid;
	//alert("containsStaticid =["+v+"]")
	 if( v===staticid){
	return true;
	}
	}
	}
	return ret;
	};
function publishIFrame2(name,src,width,height,staticid){
floatWindow.createBack();
// NEW VERSION WITH IFRAME
height+=20;
//width+=5;
floatWindow.customFunctionCreateWindowIframe(name,src,width,height,staticid);
}