// Gestion des Evénements

WG_addEvent(window, 'load', function() {
	//menu haut
	startMenu();
	// Evénements
	var allElements = document.getElementsByTagName("*");
	
	for(i = 0;i < allElements.length;i++){	
		// Switche les classes
		switch(allElements[i].className){
			case "choixGamme":	
				WG_addEvent(allElements[i], 'change', function() {		
					if (isIE) {
						e = window.event.srcElement;
					} else {
						e = this;
					}
					thisId= e.id;		
					optionsTags = e.getElementsByTagName("OPTION");
					for(i=0;i<optionsTags.length;i++){							
						if(optionsTags[i].selected){
							switch(optionsTags[i].className){
								case "choixGamme1":
									currentColor = 1;
									secondColor = "2";
									thirdColor = "3";
									break;
								case "choixGamme2":
									currentColor = 2;
									secondColor = "1";
									thirdColor = "3";
									break;
								case "choixGamme3":
									currentColor = 3;
									secondColor = "2";
									thirdColor = "1";
									break;
							}
						}
					}
					/* Vide les select */
					// SelectBox de paume 
					paume = WG_getE("paume_"+thisId);
					paumeChilds = paume.childNodes;
					while(paume.hasChildNodes()){
						paumeChild = paumeChilds.item(0);
						paume.removeChild(paumeChild);
					}
					// SelectBox de poche 
					poche = WG_getE("poche_"+thisId);
					pocheChilds = poche.childNodes;
					while(poche.hasChildNodes()){
						pocheChild = pocheChilds.item(0);
						poche.removeChild(pocheChild);
					}
					// SelectBox de ext 
					ext = WG_getE("ext_"+thisId);
					extChilds = ext.childNodes;
					while(ext.hasChildNodes()){
						extChild = extChilds.item(0);
						ext.removeChild(extChild);
					}
					// SelectBox de laniere 
					laniere = WG_getE("laniere_"+thisId);
					laniereChilds = laniere.childNodes;
					while(laniere.hasChildNodes()){
						laniereChild = laniereChilds.item(0);
						laniere.removeChild(laniereChild);
					}
					/* Insère la balise option "selectionnez" FO_SHOP_SELECTIONNER */
					paumeChild = document.createElement('option');
					paume.setAttribute("value","none");
					paume.appendChild(paumeChild);
					paumeChild.text = FO_SHOP_SELECTIONNER;
					pocheChild = document.createElement('option');
					poche.setAttribute("value","none");
					poche.appendChild(pocheChild);
					pocheChild.text = FO_SHOP_SELECTIONNER;
					extChild = document.createElement('option');
					ext.setAttribute("value","none");
					ext.appendChild(extChild);
					extChild.text = FO_SHOP_SELECTIONNER;
					laniereChild = document.createElement('option');
					laniere.setAttribute("value","none");
					laniere.appendChild(laniereChild);
					laniereChild.text = FO_SHOP_SELECTIONNER;
					/* Rempli les select */
					var couleurs = new Array();
					var optionBox = new String();
					couleurs = WG_getE("couleurs_"+currentColor+"_"+thisId).value.split('_');
					for(var i=0; i<couleurs.length; i++){
						paumeChild = document.createElement('option');
						paume.appendChild(paumeChild);
						paumeChild.text = couleurs[i];
						pocheChild = document.createElement('option');
						poche.appendChild(pocheChild);
						pocheChild.text = couleurs[i];
						extChild = document.createElement('option');
						ext.appendChild(extChild);
						extChild.text = couleurs[i];
						laniereChild = document.createElement('option');
						laniere.appendChild(laniereChild);		
						laniereChild.text = couleurs[i];			
					}
					/* Affiche le prix */
					show("prix_"+currentColor+"_"+thisId);
					hide("prix_"+secondColor+"_"+thisId);
					hide("prix_"+thirdColor+"_"+thisId);
				});
				break;
			case "openPopupImage":
				WG_addEvent(allElements[i], 'mouseover', function() {		
					if (isIE) {
						e = window.event.srcElement;
					} else {
						e = this;
					}
					e.style.cursor = "pointer";
				});
				WG_addEvent(allElements[i], 'click', function() {		
					if (isIE) {
						e = window.event.srcElement;
					} else {
						e = this;
					}
					FO_openPopupImage(e.id);
				});
				break;
			case "openPopup":
				WG_addEvent(allElements[i], 'mouseover', function() {		
					if (isIE) {
						e = window.event.srcElement;
					} else {
						e = this;
					}
					e.style.cursor = "pointer";
					e.style.color = "#8AC016";
				});
				WG_addEvent(allElements[i], 'mouseout', function() {		
					e.style.color = "#434343";
				});
				WG_addEvent(allElements[i], 'click', function() {		
					if (isIE) {
						e = window.event.srcElement;
					} else {
						e = this;
					}
					FO_openPopup();
				});
				break;
			case "openPopupConditions":
				WG_addEvent(allElements[i], 'mouseover', function() {		
					if (isIE) {
						e = window.event.srcElement;
					} else {
						e = this;
					}
					e.style.cursor = "pointer";
				});
				WG_addEvent(allElements[i], 'click', function() {		
					if (isIE) {
						e = window.event.srcElement;
					} else {
						e = this;
					}
					FO_openPopupConditions();
				});
				break;
			case "produit":
				allForms = allElements[i].getElementsByTagName("FORM");
				for(j=0;j<allForms.length;j++){
					allForms[j].onsubmit = function(){
						allSelects = this.getElementsByTagName("SELECT");
						hasError = false;
						for(k=0;k<allSelects.length;k++){
							if(allSelects[k].value == "none"){
								hasError = true;
								break;
							}
						}						
						if(hasError){
							alert(FO_SHOP_MANQUE_PARAMS);
							return false;
						}else{
							return true;
						}
					}
				}
				break;
			default:
				break;
		}
		
		// Switche les ids
		switch(allElements[i].id){
			case "monEspace":
				allElements[i].onclick = function() {					
					if(WG_getE("login").style.display != "none"){
						hide("login");
						WG_getE("arrow_monEspace").src = "/img/common/btn-down.gif";
					}else{
						show("login");
						WG_getE("arrow_monEspace").src = "/img/common/btn-up.gif";
					}
				}
				break;
			case "monPanier":
				allElements[i].onclick = function() {					
					if(WG_getE("contenuPanier").style.display != "none"){
						hide("contenuPanier");
						WG_getE("arrow_monPanier").src = "/img/common/btn-down.gif";
					}else{
						show("contenuPanier");
						WG_getE("arrow_monPanier").src = "/img/common/btn-up.gif";
					}
				}
				break;
			case "fermerErreur":
				allElements[i].onclick = function() {	
					hide("centrage");
				}
				break;
			case "fermerInformation":
				allElements[i].onclick = function() {	
					hide("centrage");
				}
				break;
			case "loginEmail":
				allElements[i].onfocus = function() {	
					this.value = "";
				}
				allElements[i].onblur = function() {	
					if(this.value == "") this.value = this.title;
				}
				break;
			case "loginMotDePasse":
				allElements[i].onfocus = function() {	
					this.value = "";
				}
				allElements[i].onblur = function() {	
					if(this.value == "") this.value = this.title;
				}
				break;	
			case "creerCompte":
				allElements[i].onclick = function() {			
					show("creerCompteForm");
				}
				break;
			case "MdpPerdu":
				allElements[i].onclick = function() {
					if(WG_getE("centrageMdp").style.display != "none"){
						hide("centrageMdp");
					}else{
						show("centrageMdp");
					}
				}
				break;
			case "fermerMdp":
				allElements[i].onclick = function() {	
					hide("centrageMdp");
				}
				break;
		
			default:
				break;
		}
	}
});

