﻿
function llx_popupWindow() {
	var modalBK = undefined
	var This=this

	this.showWindow = function(w, x, y) {
	
	if (w.id == undefined) { w = document.getElementById(w) }
		w.style.position = 'absolute'
		//w.style.visibility = 'hidden'
		w.style.display = 'block'
		BringToFront(w)
		if (x == undefined) { x = -1 }
		if (y == undefined) { y = -1 }
		var cw = document.documentElement.clientWidth;
		var ch = document.documentElement.clientHeight;
		if (x < 0) { x = Math.round(cw / 2) - Math.round(w.offsetWidth / 2) + document.documentElement.scrollLeft * 1 }
		if (y < 0) { y = Math.round(ch / 2) - Math.round(w.offsetHeight / 2) + document.documentElement.scrollTop * 1 }
		w.style.top = y + "px";
		w.style.left = x + "px";
		//		alert(document.documentElement.scrollTop)
		//		alert(document.documentElement.scrollHeight)
		//		alert(document.documentElement.offsetHeight)
		if ((w.offsetTop * 1) < (document.documentElement.scrollTop * 1)) { w.style.top = (document.documentElement.scrollTop * 1) + 'px' }
		if ((w.offsetLeft * 1) < (document.documentElement.scrollLeft * 1)) { w.style.left = (document.documentElement.scrollLeft * 1) + 'px' }
		w.style.visibility = 'visible'
		w.style.display = 'none'
		$(w).fadeIn(300)
	}
	this.showModalWindow = function(w) {
		modalBK = document.createElement("div")
		document.body.appendChild(modalBK)
		modalBK.style.backgroundColor = 'black'
		modalBK.style.position = 'absolute'
		modalBK.style.top = '0px'
		modalBK.style.left = '0px'
		modalBK.style.width = (document.documentElement.offsetWidth * 1) + 'px'
		if ((document.documentElement.offsetHeight * 1) > (document.body.offsetHeight * 1)) { modalBK.style.height = (document.documentElement.offsetHeight * 1) + 'px' } else { modalBK.style.height = (document.body.offsetHeight * 1) + 'px' }
		try { modalBK.style.filter = 'alpha(opacity=60)' } catch (e) { }
		try { modalBK.style.opacity = .6 } catch (e) { }
		//$(modalBK).fadeIn(300)
		BringToFront(modalBK)
		This.showWindow(w)
	}
	this.hideWindow = function(w) {
		$(w).fadeOut(300, function() {w.style.display='none' })
		if (modalBK) { document.body.removeChild(modalBK) }
	}


	var moveIntv = 0
	var moveBgw=undefined


	this.moveWindow = function(w, e) {
		//BringToFront(w) 
		if (window.event) { e = window.event; e.cancelBubble = true; w.setCapture(); }
		var x0 = e.clientX - w.offsetLeft;
		var y0 = e.clientY - w.offsetTop;
		var x = 0;
		var y = 0;
		if (moveBgw) { stopPos() }
		moveBgw = document.createElement("DIV");
		document.body.appendChild(moveBgw);
			BringToFront(moveBgw)	
		BringToFront(w) 


		moveBgw.style.position = "absolute";
		moveBgw.style.top = "0px"
		moveBgw.style.left = "0px"
		moveBgw.style.width = document.body.offsetWidth + 'px'
		moveBgw.style.height = document.body.offsetHeight + 'px'
		setPos(e)
		moveIntv = setInterval(function() { w.style.left = x + 'px'; w.style.top = y + 'px'; }, 16);
		addListener(w, "mousemove", function(event) { setPos(event); })
		addListener(moveBgw, "mousemove", function(event) { setPos(event); })
		addListener(w, "mouseup", function() { stopPos() })
		addListener(moveBgw, "mouseup", function() { stopPos() })
		var e1
		function setPos(e1) { x = e1.clientX - x0; y = e1.clientY - y0 }
		function stopPos() { clearInterval(moveIntv); if (moveBgw) { document.body.removeChild(moveBgw) }; moveBgw = undefined; if (window.event) { w.releaseCapture(); } }
		return false
	}
	
	function BringToFront(w) {
		var o = document.body.childNodes
		var i = 0
		if (w.parentNode != document.body) { document.body.appendChild(w) }
		for (i = 0; i < o.length; i++) { if (o[i].nodeType != 3) { if (o[i].style.zIndex * 1 >= w.style.zIndex * 1) { w.style.zIndex = o[i].style.zIndex * 1 + 1 } } }
		if (w.style.zIndex < 10000) { w.style.zIndex=10000 }
	}

	function addListener(element, event, listener, bubble) {
		if (element.addEventListener) {
			if (typeof (bubble) == "undefined") bubble = false;
			element.addEventListener(event, listener, bubble);
		} else if (this.attachEvent) {
			element.attachEvent("on"+ event, listener);
		}
	}




 }