function PopupImage(img) { 
titre="Agrandissement"; 
w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=no'); 
w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>"); 
w.document.write("<SCRIPT language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+100,document.images[0].height+130); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT>"); 
w.document.write("<BODY onload='checksize()' onblur='window.close()' onclick='window.close()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
w.document.write("<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><TR>");
w.document.write("<TD valign='middle' align='center'><IMG src='"+img+"' border=0 alt='Mon image'>"); 
w.document.write("</TD></TR></TABLE>");
w.document.write("</BODY></HTML>"); 
w.document.close(); 
} 
/***************************************************************************************************************/
function boogleElement(id){
  for(i=0;i<arguments.length;++i){
    if(document.getElementById(arguments[i])){
      if(document.getElementById(arguments[i]).style.display == "none"){
        document.getElementById(arguments[i]).style.display = "block";
      } else {
        document.getElementById(arguments[i]).style.display = "none";
      }
    }
  }
  return true;
}
/***************************************************************************************************************/

function doAjaxQuery(action,param){
  if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
  else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  else return(false);

  xhr_object.open("GET", 'config/ajax.php?action=' + action + '&' + param, false);
  xhr_object.send(null);


  if(xhr_object.readyState == 4) {
    return unescape(xhr_object.responseText);
  } else {
    alert("error");
  }
}
/***************************************************************************************************************/
function hideElement(id){
  for(i=0;i<arguments.length;++i){
    if(document.getElementById(arguments[i])){
      document.getElementById(arguments[i]).style.display = "none";
    }
  }
  return false;
}
/***************************************************************************************************************/
function showElement(id){
  for(i=0;i<arguments.length;++i){
    if(document.getElementById(arguments[i])){
      document.getElementById(arguments[i]).style.display = "block";
    }
  }
  return false;
}
/***************************************************************************************************************/

function getValue(id){
 if(document.getElementById(id)) returnval = document.getElementById(id).value;
 else returnval = '';
 return returnval;
}
 /***************************************************************************************************************/

function setHtml(id,value,type){
  if(type=='a') {
    document.getElementById(id).innerHTML = document.getElementById(id).innerHTML + value;
  } else if(type=='-a') {
    document.getElementById(id).innerHTML = value + document.getElementById(id).innerHTML;
  } else {
    document.getElementById(id).innerHTML = value;
  }
  return true;
}
/***************************************************************************************************************/
function addToSelect(sel, value, label){
  to = document.getElementById(sel);
  toLength = to.options.length

  to.options[toLength] = new Option(label,value);
}
/***************************************************************************************************************/
function resetSelect(sel){
  to = document.getElementById(sel);
  to.options.length = 0;

}
/***************************************************************************************************************/
function getProfessionnel(){
  result = doAjaxQuery('getProfessionnel','search='+getValue('professionnel_search'));
  if(result == '') {alert('Aucun professionnel ne correspond à votre recherche. Insérez le.'); showElement('newProfessionnel');}
  else {
	 resetSelect('professionnel'); 
	arrResult = result.split('|');
	for(i=0 ; i<arrResult.length ; ++i){
		values = arrResult[i].split('#');
		addToSelect('professionnel', values[0], values[1]);
	}
  }
}
/***************************************************************************************************************/
function insertNewProfessionnel(){
nom = getValue('nomProfessionnel');
prenom = getValue('prenomProfessionnel');
complete = nom + ' ' + prenom;
  result = doAjaxQuery('insertNewProfessionnel','nom='+nom + '&prenom='+prenom);
  sel = document.getElementById('professionnel');
  sel.options.length = 0;
		addToSelect('professionnel', result, complete);
alert(complete + ' a été rajouté à la base de données'); 
hideElement('newProfessionnel');
}
/***************************************************************************************************************/
function insertProfessionnel(id, table, type){
  result = doAjaxQuery('insertProfessionnel','table='+table + '&type='+type + '&typeID='+id + '&professionnel='+getValue('professionnel'));
  sel = document.getElementById('professionnel');
  fromValue = sel.options[sel.selectedIndex].text;
  links = '<span id="professionnelToDelete'+getValue('professionnel')+'"><a href="javascript:;" onClick="deleteProfessionnel('+ id +', \'' + type + '\', \'' + table + '\', ' + getValue('professionnel') +')">[Supprimer] ' + fromValue + '</a></span><br>';
 if(!document.getElementById('professionnelToDelete'+getValue('professionnel')))
 setHtml('professionnelToDeleteContainer',links, 'a');
}
/***************************************************************************************************************/
function deleteProfessionnel(ref, type, table, id){
  result = doAjaxQuery('deleteProfessionnel','table='+table + '&type='+type + '&typeID='+ref + '&professionnel='+id);
  if(result == 'OK') 
  hideElement('professionnelToDelete'+id);
}

/***************************************************************************************************************/
function insertTechnicien(id, table, type){
  result = doAjaxQuery('insertTechnicien','table='+table + '&type='+type + '&typeID='+id + '&professionnel='+getValue('professionnel')+ '&categorie='+getValue('categorie'));
  sel = document.getElementById('professionnel');
  fromValue = sel.options[sel.selectedIndex].text;
  links = '<span id="technicienToDelete'+getValue('professionnel')+'"><a href="javascript:;" onClick="deleteTechnicien('+ id +', \'' + type + '\', \'' + table + '\', ' + getValue('professionnel') + ', ' +  getValue('categorie') +')">[Supprimer] ' + fromValue + '</a></span><br>';
 if(!document.getElementById('technicienToDelete'+getValue('professionnel')))
 setHtml('technicienToDeleteContainer',links, 'a');
}
/***************************************************************************************************************/
function deleteTechnicien(ref, type, table, id, categorie){
  result = doAjaxQuery('deleteTechnicien','table='+table + '&type='+type + '&typeID='+ref + '&professionnel='+id + '&categorie='+categorie);
  if(result == 'OK') 
  hideElement('technicienToDelete'+id);
}



/***************************************************************************************************************/
function getOrganisation(){
  result = doAjaxQuery('getOrganisation','search='+getValue('organisation_search'));
  if(result == '') alert('Not found');
  else {
	 resetSelect('organisation'); 
	arrResult = result.split('|');
	for(i=0 ; i<arrResult.length ; ++i){
		values = arrResult[i].split('#');
		addToSelect('organisation', values[0], values[1]);
	}
  }
}
/***************************************************************************************************************/
function insertOrganisation(id, table, type){
  result = doAjaxQuery('insertOrganisation','table='+table + '&type='+type + '&typeID='+id + '&organisation='+getValue('organisation'));
  sel = document.getElementById('organisation');
  fromValue = sel.options[sel.selectedIndex].text;
  links = '<span id="organisationToDelete'+getValue('organisation')+'"><a href="javascript:;" onClick="deleteOrganisation('+ id +', \'' + type + '\', \'' + table + '\', ' + getValue('organisation') +')">[Supprimer] ' + fromValue + '</a></span><br>';
 setHtml('organisationToDeleteContainer',links, 'a');
}
/***************************************************************************************************************/
function deleteOrganisation(ref, type, table, id){
  result = doAjaxQuery('deleteOrganisation','table='+table + '&type='+type + '&typeID='+ref + '&organisation='+id);
  if(result == 'OK') 
  hideElement('organisationToDelete'+id);
}
/***************************************************************************************************************/
function insertOrganisationCategorie(organisation){
  result = doAjaxQuery('insertOrganisationCategorie','id=' + organisation + '&categorie='+getValue('categorie'));
  sel = document.getElementById('categorie');
  fromValue = sel.options[sel.selectedIndex].text;

links = '<span id="categorieToDelete'+getValue('categorie')+'"><a href="javascript:;" onClick="deleteOrganisationCategorie('+ organisation +', ' + getValue('categorie') + ')">[Supprimer] ' + fromValue + '</a></span><br>';
 if(!document.getElementById('categorieToDelete'+getValue('categorie'))) setHtml('categorieToDeleteContainer',links, 'a');
}
/***************************************************************************************************************/
function insertProfessionnelCategorie(professionnel){
  result = doAjaxQuery('insertProfessionnelCategorie','id=' + professionnel + '&categorie='+getValue('categorie'));
  sel = document.getElementById('categorie');
  fromValue = sel.options[sel.selectedIndex].text;

links = '<span id="categorieToDelete'+getValue('categorie')+'"><a href="javascript:;" onClick="deleteProfessionnelCategorie('+ professionnel +', ' + getValue('categorie') + ')">[Supprimer] ' + fromValue + '</a></span><br>';
 if(!document.getElementById('categorieToDelete'+getValue('categorie'))) setHtml('categorieToDeleteContainer',links, 'a');
}
/***************************************************************************************************************/
function deleteOrganisationCategorie(organisation, categorie){
  result = doAjaxQuery('deleteOrganisationCategorie','id=' + organisation + '&categorie='+categorie);
  hideElement('categorieToDelete'+categorie);
}
/***************************************************************************************************************/
function deleteProfessionnelCategorie(professionnel, categorie){
  result = doAjaxQuery('deleteProfessionnelCategorie','id=' + professionnel + '&categorie='+categorie);
  hideElement('categorieToDelete'+categorie);
}
/***************************************************************************************************************/
function getFilm(){
  result = doAjaxQuery('getFilm','search='+getValue('film_search'));
  if(result == '') alert('Not found');
  else {
	 resetSelect('film'); 
	arrResult = result.split('|');
	for(i=0 ; i<arrResult.length ; ++i){
		values = arrResult[i].split('#');
		addToSelect('film', values[0], values[1]);
	}
  }
}
/***************************************************************************************************************/
function insertFilm(id, table, type){
  result = doAjaxQuery('insertFilm','table='+table + '&type='+type + '&typeID='+id + '&film='+getValue('film'));
  sel = document.getElementById('film');
  fromValue = sel.options[sel.selectedIndex].text;
  links = '<span id="filmToDelete'+getValue('film')+'"><a href="javascript:;" onClick="deleteFilm('+ id +', \'' + type + '\', \'' + table + '\', ' + getValue('film') +')">[Supprimer] ' + fromValue + '</a></span><br>';
 setHtml('filmToDeleteContainer',links, 'a');
}
/***************************************************************************************************************/
function deleteFilm(ref, type, table, id){
  result = doAjaxQuery('deleteFilm','table='+table + '&type='+type + '&typeID='+ref + '&film='+id);
  if(result == 'OK') 
  hideElement('filmToDelete'+id);
}
/***************************************************************************************************************/
function createFolder(type, name){
  result = doAjaxQuery('createFolder','type='+type + '&name='+name );
  setHtml('folderName', result);
}

/***************************************************************************************************************/
function updateGalery(type, name, id){
  result = doAjaxQuery('updateGalery','type='+type + '&name='+name + '&id='+id );
  document.getElementById('defaultImage').src=result;
}
/***************************************************************************************************************/
function deleteReponseConcours(id){
	rep = confirm('Voulez-vous effacer cette réponse ?');
	if (rep){
  result = doAjaxQuery('deleteReponseConcours','id='+id);
  if(result == 'OK') 
  hideElement('reponse'+id);
	}
}
/***************************************************************************************************************/
function insertWebzineLink(id, table){
if(!document.getElementById(table+'ToDelete'+getValue(table))){
result = doAjaxQuery('insertWebzineLink','table='+table + '&webzine='+id + '&id='+getValue(table));
  sel = document.getElementById(table);
  fromValue = sel.options[sel.selectedIndex].text;
  links = '<span id="' + table +'ToDelete'+getValue(table)+'"><a href="javascript:;" onClick="deleteWebzineLink('+ getValue(table) +', \'' + table + '\', ' + id + ')">[Supprimer]</a> ' + fromValue + '<br><br></span>';
 
 setHtml(table+'ToDeleteContainer',links, 'a');
}
}
/***************************************************************************************************************/
function deleteWebzineLink(id, table, webzine){
  result = doAjaxQuery('deleteWebzineLink','table='+table + '&webzine='+webzine + '&id='+id);
  if(result == 'OK') 
  hideElement(table+'ToDelete'+id);
}
/***************************************************************************************************************/
function updateAnnuaireCategorie(table, id, nom, description){
	result = doAjaxQuery('updateAnnuaireCategorie','table='+table + '&id='+id + '&nom='+getValue(nom)+ '&description='+getValue(description));
	alert("Catégorie mise à jour !");
}
/***************************************************************************************************************/
function insertAnnuaireCategorie(table,nom,description,container){
	nom = getValue(nom);
	description = getValue(description);
	doAjaxQuery('insertAnnuaireCategorie','table='+table  + '&nom='+nom+ '&description='+description);
	setHtml(container,nom+'<br>', 'a');
	alert("Catégorie ajoutée !");
}
/***************************************************************************************************************/
function deleteAnnuaireCategorie(table,id){
	rep = confirm("Etes-vous certain de vouloir supprimer cette catégorie?");
	if(rep){
		doAjaxQuery('deleteAnnuaireCategorie','table='+table  + '&id='+id);
		hideElement(table+id);

	} 
}
/***************************************************************************************************************/
function deleteJuridique(id){
	rep = confirm("Etes-vous certain de vouloir supprimer cette question?");
	if(rep){
		doAjaxQuery('deleteJuridique','id='+id);
		setHtml('sujet'+id, '[QUESTION EFFACEE]');

	}
}
/***************************************************************************************************************/
function deleteLivreDor(id){
	rep = confirm("Etes-vous certain de vouloir supprimer ce commentaire?");
	if(rep){
		doAjaxQuery('deleteLivreDor','id='+id);
		setHtml('sujet'+id, '[COMMENTAIRE EFFACE]');

	}
}
/***************************************************************************************************************/
function deleteSuggestion(id){
	rep = confirm("Etes-vous certain de vouloir supprimer cette suggestion?");
	if(rep){
		doAjaxQuery('deleteSuggestion','id='+id);
		setHtml('sujet'+id, '[SUGGESTION EFFACEE]');

	}
}
/***************************************************************************************************************/
function deleteAnnonce(id){
	rep = confirm("Etes-vous certain de vouloir supprimer cette annonce?");
	if(rep){
		doAjaxQuery('deleteAnnonce','id='+id);
		setHtml('annonce'+id, '[ANNONCE EFFACEE]');

	}
}
/***************************************************************************************************************/
function deleteBreveComment(id){
	rep = confirm("Etes-vous certain de vouloir supprimer ce commentaire?");
	if(rep){
		doAjaxQuery('deleteBreveComment','id='+id);
		setHtml('comment'+id, '[COMMENTAIRE EFFACE]');

	}
}
/***************************************************************************************************************/
function deleteFilmComment(id){
	rep = confirm("Etes-vous certain de vouloir supprimer ce commentaire?");
	if(rep){
		doAjaxQuery('deleteFilmComment','id='+id);
		setHtml('comment'+id, '[COMMENTAIRE EFFACE]');

	}
}
/***************************************************************************************************************/
function changeCommandeStatus(id){
	rep = confirm("Etes-vous certain de vouloir changer le statut de cette commande?");
	if(rep){
	boogleElement('commandewaiting'+id,'commandedone'+id );
	if(document.getElementById('commandedone'+id).style.display =='none') statut = 0;
	else statut = 1;
		doAjaxQuery('changeCommandeStatus','id='+id+'&statut='+statut);
	}
}
/***************************************************************************************************************/
function filterList(name, id){
	alert(name);
	pays = document.getElementById('pays').value;
	result = doAjaxQuery('filterList','table='+name+'&id='+id+'&pays='+pays);
	arrResponse = result.split('#');
	// block
	arrResult = arrResponse[0].split('-');
	for(i=0 ; i<arrResult.length ; ++i){
	if(document.getElementById(name+arrResult[i]))
	document.getElementById(name+arrResult[i]).style.display ='block';
	}
	
	// none
	arrResult = arrResponse[1].split('-');
	for(i=0 ; i<arrResult.length ; ++i){
	if(document.getElementById(name+arrResult[i]))
	document.getElementById(name+arrResult[i]).style.display ='none';
	}
	
	}