var AjaxFunctions = {
	loader: null,
	overlay: null,
	holder: null,
	lock: false,
	
/* promotions */
	
	partypokerregister: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('promotions/register/', {
				method: 'post',
				parameters: {
					name: $('name').getValue(),
					lastname: $('lastname').getValue(),
					nickname: $('nickname').getValue(),
					email: $('email').getValue(),
					check: $('check').getValue()
				},
				onCreate: function() {
					AjaxFunctions.showSplashScreen();
				},
				onComplete: function(transport) {
					AjaxFunctions.hideSplashScreen();
					AjaxFunctions.showPopUp(transport.responseText);
				}
			})
		}
	},	
	

/* end of promotions */

	showPopUp: function(data) {
		if (!AjaxFunctions.overlay) {
			AjaxFunctions.overlay = document.createElement('div');
			AjaxFunctions.overlay.setAttribute('id', 'ajaxoverlay');
			AjaxFunctions.overlay.style.display = 'none';
			document.body.appendChild(AjaxFunctions.overlay);
			$('ajaxoverlay').style.width = AjaxFunctions.windowWidth()+'px';
			$('ajaxoverlay').style.height = AjaxFunctions.windowHeight()+'px';
			$('ajaxoverlay').style.zIndex = 100;
			if (AjaxFunctions.version() < 7) {
				$('ajaxoverlay').style.position = 'absolute';
				$('ajaxoverlay').style.top = AjaxFunctions.scrollTop()+'px';
			} else {
				$('ajaxoverlay').style.position = 'fixed';
				$('ajaxoverlay').style.top = '0px';
			}
			$('ajaxoverlay').style.left = '0px';
			
			AjaxFunctions.holder = document.createElement('div');
			AjaxFunctions.holder.setAttribute('id', 'ajaxholder');
			AjaxFunctions.holder.style.display = 'none';
			document.body.appendChild(AjaxFunctions.holder);
			$('ajaxholder').style.position = 'absolute';
			$('ajaxholder').style.zIndex = 150;
		}
		$('ajaxoverlay').style.display = 'block';
		$('ajaxholder').innerHTML = data;
		$('ajaxholder').style.display = 'block';
		$('ajaxholder').style.left = Math.round((AjaxFunctions.windowWidth()-$('ajaxholder').offsetWidth)/2)+'px';
		$('ajaxholder').style.top = (AjaxFunctions.scrollTop()+Math.round((AjaxFunctions.windowHeight()-$('ajaxholder').offsetHeight)/2))+'px';
	},
	
	hidePopUp: function() {
		$('ajaxoverlay').style.display = 'none';
		$('ajaxholder').style.display = 'none';
	},
	
	showSplashScreen: function(element) {
		if (!AjaxFunctions.loader) {
			AjaxFunctions.loader = document.createElement('div');
			AjaxFunctions.loader.setAttribute('id', 'ajaxloader');
			AjaxFunctions.loader.style.display = 'none';
			document.body.appendChild(AjaxFunctions.loader);
			var ajaxbar = document.createElement('div');
			ajaxbar.setAttribute('id', 'ajaxbar');
			AjaxFunctions.loader.appendChild(ajaxbar);
		}
		if (!element) {
			AjaxFunctions.loader.width = AjaxFunctions.windowWidth();
			AjaxFunctions.loader.height = AjaxFunctions.windowHeight();
		} else {
			AjaxFunctions.loader.width = $(element).getWidth();
			AjaxFunctions.loader.height = $(element).getHeight();
		}
		$('ajaxloader').style.width = AjaxFunctions.loader.width+'px';
		$('ajaxloader').style.height = AjaxFunctions.loader.height+'px';
		swfobject.embedSWF("/img/preload.swf", "ajaxbar", AjaxFunctions.loader.width, AjaxFunctions.loader.height, "9.0.0", "expressInstall.swf", null, {quality:'high', scale:'noscale', wmode:'transparent', salign:'tl'});
		$('ajaxloader').style.display = 'block';
		$('ajaxloader').style.zIndex = 200;
		if (!element) {
			if (AjaxFunctions.version() < 7) {
				$('ajaxloader').style.position = 'absolute';
				$('ajaxloader').style.top = AjaxFunctions.scrollTop()+'px';
			} else {
				$('ajaxloader').style.position = 'fixed';
				$('ajaxloader').style.top = '0px';
			}
			$('ajaxloader').style.left = '0px';
		} else {
			$('ajaxloader').style.position = 'absolute';
			var poz = $(element).cumulativeOffset();
			$('ajaxloader').style.top = poz.top+'px';
			$('ajaxloader').style.left = poz.left+'px';
		}
	},
	
	hideSplashScreen: function() {
		$('ajaxloader').style.display = 'none';
		AjaxFunctions.lock = false;
	},

	scrollTop: function() {
		var result = window.pageYOffset?window.pageYOffset:0;
		result = (document.documentElement && result == 0)?document.documentElement.scrollTop:result;
		result = (document.body && result == 0)?document.body.scrollTop:result;
		return result;
	},

	windowWidth: function() {
		var result = window.innerWidth?window.innerWidth:0;
		result = (document.documentElement && result == 0)?document.documentElement.clientWidth:result;
		result = (document.body && result == 0)?document.body.clientWidth:result;
		return result;
	},

	windowHeight: function() {
		var result = window.innerHeight?window.innerHeight:0;
		result = (document.documentElement && result == 0)?document.documentElement.clientHeight:result;
		result = (document.body && result == 0)?document.body.clientHeight:result;
		return result;
	},

	version: function() {
		var version = 999;
		if (navigator.appVersion.indexOf("MSIE") != -1) version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		return version;
	}
	
}
