/************************************************************************/
/***  FONCTIONS JAVASCRIPT GLOBALES DU SITE ANNUAIRE  *******************/
/************************************************************************/

// FONCTIONS POUR LE ROLL-OVER DES IMAGES
function MM_preloadImages(){
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore(){
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d){
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage(){
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/***************************************************************************************************/

// FONCTION VIDE POUR CALQUE
function K(){
	
}

// FONCTION POUR LA RECHERCHE PAR ACTIVITE
function box_activite(chemin){
	if(document.getElementById('_Choix').value != 'PS'){
		document.getElementById('box_etape_1').src = chemin + 'box_etape_1_activite.gif';
		document.getElementById('box_etape_1').alt = '1 - Entrez l\'activité :';
		document.getElementById('box_case_activite').src = chemin + 'box_case_on.gif';
		document.getElementById('box_case_raison_sociale').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_marque').src = chemin + 'box_case_off.gif';
		document.getElementById('_Choix').value = 'PS';
	}else{
		document.getElementById('box_etape_1').src = chemin + 'box_etape_1_mot_cle.gif';
		document.getElementById('box_etape_1').alt = '1 - Entrez le mot-clé :';
		document.getElementById('box_case_activite').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_raison_sociale').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_marque').src = chemin + 'box_case_off.gif';
		document.getElementById('_Choix').value = '';
	}
}

// FONCTION POUR LA RECHERCHE PAR RAISON SOCIALE
function box_raison_sociale(chemin){
	if(document.getElementById('_Choix').value != 'CN'){
		document.getElementById('box_etape_1').src = chemin + 'box_etape_1_raison_sociale.gif';
		document.getElementById('box_etape_1').alt = '1 - Entrez la raison sociale :';
		document.getElementById('box_case_activite').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_raison_sociale').src = chemin + 'box_case_on.gif';
		document.getElementById('box_case_marque').src = chemin + 'box_case_off.gif';
		document.getElementById('_Choix').value = 'CN';
	}else{
		document.getElementById('box_etape_1').src = chemin + 'box_etape_1_mot_cle.gif';
		document.getElementById('box_etape_1').alt = '1 - Entrez le mot-clé :';
		document.getElementById('box_case_activite').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_raison_sociale').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_marque').src = chemin + 'box_case_off.gif';
		document.getElementById('_Choix').value = '';
	}
}

// FONCTION POUR LA RECHERCHE PAR MARQUE
function box_marque(chemin){
	if(document.getElementById('_Choix').value != 'TN'){
		document.getElementById('box_etape_1').src = chemin + 'box_etape_1_marque.gif';
		document.getElementById('box_etape_1').alt = '1 - Entrez la marque :';
		document.getElementById('box_case_activite').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_raison_sociale').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_marque').src = chemin + 'box_case_on.gif';
		document.getElementById('_Choix').value = 'TN';
	}else{
		document.getElementById('box_etape_1').src = chemin + 'box_etape_1_mot_cle.gif';
		document.getElementById('box_etape_1').alt = '1 - Entrez le mot-clé :';
		document.getElementById('box_case_activite').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_raison_sociale').src = chemin + 'box_case_off.gif';
		document.getElementById('box_case_marque').src = chemin + 'box_case_off.gif';
		document.getElementById('_Choix').value = '';
	}

}

/***************************************************************************************************/

// FONCTION CONTROLE FORMULAIRE
function checkString(entry){
	for(var i=0; i<entry.length; i++){
		if(entry.charAt(i) != " "){ return true; }
	}

	return false;
}

/***************************************************************************************************/

// FONCTION CONTROLE FORMULAIRE DE LA BOX DE RECHERCHE
function verification(formulaire){

	if(document.getElementById('_Choix').value==''){
		ouvre('recherche_incorrecte.php?msg=1', 'recherche_incorrecte', 390, 250, 'scrollbars=no');
		return false;
	}

	if(document.getElementById('_Choix').value!='' && !checkString(formulaire._Keyword.value)){
		formulaire._Keyword.focus();
		ouvre('recherche_incorrecte.php?msg=2', 'recherche_incorrecte', 390, 250, 'scrollbars=no');
		return false;
	}

	return true;
}

/***************************************************************************************************/

// FONCTION OUVERTURE POP-UP
function ouvre(adresse, fenetre, largeur, hauteur, options){
	var top = (screen.height-hauteur) / 2;
	var left = (screen.width-largeur) / 2;

//	window.open(adresse, fenetre, "top=" + top + ",left=" + left + ",width=" + largeur + ",height=" + hauteur + "," + options);
	window.open(adresse,fenetre,"width="+largeur+", height="+hauteur+",top="+top+",left="+left+","+options);
	
}


/***************************************************************************************************/

// FONCTIONS POUR LES CALQUES (ex: Langues)

// Détermine le navigateur de l'utilisateur
var nn4 = (document.layers);
var dom = (document.getElementById);
var iex = (document.all);

// CLASSE CALQUE POUR DES CALQUES EXISTANTS
// Le constructeur de la classe Calque admet 2 arguments :
// - l'id du layer
// - si le layer est visible ou pas (false/true) :
//   si cet argument est omis, le layer est rendu visible
function Calque(id) {
	this.id = id;
	this.x = null;
	this.y = null;
	this.layer = null;
	this.style = null;
	if (arguments.length == 2) this.visible = arguments[1];
	else this.visible = true;
	if (nn4) {
		if (document.layers[id]) {
			this.layer = document.layers[id];
			this.style = document.layers[id];
		}
	}
	else if (dom) {
		if (document.getElementById(id)) {
			this.layer = document.getElementById(id);
			this.style = document.getElementById(id).style;
		}
	}
	else if (iex) {
		if (document.all[id]) {
			this.layer = document.all[id];
			this.style = document.all[id].style;
		}
	}
	if (this.style) this.z = this.style.zIndex;
	else this.z = null;
}

// permet de masquer le calque
Calque.prototype.masquer = function() {
	if (this.style) {
		this.style.visibility = "hidden";
		this.visible = false;
	}
}

// permet de réafficher le calque
Calque.prototype.montrer = function() {
	if (this.style) {
		this.style.visibility = "visible";
		this.visible = true;
	}
}


// CLASSE DE GESTION DES CALQUES
function GestionCalques() {
	this.calques = new Array(); // tableau des calques
	this.calque_cour = -1;
}

// détermine quel indice de this.calques correspond à l'id
// si aucun calque n'a cette id, on en crée un nouveau
GestionCalques.prototype.cherche_id = function(id) {
	this.calque_cour = -1;
	for (var i=0;i<this.calques.length;i++) {
		if (this.calques[i].id == id) {
			this.calque_cour = i;
			break;
		}
	}
	if (this.calque_cour == -1) {
		this.calques[this.calques.length] = new Calque(id);
		this.calque_cour = this.calques.length - 1;
	}
}

// cache le calque d'id "id"
GestionCalques.prototype.masquer = function() {
	if (arguments.length == 1) this.cherche_id(arguments[0]);
	this.calques[this.calque_cour].masquer();
}

// réaffiche le calque d'id "id"
GestionCalques.prototype.montrer = function() {
	if (arguments.length == 1) this.cherche_id(arguments[0]);
	this.calques[this.calque_cour].montrer();
}

/***************************************************************************************************/

// Retourne si possible un objet XMLHttpRequest
function getXMLHttpRequestObject()
{
	var xhr_object = null
	if(window.XMLHttpRequest){ // Firefox 
		xhr_object = new XMLHttpRequest(); 
	}else if(window.ActiveXObject){ // Internet Explorer 
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	else { // XMLHttpRequest non supporté par le navigateur 
		//alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	}
	
	if( xhr_object != null ) 
	{
		return xhr_object;
	}
	else
	{
		return false;
	}
}
