﻿// dhtmlDHWindow
var FWC_DHWindows=new Array()
var FWC_MovingDHWindow=null
var FWC_MovingDHWindowX0=0
var FWC_MovingDHWindowY0=0
var FWC_MovingDHWindowX1=0
var FWC_MovingDHWindowY1=0
var FWC_DHWindowInterval=0

function FWC_OpenDHWindow(name,style1,content1,style2,content2,btnContent,activeLayer){
	if(FWC_DHWindows[name]==undefined){
		FWC_DHWindows[name]=document.createElement("DIV")
		FWC_DHWindows[name].style.cssText=style1
		FWC_DHWindows[name].style.position='absolute'
		FWC_DHWindows[name].style.display='block'
		FWC_DHWindows[name].style.zIndex='10000'
		FWC_DHWindows[name].innerHTML=content1
		var Layer2=document.createElement("DIV")
		FWC_DHWindows[name].appendChild(Layer2)
		Layer2.innerHTML=content2
		Layer2.style.cssText=style2
		
		if (btnContent!=''){//close btn
			FWC_DHWindows[name].innerHTML+=btnContent
		}
		if (activeLayer==-1){
			FWC_DHWindows[name].onmouseover=FWC_DHWindow_onMouseOver
			FWC_DHWindows[name].onmousedown=FWC_DHWindow_onMouseDown
			FWC_DHWindows[name].onmouseup=FWC_DHWindow_onMouseUp
			FWC_DHWindows[name].onmousemove=FWC_DHWindow_onMouseMove
			FWC_DHWindows[name].onselect=returnFalse
			FWC_DHWindows[name].onselectstart=returnFalse
			FWC_DHWindows[name].onmouseout=returnFalse
		}else if (activeLayer==-2){
			Layer2.onmouseover=FWC_DHWindow_onMouseOver
			Layer2.onmousedown=FWC_DHWindow_onMouseDown
			Layer2.onmouseup=FWC_DHWindow_onMouseUp
			Layer2.onmousemove=FWC_DHWindow_onMouseMove
			Layer2.onselect=returnFalse
			Layer2.onselectstart=returnFalse
			Layer2.onmouseout=returnFalse		
		}else{
			FWC_DHWindows[name].childNodes[activeLayer].onmouseover=FWC_DHWindow_onMouseOver
			FWC_DHWindows[name].childNodes[activeLayer].onmousedown=FWC_DHWindow_onMouseDown
			FWC_DHWindows[name].childNodes[activeLayer].onmouseup=FWC_DHWindow_onMouseUp
			FWC_DHWindows[name].childNodes[activeLayer].onmousemove=FWC_DHWindow_onMouseMove
			FWC_DHWindows[name].childNodes[activeLayer].onselect=returnFalse
			FWC_DHWindows[name].childNodes[activeLayer].onselectstart=returnFalse
			FWC_DHWindows[name].childNodes[activeLayer].onmouseout=returnFalse
		}
		document.body.appendChild(FWC_DHWindows[name])	
		FWC_DHWindows[name].style.top=(document.documentElement.clientHeight/2)+document.documentElement.scrollTop-(FWC_DHWindows[name].offsetHeight/2)+'px'
		FWC_DHWindows[name].style.left=(document.documentElement.clientWidth/2)+document.documentElement.scrollLeft-(FWC_DHWindows[name].offsetWidth/2)+'px'
		if(FWC_DHWindows[name].offsetTop<0){FWC_DHWindows[name].style.top='0px'}
		if(FWC_DHWindows[name].offsetLeft<0){FWC_DHWindows[name].style.left='0px'}	
	}
	FWC_DHWindows[name].style.display='block'
}

function FWC_CloseDHWindow(name){
	document.body.removeChild(FWC_DHWindows[name])
	FWC_DHWindows[name]=undefined
}

// events

function FWC_DHWindow_onMouseOver(){
	this.style.cursor='move'
}
function FWC_DHWindow_onMouseDown(e){
	if(e==undefined){e=window.event}
	FWC_MovingDHWindow=this
	var allDivs=document.getElementsByTagName("DIV")
	for (i=0;i<allDivs.length;i++){if ((allDivs[i].style.zIndex*1>=this.style.zIndex*1)&&(allDivs[i]!=this)){this.style.zIndex=allDivs[i].style.zIndex*1+1;}}
	if (this.parentNode.tagName=="BODY"){
		FWC_MovingDHWindowX0=e.clientX-this.offsetLeft
		FWC_MovingDHWindowY0=e.clientY-this.offsetTop
	}else{
		FWC_MovingDHWindowX0=e.clientX-this.parentNode.offsetLeft
		FWC_MovingDHWindowY0=e.clientY-this.parentNode.offsetTop
	}
	clearInterval(FWC_DHWindowInterval)
	//FWC_DHWindowInterval=setInterval(FWC_DHWindow_moving,50)
	try{this.setCapture()}catch(e){}
	return false
}
function FWC_DHWindow_onMouseUp(){
	FWC_MovingDHWindow=null
	try{this.releaseCapture()}catch(e){}
	//clearInterval(FWC_DHWindowInterval)
}
function FWC_DHWindow_onMouseMove(e){
	if(e==undefined){e=window.event}
	if (FWC_MovingDHWindow!=this){return false}
	FWC_MovingDHWindowX1=e.clientX-FWC_MovingDHWindowX0+'px'
	FWC_MovingDHWindowY1=e.clientY-FWC_MovingDHWindowY0+'px'
	FWC_DHWindow_moving(this)
	return false
}

function FWC_DHWindow_moving(o){
	if (FWC_MovingDHWindow==null){return false}
	if (o.parentNode.tagName=="BODY"){
		FWC_MovingDHWindow.style.top=FWC_MovingDHWindowY1
		FWC_MovingDHWindow.style.left=FWC_MovingDHWindowX1
	}else{
		FWC_MovingDHWindow.parentNode.style.top=FWC_MovingDHWindowY1
		FWC_MovingDHWindow.parentNode.style.left=FWC_MovingDHWindowX1
	}


}

function returnFalse(){return false}
