function positionneSelect(idSelect,valeur){
	var longueur=document.getElementById(idSelect).length;
	var i;
	for(i=longueur-1;i>=0;i--){
		if(document.getElementById(idSelect).options[i].value==valeur){
			document.getElementById(idSelect).selectedIndex=i;
			return;
		}
	}
}
/**
	Gestion des cookies
*/

function EcrireCookie(nom, valeur)
{
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return "";
}

function EffaceCookie(nom)
{
	date=new Date;
	date.setFullYear(date.getFullYear()-1);
	EcrireCookie(nom,null,date);
}

function checkValid(form,avecPart){
    avecP = avecPart || false;
	if(coloreColonnes()){
		EcrireCookie("artToAdd","oui");
		if (!avecP) {
		    form.elements["montantParticipation"].value="0";
		}
		form.submit();
		//return false;
	}
}
function checkValidPanier(form){
	EcrireCookie("artToAdd","oui");
	form.submit();
}


/**
 *
 * @access public
 * @return void
 **/
function checkValidPartGlobale(form){
    if(form.montantParticipationGlobale.value!="" && form.montantParticipationGlobale.value>0){
        EcrireCookie("artToAdd","oui",null,"/produits/");
        form.submit();
    }
    else{
        alert("Le montant doit être supérieur à 0");
    }
}

function coloreColonneQtes(){
	var total=0;
	var leReturn=true;
	var part = document.forms["ajoutProduit"].elements["montantParticipation"].value;
    if (part=="" || parseInt(part)==0) {
    	for(i in qtes){
    		total+=1*(document.forms["ajoutProduit"].elements["YAPBout_qtes[" + qtes[i] + "]"].value);
    	}
    	for(i in qtes){
    		var cellule=document.forms["ajoutProduit"].elements["YAPBout_qtes[" + qtes[i] + "]"].parentNode;
    		if(total){
    			cellule.className="selection";
    			document.getElementById("choixObligatoire").style.display="none";
    			document.getElementById("choixObligatoire").firstChild.nodeValue="";
    		}else{
    			cellule.className="selectionHighlight";
    			document.getElementById("choixObligatoire").style.display="block";
    			document.getElementById("choixObligatoire").firstChild.nodeValue="Vous devez choisir au moins une quantité !";
    			leReturn=false;
    		}
    	}
    }
	return leReturn;
}
function coloreColonneValeur(){
	var leReturn=true;
	for(i in qtes){
		var sousTotal=1*(document.forms["ajoutProduit"].elements["YAPBout_qtes[" + qtes[i] + "]"].value);
		var cellule=document.forms["ajoutProduit"].elements["YAPBout_idArticles[" + qtes[i] + "]"].parentNode;
		if(sousTotal){
			if(!document.forms["ajoutProduit"].elements["YAPBout_idArticles[" + qtes[i] + "]"].value){
				document.getElementById("choixObligatoire").style.display="block";
				document.getElementById("choixObligatoire").firstChild.nodeValue="Vous devez choisir une valeur !";
				cellule.className="selectionHighlight";
				leReturn=false;
			}else{
				document.getElementById("choixObligatoire").style.display="block";
				document.getElementById("choixObligatoire").firstChild.nodeValue="";
				cellule.className="selection";
			}
		}else{
			cellule.className="selection";
		}
	}
	return leReturn;
}
function coloreColonnes(){
	return coloreColonneQtes() && coloreColonneValeur();
}

ancPrix=new Array();