function ChangeMessage(message,champ)
  {
  if(document.getElementById)
    document.getElementById(champ).innerHTML = message;
  }

var req;
var xhrEnCours;

function loadXMLDoc(url,fonction) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		var lafonction = fonction;
		var b = new Array();
		if(arguments.length > 2) {
			for(var i = 2; i < arguments.length; i++) {
				b.push(arguments[i]);
			}
		}
		req.onreadystatechange = function() { lafonction.apply(null, b); };
		req.open("GET", url, true);
		req.send(null);
	}
}
function loadXMLDocSync(url,fonction) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		req.open("GET", url, false);
		req.send(null);
		var b = new Array();
		if(arguments.length > 2) {
			for(var i = 2; i < arguments.length; i++) {
				b.push(arguments[i]);
			}
		}
		fonction.apply(null, b);
	}
}

function sublogin() {
	var texte="dbdch=1";
	for(var i=0; i<document.loginform.elements.length; i++) {
		texte+='&'+document.loginform.elements[i].name+'='+document.loginform.elements[i].value;
	}
	req.open("POST", document.loginform.action, true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(texte);
	req.onreadystatechange = checklogin;
}

function remplir(div) {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
 		document.getElementById(div).innerHTML=req.responseText;           
        }
    }
}


function placer_div(input, div) {
	pos = $(input).cumulativeOffset();
	larg = $(input).getWidth();
	$(div).setStyle({top: pos.top+$(input).offsetHeight+"px", left: pos.left+"px", width: larg+"px"});
}

Ajax.Request.prototype.abort = function() {
    // prevent and state change callbacks from being issued
    this.transport.onreadystatechange = Prototype.emptyFunction;
    // abort the XHR
    this.transport.abort();
    // update the request counter
    Ajax.activeRequestCount--;
};

function init_div_ville(langue, input, div, hidden_ville, hidden_dep) {
	placer_div(input, div);
	$(input).observe("keyup", function(ev) {
		/*
		if(ev.keyCode == 38 || ev.keyCode ==40) {
			fleche(ev, div);
		} else {
		*/
			$(hidden_ville).value="";
			$(hidden_dep).value="";
			if(typeof xhrEnCours == 'object') {
				xhrEnCours.abort();
			}
			
			xhrEnCours = new Ajax.Request('/'+langue+'/ajax/villes_dep.php', 
				{
					parameters: {i: $(input).value, dep:((hidden_dep===false) ? false : true)},
					onSuccess: function(retour) {
						if(retour.responseXML.getElementsByTagName("req").item(0).firstChild.data == "Rien") {
							Event.stopObserving(document.body, "click", cacher.bindAsEventListener(window, div, input, hidden_ville, hidden_dep));
							document.getElementById(div).style.display="none";
						} else if(retour.responseXML.getElementsByTagName("req").item(0).firstChild.data == $(input).value) {
							if(retour.responseXML.getElementsByTagName("commun").item(0).firstChild.data == "Rien") {
								Event.stopObserving(document.body, "click", cacher.bindAsEventListener(window, div, input, hidden_ville, hidden_dep));
								document.getElementById(div).style.display="none";
							} else {
								Event.observe(document.body, "click", cacher.bindAsEventListener(window, div, input, hidden_ville, hidden_dep));
								document.getElementById(div).innerHTML = retour.responseXML.getElementsByTagName("commun").item(0).firstChild.data;
								document.getElementById(div).style.display="block";
							}
						}
					}
				}
			);
		//}
	});

}

function cacher(ev, acacher, input, hidden_ville, hidden_dep) {
	if(Event.element(ev).descendantOf($(acacher))) {
		$(input).value=Event.element(ev).firstChild.data;
		if(Event.element(ev).className.indexOf("ville", 0) != -1) {
			$(hidden_ville).value = Event.element(ev).className.substring(5);
		} else if(Event.element(ev).className.indexOf("departement", 0) != -1) {
			$(hidden_dep).value = Event.element(ev).className.substring(11);
		}
		document.getElementById(acacher).style.display="none";
		Event.stop(ev);
		Event.stopObserving(document.body, "click", cacher.bindAsEventListener(window, acacher, input, hidden_ville, hidden_dep));
	}
}



function popupWindow(url) {
window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=640, height=640,screenX=30,screenY=30,top=30,left=30')
}
function popupWindowtaille(url,larg,haut) {
window.open(url,'popupWindowtaille','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+larg+', height='+haut+',screenX=30,screenY=30,top=30,left=30')
}



function pintaflash (plugin, strAviso, paramtd, pathfitxer, width, height, textAlt) {
	if (plugin) {
		document.write('<td ' + paramtd + '>');
		document.write(' <object id="flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"');
		if (textAlt && textAlt!=null && textAlt!='')
			document.write(' alt="' + textAlt + '"');
		document.write(' width="' + width + '" height="' + height + '" border="0">'); 	 
		document.write('  <param name=movie value="' + pathfitxer + '">'); 	 
		document.write('  <param name=quality value=high>'); 	 
		document.write('  <param name="wmode" value="transparent">'); 	 
		document.write('  <param name="menu" value="false">'); 	 
		document.write('  <param name="SCALE" value="noborder">'); 	 
		document.write('    <embed src="' + pathfitxer + '" quality=high pluginspage="//www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"');
		if (textAlt && textAlt!=null && textAlt!='')
			document.write(' alt="' + textAlt + '"');
		document.write(' width="' + width + '" height="' + height + '" wmode="transparent" menu="false" scale="noborder">'); 	 
		document.write('    </embed>'); 	 
		document.write(' </object>'); 	 
		document.write('</td>'); 	
	} else {
		document.write('<td bgcolor="#DFDFDF" ' + paramtd + '>');
		document.write(strAviso);
		document.write('</td>'); 
	}
}