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				: '/js/ajax/login.php',
		data			: { 'theUserNameLog' : theUserNameLog, 'thePassWordLog' : thePassWordLog },
		update			: $('login_result'),
		onComplete		: function(response) { 
			// alert(response);
		}
	}).send();
	return false;
}






function getNieuwsbriefMask( mask )
{
	var req = new Request.HTML({
		method		: 'post',
		url			: "/js/ajax/nieuwsbrief.php",
		data		: {  },
		update		: $('subscribe_newsletter'),
		onComplete	: function(response) { 
			openMask('subscribe_newsletter');
		}
	}).send();
	return false;
}



function saveNewsLetter( form )
{
	var userName			= form.userName.value;
	var email				= form.email.value;
	var category			= new Array();
	
	for( var i=0; i< form.elements['category[]'].length;i++){
		if ( form.elements['category[]'][i].checked ) {
			category[i] = form.elements['category[]'][i].value;
		}
	}
	
	var req = new Request.HTML({
		method		: 'post',
		url			: "/js/ajax/nieuwsbrief.php",
		data		: { 'userName' : userName, 'email' : email, 'category' : category },
		update		: $('subscribe_newsletter'),
		onComplete	: function(response) { 
			// alert(response);
		}
	}).send();
	
	return false;
}
