﻿var _is_show = false;
var _moveable = false;
var x0=0,y0=0,x1=0,y1=0;
var _diffHeight = 0;

var keyBuff = '';
var scrollBuff = '';

function startDrag(_obj, _win)
{
	if (event.button == 1)
	{
		_obj.setCapture();
		x0 = event.clientX;
		y0 = event.clientY;
		x1 = parseInt(_win.style.left);
		y1 = parseInt(_win.style.top);
		_moveable = true;
	}
}
function drag(_win)
{
	if (_moveable)
	{
		_win.style.left = x1 + event.clientX - x0;
		_win.style.top = y1 + event.clientY - y0;
	}
}
function stopDrag(_obj, _win)
{
	if (_moveable)
	{
		_obj.releaseCapture();
		_moveable = false;
		
		_diffHeight = parseInt(_win.style.top) - document.documentElement.scrollTop;
	}
}
function showPop(_win, _cov)
{
	if (_cov != null && typeof(_cov) != 'undefined')
	{
		_cov.style.position = 'absolute';
	
		_cov.style.height = document.body.clientHeight;
		_cov.style.width = document.body.clientWidth;
		
		_cov.style.left = 0 + 'px';
		_cov.style.top = 0 + 'px';
		
		_cov.style.display = 'block';
		
		var allSelects = document.getElementsByTagName("select");
		for(var i=0;i<allSelects.length;i++) {
			///allSelects[i].style.display = "none";
			allSelects[i].disabled = "none";
		///	allSelects[i].filter = "alpha(opacity=30)";
		}
	}
	
	_win.style.display = 'block';
	
	_win.style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - _win.offsetHeight) / 2 + 'px';
	_win.style.left = (document.documentElement.clientWidth - _win.offsetWidth) / 2 + 'px';
	
	_diffHeight = parseInt(_win.style.top) - document.documentElement.scrollTop;
	
	_is_show = true;
}
function closeME(_win, _cov)
{
	if (_win.style.display == 'none')
		return;
	
	if (_cov != null && typeof(_cov) != 'undefined')
	{
		_cov.style.display = 'none';
		var allSelects=document.getElementsByTagName("select");
		for(var i=0;i<allSelects.length;i++) {
			allSelects[i].disabled = "";
			///allSelects[i].style.display = "";
		}
	}
	
	_win.style.display = 'none';
	
	_is_show = false;
}
function addEvent(_win, _cov)
{
	if (_cov != null && typeof(_cov) != 'undefined')
	{
		keyBuff += 'closeME(' + _win.id + ',' + _cov.id + ');';
	}
	else
	{
		keyBuff += 'closeME(' + _win.id + ');';
	}
	
	scrollBuff += 'if (' + _win.id + '.style.display == \'block\') ';
	scrollBuff += _win.id + '.style.top = document.documentElement.scrollTop + _diffHeight + \'px\';';
}
function rebuildEvent()
{
	if (keyBuff == '')
		return;
	
	document.onkeydown = function()
	{
		if (event.keyCode == 27 && _is_show)
		{
			eval(keyBuff);
		}
	}
	window.onscroll = function()
	{
		if (_is_show)
		{
			eval(scrollBuff);
		}
	}
}