
var idCommandClick = null;

//validatation formulaire
$('#form').validate({
	rules: {
	    email: "required",
	    confirm_email: {
	      equalTo: "#email"
	    }
  }
});


var left = (getWidthDocument()/2 - $('#block_6').width()/2);

$(document).ready(function() {
  $('#block_6').jqDrag('.jqDrag');
});


$('#block_6 span img').click(
		function(){
			$('#mask').fadeOut(500);
			$('#block_6').fadeOut(300);
		}
);

function displayFormCommande(){
	setMask();

	var block = $('#block_6');
	
	var winH = $(window).height();
	var blockH = block.height();
	
	//cas ou si le ecran est plus petit que le modal
	var versionIE = $.browser.version.substr(0,1);
	if($.browser.msie && versionIE < 7){
		block.css('position', 'absolute');
	}else{
		block.css('top',parseInt((winH - blockH)/2 - 5) + 'px');
		block.css('position', 'fixed');
	}
	
	block.css('left', left);
	block.css('z-index', '1000');
	
	block.fadeIn(500);
}

$('#submit_1').click(function(){ idCommandClick = $(this).val('id'); displayFormCommande(); });
$('#submit_2').click(function(){ idCommandClick = $(this).val('id'); displayFormCommande(); });
$('#submit_3').click(function(){ idCommandClick = $(this).val('id'); displayFormCommande(); });
$('#submit_4').click(function(){ idCommandClick = $(this).val('id'); displayFormCommande(); });
$('#submit_speciale').click(function(){ idCommandClick = $(this).val('id'); displayFormCommande(); });

//submit command
$('#order_paypal').click(
	function(){
		
		//indique le pack selectionner
		$('#pack').val(idCommandClick.attr('pack'));
		
		//send mail
		$.ajax({
			type: 'POST',
			url: '/actions/sendcommande.html',
			data: $('#form').serialize(),
			success: function(xhr){
				//send mail ok and //submit paypal
				if(xhr == "true") idCommandClick.parent().submit();
				if(xhr == 'member_exist') alert('Erreur de traitement');
			}
		});
	}
);

