function getLayoutOffsets(){
	var de = document.documentElement;
	var screenWidth = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var screenHeight = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	return [screenWidth,screenHeight];
}

function centerOnScreen(obj){
	var screenOffsetWidth = getLayoutOffsets()[0];
	var screenOffsetHeight = getLayoutOffsets()[1];
	if(obj.style.position!='absolute') obj.style.position = 'absolute';
	obj.style.left = (screenOffsetWidth/2)-(obj.getWidth()/2)+'px';
	obj.style.top = (screenOffsetHeight/2)-(obj.getHeight()/2)+'px';
}

function initMsgBox(){
	var msgBox = document.createElement('div');
	msgBox.id = 'msgBox';
	msgBox.style.display = 'none';

	var header = document.createElement('div');
	header.className = 'header';
	header.id = 'msgBoxHandle';

	var btnClose = document.createElement('div');
	btnClose.className = 'close';
	btnClose.onmouseover = function(){
		this.style.backgroundPosition = 'bottom left';
	}
	btnClose.onmouseout = function(){
		this.style.backgroundPosition = 'top left';
	}
	btnClose.onclick = function(){
		closeMsgBox();
	}

	var content = document.createElement('div');
	content.id = 'msgBoxContent';

	var zoneBtn = document.createElement('div');
	zoneBtn.className = 'msgBoxZoneBtn';

	var btn = document.createElement('input');
	btn.type = 'image';
	btn.value = '';
	btn.src = 'images/popup/confirm_en.jpg';
	btn.onclick = function(){
			ajaxEditUser(null);
			closeMsgBox();
	}

	var zoneBtn2 = document.createElement('div');
	zoneBtn2.className = 'msgBoxZoneBtn2';

	var btn2 = document.createElement('input');
	btn2.type = 'image';
	btn2.value = '';
	btn2.src = 'images/popup/cancel_en.jpg';
	btn2.onclick = function(){
		closeMsgBox();
	}

	var footer = document.createElement('div');
	footer.className = 'footer';

	var pN = $A(document.getElementsByTagName('body'))[0];

	msgBox.appendChild(header);
	header.appendChild(btnClose);
	msgBox.appendChild(content);
	zoneBtn.appendChild(btn);
	msgBox.appendChild(zoneBtn);
	zoneBtn2.appendChild(btn2);
	msgBox.appendChild(zoneBtn2);
	msgBox.appendChild(footer);
	pN.appendChild(msgBox);

	new Draggable('msgBox', {revert:false, starteffect:false, endeffect:false, handle:'msgBoxHandle'});
	window.confirm = function(msg){
		showMsgBox(msg);

	}
}

function showMsgBox(content){
	var lstInputs = $A(document.getElementsByTagName('INPUT'));
	lstInputs.each(function(input){
		if(input.focus){
			input.blur();
			throw $break;
		}
	});
	$('msgBoxContent').innerHTML = content;
	centerOnScreen($('msgBox'));
	new Effect.Appear('msgBox',{duration:0.2});
	new Effect.Appear('cache',{from: 0.0, to: 0.4, duration: 0.2});
	cacheSelect();
}

function closeMsgBox(){
	new Effect.Fade('msgBox',{duration:0.2});
	new Effect.Fade('cache',{duration: 0.2});
	displaySelect();
}

function handleKeyPress(event){
	if((event.keyCode==27 || event.keyCode==13) && $('msgBox').visible()){
		closeMsgBox();
	}
}

function cacheSelect()
{
	i=0;
    size = document.getElementsByTagName('select').length;
	for(i=0;i <size; i++)
	{
	    document.getElementsByTagName('select')[i].style.display='none';
	    i++;
	}
}

function displaySelect()
{
	i=0;
    size = document.getElementsByTagName('select').length;
	for(i=0;i <size; i++)
	{
	    document.getElementsByTagName('select')[i].style.display='';
	    i++;
	}
}