function DesactiverEntrer(idFormulaire){
	$('#'+idFormulaire).bind("keypress",
		function(e){
			if(e.keyCode == 13)
				return false;
		}
	);
}

function checknumber(objet)
{  
   var x = objet.value;
   var anum=/(^\d+$)|(^\d+\.\d+$)/;
   if (anum.test(x))
      testresult=true;
   else
   {
      alert("Entrez uniquement des chiffres");
	  objet.value='';
      testresult=false;
   }
   return (testresult);
}
 
function checkQte(objet)
{  
   if (document.layers||document.all||document.getElementById)  
      return checknumber(objet);
   else  
         return true;
}


function testNbBout()
{
	
	if(parseInt($("#TBouteilles").val())%6!=0)
	alert("Attention, votre commande doit contenir un nombre total de bouteilles qui soit multiple de 6. (voir Conditions Générales de Vente");

	
}

function copierElement()
{
	if($("#cbcopy").is(':checked'))
	{$("input.fieldcp").addClass("abstract_val"); 
	
	$("input.fieldcp").each(function(index) {
   $(this).next("span:first").hide();
  });
  
  }
	else
	{$("input.fieldcp").removeClass("abstract_val");
	
	$("input.fieldcp").each(function(index) {
   $(this).next("span:first").show();
  });
	}
	
	
}

function switcherApercu(im)
{
$("img.apercuG").not("#"+im).slideUp("fast");	
$("#"+im).slideDown("fast");	
}




//popup CGV
function fenetrevolante()
    {
        window.open("CGV.html", "fenetrevolante", "toolbar=no, location=no, directories=no,status=yes,scrollbars=yes, resizable=no, copyhistory=no, width=880, height=700, left=0, top=0");
		
	}

//fin popup CGV





$(document).ready(function(){
	
	DesactiverEntrer('fvalider');

	//blur des qte
	$(".qte_input").change(function(){
		
		
	var total_global=0;
	var total_com=0;
	var qte_global=0;
	var prixu=parseFloat($(this).next("input.priceu:first").val());
	
	prixu = prixu.toFixed(2);
	
	var qte=parseInt($(this).val());
	var subTotal=(prixu*qte).toFixed(2);
	if($(this).val()=="")
		subTotal="";
	
	var rel=$(this).attr('rel');

	$('#'+rel+'').val(subTotal);
	
	//calcul des totaux******************
	$('input.subtotal').each(function(index) {
   		if($(this).val()!="")
  			total_global= (parseFloat(total_global) +(parseFloat($(this).val()))).toFixed(2);
			 
			
   
  	});
  
  	//calcul des qte******************
	$('input.qte_input').each(function(index) {
   	if($(this).val()!="")
   		qte_global+=parseInt($(this).val());
    });
  
	$("#total_global").val(""+total_global);
	$("#TBouteilles").val(""+qte_global);
		
	//calcul des frais de port
	if(total_global<parseFloat($("#froncop").val())){
		$("#Ttransport").val('');
		if(qte_global<=6)
			$("#Ttransport").val((parseFloat($("#bt6").val())).toFixed(2));
		
		if((qte_global>6)&&(qte_global<=12))
			$("#Ttransport").val((parseFloat($("#bt12").val())).toFixed(2));
		
		if((qte_global>12))
			$("#Ttransport").val((parseFloat($("#bt12plus").val())).toFixed(2));
		
	}
	else
		$("#Ttransport").val((0).toFixed(2));
	
	if($("#Ttransport").val()!=''){
		total_com=(parseFloat(total_global)  + parseFloat($("#Ttransport").val())).toFixed(2);
		
	}
	else
		total_com=total_global;
	
	//alert("totatl global est"+total_com);
	
	$("#TtotalTTC").val('');
	$("#TtotalTTC").val(total_com);
		
	});	

	//$(".qte_input").numeric();
	//$("#numeric").numeric();
	
	
		
	//$("#numeric").numeric();
	//$(".numeric").numeric();
	$(".integer").numeric(false, function() { alert("Integers only"); this.value = ""; this.focus(); });
	$(".positive").numeric({ negative: false }, function() { alert("No negative values"); this.value = ""; this.focus(); });
	$(".positive-integer").numeric({ decimal: false, negative: false }, function() { alert("Positive integers only"); this.value = ""; this.focus(); });
	
	if($('#gauche').height()>$('#contenu').height()-30)
		$('#contenu').height($('#gauche').height()-30);
	
	
	//fancybox
	if($("#amsgbox").length>0)
	{
		$("#amsgbox").fancybox({
			'showCloseButton': false,
			'padding'			: 0,
			'titlePosition'		: 'inside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		});
	}

	//fancybox
	if($("#amsgbox_val").length>0)
	{
		$("#amsgbox_val").fancybox({
			'showCloseButton': false,
			'padding'			: 0,
			'titlePosition'		: 'inside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		});
	}
	 	
	$("#fvalider").validate({
		
		ignore: ".abstract_val",
		onfocusout: false,
		onkeyup: false,
		meta: "validate",					   
		submitHandler: function(form) {
			form.submit();
		},					  
		showErrors: function(errorMap, errorList){ 
			if (errorList.length > 0) {
				//alert("erreur");
				
				alert(errorList[0].message);
				//jQuery('#inline1').html( errorList[0].message); $("#amsgbox").click();
			}
		}
	});
	
	
	$("#fnewsletter").validate({
		
		ignore: ".abstract_val",
		onfocusout: false,
		onkeyup: false,
		meta: "validate",					   
		submitHandler: function(form) {
			form.submit();
		},					  
		showErrors: function(errorMap, errorList){ 
			if (errorList.length > 0) {
				//alert("erreur");
				jQuery('#inline1').html( errorList[0].message); $("#amsgbox").click();
			}
		}
	});
	
	$("form.validerf").validate({
		
		ignore: ".abstract_val",
		onfocusout: false,
		onkeyup: false,
		meta: "validate",					   
		submitHandler: function(form) {
			form.submit();
		},					  
		showErrors: function(errorMap, errorList){ 
			if (errorList.length > 0) {
				//alert("erreur");
				jQuery('#inline1').html( errorList[0].message); $("#amsgbox").click();
			}
		}
	});
	
	
	$('#Remarques').bind('keypress', function(e) {
		//alert('ok');
        if(e.keyCode==13){
                // Enter pressed... do anything here...
				//$('#Remarques').append('<br />');
				$('#Remarques').val($('#Remarques').val()+'\n');
				
        }
	});

	

});
	
