// Variables globales

var chemin ="";
var loaded = 0;         // pour le préload des images, la variable passe à "1" si les images sont préloadées

/**
 * Fonction qui permet d'accéder directement à une fiche annonce.
 *
 * @param   myform    le formulaire appelant cette fonction
 * @param   myref     le champ text contenant la référence de l'annonce recherchée
 *
 * @result  redirection vers la fiche annonce
 */
function accederFicheAnnonce(myform, myref) {
  ref = myref.value;
  if (ref != "") {
    myform.action = "/annonces/fiche_annonce.php?ref="+ref+"&mode=consultation&acces=ref";
  } else {
    return false;
  }
}




//---------------------------//
// Detailed Browser Sniffing //
//---------------------------//

function Is()
{
var agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
this.ns2 = (this.ns && (this.major == 3));
this.ns3 = (this.ns && (this.major == 3));
this.ns4b = (this.ns && (this.minor < 4.04));
this.ns4 = (this.ns && (this.major >= 4));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = (agent.indexOf("msie") != -1);
this.ie3 = (this.ie && (this.major == 2));
this.ie4 = (this.ie && (this.major >= 4));
this.ie5  = (this.ie && (agent.indexOf("msie 5")!=-1));
this.op3 = (agent.indexOf("opera") != -1);
this.win = (agent.indexOf("win")!=-1);
this.mac = (agent.indexOf("mac")!=-1);
this.unix = (agent.indexOf("x11")!=-1);
}

var is = new Is();

//---------------------------//
// Définit un chemin de base //
//---------------------------//

function defineChemin()
{
chemin = document.domain;
if ((chemin == 'maquette') || (chemin == 'maquette.quaeris.com'))
	{
	chemin = 'http://' + chemin + '/afi/site/';
	}
else if ((chemin == 'kea') || (chemin == 'kea.quaeris.com'))
	{
	chemin = 'http://' + chemin + '/afi-php/site/';
	}
else
	{
	chemin = "http://" + chemin + "/";
	}
}

//-------------------------------------------------------//
// Initialisation de variables pour manipuler les layers //
//-------------------------------------------------------//

function InitVar()
{
if(is.ns4)
	{
	doc = "document";
	sty = "";
	htm = ".document";
	}
else if(is.ie4)
	{
	doc = "document.all";
	sty = ".style";
	htm = "";
	}
}

//------------------------------------------------------------------------------------------------------------------------------------------------------//
// Appelle l'image "on" qd la souris passe sur l'image "off"                                                                                            //
// Arguments : mettre le nom "name" des images                                                                                                          //
// Appel : <a href="#" onMouseOver="onlight('general')"><img src="images/general_off.gif" width="128" height="30" border="0" name="general"></a>        //
//------------------------------------------------------------------------------------------------------------------------------------------------------//

function onlight()
{
var nb_arg = onlight.arguments;
if (((is.ns4) || (is.ie4)) && loaded == "1")
        {
        for (var i=0 ; i<nb_arg.length ; i++)
                {
                img_name = nb_arg[i];
                document[img_name].src = eval(img_name + "_on.src");
                }
        }
}


//------------------------------------------------------------------------------------------------------------------------------------------------------//
// Appelle l'image "off" qd la souris quitte l'image "off"                                                                                              //
// Arguments : mettre le nom "name" des images                                                                                                          //
// Appel : <a href="#" onMouseOut="offlight('general')"><img src="images/general_off.gif" width="128" height="30" border="0" name="general"></a>        //
//------------------------------------------------------------------------------------------------------------------------------------------------------//

function offlight()
{
var nb_arg = offlight.arguments;
if (((is.ns4) || (is.ie4)) && loaded == "1")
        {
        for (var i=0 ; i<nb_arg.length ; i++)
                {
                img_name = nb_arg[i];
                document[img_name].src = eval(img_name + "_off.src");
                }
        }
}

//----------------------------------------------------------------//
// Initialise l'image qui doit être "on" au chargement de la page //
//----------------------------------------------------------------//

function InitOnlight(img_name)
{
if (((is.ns4) || (is.ie4)) && loaded == "1")
	{
	document[img_name].src = eval(img_name + "_on.src");
	}
}

//------------------------------------------------------------//
// Rendre visible ou invisible un layer                       //
// layer_id : identifiant du layer                            //
//------------------------------------------------------------//

function ShowHideLayer()
{
var nb_arg = ShowHideLayer.arguments;
InitVar();

for (var i=0 ; i<nb_arg.length ; i++)
	{
	layer_id = nb_arg[i];
	layer_objet = eval(doc + '["' + layer_id + '"]' + sty);

	if ((layer_objet.visibility == "show") || (layer_objet.visibility == "visible"))
		{
		layer_objet.visibility = "hidden";
		}
	else if ((layer_objet.visibility == "hide") || (layer_objet.visibility == "hidden"))
		{
		layer_objet.visibility = "visible";
		}
	}
}

//------------------------------------------------------------//
// Rendre visible un layer                                    //
// Arguments :                                                //
//      layer_id(s) : identifiant du ou des layers            //
//------------------------------------------------------------//

function ShowLayer()
{
var nb_arg = ShowLayer.arguments;
InitVar();

for (var i=0 ; i<nb_arg.length ; i++)
        {
        layer_id = nb_arg[i];
        layer_objet = eval(doc + '["' + layer_id + '"]' + sty);

        layer_objet.visibility = "visible";
        }
}

//------------------------------------------------------------//
// Rendre invisible un layer                                  //
// Arguments :                                                //
//      layer_id(s) : identifiant du ou des layers            //
//------------------------------------------------------------//

function HideLayer()
{
var nb_arg = HideLayer.arguments;
InitVar();

for (var i=0 ; i<nb_arg.length ; i++)
        {
        layer_id = nb_arg[i];
        layer_objet = eval(doc + '["' + layer_id + '"]' + sty);

        layer_objet.visibility = "hidden";
        }
}






//----------------------------------------------//
// Préload des images du menu                   //
// Appel : <body ... onLoad="loadImgs();" ...>  //
//----------------------------------------------//

function loadImgs()
{ 
if ((is.ns4) || (is.ie4))
	{
	defineChemin();

	annonces_on = new Image(120,21);
	annonces_on.src = chemin + "images/nav_gauche/annonces_on.gif";
	annonces_off = new Image(120,21);
	annonces_off.src = chemin + "images/nav_gauche/annonces_off.gif";
	
	metiers_on = new Image(120,21);
	metiers_on.src = chemin + "images/nav_gauche/metiers_on.gif";
	metiers_off = new Image(120,21);
	metiers_off.src = chemin + "images/nav_gauche/metiers_off.gif";
	
	on_cherche_on = new Image(120,21);
	on_cherche_on.src = chemin + "images/nav_gauche/on_cherche_on.gif";
	on_cherche_off = new Image(120,21);
	on_cherche_off.src = chemin + "images/nav_gauche/on_cherche_off.gif";
	
	qui_on = new Image(120,21);
	qui_on.src = chemin + "images/nav_gauche/qui_on.gif";
	qui_off = new Image(120,21);
	qui_off.src = chemin + "images/nav_gauche/qui_off.gif";
	
	loaded = 1;
	
	} 
}

 //--------------------------------------//
 // Ouvre une nouvelle fenêtre           //
 // Paramètres :                         //
 //      - nom du fichier à ouvrir       //
 //      - nom de la fenêtre à ouvrir    //
 //      - largeur de la fenêtre         //
 //      - hauteur de la fenêtre         //
 //--------------------------------------//

 function ouvre(page,nom_win,largeur,hauteur)
 {
 var l = largeur;
 var h = hauteur;
 ouvre_win = window.open(page,nom_win,"toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=no,resizable=no,width="+l+",height="+h);
}


//--------------------------------------------------------------------------------------//
// Fonction fermuture de popup                   			                //
//--------------------------------------------------------------------------------------//

function shutup()
{
parent.close();
}
