function onEndCrop(coords,dimensions) {
	 x1 	= coords.x1;
	 y1  	= coords.y1;
	 x2 	= coords.x2;
	 y2  	= coords.y2;
	 width  = dimensions.width;
	 height = dimensions.height;
}

function isMail(email) {
	var expressionReguliere = new RegExp("^[a-zA-Z0-9_-].+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,6}$");
	return expressionReguliere.test(email);
}

function patientez() {

	$("envoyer").hide();
	$("patientez").show();
}

function miniature_emoticone(source) {

	new Ajax.Request(
		'step1.php',{
			parameters: "xhr=creer_emoticone&source=" + source
						+ "&x1="		+ x1
						+ "&y1=" 		+ y1
						+ "&x2="		+ x2
						+ "&y2=" 		+ y2
						+ "&width=" 	+ width
						+ "&height="	+ height,

			onSuccess: function(xhr) {

				if(xhr.responseText == 'ok') document.location.href="step2.php";
			}
		}
	);
}

function affichePreview(n, nb, num_cde) {

	$("choix_anim_"+n).checked = 1;

	for(i=0; i<=nb; i++) {
		$("label_"+i).update('<img id="demo_'+ i +'" onclick="affichePreview('+ i +', '+ nb +', \''+ num_cde +'\')" src="imgs/apercu.png" alt="" />');
	}

	$("choix_anim_"+n).checked = 1;

	var html = '<object id="preview_'+ n +'" type="application/x-shockwave-flash" data="preview.swf" width="50" height="50">'
					+'<param name="movie" value="preview.swf" />'
					+'<param name="wmode" value="transparent" />'
					+'<param name="flashvars" value="n='+ n +'&amp;num_cde='+ num_cde +'" />'
				+'</object>';

	$("label_"+n).update(html);
}

function afficherDansGalerie() {

	new Ajax.Request(
		'step4.php',{
			parameters: "xhr=afficherDansGalerie&affiche=" + $("galerie").checked
		}
	);
}

function valideCGU() {
	
	if($('cgu').checked) new Effect.BlindDown	('terminer', {duration:0.5});
	else 				 new Effect.BlindUp		('terminer', {duration:0.5});
}

function afficheAllopass() {

	if($('cgu').checked) {
		new Effect.BlindDown('zone_allopass', {duration:0.5});
		new Effect.ScrollTo('zone_allopass',  {delay:0.5});

	} else new Effect.BlindUp('zone_allopass', {duration:0.5});
}

function envoiAmis(num_commande) {

	var n = 0;
	for(i=1; i<=5; i++) if(isMail($F("email"+i))) n++;

	if(n == 0) {
		alert("Vous devez saisir au moins une adresse email valide !");
		$("email1").select();

	} else {

		new Ajax.Request(
			'validation.php',{
				parameters: "xhr=envoiAmis&num_commande="+num_commande+"&email1="+$F("email1")+"&email2="+$F("email2")+"&email3="+$F("email3")+"&email4="+$F("email4")+"&email5="+$F("email5"),
				onSuccess: function(xhr) {

					if(xhr.responseText > 0) {
						alert("Votre émoticône a bien été envoyée à vos amis !");
						new Effect.BlindUp('formEnvoiAmis', {duration:0.5});
					}
				}
			}
		);
	}
}
