function positionBox(box) {
	bWidth = box.getStyle('width').toInt();
	bHeight = box.getStyle('height').toInt();
	box.style.left = ((getWidth() / 2) - (bWidth / 2)) + 'px';
	box.style.top = ((getHeight() / 2) - (bHeight / 2)) + getScrollTop() + 'px';
}

function keepbox() {
	fx.start({
		'top': ((getHeight() / 2) - (bHeight / 2)) + getScrollTop(),
		'left': ((getWidth() / 2) - (bWidth / 2))
	})
	//theBox.style.top = ((getHeight() / 2) - (bHeight / 2)) + getScrollTop() + 'px';
	theKeeper=setTimeout('keepbox()', 100 );
}

function openMask(boxID) {
	corrIE = 0;			
	var theMask = $('mask');
	theBox = $(boxID);
	theMask.style.display = 'block';
	if (!window.XMLHttpRequest) {
		corrIE = 25;
	}
	theMask.style.height = getScrollHeight() + 'px';
	theBox.style.visibility = 'hidden';
	theBox.style.display = 'block';			
	//fx = theBox.effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});

	fx = new Fx.Morph(theBox, {
		duration: 500,
		wait: false,
		transition: Fx.Transitions.Quad.easeOut
	});

	var bHeight = theBox.getStyle('height').toInt() - corrIE;
	positionBox(theBox);
	theBox.style.overflow	= 'hidden';
	theBox.style.width 		= '0px';
	theBox.style.height 	= '0px';
	theBox.style.visibility = 'visible';
	//alert(fx.bHeight);
	fx.start({
		'height': bHeight,
		'width': 370
	}).chain(function() {
		keepbox();
	});
	return false;
}

function closeMask(id) {
	clearTimeout(theKeeper);
	fx.start({
		'height': 0,
		'width': 0
	}).chain(function() {
		$(id).style.display = 'none'
		$('mask').style.display = 'none'
		this.start({
			'height': bHeight,
			'width': bWidth
		});
	});
}

function openCloseMask(id1,id2) {
	clearTimeout(theKeeper);
	fx.start({
		'height': 0,
		'width': 0
	}).chain(function() {
		$(id1).style.display = 'none'
		$('mask').style.display = 'none'
		this.start({
			'height': bHeight,
			'width': bWidth
		});
	}).chain(function() {
		openMask(id2);
	});
}


function getLogin( form )
{	
	var theUserNameLog		= form.theUserNameLog.value;
	var thePassWordLog		= form.thePassWordLog.value;
	
	var req = new Request.HTML({
		method			: 'post',
		url				: '/ajax/login.php',
		data			: { 'theUserNameLog' : theUserNameLog, 'thePassWordLog' : thePassWordLog },
		update			: $('login_result'),
		onComplete		: function(response) { 
			// alert(response);
		}
	}).send();
	return false;
}


function popUp(pageId, w, h) {
	var y = (screen.availHeight - h) / 2;
	var x = (screen.availWidth  - w) / 2;
	
	var myWin = window.open('/popup.php?page='+pageId, 'popup', 'width='+w+', height='+h+', left='+x+', top='+y+', scrollbars=yes');
	myWin.focus();
}

/*function ReplaceInputPassword()
{
	document.getElementById('input_password').innerHTML = '<input class="square" type="password" name="pw" onKeyPress="return submitenter(this,event)" />';
}*/

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13)
	{
	myfield.form.submit();
	return false;
	}
	else
	return true;
}

