var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
var IE4 = (document.all && !document.getElementById)? true : false;
var IE5 = (document.getElementById && document.all)? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var W3C = (document.getElementById)? true : false;

top.focus();

// ROLLOVER pour les Menus

var cpt,niv1, niv2, niv3, niv4, niv5;

function rollhide(obj,niv) {
	if (niv<6 && niv5) { if (obj.id.search(niv5.id.substr(0,niv5.id.length-1))) { niv5.style.display = "none";niv5 = null; } }
	if (niv<5 && niv4) { if (obj.id.search(niv4.id.substr(0,niv4.id.length-1))) { niv4.style.display = "none";niv4 = null; } }
	if (niv<4 && niv3) { if (obj.id.search(niv3.id.substr(0,niv3.id.length-1))) { niv3.style.display = "none";niv3 = null; } }
	if (niv<3 && niv2) { if (obj.id.search(niv2.id.substr(0,niv2.id.length-1))) { niv2.style.display = "none";niv2 = null; } }
	if (niv<2 && niv1) { if (obj.id.search(niv1.id.substr(0,niv1.id.length-1))) { niv1.style.display = "none";niv1 = null; } }
}
function rollhide1() {
	if (niv5) { niv5.style.display = "none";niv5 = null; }
	if (niv4) { niv4.style.display = "none";niv4 = null; }
	if (niv3) { niv3.style.display = "none";niv3 = null; }
	if (niv2) { niv2.style.display = "none";niv2 = null; }
	if (niv1) { niv1.style.display = "none";niv1 = null; }
}
function rollmenu(obj,type,dyn) {
	var niv;

	if (!obj.className) obj = obj.parentNode;
	if (obj.className == "mbout")
	{
		if (obj.className != "mnoroll" && obj.className != "mroll" && obj.className != "mclick") obj = obj.parentNode;
		if (obj.className != "mnoroll" && obj.className != "mroll" && obj.className != "mclick") obj = obj.parentNode;
		if (obj.className != "mnoroll" && obj.className != "mroll" && obj.className != "mclick") obj = obj.parentNode;
		if (obj.className != "mnoroll" && obj.className != "mroll" && obj.className != "mclick") obj = obj.parentNode;

		if (obj.className == "mnoroll" || obj.className == "mroll" || obj.className == "mclick") {
			if (type) clearTimeout(cpt);
			else cpt = setTimeout("rollhide1()",500);

			if (type == 1) obj.className = "mroll";
			else if (type == 2) obj.className = "mclick";
			else obj.className = "mnoroll";

			if (dyn) {
				if (niv = document.getElementById(obj.id+"n")) {
					if (niv.className == "niv1") { if (niv1) rollhide(obj,1);niv1 = niv; }
					else if (niv.className == "niv2") { if (niv2) rollhide(obj,2);niv2 = niv; }
					else if (niv.className == "niv3") { if (niv3) rollhide(obj,3);niv3 = niv; }
					else if (niv.className == "niv4") { if (niv4) rollhide(obj,4);niv4 = niv; }
					else if (niv.className == "niv5") { if (niv5) rollhide(obj,5);niv5 = niv; }

					if (type) niv.style.display = "block";
				}
				else rollhide(obj,1);
			}
		}
	}
}
function roverd(e) {
	if (window.Event) var obj = e.target;
	else var obj = window.event.srcElement;
	rollmenu(obj,1,1);
}
function routd(e) {
	if (window.Event) var obj = e.target;
	else var obj = window.event.srcElement;
	rollmenu(obj,0,1);
}
function rover(e) {
	if (window.Event) var obj = e.target;
	else var obj = window.event.srcElement;
	rollmenu(obj,1,0);
}
function rout(e) {
	if (window.Event) var obj = e.target;
	else var obj = window.event.srcElement;
	rollmenu(obj,0,0);
}
function rdown(e) {
	if (window.Event) var obj = e.target;
	else var obj = window.event.srcElement;
	rollmenu(obj,2,0);
}
function rup(e) { 
	if (window.Event) var obj = e.target;
	else var obj = window.event.srcElement;
	rollmenu(obj,2,0);
}
function rmenu(obj,dyn) {
	var melm = document.getElementById(obj);
	if (dyn) {
		melm.onmouseover = roverd;
		melm.onmouseout = routd;
	}
	else {
		melm.onmouseover = rover;
		melm.onmouseout = rout;
	}
	melm.onmouseup = rup;
	melm.onmousedown = rdown;
}

// ******************************************************************
// **************************************************************************
var ns, ie;
var Vmajor = parseInt(navigator.appVersion);
if(navigator.appName == "Netscape") { ns = true; ie = false; }
else if(navigator.appName == "Microsoft Internet Explorer") { ie = true; ns = false; }
else { ns = false; ie = false; }

function checkKey(){
	if(ns) val = event.which;
	else val = event.keyCode;
	if(window.event.shiftKey) event.returnValue=true;
	if( val == 8 || val == 9 || val == 39 ) return;
	if( val == 38 || val == 40 || val == 190 || val == 110 || val == 46){
		event.returnValue=false;
		return ;
	}
	document.selection.clear() ;
	if( val < 48 || val > 57 ){
		event.returnValue=false;
		return ;
	}

	num = parseInt( window.event.srcElement.value + (window.event.keyCode-48) , 10 ) ;
	
	if( num > 9999 ){
		event.returnValue=false;
	}else if( window.event.srcElement.value.length>0 && num < 10){
		//window.event.srcElement.value = num ;
		window.event.srcElement.value += (window.event.keyCode-48); 
		event.returnValue=false;
	}
	return ;
}

function checkLength(){
	if(ns) val = event.which;
	else val = event.keyCode;
	if( val == 9 || val == 37 || val== 39 ) return;

	// pour sauter au champ suivant (48 a 57 pour les chiffres) 
	if( ( val >= 48 && val <= 57 ) || ( val >=96 && val <= 105) || val==190 || val ==40 || val==110 || val==38 || val==109){
		event.returnValue=true;
	}else{
		event.returnValue=false;
		return ;		
	}		
	if( val == 190 || val == 40 || val == 110 || val == 109){
		nextInput( parseInt( window.event.srcElement.order ) ) ;
	}
	else if( val == 38 ){
		prevInput( parseInt( window.event.srcElement.order ) ) ;
	}		
	else if( window.event.srcElement.value.length == 4 ){
		nextInput( parseInt( window.event.srcElement.order ) ) ;
	}

}

function checkTel(){
	if(ns) val = event.which;
	else val = event.keyCode;
	if(window.event.shiftKey) event.returnValue=true;
	if( val == 8 || val == 9 ) return;
	if( val == 38 || val == 40 || val == 190 || val == 110 || val == 46){
		event.returnValue=false;
		return ;
	}
	document.selection.clear() ;
	if( val < 48 || val > 57 ){
		event.returnValue=false;
		return ;
	}

	num = parseInt( window.event.srcElement.value + (window.event.keyCode-48) , 10 ) ;
	
	return ;
}

function nextInput(index){
	if( index < 2 ){
		window.event.srcElement.parentElement.children.item(index+1).focus() ;
		window.event.srcElement.parentElement.children.item(index+1).select() ;
	}
}
function prevInput(index){
	if( index > 0 ){
		window.event.srcElement.parentElement.children.item(index-1).focus() ;
		window.event.srcElement.parentElement.children.item(index-1).select() ;
	}
}
// **************************************************************************
function fcentre(id) {
        var elm;
        if (elm = document.getElementById(id)) {
                var fleft,ftop;
                if (fleft = parseInt((document.body.clientWidth-parseInt(elm.offsetWidth))/2)) elm.style.left = fleft+"px";
                if (ftop = parseInt((document.body.clientHeight-parseInt(elm.offsetHeight))/2)) elm.style.top = ftop+"px";
        } 
}        
// **************************************************************************
function dhide(id) {
        var elm;
        if (elm = document.getElementById(id)) elm.style.visibility = "hidden";
}

// Ecrit dans le document
function wdoc(str) {
        document.write(str);
}

// Ouvrir une nouvelle fenetre
function OuvreFenetre(theURL, Targ, Param)
{
	window.open(theURL, Targ, Param);
}
// Ouvrir une nouvelle fenetre avec redimensionnement automatique
function PopupImage(img) {
	titre="Popup Image";
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');	
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+80); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}
// intervertit les images entre les images principales et les vignettes
function changeImage(idElement){
	//idElement = (evt) ? evt.target.id : window.event.srcElement.id;
	var srcImage = document.getElementById(idElement).src;
	document.getElementById("img0").src = srcImage;
}
function changeImage2(idElement){
	//idElement = (evt) ? evt.target.id : window.event.srcElement.id;
	var srcImage = document.getElementById(idElement).src;
	document.getElementById("imga").src = srcImage;
}
function cartefocus() {
	if (document.saisie) document.saisie.user1.focus();
}

// Affiche ou fait disparaitre un DIV
var vadivo = null,vadivcpt = null;
function fdiv() {
	var vadiv;
	if (vadiv = document.getElementById(vadivo)) {
		vadiv.style.display = "none";
		vadivo = null;
                if(vadivcpt) clearTimeout(vadivcpt);
		vadivcpt = null;
	}
}
function adiv(obj,type) {
	var vadiv;
	if (vadiv = document.getElementById(obj)) {
		if(type==0 || (type==2 && vadiv.style.display == "block")) {
			vadiv.style.display = "none";
		} else if(type>2) {
			if(type==4 && vadivo == obj) {
				vadiv.style.display = "none";
				vadivo = null;
			} else {
				if(vadivo) fdiv();
				vadivo = obj;
				vadiv.style.display = "block";
                		if(vadivcpt) clearTimeout(vadivcpt);
				if(type>4) vadivcpt = setTimeout("fdiv()",type);
			}
		} else {
			vadiv.style.display = "block";
		}
	}
}

// ******************** Fonctions AJAX ***************************
function getHObjet() {
        var xmlhttp = false;
 
        /* Compilation conditionnelle d'IE */
        /*@cc_on
        @if (@_jscript_version >= 5)
                try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
                catch (e) {
                        try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
                        catch (E) { xmlhttp = false; }
                }
        @else
                xmlhttp = false;
        @end @*/
 
        /* on essaie de creer l'objet si ce n'est pas deja fait */
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
                try { xmlhttp = new XMLHttpRequest();xmlhttp.overrideMimeType('text/xml'); }
                catch (e) { xmlhttp = false; }
        }
 
        return xmlhttp;
}
function getHObjetById(id,url) {
        var xmlhttp = getHObjet();
        if (xmlhttp) {
                /* on definit ce qui doit se passer quand la page repondra */
                xmlhttp.onreadystatechange=function() {
                        if (xmlhttp.readyState == 4) {  /* Donnees charges */
                                if (xmlhttp.status == 200) {    /* 200 : code HTTP pour OK */
                                        var obj = document.getElementById(id);
                                        if (obj) { obj.innerHTML = xmlhttp.responseText; }
                                }
                        }
                }
        }
        xmlhttp.open("GET", url,true);
        xmlhttp.send(null);
}

// ******************** Recherche en AJAX **********************
function rechOn(el,grp) {   // Ouvre la zone de recherche (click dans le champ de visualisation)
        var elm1 = Ext.get(el+'d');
        var elm2 = Ext.get(el+'v');
        var elm3 = Ext.get(el+'r');
        if(elm1 && elm2 && elm3) {
                elm2.setStyle('display','none');
                elm3.setStyle('display','block');
                elm1.setStyle('display','block');
                elm3.dom.focus();
        }
        rechKeyUp(el,grp);
}
function rechOff(el) {  // Ferme la zone de recherche (bouton annuler)
        var elm1 = Ext.get(el+'d');
        var elm2 = Ext.get(el+'v');
        var elm3 = Ext.get(el+'r');
        if(elm1 && elm2 && elm3) {
                elm1.setStyle('display','none');
                elm3.setStyle('display','none');
                elm2.setStyle('display','block');
        }
}
function rechKeyUp(el,grp){ // Effectue la recherche (appeler a chaque touche presse)
        var elm = Ext.get(el);
        var elm1 = Ext.get(el+'d');
        var elm3 = Ext.get(el+'r');
        var elm4 = Ext.get(el+'t');
        if (elm1 && elm3){
                if(elm3.getValue().length>=0){
                        var params = "&f_r="+elm3.getValue()+"&f_t="+elm4.getValue()+"&f_n="+el+"&f_s="+elm.getValue+"&f_grp=" + grp;

                        Ext.Ajax.request({
                                url: "/modules/recherche_magique.adml?" + params,
                                params : {
                                        f_r : elm3.getValue(),
                                        f_n : el,
                                        f_s : elm.getValue()
                                },
                                success : function(r){
                                        if (r) {
                                                elm1.dom.innerHTML = r.responseText;
                                        }
                                }
                        });
                } else {
                        if (elm1 = Ext.get("crech")) {
                                elm1.setStyle('visibility','hidden');
                        //if (elm1 = document.getElementById("crech")) {
                                //elm1.style.visibility = "hidden";
                        }
                }
        }
}
function rechSelect(el){        // Selection d'un contact (bouton selectionner ou double click de la souris)
        var elm = Ext.get(el);
        var elm1 = Ext.get(el+'v');
        var elm3 = Ext.get(el+'s');
        if(elm3){
                if(elm3.dom.selectedIndex>=0) {
                        if(elm) elm.dom.value = elm3.dom.options[elm3.dom.selectedIndex].value;
                        if(elm1) elm1.dom.value = elm3.dom.options[elm3.dom.selectedIndex].text;
                }
        }
        rechOff(el);
}

