var loaded = false;
	
/*
    Copyright Robert Nyman, http://www.robertnyman.com
    Free to use if this text is included
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
    var oCurrent;
    var oAttribute;
    for(var i=0; i<arrElements.length; i++){
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0){
            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
                arrReturnElements.push(oCurrent);
            }
        }
    }
    return arrReturnElements;
}

function clicMenu(num,s,ferme,nom) 
{ 	// num = numéro de menu s = id des menus

    // Booléen reconnaissant le navigateur
  isIE = (document.all); 
  isNN6 = (!isIE) && (document.getElementById);
    
  // Compatibilité : l'objet menu est détecté selon le navigateur 
   if (isIE) menu = document.all[ s + num];
   if (isNN6) menu = document.getElementById( s + num);
 
  // On ouvre ou ferme
  if (menu.style.display == "none")
  {	  
   // Cas ou le tableau est caché 

  	if ( ferme == "true" )	  // cas ou le menu doi fermer tous ceux de son level
	{		
				/* Test si ie ou gecko car ie predn l'attribut ID pour le getElementsByName dans un tr */
				
				 if (isIE)
				 {
				  /* appel de une fonction recherchant les attribut d'un tag spécifié */
				  var noeud = getElementsByAttribute(document.body, "tr", "name", nom); 
				  for ( i=0; i < noeud.length ; i++ )
				  {
				    noeud[i].style.display = "none";
				  }
				  
				 }
				 else
				 {
					for ( i=0 ; i <  document.getElementsByName( nom ).length; i++)
					{	
					 	 document.getElementsByName( nom )[i].style.display = "none";
					}
				}
				
	}
	menu.style.display = "";
	menu.style.color = "#FFFFFF";
	document.getElementById('iframe1').src = '/mwqnew/acceuil.php';
	
  }  	 
  else 
  {
    menu.style.display = "none";
	menu.style.color = "#000000";
   }
}

function changeSrc(action,nomFichier)	 // Fonction qui permet le changement de page dans 'IFRAME'
{ 
    baseSrc = document.getElementById('iframe1').src;
	
	if ( action == "pdf")
	{
 	// document.getElementById('iframe1').src = "pdf/pdf.php?fn=" + nomFichier;
	 var refPdf = window.open( "pdf/"+nomFichier);
	}
	if ( action == "carto")
	{
	 document.getElementById('iframe1').src = "carto/" + nomFichier;
	}
	if ( action == "Formulaire")
	{

	 nomFichier = "formulaires/" + nomFichier;
	 h1 = screen.availHeight -40;
	 w1 = screen.availWidth -40;
	 WindowObjectReference = window.open(nomFichier, "Formulaire_Connaitre", "top=0,left=0,width="+w1+",height="+h1+",menubar=no,location=no,resizable=no,scrollbars=yes,status=no");
	 	
	}
	
}


/* function appelée lors du click sur une image du menu */

function image(type,arg,obj)
{	 
	if ( type == "submitSelectPdf" )  // Selection d'un pdf choisis dans une liste déroulante
	{
	 
	   var select  = document.getElementsByName( arg )[0];
	   pattern = Array("é", "è", "ê", "ç", "à", "â", "î", "ï", "ù", "ô", "/", " ","'");
	   rep_pat = Array("e", "e", "e", "c", "a", "a", "i", "i", "u", "o", "", "","");
	   var x = select.options[select.options.selectedIndex].text;
       test = preg_replace( pattern, rep_pat , x ); 
	 
	   if (select.options[select.options.selectedIndex].text != "--Faites votre choix--")
	   {
	    //document.getElementById('iframe1').src = "pdf/pdf.php?fn=" + select.options[select.options.selectedIndex].text +".pdf";
		//document.getElementById('iframe1').src = "pdf/pdf.php?fn=" + test +".pdf";
		//var refPdf = window.open( "pdf/"+ test +".pdf");
		var refPdf = window.open( "pdf/"+ obj.value +".pdf");
		select.options.selectedIndex = 0;
		return false;
	   }
		else { alert ('Veuillez choisir un element dans la liste déroulante !'); }
	 
	  	
	}
	else
	{
	  	t = testFrame();  // on met la bonne src a l'image
		
		
		if( t == false ) // si la page est en trein de se charger alors appel recursif pour que la page del'iframe aient le temps de se charger
		{ 
		
		//setTimeout("reste('"+type+"','"+arg+"')",4000);
		setTimeout("image('"+type+"','"+arg+"')",1000);
		
		}
		else
		{
	          
		 	reste(type,arg);
		 	
		 
		}
	}
	
} 

/* Fonction de changement du src de la frame */
function testFrame()
{ 	 
 	
 	var chaine = document.getElementById('iframe1').src;
 	//alert('chaine : ' + chaine + ' reste : ' + chaine.substring(chaine.lastIndexOf("/", chaine.length),chaine.length) );	
  //if ( document.getElementById('iframe1').src != '/mwqnew/carto/index.php' )
  if(chaine.substring(chaine.lastIndexOf("/", chaine.length),chaine.length)  != "/index.php")
  {
  			loaded = false;
			document.getElementById('iframe1').src = '/mwqnew/carto/index.php';
			
			return false;		
  }
  else
  {	  
  	
  	return true;
  }
}
/* Recu^pération des valeurs du menu et envoi dans la frame contenant la page carto*/

function reste(type,arg)
{	  					  
						  
   	/* Affichage du div de chargement */
	try {
	
	if ( document.all )
		{
			theFrame = frames['ZONE1'].document;			
		}
		else
		{
			theFrame = document.getElementById('iframe1').contentDocument;
			
		}
        try {		
	theFrame.getElementById( 'extent_h' ).value = "40000.351563 21169.929688 310000.000000 167662.203125";	
	}
	catch ( Ex ) {
		
	setTimeout("reste('"+type+"','"+arg+"')",1000);	
		}
	parent.window.document.getElementById('chargement').style.display = "block";
	//theFrame.getElementById( 'spanPwqPdf' ).style.display = 'none';
 	if ( type == "submit" )
	{
		document.formmenu.submit();
	}
	if ( type == "submitPrixWallon" )  /* Carotgraphie pour le prix wallon pour la qualité */
	{
	   var selectAns = document.getElementsByName( 'SelectPrixWallon' )[0];
	   if ( document.all )
		{
			theFrame = frames['ZONE1'].document;			
		}
		else
		{
			theFrame = document.getElementById('iframe1').contentDocument;
			
		}		
		if ( theFrame != null )
		{
			var contenu = ""  + "pwq" + ";"  + selectAns.options[selectAns.options.selectedIndex].text + ";" + " " + ";" + " " + ";" + "" +";new";
			theFrame.getElementsByName( 'themRegroup' )[0].value = contenu;
			
			
			theFrame.getElementById( 'textExplicatif' ).value = "Nombre de candidats participants au \u0022Prix Wallon de la Qualité\u0022 par Provinces";
			theFrame.mainform.submit();
		}	
	}
	if ( type == "submitSystemesCertifieActuel" ) /* Thematique pour les système certifiés */
	{
		var selectRepresentation = document.getElementsByName( 'SelectRegroupement' )[0]; // SelectRegroupement
		var selectdomaine = document.getElementsByName( 'SelectDomaine' )[0];// SelectDomaine
		var selecttheme = document.getElementsByName( 'SelectTheme' )[0]; // SelectTheme
		var typecertificat = document.getElementsByName( 'SelectCertificat' )[0]; // SelectCertificat
		var theFrame = null;
		if ( document.all )
		{
			theFrame = frames['ZONE1'].document;			
		}
		else
		{
			theFrame = document.getElementById('iframe1').contentDocument;
			
		}		
		if ( theFrame != null )
		{
			representation = selectRepresentation.options[selectRepresentation.options.selectedIndex].text;
			domaine = selectdomaine.options[selectdomaine.options.selectedIndex].text;
			theme = selecttheme.options[selecttheme.options.selectedIndex].text;
			certificat = typecertificat.options[typecertificat.options.selectedIndex].text;
			theFrame.getElementsByName( 'NavigMode' )[0].value = '0';



			//theFrame.getElementById( 'stylePdfPwq' ).value = 'none';
			theFrame.getElementsByName( 'themRegroup' )[0].value = ""  + representation + ";"  + domaine + ";" + theme + ";" + certificat +";;new";
			//alert ( theFrame.getElementsByName( 'themRegroup' )[0].value );
			var mt = "";
			
			if ( selectRepresentation.options.selectedIndex != 0 )
			{
			
			    if (  selecttheme.options.selectedIndex != 0 )
				{
				   mt += "" + theme + " - ";
				}
				if (  typecertificat.options.selectedIndex != 0 )
				{
				   mt += "" + certificat + " - ";
				}
				
				if (  selectdomaine.options.selectedIndex != 0 )
				{
				   mt += " " + domaine + " - ";
				}
				mt += " Nombre d´organismes certifiés";
				/*
				if ( representation != "region" )
				{
				 mt += " par "+ representation.substring(0,(representation.length -1)) + " ";
				}
				else
				{
				*/
				  mt += " par "+ representation + " ";
				//} 
				
			}
			else
			{
			 	mt += "Un regroupement doit être séléctionné ! ";
			}
			//mt += "<span>";
			theFrame.getElementById( 'textExplicatif' ).value = mt + "\n";
			theFrame.mainform.submit();
		}		
		
	}
	if ( type == "submitLabel" )   /* affichages des thémtiques par labels */
	{
		var selectRepresentation = document.getElementsByName('SelectRepresentation')[0];
		var typeLabel = document.getElementsByName( 'SelectTypeLabel' )[0];
		
		if (typeLabel.options.selectedIndex == 0)
		{
		 tl = "tous";
		}
		else
		{
		 tl = typeLabel.options[typeLabel.options.selectedIndex].text;
		}
		var theFrame = null;
		
		
		if ( document.all )
		{
			theFrame = frames['ZONE1'].document;			
		}
		else
		{
			theFrame = document.getElementById('iframe1').contentDocument;
			
		}		
		if ( theFrame != null )
		{
			var contenu = ""  + selectRepresentation.options[selectRepresentation.options.selectedIndex].text + ";"  + " " + ";" + " " + ";" + " " + ";" + tl +";new";
			theFrame.getElementsByName( 'themRegroup' )[0].value = contenu;
			theFrame.getElementsByName( 'NavigMode' )[0].value = '0';
			//theFrame.getElementById( 'stylePdfPwq' ).value = 'none';
			var mt = "";
			//if (  selectRepresentation.options[selectRepresentation.options.selectedIndex].text != "--Tous--" )
			if (  selectRepresentation.options.selectedIndex != 0)
			{
			
			   
				if ( typeLabel.options.selectedIndex != 0 )
				{
				   mt += " " + typeLabel.options[typeLabel.selectedIndex].text + " - ";
				}
				mt += " Nombre d´organismes labéllisés ";
				
				/*
				if ( selectRepresentation.options[selectRepresentation.options.selectedIndex].text != "region" )
				{
				 mt += " par "+ selectRepresentation.options[selectRepresentation.options.selectedIndex].text.substring(0,(selectRepresentation.options[selectRepresentation.options.selectedIndex].text.length -1)) + " ";
				}
				else
				{
				
				  mt += " par "+ selectRepresentation.options[selectRepresentation.options.selectedIndex].text + " ";
				  
				} 
				*/
				mt += " par "+ selectRepresentation.options[selectRepresentation.options.selectedIndex].text + " ";
				
			}
			else
			{
			 	mt += "Un regroupement doit être séléctionné ! ";
			}
			//mt += "<span>";
			theFrame.getElementById( 'textExplicatif' ).value = mt + "\n";
			
			theFrame.mainform.submit();
		}	
	}
	if ( type == "submitAutreDemarche" )
	{ 
	   	var selectRepresentation = document.getElementsByName('SelectAutreRepresentation')[0];
		var typeAutreDemarche = document.getElementsByName( 'Selectautredemarche' )[0];
		
		if (typeAutreDemarche.options.selectedIndex == 0)
		{
		 tl = "tous";
		}
		else
		{
		 tl = typeAutreDemarche.options[typeAutreDemarche.options.selectedIndex].text;
		}
		var theFrame = null;
		
		
		if ( document.all )
		{
			theFrame = frames['ZONE1'].document;			
		}
		else
		{
			theFrame = document.getElementById('iframe1').contentDocument;
			
		}		
		if ( theFrame != null )
		{
		    var contenu = ""  + selectRepresentation.options[selectRepresentation.options.selectedIndex].text + ";"  + " " + ";" + " " + ";" + " " + ";" + " "+";new"+ ";" +tl;
			theFrame.getElementsByName( 'themRegroup' )[0].value = contenu;
			theFrame.getElementsByName( 'NavigMode' )[0].value = '0';
			var mt = "";
			
			if (  selectRepresentation.options.selectedIndex != 0 )
			{
			
			   
				if ( typeAutreDemarche.options.selectedIndex != 0 )
				{
				   mt += " " + typeAutreDemarche.options[typeAutreDemarche.selectedIndex].text + " - ";
				}
				mt += " Nombre d´organismes ";
				
				/*
				if ( selectRepresentation.options[selectRepresentation.options.selectedIndex].text != "region" )
				{
				 mt += " par "+ selectRepresentation.options[selectRepresentation.options.selectedIndex].text.substring(0,(selectRepresentation.options[selectRepresentation.options.selectedIndex].text.length -1)) + " ";
				}
				else
				{
				  mt += " par "+ selectRepresentation.options[selectRepresentation.options.selectedIndex].text + " ";
				}
				*/ 
				mt += " par "+ selectRepresentation.options[selectRepresentation.options.selectedIndex].text + " ";
				
			}
			else
			{
			 	mt += "Un regroupement doit être séléctionné ! ";
			} 
			
			
			theFrame.getElementById( 'textExplicatif' ).value = mt + "\n";
			theFrame.mainform.submit();
		}
		
	}
	if ( type == "submitRecherche" )   /* Choix Besoin d'un recherche , affichage des organisations */
	{
	
		var selectOrganisme = document.getElementsByName( 'TexteRechercheOrganisme' )[0];
		var selectDomaine = document.getElementsByName( 'SelectRechercheDomaine' )[0];
		var selectTheme = document.getElementsByName( 'SelectRechercheTheme' )[0];
		var selectDemarche = document.getElementsByName( 'SelectRechercheTypeDemarche' )[0];
		var selectProvince = document.getElementsByName( 'SelectRechercheProvince' )[0];
		var selectCommune = document.getElementsByName('SelectRechercheCommune')[0];
		var selectTypeRecherche = document.getElementsByName('ChoixTypeRecherche')[0];
		var selectLabel = document.getElementsByName('SelectRechercheLabel')[0];
		
		var theFrame = null;
		
		
		if ( document.all )
		{
			theFrame = frames['ZONE1'].document;			
		}
		else
		{
			theFrame = document.getElementById('iframe1').contentDocument;			
		}		
		if ( theFrame != null )
		{
			
			if ( selectTypeRecherche.value == "ChoixTypeRecherche1" || selectTypeRecherche.value == "-1" )
			{ var contenu = ""  + selectOrganisme.value + ";" + selectDomaine.options[selectDomaine.options.selectedIndex].text + ";" + selectTheme.options[selectTheme.options.selectedIndex].text + ";" + selectDemarche.options[selectDemarche.options.selectedIndex].text + ";" + selectProvince.options[selectProvince.options.selectedIndex].text + ";" + selectCommune.options[selectCommune.options.selectedIndex].text + ";" + "new" + ";" + ""                                                           + ";" + "certificat";}
			else
			{ var contenu = ""  + selectOrganisme.value + ";" + selectDomaine.options[selectDomaine.options.selectedIndex].text + ";" + ""                                                          + ";" + ""                                                                + ";" + selectProvince.options[selectProvince.options.selectedIndex].text + ";" + selectCommune.options[selectCommune.options.selectedIndex].text + ";" + "new" + ";" + selectLabel.options[selectLabel.options.selectedIndex].text  + ";" + "label";}
			
			theFrame.getElementsByName( 'showOrga_h' )[0].value = contenu;
			theFrame.getElementById( 'textExplicatif' ).value ="";
			theFrame.getElementsByName( 'NavigMode' )[0].value = '3';
			//theFrame.getElementById( 'stylePdfPwq' ).value = 'none';
			
			var mt = "";
			 if( selectTypeRecherche.options[selectTypeRecherche.options.selectedIndex].text != "Labels")
			 {
				
			        if (  selectTheme.options.selectedIndex != 0 )
				{
				   mt += " " + selectTheme.options[selectTheme.options.selectedIndex].text + " - ";
				}
				if (  selectDemarche.options.selectedIndex != 0 )
				{
				   mt += " " + selectDemarche.options[selectDemarche.options.selectedIndex].text + " - ";
				}
				
				if (  selectDomaine.options.selectedIndex != 0 )
				{
				   mt += "" + selectDomaine.options[selectDomaine.options.selectedIndex].text + " - ";
				}
				
				
				 mt += " " + selectTypeRecherche.options[selectTypeRecherche.options.selectedIndex].text + " - ";
				
				if ( selectCommune.options.selectedIndex != 0 )
				{
				   mt += "" + selectCommune.options[selectCommune.options.selectedIndex].text + " - ";
				}
			}
			else
			{
			
			       if (  selectDomaine.options.selectedIndex != 0 )
				{
				   mt += "" + selectDomaine.options[selectDomaine.options.selectedIndex].text + " - ";
				}
				if( selectTypeRecherche.options.selectedIndex != 0 )
				{
				 mt += " " + selectTypeRecherche.options[selectTypeRecherche.options.selectedIndex].text + " - ";
				}
				if( selectLabel.options.selectedIndex != 0 )
				{
					mt += "" + selectLabel.options[selectLabel.options.selectedIndex].text + " - ";
				}
			}
				mt += " Positionnement des organismes ";
			//mt += "<span>";
			theFrame.getElementById( 'textExplicatif' ).value = mt + "\n";
			theFrame.mainform.submit();
		}
		
	}
	
	}catch ( Ex ) {
		
	setTimeout("reste('"+type+"','"+arg+"')",1000);	
		}
}

	function preg_replace (array_pattern, array_pattern_replace, my_string) 
	{
		var new_string = String (my_string);
		for (i=0; i<array_pattern.length; i++) {
			var reg_exp= RegExp(array_pattern[i], "gi");
			var val_to_replace = array_pattern_replace[i];
		  	new_string = new_string.replace (reg_exp, val_to_replace);
		}
		return new_string;
	}

	function getCommuneFromProvince(obj)
	{
	 		 theProvince = obj.options[obj.options.selectedIndex].text;
			 
			 var searchCom = new Connection()
			 searchCom.appendData('province', theProvince );
			 searchCom.sendAndLoad('carto/getCommune.php','GET',remplirLaCom);		
			 return true; 
	}
	var remplirLaCom = function (obj) {
	
			rep =  obj.responseXML.documentElement;
			
			var listeCom;
			x = rep.getElementsByTagName('commune');
			selectCom = document.getElementsByName('SelectRechercheCommune')[0];
			
			if ( x.length != 0 )
			{
				for ( i = 0 ; i < x.length ; i++)
				{
				 	selectCom.options[i+1] = new Option(x[i].firstChild.data,(i+1),false,true);
				}
				selectCom.options.length = (x.length+1);
				selectCom.options.selectedIndex = 0;
			}
			else
			{
			 	selectCom.options[i+1] = new Option("--Tous--","-1",false,true);
			 	selectCom.options.length = 1;
				selectCom.options.selectedIndex = 0;
			 	
			}
			
	} 
	
	
	
	

