//document.captureEvents(Event.KEYDOWN); 
//document.onkeydown = fMettreAJourBlocTextuel('contenant',window.event.keyCode);


function fTypeFureteurInternetExplorer()
{
	var fureteurNom = navigator.appName; 
	if (fureteurNom=="Microsoft Internet Explorer")
	{
		return 1;
	}
	return 0;
}

function fPopupDiapo(pPage, pLargeur, pHauteur, pSource, pTitre)
{
	if(window.popupImage)
	{
		if(!window.popupImage.closed)
			window.popupImage.close();
	}
	var largeur = parseInt(pLargeur) + 40;
	var hauteur = parseInt(pHauteur) + 40;
	popupImage=open(""+pPage+"?source="+pSource+"&titre="+pTitre+"","popupImage","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width="+ largeur+",height="+ hauteur+"")
	window.popupImage.moveTo ((((screen.availWidth / 2) - (pLargeur/2))) , (((screen.availHeight / 2) - (pHauteur/2))) )     
}


function fAjax(pUrl, pContenant, pMessageTelechargement)
{
	var requete_http = false;
	document.getElementById(pContenant).innerHTML = '<div class="telechargement">'+ pMessageTelechargement+'</div>';
	// Safari, Firefox...
	if (window.XMLHttpRequest) 
	{
		requete_http = new XMLHttpRequest();
		if (requete_http.overrideMimeType) 
		{
			requete_http.overrideMimeType('text/xml');
		}
	} 
	//IE
	else if (window.ActiveXObject) 
	{
		try 
		{
			requete_http = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				requete_http = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{}
		}
	}

	if (!requete_http) 
	{
		alert('Impossible de créer une requête http.');
		return false;
	}
	requete_http.onreadystatechange = function() 
	{ 
        if (requete_http.readyState == 4) 
        {
            if (requete_http.status == 200) 
            {
                //alert(requete_http.responseText);
                if (fTypeFureteurInternetExplorer() == 1)
				{
                	document.getElementById(pContenant).innerHTML = requete_http.responseText;
                }
                else
                {
                	// Afficher avant autre code
                	/*var r = document.getElementById(pContenant).ownerDocument.createRange();
					r.setStartBefore(document.getElementById(pContenant));
					var parsedHTML = r.createContextualFragment(requete_http.responseText);
					document.getElementById(pContenant).appendChild(parsedHTML);*/
					document.getElementById(pContenant).innerHTML = requete_http.responseText;
				}
            } 
            else 
            {
                alert('La requête http est incorrecte.');
            }
        }

	};
	//Pour POST
	//requete_http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	requete_http.open('GET', pUrl, true);
	requete_http.send(null);
}

function fViderContenant(pContenant, pValeur)
{
	document.getElementById(pContenant).innerHTML = '';
}

function fCreationBoiteModifiable(pBoite) 
{
  document.getElementById(pBoite).contentWindow.document.designMode = "on";
  try 
  {
    document.getElementById(pBoite).contentWindow.document.execCommand("undo", false, null);
  }  
  catch (e) 
  {
    alert("This demo is not supported on your level of Mozilla.");
  }

  /*InitToolbarButtons();
  if (document.addEventListener) 
  {
    document.addEventListener("mousedown", dismisscolorpalette, true);
    document.getElementById("edit").contentWindow.document.addEventListener("mousedown", dismisscolorpalette, true);
    document.addEventListener("keypress", dismisscolorpalette, true);
    document.getElementById("edit").contentWindow.document.addEventListener("keypress", dismisscolorpalette, true);
  } 
  else if (document.attachEvent) 
  {
    document.attachEvent("mousedown", dismisscolorpalette, true);
    document.getElementById("edit").contentWindow.document.attachEvent("mousedown", dismisscolorpalette, true);
    document.attachEvent("keypress", dismisscolorpalette, true);
    document.getElementById("edit").contentWindow.document.attachEvent("keypress", dismisscolorpalette, true);
  }*/
}


function fMettreAJourBlocTextuel(pContenant, pValeur)
{
	//alert('a');
	var r = document.getElementById(pContenant).ownerDocument.createRange();
	r.setStartBefore(document.getElementById(pContenant));
	var parsedHTML = r.createContextualFragment(pValeur);
	document.getElementById(pContenant).appendChild(parsedHTML);
}

function fAction(pSection)
{
	document.frmAction.invSection.value = pSection;
	document.frmAction.invMode.value = pMode;
	document.frmAction.submit();
}

function fStatutAlerte(pSel)
{
	if (fTypeFureteurInternetExplorer() == 1)
	{
		document.all("messageEnAttente").style.display = "none"; 
	}
	else
	{
		document.getElementById("messageEnAttente").style.display = "none"; 
	}
	if(pSel == 0)
	{
		if (fTypeFureteurInternetExplorer() == 1)
		{
			document.all('indiceStatut').style.backgroundImage = "url(img/statut-hors-ligne.gif)";
		}
		else
		{
			document.getElementById("indiceStatut").style.backgroundImage = "url(img/statut-hors-ligne.gif)"; 
		}
	}
	if(pSel == 1)
	{
		if (fTypeFureteurInternetExplorer() == 1)
		{
			document.all('indiceStatut').style.backgroundImage = "url(img/statut-en-ligne.gif)";
		}
		else
		{
			document.getElementById("indiceStatut").style.backgroundImage = "url(img/statut-en-ligne.gif)"; 
		}
	}
	if(pSel == 2)
	{
		if (fTypeFureteurInternetExplorer() == 1)
		{
			document.all('indiceStatut').style.backgroundImage = "url(img/statut-en-attente.gif)";
			document.all('messageEnAttente').style.display = "block";
		}
		else
		{
			document.getElementById("messageEnAttente").style.display = "block"; 
			document.getElementById("indiceStatut").style.backgroundImage = "url(img/statut-en-attente.gif)"; 
		}
	}
	if(pSel == 3)
	{
		if (fTypeFureteurInternetExplorer() == 1)
		{
			document.all('indiceStatut').style.backgroundImage = "url(img/statut-supprimer.gif)";
		}
		else
		{
			document.getElementById("indiceStatut").style.backgroundImage = "url(img/statut-supprimer.gif)"; 
		}
		alert("La sauvegarde de ce statut entrainera la suppression définitive de cet item.");
	}
}

function fOutilTexte(pEffet, pNomChamp) 
{
	// IE
    if (fTypeFureteurInternetExplorer() == 1)
	{
		if (document.selection)
		{
			if (pEffet == "lien")
			{
				var selection = document.selection.createRange();
				var textuel = selection.text;
				var url = prompt("URL:","http://");
	  			if (url != null) 
				{
	    			selection.text = "{url:"+ url +"}["+ textuel +"]";
				}
			}
			if (pEffet == "courriel")
			{
				var selection = document.selection.createRange();
				var textuel = selection.text;
				var url = prompt("E-mail address/Adresse courriel","");
	  			if (url != null) 
				{
	    			var sujet = prompt("sujet/subject", "");
	    			if(sujet != null)
	    			{
	    				selection.text = "{url:mailto:"+ url +"?subject="+ sujet+"}["+ textuel +"]";
					}
					else
					{
						selection.text = "{url:mailto:"+ url +"}["+ textuel +"]";
					}
				}
			}
			if (pEffet == "gras")
			{
				var selection = document.selection.createRange();
				var textuel = selection.text;
				selection.text = "<b>"+ textuel +"</b>";
			}
			if (pEffet == "italique")
			{
				var selection = document.selection.createRange();
				var textuel = selection.text;
				selection.text = "<i>"+ textuel +"</i>";
			}
		}
		//alert(selection.text);
	}
	else
	{
		var nomChamp = eval("document.frmAction."+pNomChamp);
		var selection = (nomChamp.value).substring(nomChamp.selectionStart, nomChamp.selectionEnd);
		
		if (selection != "")
		{
			if (pEffet == "lien")
			{
				var url = prompt("","http://");
	 			if (url != null) 
				{
					var chaine = "{url:"+ url +"}["+ selection +"]";
				}
				else
				{
					var chaine = selection;
				}
			}
			if (pEffet == "courriel")
			{
				var url = prompt("E-mail address/Adresse courriel","");
	 			if (url != null) 
				{
	 				var sujet = prompt("sujet/subject", "");
	 				if(sujet != null)
	    			{
	 					var chaine = "{url:mailto:"+ url +"?subject="+ sujet+"}["+ selection +"]";
					}
					else
					{
						var chaine = "{url:mailto:"+ url +"}["+ selection +"]";
					}
				}
				else
				{
					var chaine = selection;
				}
			}
			if (pEffet == "gras")
			{
	 			var chaine = "<b>"+ selection +"</b>";
			}
			if (pEffet == "italique")
			{
	 			var chaine = "<i>"+ selection +"</i>";
			}
			
			var debut = nomChamp.selectionStart;
			var fin = nomChamp.textLength;
			var finTexte = nomChamp.value.substring(nomChamp.selectionEnd, fin);
   			var debutTexte = nomChamp.value.substring(0, debut);
			nomChamp.value = debutTexte + chaine + finTexte;
   			nomChamp.selectionStart = debut;
   			nomChamp.selectionEnd = debut;
		}
		return; 
	}
}


function fRemplaceDiv(pNomDiv,pNomNouveauDiv)
{
	if (fTypeFureteurInternetExplorer() == 1)
	{
		document.all(pNomDiv).style.display = "none";
		if (pNomNouveauDiv != '')
		{
			document.all(pNomNouveauDiv).style.display = "block";
		}
	}
	else
	{
		document.getElementById(pNomDiv).style.display = "none"; 
		if (pNomNouveauDiv != '')
		{
			document.getElementById(pNomNouveauDiv).style.display = "table";
		}
	}
}

function fNouveauDiv(pNomDiv, pTitre, pTitre2, pNomChamp)
{
	if (fTypeFureteurInternetExplorer() == 1)
	{
		var valeurAleatoire = Math.ceil(Math.random()*10000);
		var nouveau = "<div class=fichier-apercu><div class=champ-fichier>"+ pTitre +" : <input type=file name=tel"+ pNomChamp +"_"+ valeurAleatoire +"></div><div>"+ pTitre2 +" : <input type=text class=medium name=txt"+ pNomChamp +"_"+ valeurAleatoire +"></div></div><br clear='all'/>";
		var valeurActuelle = document.all[pNomDiv].innerHTML;
		document.all[pNomDiv].insertAdjacentHTML("beforeEnd", nouveau);
	}
	else
	{
		var valeurAleatoire = Math.ceil(Math.random()*10000);
		var nouveau = "<div class=fichier-apercu><div class=champ-fichier>"+ pTitre +" : <input type=file name=tel"+ pNomChamp +"_"+ valeurAleatoire +"></div><div>"+ pTitre2 +" : <input type=text class=medium name=txt"+ pNomChamp +"_"+ valeurAleatoire +"></div></div><br clear='all'/>";
		var r = document.getElementById(pNomDiv).ownerDocument.createRange();
		r.setStartBefore(document.getElementById(pNomDiv));
		var parsedHTML = r.createContextualFragment(nouveau);
		document.getElementById(pNomDiv).appendChild(parsedHTML);
	}
}

function fInfoInvisible(pChamp, pValeur)
{
	if (fTypeFureteurInternetExplorer() == 1)
	{
		var valeurChamp = eval("document.frmAction."+pChamp).value;
		if (valeurChamp == '')
		{
			eval("document.frmAction."+pChamp).value = pValeur;
		}
		else
		{
			eval("document.frmAction."+pChamp).value = eval("document.frmAction."+pChamp).value +","+ pValeur;
		}
	}
	else
	{
		var valeurChamp = eval("document.frmAction."+pChamp).value;
		if (valeurChamp == '')
		{
			eval("document.frmAction."+pChamp).value = pValeur;
		}
		else
		{
			eval("document.frmAction."+pChamp).value = eval("document.frmAction."+pChamp).value +","+ pValeur;
		}
	}
}

function fCarteGoogle()
{
    if (GBrowserIsCompatible()) 
    {
		
		var map = new GMap2(document.getElementById("carte"));
       	//map.setMapType( "G_SATELLITE_MAP");
       	//map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GSmallMapControl());
		map.addControl(new GOverviewMapControl);
        map.setCenter(new GLatLng(-41.848857,171.759865), 6);
        map.setMapType(G_NORMAL_MAP);
        
        var icon = new GIcon();
		icon.image = "http://www.google.com/mapfiles/marker.png";
		icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		icon.iconSize = new GSize(20, 34);
		icon.shadowSize = new GSize(37, 34);
		
		
        
       	// BULLE D'INFO
       	//map.openInfoWindow(map.getCenter(),document.createTextNode("Expédition en Bolivie"));
      	
     	 // Our info window content
			var infoTabs = [
  			new GInfoWindowTab("Expédition", "This is tab #1 content"),
  			new GInfoWindowTab("Détails", "This is tab #2 content")
			];
      	
  			// CREATION MARQUEUR
  			var point = new GLatLng(-36.848857,174.759865); 
  			var marker = new GMarker(point);
			GEvent.addListener(marker, "click", function() {
				window.setTimeout(function() {
  				//map.zoomIn(20,12);
  				}, 1000);
  				//marker.openInfoWindowTabsHtml(infoTabs);
			});
			map.addOverlay(marker);
  			
  			var polyline = new GPolyline([
  			new GLatLng(-36.848857,174.759865),
  			new GLatLng(-38.138877,176.239929),
  			new GLatLng(-41.278839,174.780121),
  			new GLatLng(-41.29896,174.020004),
  			new GLatLng(-45.039082,168.640137)
			], "#D70882", 10);
			map.addOverlay(polyline);
			
	}
}

function fCarteGoogle(pDepartLa, pDepartLo, pZoom)
{
    if (GBrowserIsCompatible()) 
    {
		
		var map = new GMap2(document.getElementById("carte"));
       	//map.setMapType( "G_SATELLITE_MAP");
       	//map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GSmallMapControl());
		map.addControl(new GOverviewMapControl);
        map.setCenter(new GLatLng(pDepartLa,pDepartLo), pZoom);
        map.setMapType(G_NORMAL_MAP);
        
        var icon = new GIcon();
		icon.image = "http://www.google.com/mapfiles/marker.png";
		icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		icon.iconSize = new GSize(20, 34);
		icon.shadowSize = new GSize(37, 34);
		
		
        
       	// BULLE D'INFO
       	//map.openInfoWindow(map.getCenter(),document.createTextNode("Expédition en Bolivie"));
      	
     	 // Our info window content
			var infoTabs = [
  			new GInfoWindowTab("Expédition", "This is tab #1 content"),
  			new GInfoWindowTab("Détails", "This is tab #2 content")
			];
      	
  			// CREATION MARQUEUR
  			//var point = new GLatLng(0,0); 
  			//var marker = new GMarker(point);
			//GEvent.addListener(marker, "click", function() {
				//window.setTimeout(function() {
  				//map.zoomIn(20,12);
  				//}, 1000);
  				//marker.openInfoWindowTabsHtml(infoTabs);
			//});
			//map.addOverlay(marker);
  			
  			/*var polyline = new GPolyline([
  			new GLatLng(-36.848857,174.759865),
  			new GLatLng(-38.138877,176.239929),
  			new GLatLng(-41.278839,174.780121),
  			new GLatLng(-41.29896,174.020004),
  			new GLatLng(-45.039082,168.640137)
			], "#D70882", 10);
			map.addOverlay(polyline);*/
			
	}
}
