/* Fonction d'affichage des divs 24/07/2006 */

function attribuer_valeur( tab_champs_valeurs )
{
	// On réceptionne un tableau à 2 
	for (i=0; i < tab_champs_valeurs.length ; i++)
    {
    	document.getElementById(tab_champs_valeurs[i][0]).value = tab_champs_valeurs[i][1];
    	
    }
}

function ouvrir(num)
{
    if (document.getElementById(num).lang == 0)
    {
    	document.getElementById(num).style.display="";
    	document.getElementById(num).lang=1;
    }
    else
    {
    	document.getElementById(num).style.display="none";
    	document.getElementById(num).lang=0;
    }
}

function ouvrirDiv( tabDivOuv , tabDivFer )
{
	if(tabDivFer[0]!="")
	{
		for (i=0; i < tabDivFer.length ; i++)
		{
			document.getElementById(tabDivFer[i]).style.display="none";
			document.getElementById(tabDivFer[i]).lang=0;
		}
	}
	for (i=0; i < tabDivOuv.length ; i++)
    {
    	document.getElementById(tabDivOuv[i]).style.display="";
    	document.getElementById(tabDivOuv[i]).lang=1;
    }
}

function check( formulaire , tabChamp , checkbox)
{
	var ok = 'vide';
	
	for ( i=0; i < tabChamp.length ; i++ )
    	if ( document.forms(formulaire)(tabChamp[i]).value != "" )
    		ok = 'faux';

	if ( ok == 'vide' )
	{
		
		document.forms(formulaire)(checkbox).checked = false;
	}
	else
	{
		document.forms(formulaire)(checkbox).checked = true;
	}
}

function controleListe( type , tabTypeInterdit , divListeVide , tabDivOuv , tabDivFer)
{
		$sol2 = 0;
		for(i=0; i<tabTypeInterdit.length; i++)
		{
			
			if(type == tabTypeInterdit[i])
				$sol2 = 1;
		}
		
		if($sol2==0)
		{
			var id = type + "_ObjId";
			if( document.getElementById( id ).length == 0 )
			{   
				ouvrirDiv( new Array( divListeVide ) , tabDivFer );
			}
			else
			{	
				ouvrirDiv( tabDivOuv , tabDivFer);
			}
		}
		else
		{
			ouvrirDiv( tabDivOuv , tabDivFer);
		}
	
	
}


/* controle pour les boutons radio*/
function GereControle(Controleur, Controle, Masquer) {
var objControleur = document.getElementById(Controleur);
var objControle = document.getElementById(Controle);
	if (Masquer=='1')
		objControle.style.visibility=(objControleur.checked==true)?'visible':'hidden';
	else
		objControle.disabled=(objControleur.checked==true)?false:true;
	return true;
}


/* Gestion des popups */

function delChild(item)
{
	obj=document.getElementById(item);
	document.body.removeChild(obj);
}

function affdelDIV(url_used, message, url_css, url_image)
{
		// compostion d'une DIV absolue avec affichage des erreurs
		var dDiv = document.createElement("div"); // Création du div 
		var largeur=(screen.width/2)-250;
		var hauteur=(screen.height/2)-250;
		var posx=largeur;
		var posy=window.pageYOffset+200;
		
		// composition du style pour défnir le positionnement de la DIV
		var DivCSS = "";
		DivCSS += " position:absolute;";
		DivCSS += "margin : auto ; "; 
		DivCSS += "z-index : 1000 ; ";
		DivCSS += "top: "+posy+"px; ";    
		DivCSS += "left:"+posx+"px;";          
		DivCSS += "width:350px ; ";                     
		DivCSS += "padding-bottom:10px ;";
		
		// Application des CSS
		dDiv.setAttribute("style",DivCSS);  // Application des CSS pour FireFox
		dDiv.setAttribute("class","msg_del_prin"); 
		
		// Ajout du bouton valider
		msg_valider="<img src='"+url_image+"/bt_valider.gif' onclick=\"parent.location.href='"+url_used+"'\" class='msg_info_btn' >";
		msg_error="<img src='"+url_image+"/bt_annuler.gif' onClick=\"parent.delChild('msg_erreur');\" style='cursor:pointer' class='msg_info_btn' >";
		// création de l'IFRAME
		var iFrame = document.createElement('IFRAME');
		if (document.all) 
		{
			// cas IE
		    var dDivIE = document.createElement("div"); // Création du div 
			var DivCSS = "";
			dDivIE.id="msg_erreur";
			DivCSS += "top: "+hauteur+"px; ";    
			DivCSS += "left:"+largeur+"px;";   
			dDiv.style.setAttribute("cssText",DivCSS);
			dDiv.setAttribute("className","msg_del_prin"); 
			//## todo Lorsque le nombre de ligne diminue
			iFrame.setAttribute("width","360");
		}// Application des CSS pour IE
		else
		{
			dDiv.id="msg_erreur"; 
			iFrame.setAttribute("width","550");
		}	
		
		iFrame.setAttribute("id","IFRAME");
		iFrame.setAttribute("border","0");
		iFrame.setAttribute("frameborder","0");
		
		//## todo Lorsque le nombre de ligne diminue
		iFrame.setAttribute("height","170"); 
		//iFrame.innerHTML =msg_erreur;
		dDiv.appendChild(iFrame);
		if (document.all) 
		{
			dDivIE.appendChild(dDiv);
			document.body.appendChild(dDivIE);
		}
		else
			document.body.appendChild(dDiv);
		
		/**
		Ecriture dans l'IFRAME
		**/
			
		myframe=document.getElementById("IFRAME");
		var docu = myframe.contentDocument;
        if (docu == undefined || docu == null)
            docu = myframe.contentWindow.document;
        
            docu.open();
        // on inclut la CSS
        inclure_css="<link href='"+url_css+"/pathGen.php?name=iframe&type=css' rel='stylesheet' type='text/css' media='screen'>";
        // on compose la structure interne de l'iframe
        titre="<div class='msg_info_del2_iframe'><div class='msg_del_iframe'>Confirmation de suppression</div><p>"+message+"</p><p align='center'>"+msg_error+msg_valider+"</p></div>";
		
        // on écrit dans l'iframe son contenu
        docu.write(inclure_css+titre+"</div>");
		docu.close();
    }
   
function affListeDIV(url_used, message, url_css, url_image, url_fichier)
{
	
		// compostion d'une DIV absolue avec affichage des erreurs
		var dDiv = document.createElement("div"); // Création du div 
		var largeur=(screen.width/2)-250;
		var hauteur=(screen.height/2)-250;
		
		// composition du style pour défnir le positionnement de la DIV
		var DivCSS = "";
		DivCSS += " position:absolute;";
		DivCSS += "margin : auto ; "; 
		DivCSS += "z-index : 1000 ; ";
		DivCSS += "top: "+hauteur+"px; ";    
		DivCSS += "left:"+largeur+"px;";          
		DivCSS += "width:350px ; ";                     
		DivCSS += "padding-bottom:10px ;";
		
		// Application des CSS
		dDiv.setAttribute("style",DivCSS);  // Application des CSS pour FireFox
		dDiv.setAttribute("class","msg_del_prin"); 
		
		// Ajout du bouton valider
		//msg_valider="<img src='"+url_image+"/bt_valider.gif' onclick=\"parent.location.href='"+url_used+"'\" class='msg_info_btn' >";
		msg_error="<a href='javascript:parent.delChild('msg_erreur');'>Fermer</a>";
		// création de l'IFRAME
		var iFrame = document.createElement('IFRAME');
		if (document.all) 
		{
			// cas IE
		    var dDivIE = document.createElement("div"); // Création du div 
			var DivCSS = "";
			dDivIE.id="msg_erreur";
			DivCSS += "top: "+hauteur+"px; ";    
			DivCSS += "left:"+largeur+"px;";   
			dDiv.style.setAttribute("cssText",DivCSS);
			dDiv.setAttribute("className","msg_del_prin"); 
			//## todo Lorsque le nombre de ligne diminue
			iFrame.setAttribute("width","360");
		}// Application des CSS pour IE
		else
		{
			dDiv.id="msg_erreur"; 
			iFrame.setAttribute("width","550");
		}	
		
		iFrame.setAttribute("id","IFRAME");
		iFrame.setAttribute("border","0");
		iFrame.setAttribute("frameborder","0");
		
		//## todo Lorsque le nombre de ligne diminue
		iFrame.setAttribute("height","170"); 
		iFrame.setAttribute("src",url_fichier);
		
		//alert(iFrame.src);
	
		dDiv.appendChild(iFrame);
		if (document.all) 
		{
			dDivIE.appendChild(dDiv);
			document.body.appendChild(dDivIE);
		}
		else
			document.body.appendChild(dDiv);
		
		/**
		Ecriture dans l'IFRAME
		**/
		iFrame.location.href=url_fichier;
		
		myframe=document.getElementById("IFRAME");
		
		var doc = myframe.contentDocument;
        if (doc == undefined || doc == null)
            doc = myframe.contentWindow.document;
       
        doc.open();
        //doc.write();
        // on inclut la CSS
        inclure_css="<link href='"+url_css+"/pathGen.php?name=iframe&type=css' rel='stylesheet' type='text/css' media='screen'>";
        // on compose la structure interne de l'iframe
        titre="<div class='msg_info_del2_iframe'><div class='msg_del_iframe'>Liste des attributs</div><p></p><p align='center'>"+msg_error+"</p></div>";
        // on écrit dans l'iframe son contenu
        doc.write(inclure_css+titre+"</div>");
		doc.close();
    }

function PopupCentrer(page,titre,largeur,hauteur,options)
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,titre,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function popupcentree(page,image,largeur,hauteur,options)
{
	var top=(screen.height-hauteur)/3;
	var left=(screen.width-largeur)/2;
					
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function jetest(ecrire)
{
	document.write(ecrire);
}

/**
Ouverture acces HTTP
*/
function openHTTP(fichier)
{
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);
	xhr_object.open("GET", fichier, false);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send(null);

	if(xhr_object.readyState == 4) 
		return(xhr_object.responseXML);
	else 
		return(false);
}

function openHTTP2(fichier,data)
{
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);
	xhr_object.open("POST", fichier, false);
	
    xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send(data);
	if(xhr_object.readyState == 4) 
		return(xhr_object.responseText);
	else 
		return(false);
}

function verifChamp(url,valeur_champ,type_champ,autre)
{
		if(texte = openHTTP(url+'?valeur_champ='+escape(valeur_champ)+'&type_champ='+type_champ+'&'+autre))
		{	
			var tabResult = texte.getElementsByTagName('resultat');
			for (var i = 0; i < tabResult.length; i++) 
			{
               resultat = tabResult.item(i); 
               var etat = resultat.getAttribute('etat');
               var valeur = resultat.getAttribute('valeur');
               	if(etat != '')
				{
					
					if(etat == "CORRECT")
					{
						writediv(type_champ,'<span class="information">'+valeur+'</span>');
					}
					else
					{
						writediv(type_champ,'<span class="erreur">'+valeur+'</span>');
						
					}
				}
				else
				{
					writediv(type_champ,'<span ></span>');
				}
			 }
		}
}

function writediv(type_champ,texte)
{
	//intialise le message top

	document.getElementById('message_information').innerHTML='';
	document.getElementById('message_information').style.display="none";
	document.getElementById(type_champ).innerHTML=texte;
}

function writediv2(type_champ,texte)
{
	//intialise le message top
	var span_temp=document.createElement("SPAN");
	span_temp.appendChild(document.createTextNode(texte));
	span_temp.className="erreur";
	document.getElementById('message_information').innerHTML='';
	document.getElementById('message_information').style.display="none";
	document.getElementById('surcout').parentNode.appendChild(span_temp);
}

// fonction d ajout favoris ie et firefox
function favoris() {
	if ( navigator.appName != 'Microsoft Internet Explorer' )
	{ window.sidebar.addPanel("ATLAS FOR MEN", "http://"+window.location.host ,""); }
	else { window.external.AddFavorite("http://"+window.location.host,"ATLAS FOR MEN"); } 
}

