document.write('<link type="text/css" rel="stylesheet" media="screen" href="/sites/all/themes/ads/alert/alert.css?r" />');

	
function x_alert(content, func_name, args)
{
	content += '<br/><br/><span class="button ok">OK</span>';
	
	x_popup('x_alert', content);
	
	$('#x_alert > .xPopupContainer > .xPopupContent > .ok').one('click', {func_name: func_name, args: args}, function(e){
		if (e.data.func_name) {
			var args = '';
			if (e.data.args) {
				args = '"' + e.data.args.join('", "') + '"';
			}
			eval(e.data.func_name + '(' + args + ')');
		}
		x_popup_close('x_alert');
	});
}
	
function x_confirm(content, func_name, args, footer_content)
{
	content += '<br/><br/><span class="button yes">OUI</span> <span class="button no">NON</span>';
	
	if (footer_content) {
		content += '<br/><br/>' + footer_content;
	}
	
	x_popup('x_confirm', content);
	
	$('#x_confirm > .xPopupContainer > .xPopupContent > .yes').one('click', {func_name: func_name, args: args}, function(e){
		if (e.data.func_name) {
			var args = '';
			if (e.data.args) {
				args = '"' + e.data.args.join('", "') + '"';
			}
			eval(e.data.func_name + '(' + args + ')');
		}
		x_popup_close('x_confirm');
	});
	
	$('#x_confirm > .xPopupContainer > .xPopupContent > .no').one('click', function(e){
		x_popup_close('x_confirm');
	});
}

function x_form(content, fn_validate, fn_execute)
{
	content += '<br/><span class="button ok">OK</span>';
	
	x_popup('x_form', content);
	
	$('#x_form > .xPopupContainer > .xPopupContent > .ok').bind('click', {
		fn_validate: fn_validate, 
		fn_execute: fn_execute
	}, function(e) {
		if (e.data.fn_validate.call()) {
			e.data.fn_execute.call();
			x_popup_close('x_form');
		}
	});
}

function x_popup(popup_id, content)
{
	var html = '';
	
	html += '<div class="xPopup" id="' + popup_id + '">';
	html += '<div class="xPopupContainer">';
	html += '<div class="xPopupHeader"></div>';
	html += '<div class="xPopupContent">';
	html += content;
	html += '</div>';
	html += '<div class="xPopupFooter"></div>';
	html += '</div>';
	html += '</div>';
	
	$('#' + popup_id).remove();
	$(document.body).append(html);

	var margin_top = Math.floor(($(window).height() - $('#' + popup_id).height()) / 3);
	// IE 6 fix
	if (jQuery.browser.msie) {
		if (parseInt(jQuery.browser.version) == 6 || parseInt(jQuery.browser.version) == 5)
			margin_top += $(window).scrollTop();
	}
	//
	$('#' + popup_id).css('marginTop', margin_top);
	
	$('.xPopupHeader').bind('click', {popup_id: popup_id}, function () {
		x_popup_close(popup_id);
	});
}

function x_popup_close(popup_id)
{
	$('#' + popup_id).remove();
}
