function afficheVignette(img){
  document.write('<a href="javascript:afficheMaxi(\''+img+'\')"><IMG SRC="Images/p'+img+'.jpg" BORDER=0></A>');
}
function afficheMaxi(chemin){
  html = '<HTML><HEAD><TITLE>Image</TITLE></HEAD>';
  html += '<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0 onBlur="javascript:window.close()">';
  html += '<table border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
  html += '<td><IMG SRC="Images/'+chemin+'_01.jpg" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width*2+14,document.imageTest.height*2+60)"></td>';
  html += '<td><IMG SRC="Images/'+chemin+'_02.jpg" BORDER=0></td>';
  html += '</tr><tr>'
  html += '<td><IMG SRC="Images/'+chemin+'_03.jpg" BORDER=0></td>';
  html += '<td><IMG SRC="Images/'+chemin+'_04.jpg" BORDER=0></td>';
  html += '</tr></table>';
  html += '</BODY></HTML>';
  popupImage = window.open('','_blank','width=350, height=350, left=50,top=10,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
  popupImage.document.open();
  popupImage.document.write(html);
  popupImage.document.close()
}

function bloque(question, numItem){
  for (var i=0;i<document.Form[question].length;i++)
	  document.Form[question][i].disabled=0;

  document.Form[question][numItem-1].disabled=1;
  document.Form[question][numItem-1].checked=0;
}
function bloqueCheck(src, dest, numItem){
	document.Form[dest+"_"+numItem].disabled=document.Form[src+"_"+numItem].checked;
}
function filtreQuest(dest, ref){
  for (var numItem=0;numItem<document.Form[ref+"_nbreItem"].value;numItem++)
    for (var i=0;i<document.Form[dest+"_"+numItem].length;i++) {
      if (document.Form[ref+"_"+numItem].checked) affiche("Ligne"+dest+"_"+numItem);
	  else {cache("Ligne"+dest+"_"+numItem, "Compl"+dest+"_"+numItem);}
	}
}
function affiche(){
  for (var i=0;i<affiche.arguments.length;i++)
    document.getElementById("Tab"+affiche.arguments[i]).style.display='block';
}
function cache(){
  for (var i=0;i<cache.arguments.length;i++) {
    document.getElementById("Tab"+cache.arguments[i]).style.display='none';
	videQuest(cache.arguments[i]);
  }
}
function coche(cible, source){
  nbreRep=0;
  
  if (document.Form[source]){ 
    if (document.Form[source].checked) nbreRep=1;
  } else if (document.Form[source+"_0"]) {
    for (var i=0;i<document.Form[source+"_nbreItem"].value;i++) 
	  if (document.Form[source+"_"+i].checked) nbreRep+=1;
	  if (document.Form[source+"_PresAutre"].value==1 && document.Form[source+"_98"].checked) nbreRep+=1;
  }

  if (nbreRep>0) affiche(cible);
  else cache(cible);
}

function videQuest(question){
	if (document.Form[question]) {
	  if (document.Form[question].type=="textarea"||document.Form[question].type=="text") vide_texte(question);
	  else if (document.Form[question][0].type=="radio") vide_radio(question);
	} else {
	  if (document.Form[question+"_1"].type=="checkbox") vide_tout(question);
	  else if (document.Form[question+"_1"][0].type=="radio") 
	    for (i=0;i<document.Form[question+"_nbreLigne"].value;i++) vide_radio(question+"_"+i);
	}
}
// fonctions spécifiques au type texte
function vide_texte(question){
  document.Form[question].value="";
}

// fonctions spécifiques au type radio
function vide_radio(question){
	for (var i=0;i<document.Form[question].length;i++)
	  document.Form[question][i].checked=false;
}

// fonctions spécifiques au type checkbox
function vide_aucun(question){
	if (document.Form[question+"_PresAucun"].value==1) document.Form[question+"_99"].checked=false;
}
function vide_tout(question){
	for (var i=0;i<document.Form[question+"_nbreItem"].value;i++)
	  document.Form[question+"_"+i].checked=false;
	if (document.Form[question+"_PresAutre"].value==1) {document.Form[question+"_98"].checked=false;document.Form[question+"_Autre"].value=""}
}

// fonctions spécifiques au type vote
function vide_vote(question){
	for (var i=0;i<document.Form[question+"_nbreItem"].value;i++)
	  document.Form[question+"_"+i].value="";
	choix=1
}
function ajoute(question,num){
  if (choix<=document.Form[question+"_nbreCriteres"].value){
    document.Form[question+"_"+num].value=choix;
    choix+=1
  }
}
function enleve(question,num){
  if (choix>=1){
    valeur=document.Form[question+"_"+num].value;
    for (i=0;i<document.Form[question+"_nbreItem"].value;i++)
	  if (document.Form[question+"_"+i].value!="" && document.Form[question+"_"+i].value>valeur)
	    document.Form[question+"_"+i].value-=1;
    document.Form[question+"_"+num].value="";
    choix-=1
  }
}
function vote(question, num){
  if (document.Form[question+"_"+num].value=="") ajoute(question,num)
  else enleve(question,num)
}



// fonctions de vérification des questions
function verif_tablo(question){
  err=0;
  
  for (var i=0;i<document.Form[question+"_nbreLigne"].value;i++)
    if (document.all["Ligne"+question+"_"+i].style.display!='none') err+=verif_ligne(question+"_"+i);

  if (err>0) document.all["Ligne"+question].className="errQuest";
  else document.all["Ligne"+question].className="question";

  return err;
}
function verif_ligne(question){	
  nbreRep=0;
  for (var i=0;i<document.Form[question].length;i++)
	if (document.Form[question][i].disabled || document.Form[question][i].checked) nbreRep=1;
	
  if (nbreRep==1) {
	document.all["Ligne"+question].className="ligne";
	err=0;
  } else {
	document.all["Ligne"+question].className="errLigne";
	err=1;
  }

  return err;
}
function verif_checkbox(question, maximum){
  nbreRep=0;
  err=0;
  
  for (var i=0;i<document.Form[question+"_nbreItem"].value;i++)
    if (document.Form[question+"_"+i] && document.Form[question+"_"+i].checked) nbreRep+=1;
	
  if (document.Form[question+"_PresAutre"].value==1 && document.Form[question+"_98"].checked) nbreRep+=1;
  if (document.Form[question+"_PresAucun"].value==1 && document.Form[question+"_99"].checked) nbreRep+=1;

  if (nbreRep==0) {err=1; document.all["Ligne"+question].className="errQuest";}
  else if (maximum!="" && nbreRep>maximum) {err=1; document.all["Ligne"+question].className="errQuest";}
  else {err=0; document.all["Ligne"+question].className="question";;}
  
  return err;
}
function verif_radio(question){	
  nbreRep=0;
  for (var i=0;i<document.Form[question].length;i++)
	if (document.Form[question][i].disabled || document.Form[question][i].checked) nbreRep=1;
	
  if (nbreRep==1) {
	document.all["Ligne"+question].className="question";
	err=0;
  } else {
	document.all["Ligne"+question].className="errQuest";
	err=1;
  }

  return err;
}
function verif_select(question){	
  if (document.Form[question].selectedIndex!==0) {
	document.all["Ligne"+question].className="question";
	err=0;
  } else {
	document.all["Ligne"+question].className="errQuest";
	err=1;
  }

  return err;
}
function verif_texte(question){	
  if (document.Form[question].value!="") {
	document.all["Ligne"+question].className="question";
	err=0;
  } else {
	document.all["Ligne"+question].className="errQuest";
	err=1;
  }

  return err;
}
function verif_nbre(question){
  if (document.Form[question].value=="" || isNaN(document.Form[question].value) || 1*document.Form[question].value>1*document.Form[question+"_nbreMax"].value) {
	document.all["Ligne"+question].className="errQuest";
	  err=1;
  } else {
	document.all["Ligne"+question].className="question";
	  err=0;
  }

  return err;
}
function verif_regexp(question){
  var modele=document.Form[question+"_modele"].value;
  
  err=0;
  if (document.Form[question].value=="") err=1;
  else if (document.Form[question].value.search(modele)) err=1;
  
  if (err) document.all["Ligne"+question].className="errQuest";
  else document.all["Ligne"+question].className="question";

  return err;
}
function verif_vote(question){
  nbreRep=0;

  for (i=0;i<document.Form[question+"_nbreItem"].value;i++)
    if (document.Form[question+"_"+i].value!="") nbreRep+=1;

  if (nbreRep<document.Form[question+"_nbreCriteres"].value) {
	document.all["Ligne"+question].className="errQuest";
	err=1;
  } else { 
	document.all["Ligne"+question].className="question";
	err=0;
  }
  return err;
}
