window.onload = function()
{
	$("input.numeric").numeric();
}

function voirAdresse(passe_liste, id_membre) {
	
	var adresse = '';
	
	if(passe_liste != '') {
		var strFichierAjax = '/liste/ajax/ajax_affiche_adresse.php';

		$.ajax({
			type: "POST",
			async: false,
			url: strFichierAjax,
			data: 'passe_liste='+passe_liste+'&id_membre='+id_membre,
			success: function(msg){
				adresse = msg;
			},
			error: function(msg){
				alert('Server error');
			}
		});
	
	} else {
		adresse = 'Vous devez saisir le mot de passe de liste de naissance afin d\'avoir l\'adresse.';
	}

	var $dialog = $('<div></div>').html('<p style="padding-top: 10px; text-align: center;">'+ adresse +'</p>').dialog({
		modal: true,
		resizable: false,
		autoOpen: false,
		title: 'Mon adresse de livraison des cadeaux',
		width: 400,
		height: 200,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}
		}
	});
	
	$dialog.dialog('open');
	
}

function dialogConfirm(titre, message, id_form) {
	
	var $dialog = $('<div></div>').html('<p style="padding-top: 10px; text-align: center;">'+ message +'</p>').dialog({
		modal: true,
		resizable: false,
		autoOpen: false,
		title: titre,
		width: 400,
		height: 200,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
				submitParticipation(id_form);	
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
	
	$dialog.dialog('open');
	
}

function participer(id_form) {
	$('#formParticipe'+id_form).toggle();
}

function addParticipation(id_form) {
	if( (eval($('#montant_participation'+id_form).val()) + eval($('#cb_participation'+id_form).val())) > eval($('#prix'+id_form).val()) ) {
		var participation = eval($('#prix'+id_form).val()) - eval($('#montant_participation'+id_form).val());
		$('#cb_participation'+id_form).val(participation);
		dialogConfirm('Prix total dépassé', 'Le montant total des dons pour ce cadeau est supérieur à son prix.<br /> Voulez-vous participer à hauteur de ' + participation + '&euro; ?', id_form);
	} else {
		dialogConfirm('Vérification', 'Validez votre participation pour ce cadeau ?', id_form);	
	}
}

function addAchete(id_form) {
	
	var $dialog = $('<div></div>').html('<p style="padding-top: 10px; text-align: center;">Si vous avez acheté ce cadeau vous pouvez le marquer comme acheté. Une fois marqué, plus personne ne pourra acheter ce cadeau.</p>').dialog({
		modal: true,
		resizable: false,
		autoOpen: false,
		title: 'Marquer ce cadeau comme acheté',
		width: 400,
		height: 200,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
				submitParticipation(id_form);	
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
	
	$dialog.dialog('open');
}

function submitParticipation(id_form) {
	$('#form'+id_form).submit();
}

/*
*
* Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
* 
* Version 1.0
* Demo: http://www.texotela.co.uk/code/jquery/numeric/
*
* $LastChangedDate$
* $Rev$
*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('r.E.W=7(c,d){c=c||".";d=q d=="7"?d:7(){};6.K(7(e){g a=e.i?e.i:e.h?e.h:0;2(a==k&&6.N.J()=="G"){5 3}f 2(a==k){5 j}g b=j;2((e.4&&a==y)||(e.4&&a==v))5 3;2((e.4&&a==t)||(e.4&&a==u))5 3;2((e.4&&a==V)||(e.4&&a==S))5 3;2((e.4&&a==R)||(e.4&&a==Q))5 3;2((e.4&&a==P)||(e.4&&a==O)||(e.L&&a==p))5 3;2(a<I||a>H){2(a==p&&6.l.F==0)5 3;2(a==c.n(0)&&6.l.o(c)!=-1){b=j}2(a!=8&&a!=9&&a!=k&&a!=D&&a!=C&&a!=M&&a!=B&&a!=A){b=j}f{2(q e.i!="z"){2(e.h==e.m&&e.m!=0){b=3}f 2(e.h!=0&&e.i==0&&e.m==0){b=3}}}2(a==c.n(0)&&6.l.o(c)==-1){b=3}}f{b=3}5 b}).x(7(){g a=r(6).w();2(a!=""){g b=T U("^\\\\d+$|\\\\d*"+c+"\\\\d+");2(!b.s(a)){d.X(6)}}});5 6}',60,60,'||if|true|ctrlKey|return|this|function||||||||else|var|keyCode|charCode|false|13|value|which|charCodeAt|indexOf|45|typeof|jQuery|exec|120|88|65|val|blur|97|undefined|46|39|36|35|fn|length|input|57|48|toLowerCase|keypress|shiftKey|37|nodeName|86|118|90|122|67|new|RegExp|99|numeric|apply'.split('|'),0,{}))