var posOn="";
var posOff="";
function choix_surbrillanceOn(idx){
	if(document.getElementById('formProduit-'+idx).checked == false) {
		tr_lignes = document.getElementById('tr-formProduit-'+idx);
		if(tr_lignes){
			tr_lignes.className = 'lignes_over lignes';
		}
	}
}
function choix_surbrillanceOff(idx){
	if(document.getElementById('formProduit-'+idx).checked == false) {
		tr_lignes = document.getElementById('tr-formProduit-'+idx);
		if(tr_lignes){
			tr_lignes.className = 'lignes';
		}
	}
}


function click_ligne(idx) {
	radio_lignes = document.getElementById('formProduit-'+idx);
	tr_ligne = document.getElementById('tr-formProduit-'+idx);
	/** initialisation des lignes en gris */
	tr_lignes = $$('tr.lignes');
	for(var cpt=0;cpt<tr_lignes.length;cpt++) {
		//tr_lignes[cpt].className=""
		tr_lignes[cpt].className='lignes';
	}
	formProduit = $('p-formProduit-'+idx);
	execElmtCRB(formProduit,true);
	if(radio_lignes) {
		if(radio_lignes.checked) {
			tr_ligne.className = 'lignes lignes_on';

			var array_tr = $$('.lignes');
			for(var i=0;i<array_tr.length;i++) {
				array_tr[i].id = (array_tr[i].id).replace(new RegExp("\\.", "g"),'*');
					
				if(array_tr[i].className == 'lignes lignes_on'){
					
					//Hack pour les id du genre "avfwpro.essentiel.s"
					
					var array_img = $$('#'+array_tr[i].id+' .noir');
					var array_img_active = $$('#'+array_tr[i].id+' .rouge');
					for(var cpt=0;cpt<array_img_active.length;cpt++) {
						array_img[cpt].style.display="";
						array_img_active[cpt].style.display="none";
					}
				}else{
					var array_img = $$('#'+array_tr[i].id+' .noir');
					var array_img_active = $$('#'+array_tr[i].id+' .rouge');
					for(var cpt=0;cpt<array_img.length;cpt++) {
						array_img_active[cpt].style.display="";
						array_img[cpt].style.display="none";
					}					
				}
				
				array_tr[i].id = (array_tr[i].id).replace(new RegExp("\\*", "g"),'.');
			}
		}
	}
}
function listenCheckRedBox(test) {
	var classCRB = $$(".inputRed");
	var elmtCRB = "";
	var size = classCRB.length;
	for(var j=0;j<size;j++) {
			elmtCRB = classCRB[j];
			if(elmtCRB.className!="inputRed libelle-produit") {
				var elmtCRB_tags="";
				var elmtCRB_input="";
				execElmtCRB(elmtCRB,false);
				Event.observe(elmtCRB,'click',execEvent);
				if(test != true){
					if($(elmtCRB.id+"-label")) {
						Event.observe($(elmtCRB.id+"-label"),'click', execEventLabel);
					}
				}
			}
	}
}
function execEventLabel(event) {
	elmtCRBInput = Event.element(event);
	elmtCRBId = (elmtCRBInput.id).replace(new RegExp("-label", "g"),'');
	elmtCRB = $(elmtCRBId);
	execElmtCRB(elmtCRB,true);
}

function execEvent(event) {
	elmtCRB = Event.element(event);
	execElmtCRB(elmtCRB,true);
}
function execElmtCRB(elmtCRB,bverif) {
	if(elmtCRB) {
		elmtCRB_tags = elmtCRB.getElementsByTagName('input');
		elmtCRB_input = elmtCRB_tags[0];
		if(elmtCRB_input) {
			
			if(elmtCRB_input.type=="radio") {
				inputList = document.getElementsByName(elmtCRB_input.name);
				if(bverif) {
					checkRedBox(elmtCRB_input);
				}
				var inputElt = "";
				var size = inputList.length;
				if($("p-"+elmtCRB_input.id)) {
						
					($("p-"+elmtCRB_input.id).id)= ($("p-"+elmtCRB_input.id).id).replace(new RegExp("\\.", "g"),'*');
					elmtCRB_input.id = elmtCRB_input.id.replace(new RegExp("\\.", "g"),'*');
					
					// bouton radio : civilite
					if($$('#'+"p-"+elmtCRB_input.id+' .pointRed').length>0) {
						imgBackground ="url(/images/color/red/picto_radio.gif) no-repeat 0 0";
						$("p-"+elmtCRB_input.id).style.background=imgBackground;
						posOn = "0 -14px";
						posOff = "0 0";
					}
					// bouton radio : choix de la formule
					if($$('#'+"p-"+elmtCRB_input.id+' .pointGrey').length>0) {
						imgBackground ="url(/images/picto_radio_1.gif) no-repeat 0 0";
						$("p-"+elmtCRB_input.id).style.background=imgBackground;	
						posOn = "0 -14px";
						posOff = "0 0";
					}
					//($("p-"+elmtCRB_input.id).id) = ($("p-"+elmtCRB_input.id).id).replace(new RegExp("\\*", "g"),'.');
					//elmtCRB_input.id = elmtCRB_input.id.replace(new RegExp("\\*", "g"),'.');
				}
				if($$('span input.formProduit').length>0) {
					imgBackground ="url(/images/color/red/bg_radio.gif) no-repeat 0 0"; 
					$("p-"+elmtCRB_input.id).style.background=imgBackground;
					posOn = "0 0";
					posOff = "0 -30px";
				}
				for(var i=0;i<size;i++) {
					inputElt = inputList[i];
					verifCheckRedBox(inputElt,$("p-"+inputElt.id),posOn,posOff);
				}
			} 	
			if(elmtCRB_input.type=="checkbox") {
				imgBackground ="url(/images/picto_checkbox.gif) no-repeat 0 0";
				posOn = "0 0px";
				posOff = "0 -14px";
				var inputElt = elmtCRB_input;
				if(bverif) {
					checkRedBox($(inputElt.id));
				}
				$("p-"+inputElt.id).style.background=imgBackground;		
				verifCheckRedBox($(inputElt.id),$("p-"+inputElt.id),posOn,posOff);
			} 
		}
	}
	elmtCRB_input.id = elmtCRB_input.id.replace(new RegExp("\\*", "g"),'.');
}
function checkRedBox(elmtCRB_input) {
	if(elmtCRB_input.checked &&  elmtCRB_input.type=="checkbox") {
		elmtCRB_input.checked = false;
	} else {
		elmtCRB_input.checked = true;
	}
}
function verifCheckRedBox(elmtCRB_input,elmtCRB,posOn,posOff) {
	(elmtCRB_input.id)= (elmtCRB_input.id).replace(new RegExp("\\.", "g"),'*');
	(elmtCRB.id)= (elmtCRB.id).replace(new RegExp("\\.", "g"),'*');
	
	if(elmtCRB_input && elmtCRB) {
		
		if(elmtCRB_input.checked) {
			elmtCRB.style.backgroundPosition = posOn;
			//elmtCRB.className = "inputRed " ;
		} else {
			elmtCRB.style.backgroundPosition = posOff;
			//elmtCRB.className = "inputRed " ;
		}
	}
	(elmtCRB_input.id)= (elmtCRB_input.id).replace(new RegExp("\\*", "g"),'.');
	(elmtCRB.id)= (elmtCRB.id).replace(new RegExp("\\*", "g"),'.');
}

function onClickCheckRedBox(input) {
	$(input).checked = true;
	listenCheckRedBox(true);
}

function listenCheckRedBoxTimeout(){
	setTimeout("listenCheckRedBox(true)",500);
}
Event.observe(window,'load',listenCheckRedBox);
