function IsNumeric(input){ return (input - 0) == input && input.length > 0; }
	 function IsIntegerPositive(input){ return (input%1)==0 &&   input>0; } 
   function acheter(id_article)
   {
            if(document.getElementById('taille_'+id_article).value!=null)
            {
             var taille=document.getElementById('taille_'+id_article).value;
            }
            if(document.getElementById('quantite_'+id_article).value!=null)
            {
             var quantite=document.getElementById('quantite_'+id_article).value;
            }
            if (IsIntegerPositive(quantite)==false) {
            	quantite =1 ;
            	document.getElementById('quantite_'+id_article).value =quantite; 
            }
            var stockarticletaille = eval('stock_'+id_article+'_'+taille);
            var s='';
            if (quantite > stockarticletaille) {
            	if (stockarticletaille>1) 
            	s ='s';
            	alert('Il ne reste que '+stockarticletaille+' unité'+s+ ' en stock pour cet article') ;
            	quantite =stockarticletaille ;
            	document.getElementById('quantite_'+id_article).value =quantite; 
            	
            }
            if(id_article!='' && taille!=''&& quantite>0)
            {
            //Get the screen height and width
						var maskHeight = $(document).height();
						var maskWidth = $(window).width();
						//Set heigth and width to mask to fill up the whole screen
						$('#mask').css({'width':maskWidth,'height':maskHeight});

						//transition effect		
						$('#mask').fadeIn("fast");	
						$('#mask').fadeTo("fast",0.6);	
					
					 
					
            
             var btn = $('#btnbuy'+id_article) ;
             var myoffset = btn.offset();
              var by =  myoffset.top - $('#panierflottant').height()/2;  
             //var bx =  myoffset.left - $('#panierflottant').width()/2;  
						 var windowWidth = document.documentElement.clientWidth;  
						 var windowHeight = document.documentElement.clientHeight;  
						 
						 if( typeof( window.innerWidth ) == 'number' ) {
						    //Non-IE
						    windowWidth = window.innerWidth;
						    windowHeight = window.innerHeight;
						  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
						    //IE 6+ in 'standards compliant mode'
						    windowWidth = document.documentElement.clientWidth;
						    windowHeight = document.documentElement.clientHeight;
						  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
						    //IE 4 compatible
						    windowWidth = document.body.clientWidth;
						    windowHeight = document.body.clientHeight;
						  }



						 var popupHeight = $("#panierflottant").height();  
						 var popupWidth = $("#panierflottant").width();  
						 //centering  windowHeight
						 $("#panierflottant").css({  
						 "position": "absolute",  
						 "top": by-popupHeight/2,  
						 "left": windowWidth/2-popupWidth/2  
						 });  
						 //only need force for IE6  
						 $("#panierflottant").css({  
						 "height": windowHeight  
						 }); 
             
             	//transition effect
             $('#panierflottant').fadeIn("fast");	
             var dest ="/panier_jquery.php/ajouter/"+id_article+"/taille/"+taille+"/quantite/"+quantite; ;
             $('#panierflottant').load(dest);
             
            }
   }
   
   
   function acheterplus(id_article)
   {
            if(document.getElementById('taille_'+id_article).value!=null)
            {
             var taille=document.getElementById('taille_'+id_article).value;
            }
            if(document.getElementById('quantite_'+id_article).value!=null)
            {
             var quantite=document.getElementById('quantite_'+id_article).value;
            }
            if (IsIntegerPositive(quantite)==false) {
            	quantite =0 ;
            }
            var nouvellequantite = Number(quantite) +1 ;
            var stockarticletaille = eval('stock_'+id_article+'_'+taille);
            var s='';
            if (nouvellequantite > stockarticletaille) {
            	if (stockarticletaille>1) 
            	s ='s';
            	alert('Il ne reste que '+stockarticletaille+' unité'+s+ ' en stock pour cet article') ;
            	quantite =stockarticletaille ;
            	document.getElementById('quantite_'+id_article).value =quantite; 
            } else {
            document.getElementById('quantite_'+id_article).value =nouvellequantite; 
            }
            /*
            if (document.getElementById('quantite_'+id_article).value>1)
            $('#atext'+id_article).html('unités');
            else 
            $('#atext'+id_article).html('unité');
            */
             
            
   }
   function achetermoins(id_article)
   {
            if(document.getElementById('taille_'+id_article).value!=null)
            {
             var taille=document.getElementById('taille_'+id_article).value;
            }
            if(document.getElementById('quantite_'+id_article).value!=null)
            {
             var quantite=document.getElementById('quantite_'+id_article).value;
            }
            if (IsIntegerPositive(quantite)==false) {
            	quantite =1 ;
            }
            var nouvellequantite = Number(quantite) -1 ;
            if(nouvellequantite<1) {
            	nouvellequantite=1;
            }
            
            var stockarticletaille = eval('stock_'+id_article+'_'+taille);
            var s='';
            if (nouvellequantite > stockarticletaille) {
            	if (stockarticletaille>1) 
            	s ='s';
            	alert('Il ne reste que '+stockarticletaille+' unité'+s+ ' en stock pour cet article') ;
            	quantite =stockarticletaille ;
            	document.getElementById('quantite_'+id_article).value =quantite; 
            } else {
            document.getElementById('quantite_'+id_article).value =nouvellequantite; 
            }
            /*
             if (document.getElementById('quantite_'+id_article).value>1)
            $('#atext'+id_article).html('unités');
            else 
            $('#atext'+id_article).html('unité');
            */ 
             
             
             
   }
   
   
 function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true;  
    }else{   
		return false; 
    }
}
function checkNaissance(inputvalue) {	
    var pattern = /^([0-3][0-9]\/(0|1)[0-9]\/(19|20)[0-9]{2})/;
    if(pattern.test(inputvalue)){         
		  return checkNaissance18ans(inputvalue) ; 
    }else{   
    alert(msformatdat);	
		return false; 
    }
}
function checkNaissance18ans(inputvalue) {	
    var myDate=new Date();
    tab = inputvalue.split("/");
		myDate.setFullYear(tab[2],(tab[1]-1),tab[0]);
		if (myDate>myDateok) {
			alert(mstropjeune );
			return false;
 		} else {
 			return true;
 		}
}
function personnalisation(idpanier,item,contenu) {
	var erreur =0  ;
	var l=90;
	if (contenu.length>(l+3)) {
		alert(erreurtroplong);
		erreur++ ;
	}
	//  alert("longueur contenu.length " + contenu.length ); 
	if (erreur>0)
	return false ;
	Expression = new RegExp("\n","gi") //\r\n représente les retours a la ligne
	var resultat = contenu.match(Expression);
	if(resultat!=null) {
	//alert("longueur resultat.length " + resultat.length ); 
  if(resultat.length > 2) {
  	alert(erreurtropligne);
  	erreur ++;
  }
  var tab = contenu.split("\n");
  for (i=0;i<tab.length;i++) {
  	if (tab[i].length > 30)  {
  	alert(erreurlignelongue1 +" '"+tab[i]+"' " + erreurlignelongue2); 
  	erreur++;
  	}
  }	
	} else {
		// une seule ligne
		if (contenu.length>(l/3)) {
		alert(erreurlignelongue1 +" '"+contenu+"' " + erreurlignelongue2); 
		erreur++ ;
		}
	}
  if (erreur>0) {
	return false ;
 } else {
	var s = '#etiquette'+idpanier+"_item_"+item+"A:checked";
	
	var res = $(s).val();
	var c =  '#perso_panierid_'+idpanier+'_item_'+item ;
	var cres = $(c).val();
	if (res!=1 && cres!='') {
	$('#etiquette'+idpanier+'_item_'+item+'A').attr('checked', true);
  }
		$.ajax({
		   type: "POST",
		   url: "personnalisation.php",
		   data: {"idpanier":""+idpanier+"","item":""+item+"","contenu":""+contenu+""  }  ,
		   success: function(msg){
		   	 location.reload();
		   }
		 });
		}
}

function formnews(f){
var erreur = 0 ; 
var ok = 0 ; 
var s= '#'+f+'inp';
var sf= '#'+f ;
var str = $(s).val() ;
if (! checkEmail(str)){
erreur =1;alert('Email Invalide'); 
}
if (erreur>0) {
return false;
} else {
$(sf).submit(); 
}
}

function affichevignette(im) {
  $('#grandeimage').attr('src',im);
}


function currency_switch(currency) {
	var dest ="/currency_jquery.php?currency="+currency ;
  $('#divcurrency').load(dest);
	if(currency=='GBP'){ 
	//Get the screen height and width
						var maskHeight = $(document).height();
						var maskWidth = $(window).width();
						//Set heigth and width to mask to fill up the whole screen
						$('#maskcurrency').css({'width':maskWidth,'height':maskHeight});
						//transition effect		
						$('#maskcurrency').fadeIn("fast");	
						$('#maskcurrency').fadeTo("fast",0.6);	
					
						//Get the window height and width
						var winH = $(window).height();
						var winW = $(window).width();
					
						//transition effect
						$('#divcurrency').fadeIn(1000); 
            var btn = $('#divcurrency') ;
             var myoffset = btn.offset();
             var by =  100;  
             var bx = winW /2  ;  
             $('#divcurrency').css("top",by);
             $('#divcurrency').css("left",bx);
             $('#divcurrency').fadeIn("fast");	
           }
}

function cocktail(im) {
	//Get the screen height and width
						var maskHeight = $(document).height();
						var maskWidth = $(window).width();
						//Set heigth and width to mask to fill up the whole screen
						$('#maskcurrency').css({'width':maskWidth,'height':maskHeight});
						//transition effect		
						$('#maskcurrency').fadeIn("fast");	
						$('#maskcurrency').fadeTo("fast",0.6);	
					
						//Get the window height and width
						var winH = $(window).height();
						var winW = $(window).width();
						 var windowWidth = document.documentElement.clientWidth;  
						 var windowHeight = document.documentElement.clientHeight;  
						 if( typeof( window.innerWidth ) == 'number' ) {
						    //Non-IE
						    windowWidth = window.innerWidth;
						    windowHeight = window.innerHeight;
						  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
						    //IE 6+ in 'standards compliant mode'
						    windowWidth = document.documentElement.clientWidth;
						    windowHeight = document.documentElement.clientHeight;
						  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
						    //IE 4 compatible
						    windowWidth = document.body.clientWidth;
						    windowHeight = document.body.clientHeight;
						  }
						 var popupHeight = $("#divcurrency").height();  
						 var popupWidth = $("#divcurrency").width();  
						 //centering  windowHeight
						 $("#divcurrency").css({  
						 "position": "absolute",  
						 "top": 450,  
						 "left": windowWidth/2-popupWidth/2  
						 });  
						 //only need force for IE6  
						 $("#divcurrency").css({  
						 "height": windowHeight  
						 }); 
             $('#divcurrency').load("cocktail_jquery.php?im="+im);
             	//transition effect
             $('#divcurrency').fadeIn("fast");	
}

function avis(f,v) {
	$('#'+f).val(v);
	for (i=1;i<6;i++) {
		if (i<=v)
		var vsrc = "/img/starOn.gif" ;
		else
		var vsrc = "/img/star.gif" ;
		$('#'+f+'_'+i).attr("src",vsrc);
	}
}

function aide(ref,cible) {
	//Get the screen height and width
						var maskHeight = $(document).height();
						var maskWidth = $(window).width();
						//Set heigth and width to mask to fill up the whole screen
						$('#maskcurrency').css({'width':maskWidth,'height':maskHeight});
						//transition effect		
						$('#maskcurrency').fadeIn("fast");	
						$('#maskcurrency').fadeTo("fast",0.6);	
						
						
						 var btn = $('#'+cible) ;
						 
						 
             var myoffset = btn.offset();
             var by =  myoffset.top  ;  
             var bx =  myoffset.left ;
             
             
						//Get the window height and width
						var winH = $(window).height();
						var winW = $(window).width();
						 var windowWidth = document.documentElement.clientWidth;  
						 var windowHeight = document.documentElement.clientHeight;  
						 if( typeof( window.innerWidth ) == 'number' ) {
						    //Non-IE
						    windowWidth = window.innerWidth;
						    windowHeight = window.innerHeight;
						  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
						    //IE 6+ in 'standards compliant mode'
						    windowWidth = document.documentElement.clientWidth;
						    windowHeight = document.documentElement.clientHeight;
						  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
						    //IE 4 compatible
						    windowWidth = document.body.clientWidth;
						    windowHeight = document.body.clientHeight;
						  }
						 var popupHeight = $("#divcurrency").height();  
						 var popupWidth = $("#divcurrency").width();  
						 $("#divcurrency").css({  
						 "position": "absolute",  
						 "top": by,  
						 "left": bx 
						 });  
						 //only need force for IE6  
						 $("#divcurrency").css({  
						 "height": windowHeight  
						 }); 
             
             $('#divcurrency').load("help_jquery.php?ref="+ref);
             	//transition effect
             $('#divcurrency').fadeIn("fast");	
}

function recproducteur() {
	var dest = $('#selectidf :selected').attr("lien");
	window.location.href = dest;
}