var popupStatusReg = 0;

function loadPopupReg(){

	if(popupStatusReg==0){
		$("#backgroundPopup").css({
			"opacity": "0.4"
		});
		$("#backgroundPopupDiv").css({
			"opacity": "0"
		});
		$("#backgroundPopupDiv").fadeIn("fast");
		$("#backgroundPopup").fadeIn("slow");
		
		//$("#registrationTable").fadeIn("slow");
		
		$("#registrationTable").css({
			"display": "block"
		});
		popupStatusReg = 1;
	}
}


function disablePopupReg(){
	if(popupStatusReg==1){
		$("#backgroundPopup").fadeOut("slow");
		//$("#registrationTable").fadeOut("slow");
		
		$("#registrationTable").css({
			"display": "none"
		});
		
		popupStatusReg = 0;
	}
}

function centerPopupReg(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#registrationTable").height();
	var popupWidth = $("#registrationTable").width();
	$("#registrationTable").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});

	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

$(document).ready(function(){
	$("#createUserButton").click(function(){
		centerPopupReg();
		loadPopupReg();
	});
	$("#registrationTableClose").click(function(){
		disablePopupReg();
	});
	$("#backgroundPopup").click(function(){
		disablePopupReg();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusReg==1){
			disablePopupReg();
		}
	});

});