
	function __doPostBack(nameForm, eventTarget, eventArgument) {
		var theform = document.forms[nameForm];
		theform.EVENTTARGET.value = eventTarget.split("$").join(":");
		theform.EVENTARGUMENT.value = eventArgument;
		theform.submit();
	}

	function get(obj){
		return document.getElementById(obj);
	
	}

	function changePlugin(obj){
		window.location.href = "?plugin=" + obj.value;
	}


	function getHTTPObject() {
			var xmlhttp;

			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (E) {
						xmlhttp = false;
					}
			}

			if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
				try {
						xmlhttp = new XMLHttpRequest();
					} catch (e) {
						xmlhttp = false;
					}
			}

			return xmlhttp;
		}
		
	/* Gestion de l'affichage des communes en callback */
	var get = function(id){ return document.getElementById(id)};
	
	var oCT;
	var oImgChargement = new Image();
	oImgChargement.src = '/web/img/charge.gif';
	
	function selCom(val,insee){
		if(get('commune'))
			get('commune').value = val;
		else alert('le champ avec id="commune" non trouvé dans le formulaire.');
		
		if(get('hidcommune'))
			get('hidcommune').value = insee;
		else alert('le champ avec id="hidcommune" non trouvé dans le formulaire.');
        get("divCommunes").style.display = get("iFrameCommunes").style.display = 'none';
	}
	
	function timerCommunes(val){
		if(oCT)
			clearTimeout(oCT);
		
		if(val == ""){
			get("divCommunes").style.display=get("iFrameCommunes").style.display="none";
		}
		else if(get("divCommunes").innerHTML.indexOf('Chargement') == -1){
			get("divCommunes").innerHTML = "<div align=center><br><br>Chargement en cours ...<br><br><img src=\"" + oImgChargement.src + "\" height=\"6\"></div>";
			get("divCommunes").style.display = get("iFrameCommunes").style.display = "";
		}
		oCT = setTimeout("searchCommune('"+val.split("'").join("\\'")+"',false)", 500);
	}
	
	function searchCommune(val,blur){
		var xhr = getHTTPObject();
		chaine=val;
		var chaine=escape(val);
		xhr.open("GET", "/syndication/getcommunes.php?c=" + chaine + "&r=" + rubrique + "&blur="+blur+"&D=" + (new Date()).toString(),false);
		xhr.send(null);
		if (xhr.readyState == 4 && xhr.status == 200) {
			if(blur)
			{
			    var sp = xhr.responseText.split('|');
			    if (trim(chaine) != '' && sp.length > 1){
			        get("hidcommune").value = sp[0];
			        get("commune").value = sp[1];
			    }
			    else
			    {
			    get("hidcommune").value = "";
			    get("commune").value = "";
			    }
			    
			}
			else
			{
			    get("divCommunes").innerHTML = xhr.responseText;
			}
		}else{
			alert("Une erreur a eu lieu durant la recherche des organismes, veuillez actualiser cette page.");
		}
	}
	function getCommune(val)
	{
		oCT = setTimeout("searchCommune('"+val.split("'").join("\\'")+"',true)", 500);
	}
    /* ------------------------------ */
    
    
	function getServerName(){
		var url = window.location.href;
		url = url.substr(7);
		url = url.substr(0,url.indexOf('/'));
		return 'http://' + url;
	}

	function initValidation(){
		for(var i in validation)
			document.getElementById('val' + i).style.color = 'black';
	}

	function requiredFieldValidator(theform,obj){
		if(theform[obj].value == ''){
			document.getElementById('val' + obj).style.color = 'red';
			return false;
		}else{
			return true;
		}
	}

    function Popup(page,largeur,hauteur,options) { 
        var top=(screen.height-hauteur)/2; 
        var left=(screen.width-largeur)/2; 
        window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options); 
    } 

	function showPopup(html,fermeture){
		document.getElementById('InfoPopupContenu').innerHTML = html;
		if(fermeture)
			document.getElementById('InfoPopupFermeture').style.display = '';
		else
			document.getElementById('InfoPopupFermeture').style.display = 'none';
		document.getElementById('InfoPopup').style.display = '';
		showCache();
	}

	function hidePopup(){
		document.getElementById('InfoPopup').style.display = 'none';
		hideCache();
	}

	function showCache(){
		document.getElementById('cache').style.display = 'block';
	}

	function hideCache(){
		document.getElementById('cache').style.display = 'none';
	}

	var sAddress = '';
	function memoriseAddress(obj){
		sAddress = obj.value;
	}

function FormaterText(chaine)
{
	tableauAccent =     ["À","Á","Â","Ã","Ä","Å","à","á","â","ã","ä","å","Ò","Ó","Ô","Õ","Ö","Ø","ò","ó","ô","õ","ö","ø","È","É","Ê","Ë","è","é","ê","ë","Ì","Í","Î","Ï","ì","í","î","ï","Ù","Ú","Û","Ü","ù","ú","û","ü","ÿ","Ñ","ñ","Ç","ç"," ","_"];
	tableauSansAccent = ["A","A","A","A","A","A","a","a","a","a","a","a","O","O","O","O","O","O","o","o","o","o","o","o","E","E","E","E","e","e","e","e","I","I","I","I","i","i","i","i","U","U","U","U","u","u","u","u","y","N","n","C","c","-","-"];
	for(var i=0; i<tableauAccent.length; i++)
	{
		var exp = new RegExp(tableauAccent[i], "g");
		chaine = chaine.replace(exp, tableauSansAccent[i]);
	}
	chaine = chaine.replace(/[^a-zA-Z0-9\-\.]*/g,'');
	return chaine;
}


	function validAddress(obj){
		if(obj.value == sAddress) return;
		
		obj.value = FormaterText(obj.value);		
		
	}

	/*****************************************
	* insertion des image depuis la mediatheque
	*****************************************/
	var winPop;
	var fieldPop;
	var bEditeur;
	var fInsertionImageRetour;
	function setValue(value,id)
	{
		if(bEditeur)
			winPop.document.forms[0].elements[fieldPop].value=value;
		else
			fInsertionImageRetour(value,id);
	}
	
	function generateGuid()
    {
        var result, i, j;
        result = '';
        for(j=0; j<32; j++)
        {
        if( j == 8 || j == 12|| j == 16|| j == 20)
        result = result + '-';
        i = Math.floor(Math.random()*16).toString(16).toUpperCase();
        result = result + i;
        }
        return result
    }

	/*****************************************
	* insertion d'un flash
	*****************************************/
	function insertFlash(strSrc, intWidth, intHeight, strAlt, strID ){
	    var guid = generateGuid();
	    document.write('<div id="'+guid+'" style="text-align:center;">Votre lecteur Flash n\'est pas à jours. Cliquez ci-dessous pour télécharger la dernière version<br/><a href="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank"><img style="border:0;" src="/swf/icone_flash.png" alt="télécharger la dernière version de Flash player"/></a></div>');
	    document.close();
	    var so = new SWFObject(strSrc, strID, intWidth, intHeight, "8", "");
            so.addParam("wmode", "transparent");
            so.useExpressInstall('/swf/expressinstall.swf');
            so.write(guid);
	}
	
	
	function insertFlashStr( strSrc, intWidth, intHeight, strAlt, strID )
    {
	    var strFlash	=  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"';
	    strFlash		+= 'width="' + intWidth + '" height="' + intHeight + '" title="' + strAlt + '">';
	    strFlash		+= '<param name="movie" value="' + strSrc + '" />';
	    strFlash		+= '<param name="quality" value="high" />';
	    strFlash		+= '<param name="menu" value="false" />';
	    strFlash		+= '<param name="wmode" value="transparent" />';
	    strFlash		+= '<embed name="'+strID+'" id="'+strID+'" src="' + strSrc + '" width="' + intWidth + '" height="' + intHeight + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>';
	    strFlash		+= '</object>';
	    return strFlash;
    }

	// permet de recuperer le contenu HTML d'une div en XHTML
	// innerHTML de IE6 ne marche pas
	innerXHTML = function($source,$string) {
	      // (v0.3) Written 2006 by Steve Tucker, http://www.stevetucker.co.uk
	      if (!($source.nodeType == 1)) return false;
	      var $children = $source.childNodes;
	      var $xhtml = '';
	      if (!$string) {
	            for (var $i=0; $i<$children.length; $i++) {
	                  if ($children[$i].nodeType == 3) {
	                        var $text_content = $children[$i].nodeValue;
	                        $text_content = $text_content.replace(/</g,'&lt;');
	                        $text_content = $text_content.replace(/>/g,'&gt;');
	                        $xhtml += $text_content;
	                  }
	                  else if ($children[$i].nodeType == 8) {
	                        $xhtml += '<!--'+$children[$i].nodeValue+'-->';
	                  }
	                  else {
	                        $xhtml += '<'+$children[$i].nodeName.toLowerCase();
	                        var $attributes = $children[$i].attributes;
	                        for (var $j=0; $j<$attributes.length; $j++) {
	                             var $attName = $attributes[$j].nodeName.toLowerCase();
	                             var $attValue = $attributes[$j].nodeValue;
	                             if ($attName == 'style' && $children[$i].style.cssText) {
	                                   $xhtml += ' style="'+$children[$i].style.cssText.toLowerCase()+'"';
	                             }
	                             else if ($attValue && $attName != 'contenteditable') {
	                                   $xhtml += ' '+$attName+'="'+$attValue+'"';
	                             }
	                        }
	                        $xhtml += '>'+innerXHTML($children[$i]);
	                        $xhtml += '</'+$children[$i].nodeName.toLowerCase()+'>';
	                  }
	            }
	      }
	      else {
	            while ($children.length>0) {
	                  $source.removeChild($children[0]);
	            }
	            $xhtml = $string;
	            while ($string) {
	                  var $returned = translateXHTML($string);
	                  var $elements = $returned[0];
	                  $string = $returned[1];
	                  if ($elements) $source.appendChild($elements);
	            }
	      }
	      return $xhtml;
	}
	function translateXHTML($string) {
	      var $match = /^<\/[a-z0-9]{1,}>/i.test($string);
	      if ($match) {
	            var $return = Array;
	            $return[0] = false;
	            $return[1] = $string.replace(/^<\/[a-z0-9]{1,}>/i,'');
	            return $return;
	      }
	      $match = /^<[a-z]{1,}/i.test($string);
	      if ($match) {
	            $string = $string.replace(/^</,'');
	            var $element = $string.match(/[a-z0-9]{1,}/i);
	            if ($element) {
	                  var $new_element = document.createElement($element[0]);
	                  $string = $string.replace(/[a-z0-9]{1,}/i,'');
	                  var $attribute = true;
	                  while ($attribute) {
	                        $string = $string.replace(/^\s{1,}/,'');
	                        $attribute = $string.match(/^[a-z1-9_-]{1,}="[^"]{0,}"/i);
	                        if ($attribute) {
	                             $attribute = $attribute[0];
	                             $string = $string.replace(/^[a-z1-9_-]{1,}="[^"]{0,}"/i,'');
	                             var $attName = $attribute.match(/^[a-z1-9_-]{1,}/i);
	                             $attribute = $attribute.replace(/^[a-z1-9_-]{1,}="/i,'');
	                             $attribute = $attribute.replace(/;{0,1}"$/,'');
	                             if ($attribute) {
	                                   var $attValue = $attribute;
	                                   if ($attName == 'value') {
	                                         $new_element.value = $attValue;
	                                   }
	                                   else if ($attName == 'class') {
	                                         $new_element.className = $attValue;
	                                   }
	                                   else if ($attName == 'style') {
	                                         var $style = $attValue.split(';');
	                                         for (var $i=0; $i<$style.length; $i++) {
	                                               var $this_style = $style[$i].split(':');
	                                               $this_style[0] = $this_style[0].toLowerCase().replace(/(^\s{0,})|(\s{0,1}$)/,'');
	                                               $this_style[1] = $this_style[1].toLowerCase().replace(/(^\s{0,})|(\s{0,1}$)/,'');
	                                               if (/-{1,}/g.test($this_style[0])) {
	                                                     var $this_style_words = $this_style[0].split(/-/g);
	                                                     $this_style[0] = '';
	                                                     for (var $j=0; $j<$this_style_words.length; $j++) {
	                                                           if ($j==0) {
	                                                                 $this_style[0] = $this_style_words[0];
	                                                                 continue;
	                                                           }
	                                                           var $first_letter = $this_style_words[$j].toUpperCase().match(/^[a-z]{1,1}/i);
	                                                           $this_style[0] += $first_letter+$this_style_words[$j].replace(/^[a-z]{1,1}/,'');
	                                                     }
	                                               }
	                                               $new_element.style[$this_style[0]] = $this_style[1];
	                                         }
	                                   }
	                                   else {
	                                         $new_element.setAttribute($attName,$attValue);
	                                   }
	                             }
	                             else $attribute = true;
	                        }
	                  }
	                  $match = /^>/.test($string);
	                  if ($match) {
	                        $string = $string.replace(/^>/,'');
	                        var $child = true;
	                        while ($child) {
	                             var $returned = translateXHTML($string,false);
	                             $child = $returned[0];
	                             if ($child) $new_element.appendChild($child);
	                             $string = $returned[1];
	                        }
	                  }
	                  $string = $string.replace(/^\/>/,'');
	            }
	      }
	      $match = /^[^<>]{1,}/i.test($string);
	      if ($match && !$new_element) {
	            var $text_content = $string.match(/^[^<>]{1,}/i)[0];
	            $text_content = $text_content.replace(/&lt;/g,'<');
	            $text_content = $text_content.replace(/&gt;/g,'>');
	            var $new_element = document.createTextNode($text_content);
	            $string = $string.replace(/^[^<>]{1,}/i,'');
	      }
	      $match = /^<!--[^<>]{1,}-->/i.test($string);
	      if ($match && !$new_element) {
	            if (document.createComment) {
	                  $string = $string.replace(/^<!--/i,'');
	                  var $text_content = $string.match(/^[^<>]{0,}-->{1,}/i);
	                  $text_content = $text_content[0].replace(/-->{1,1}$/,'');
	                  var $new_element = document.createComment($text_content);
	                  $string = $string.replace(/^[^<>]{1,}-->/i,'');
	            }
	            else $string = $string.replace(/^<!--[^<>]{1,}-->/i,'');
	      }
	      var $return = Array;
	      $return[0] = $new_element;
	      $return[1] = $string;
	      return $return;
	}

	function changeVisibility(elemID){
		var elem=document.getElementById(elemID);
		if(elem)
			elem.style.display = elem.style.display=='none' ? 'block' : 'none';
	}
	
	
	function UpdateVisio(value)
	{
		listeImage = document.getElementById('visionneuse').getElementsByTagName('img');
		selectedIndex = 1;
		for (i=0; i<listeImage.length; i++)
		{
			if (listeImage[i].style.display != 'none')
				selectedIndex = i;
		}
		newIndex = selectedIndex+(value);
		if (newIndex < 0) newIndex = listeImage.length - 1;
		if (newIndex >= listeImage.length) newIndex = 0;
		listeImage[selectedIndex].style.display = 'none';
		listeImage[newIndex].style.display = '';
		document.getElementById('VisioCount').innerHTML = (newIndex +1);
		
	}
	
	function showPhoto(img)
	{
	    document.getElementById('imgPopup').src = img.src.split('&')[0]+'&xm=500&ym=500';
	    document.getElementById('zoom').style.display = '';
	}
	
	function showPhotoFlash(img)
	{
	    document.getElementById('imgPopup').src = img;
	    document.getElementById('zoom').style.display = '';
	}

    //Gestion du controle localisation
    function selectLocalisation(val)
    {
			
        //reinitialisation
        /*
        document.getElementById('chkDepartement18').checked = false;
        document.getElementById('chkDepartement28').checked = false;
        document.getElementById('chkDepartement36').checked = false;
        document.getElementById('chkDepartement37').checked = false;
        document.getElementById('chkDepartement41').checked = false;
        document.getElementById('chkDepartement45').checked = false;
        */
    	document.getElementById('chkDepartement1').checked = false;
        document.getElementById('chkDepartement2').checked = false;
        
        document.getElementById('hidcommune').value = '';
        document.getElementById('commune').value = '';
        
        /*for(var i=0;i<document.getElementById('ddlZone').options.length;i++)
		{
			document.getElementById('ddlZone').options[i].selected= (i==0);
		}*/
        for(var i=0;i<document.getElementById('ddlLocalisation').options.length;i++)
        {
            if((document.getElementById('ddlLocalisation').options[i].value!=val || val=="") && document.getElementById('ddlLocalisation').options[i].value!="")
            {
				try {
					document.getElementById('div'+document.getElementById('ddlLocalisation').options[i].value).style.display='none';
				}
				catch (e) {
					/*alert(e);*/
				}
			}
         }
        if(document.getElementById('div'+val)) document.getElementById('div'+val).style.display='';
    }
    
    function modifDisplayId(id)
    {
        if (document.getElementById(id).style.display == "")
        {
            document.getElementById(id).style.display = "none";
        }
        else
        {
            document.getElementById(id).style.display = "";
        }
    }
    
function trim(string)
{
	return string.replace(/(^\s*)|(\s*$)/g,'');
}

function ClosePub(){
    document.getElementById("MaPopupPub").style.display = "none";
}
