var ns6=(!document.all && document.getElementById)?1:0;
var ie5=(document.all)?1:0;			
function Verif(x,y,indice){
		//x: val min
		//y: quantite
		y=parseInt(y);		
		var c1,c2,Prix,p=0;	// condionnement							
		if(ns6) formart = document.forms["formart"];
		var qmin = QteMinimum(indice);	
		qmin=parseInt(qmin);	
		var minim = Array();
		
		if (qmin==0) return true;
		if((y%qmin)!=0){			
			alert("La quantité doit être un multiple entier de "+x);	
			var condition = eval('formart.cond'+indice);	
			/* gestion de l'objet select option */
			var i=0;			
			while(i<condition.length)
			{
				c1= condition.options[i].value;
				c2= c1.split('-');							
				minim[i] = parseInt(c2[0]);				
				if(i!=0 && minim[i-1] < y && y < minim[i]){
					condition.options[i-1].selected=true;					
					i=condition.length;					
				}					
				i++;				
			}								
			var Qty = eval('formart.quantity'+indice);				
			Qty.focus();				
		}
		else{
			var condition = eval('formart.cond'+indice);				
			for(i=0;i<condition.length;i++)
			{
				c1= condition.options[i].value;
				c2= c1.split('-');				
				var mini = parseInt(c2[0]);
				var maxi = parseInt(c2[1]);
				if(mini<=y && maxi>=y)
				{
					Prix = eval('formart.pu'+indice);
					Prix.value=c2[2]; // prix u
					p=c2[2];
				}
				// si y > max , on affiche la derniere val de prix u
				if(p==0) prixf=c2[2];
				minim[i] = parseInt(c2[0]);
			}
			if(p==0 && y!=""){
				Prix = eval('formart.pu'+indice);
				Prix.value=prixf;
			}
			/* gestion de l'objet select option */
			i=0;
			while(i<condition.length)
			{
				c1= condition.options[i].value;
				c2= c1.split('-');				
				minim[i] = parseInt(c2[0]);						
				if(i!=0 && minim[i-1] <= y && y <= minim[i]){
					if(y == minim[i]) condition.options[i].selected=true;
					else condition.options[i-1].selected=true;	
					/*if(minim[i-1] == y || y == minim[i]) condition.options[i].selected=true;	
					else condition.options[i-1].selected=true;	*/
					i=condition.length;					
				}					
				i++;				
			}			
		}	
		/* si la quantite est inferieur a la quantite minimum */
		if(y<qmin) condition.options[0].selected=true; 	
		/* si la quantite est superieure a la quantite max des qte min */				
		if(y > minim[condition.length-1]) 	condition.options[condition.length-1].selected=true; 	
}

function QteMinimum (indice){
	var condition1 = eval('formart.cond'+indice);
	//var zindex =condition1.selectedIndex;
	var vzindex = condition1.options[0].value;			
	var qmin = vzindex.split('-')[0];	
	return (qmin);
}
	
function AjoutCaddie(index){	
	var Qty = eval('document.formart.quantity'+index);		
	var x = Qty.value;
	var qmin =QteMinimum(index);	
	if((x%qmin == 0 && (x!=0 || x!="")) || (qmin==0)){
		document.formart.action="ajout_caddy.php?index="+index;
		document.formart.submit();		
	}
	else{
			alert("La quantité doit être un multiple entier de "+qmin);	
	}
}
	
function personnaliser(index,perso){

	//if(ns6) formart = document.forms["formart"];		
	var Qty = eval('document.formart.quantity'+index);	
	var x = Qty.value;
	var qmin =QteMinimum(index);	
	if(x%qmin == 0 && (x!=0 || x!="")){
		document.formart.action="index2.php?page=perso&index="+index+"&perso_arw="+perso;
		document.formart.submit();
	}
	else{
		alert("La quantité doit être un multiple entier de "+qmin);
	}
}

function popupwin(url){
	var hauteur=500;
	var largeur = 510;
	var winl=(screen.width - largeur) / 2;			
	var wint=(screen.height - hauteur) / 2;		
	var winprops = 'height='+hauteur+',width='+largeur+',top='+wint+',left='+winl+',scrollbars=auto,resizable'	
	var w = window.open(url,'popup',winprops);	
}
