function hover(obj,over)
{
	if(document.all)
	{
		UL = obj.getElementsByTagName('ul');
		if(UL.length > 0)
		{
			sousMenu = UL[0].style;

			if (over==1)
			{
				//obj.style.background='url(images/site/www/fleche-rouge-menu.gif) no-repeat 2% 50%';
				sousMenu.display = 'block';
			}
			else
			{
				//obj.style.background='url(images/site/www/fleche-noir-menu.gif) no-repeat 2% 50%';
				sousMenu.display = 'none';
			}
		}
	}
}

function hover_couleur(obj,over,couleur)
{
	if(document.all)
	{
		UL = obj.getElementsByTagName('ul');
		if(UL.length > 0)
		{
			sousMenu = UL[0].style;

			if (over==1)
			{
				obj.style.background= couleur + ' url(images/site/www/fleche-rouge-menu.gif) no-repeat 2% 50%';
				sousMenu.display = 'block';
			}
			else
			{
				obj.style.background= 'url(images/site/www/fleche-noir-menu.gif) no-repeat 2% 50%';
				sousMenu.display = 'none';
			}
		}
	}
}


function genereMenuDeroulant(obj)
{
	if ( eval("document.getElementById('"+obj+"')")!=null )
	{
		LI = eval("document.getElementById('"+obj+"').getElementsByTagName('li')");
		nLI = LI.length;
		for(i=0; i < nLI; i++)
		{
			//LI[i].style.value='none';
			LI[i].onmouseover = function(){hover(this,1);}
			LI[i].onmouseout = function(){hover(this,0);}
		}
	}
}

function genereMenuDeroulantCouleur(obj, couleur)
{
	if ( eval("document.getElementById('"+obj+"')")!=null )
	{
		LI = eval("document.getElementById('"+obj+"').getElementsByTagName('li')");
		nLI = LI.length;
		for(i=0; i < nLI; i++)
		{
			LI[i].style.value='none';
			LI[i].onmouseover = function(){hover_couleur(this,1,couleur);}
			LI[i].onmouseout = function(){hover_couleur(this,0,couleur);}
		}
	}
}

/*Scripts pour la page Mes Achats*/

function AjoutCommentaire(Reference,idPartenaire){
	window.open("AjoutCommentaire.jsp?Reference="+Reference+"&idPartenaire="+idPartenaire,"test","toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,width=550,height=150,left=" + (screen.availWidth-1024) + ",top=250");
}

function AchatSuppression(Reference){
	window.open("SuppressionAchat.jsp?Reference="+Reference,"test","toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,width=550,height=350,left=" + (screen.availWidth-1024) + ",top=250");
}
/**/



/* Page Mes Pref */
function moveSelected(from, to, ajout, champListe) 
{	
	len = from.options.length - 1;
	
	for (i = len; i >= 0; i--) 
	{		
		if (from.options[i].selected) 
		{
			if ( ajout == 1 )  // concaténation des valeurs
			{	
				var tableau = champListe.value.split(/[;]/);
				if (tableau.length>10)
				{
					alert('You can\'t choose more than 10 favourite retailers.');
					return false;
				}
				else
				{
					champListe.value = champListe.value + from.options[i].value +";"; 
				}
			}

			to.options[to.options.length] = new Option(from.options[i].text, from.options[i].value);
			from.options[i] = null;				
		}
	}

	if ( ajout == 0 ) // on recupere les elements dans l'ordre de la liste de selection
	{
		champListe.value = '';
		nbreElements = from.options.length - 1;
		for (i = nbreElements; i >= 0; i--) 
		{
			champListe.value = from.options[i].value + ";" + champListe.value ; 
		}
	}
	return true;
}


function Deplacer(sens, Liste, champListe)
{
    if(Liste==null){return false;};
    var OptionSel= Liste.selectedIndex;	
	
	switch (true)
	{
		case ( Liste.length == -1 & sens==-1):
			alert('there is no retailer to move');
			break;
		case(OptionSel== -1):
			alert('select the retailer to move');
			break;
		case(Liste.length==0):
			alert('there is only one retailer!');
			break;
		case(OptionSel== 0 && sens==-1):
			//alert('La première option ne peut être déplacée plus haut');
			break;
		case(OptionSel== Liste.length-1 && sens==1):
			//alert('La dernière option ne peut être déplacée plus bas');
			 break;
		case(sens==-1):
			// Ce code est le code qui est appelé lorque l'on veut remonter une 
			//		option dans la liste
			// On mémorise dans des variables le texte et les valeurs des éléments 
			// 		que l'on déplace.
			// Il suffit ensuite d'échanger les deux éléments
			var moveText1 = Liste[OptionSel-1].text;
			var moveText2 = Liste[OptionSel].text;
			var moveValue1 = Liste[OptionSel-1].value;
			var moveValue2 = Liste[OptionSel].value;
			// Echange des éléments
			Liste[OptionSel].text = moveText1;
			Liste[OptionSel].value = moveValue1;
			Liste[OptionSel-1].text = moveText2;
			Liste[OptionSel-1].value = moveValue2;
			Liste.selectedIndex = OptionSel-1;
			break;
		case(sens==1):
			 // On procède de la même manière que pour faire monter une option.
			 // La différence, c que dans ce cas, on prend en compte l'option suivante, 
			 // 	et non la précedente comme auparavant
			 var moveText1 = Liste[OptionSel].text;
			 var moveText2 = Liste[OptionSel+1].text;
			 var moveValue1 = Liste[OptionSel].value;
			 var moveValue2 = Liste[OptionSel+1].value;
			 Liste[OptionSel].text = moveText2;
			 Liste[OptionSel].value = moveValue2;
			 Liste[OptionSel+1].text = moveText1;
			 Liste[OptionSel+1].value = moveValue1;
			 Liste.selectedIndex = OptionSel+1;
			 break;
    }

	champListe.value = '';
	nbreElements = Liste.options.length - 1;
	for (i = 0; i <= nbreElements; i++) 
	{
		champListe.value = champListe.value + Liste.options[i].value +";"; 
	}
}


function switchcolor(id,color) 
{
	var element=document.getElementById(id);
	element.style.color=color;
}



function CheckForm()
{
	if(document.FormulaireQuestionnaire.critere_3.value == '0')
	{
		alert("To valid the questionnaire, you must indicate your professional situation.");
	 	return false;
	}
	else if(document.FormulaireQuestionnaire.critere_6.value == '0')
	{
		alert("To valid the questionnaire, you must indicate your internet connection.");
		return false;
	}
	
	else if(document.FormulaireQuestionnaire.critere_7.value == '0')
	{
		alert("To valid the questionnaire,you must indicate your internet service provider.");
	 	return false;
	}
	else if(document.FormulaireQuestionnaire.critere_8.value == '0')
	{
		alert("To valid the questionnaire, you must indicate your mobile phone provider.");
	 	return false;
	}
	else if (document.FormulaireQuestionnaire.texte_8.value != '' && document.FormulaireQuestionnaire.texte_8.value.length != 11)
	{
		alert("your number must :\n- start with 07\n- have 11 numbers");
		return false;
	}
	/*
	else if(document.FormulaireQuestionnaire.critere_10[0].checked == false && document.FormulaireQuestionnaire.critere_10[1].checked == false)
	{
		alert("Pour valider le questionnaire, vous devez préciser si vous désirez recevoir des offres par SMS.");
	 	return false;
	}
	*/
	/*
	else if(document.FormulaireQuestionnaire.condition.checked == false )
	{
		alert("To valid the questionnaire, you must certify provided information is correct.");
	 	return false;
	}
	*/

	alert("Your questionnaire has been successfully updated.");
	return true;
}