/* popbox */
var popboxW = null;
var popboxH = null;

function updateWnd() {
	
	var w = window.innerWidth  || document.body.clientWidth;
	var h = window.innerHeight || document.body.clientHeight;
	var o = document.getElementById('popboxwnd');
	
	if (!popboxW && !popboxH) { // fit
		o.style.width  = Math.round(w / 1.5) + 'px';
		o.style.height = Math.round(h / 1.5) + 'px';
		o.style.left   = (w / 6) + 'px';
		o.style.top    = (h / 6) + 'px';
		//document.getElementById('popboxframe').style.height = (Math.round(h / 1.5) - 33) + 'px';
	} else { // fixed size
		o.style.width  = popboxW + 'px';
		o.style.height = popboxH + 'px';
		o.style.left   = ((w / 2) - (popboxW / 2)) + 'px';
		o.style.top    = ((h / 2) - (popboxH / 2)) + 'px';
		//document.getElementById('popboxframe').style.height = (popboxH - 32) + 'px';
	}
	
	
	document.getElementById('popboxtr').style.left = (parseInt(o.style.width ) - 16) + 'px';
	document.getElementById('popboxbr').style.left = (parseInt(o.style.width ) - 16) + 'px';
	document.getElementById('popboxbl').style.top  = (parseInt(o.style.height) - 16) + 'px';
	document.getElementById('popboxbr').style.top  = (parseInt(o.style.height) - 16) + 'px';
	
	f = document.getElementById('popboxframe');
	f.style.top    = (parseInt(o.style.top)    + 44) + 'px';
	f.style.left   = (parseInt(o.style.left)   + 16) + 'px';
	f.style.width  = (parseInt(o.style.width)  - 32) + 'px';
	f.style.height = (parseInt(o.style.height) - 60) + 'px';

	//b = document.getElementById('popboxfoot');
	//b.style.top    = (parseInt(o.style.height) - 44) + 'px';
	//b.style.left   = (parseInt(o.style.left)   + 0 ) + 'px';
	//b.style.width  = (parseInt(o.style.width)  - 0 ) + 'px';
}

function popboxShow(title, url, w, h) {
	popboxW = 760;
	popboxH = 560;
	//alert(window);
	document.documentElement.style.overflow = 'hidden';
	//document.body.style.overflow = 'hidden';
	//obj.href = "javascript:void(0)";
	document.getElementById('popboxcaption').innerHTML = title; //obj.title;
	//document.getElementById('popboxbg').onclick = function() { popboxHide(); };
	//document.getElementById('popboxwnd').onselectstart = function() { return false; };
	document.getElementById('popboxframe').innerHTML = '<img src="/images/wait.gif" style="position:absolute;left:'+((popboxW/2)-30)+';top:'+((popboxH/2)-60)+';width:30px;height:30px;">';
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp != null) {
		xmlHttp.onreadystatechange = function() { 
			if (xmlHttp.readyState == 4) {
				document.getElementById('popboxframe').innerHTML = xmlHttp.responseText;					
			}
		};	
		xmlHttp.open("GET", "/inc/asp/ajax/artpop.asp?" + url + "&nocache=" + Math.random(), true);
		xmlHttp.send(null);
	}
	
	updateWnd();			
	document.getElementById('popboxbg').style.display = 'block';
	document.getElementById('popboxwnd').style.display = 'block';
}

function popboxHide() {
	document.getElementById('popboxbg').style.display = 'none';
	document.getElementById('popboxwnd').style.display = 'none';
	document.getElementById('popboxframe').innerHTML = '';
	document.documentElement.style.overflow = 'auto';
	//document.body.style.overflow = 'auto';
}

function popboxKeys(e) { 	
	keycode = (e == null) ? event.keyCode : e.which;
	if (keycode == 27) { // ESC
		popboxHide(); 
	}
}

document.onkeydown=popboxKeys;
window.onresize=updateWnd;

