var path_img = 'annuaires_referencement/img/';

/************************************************************************/
/***  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_activity(path){

//var path_img = '/img/';

        if(document.getElementById('choice').value != 'PS'){
                document.getElementById('box-step-1').src = path + 'box_step_1_activity-trans.png';
                document.getElementById('box-step-1').alt = '1 - Introduce la actividad :';
                document.getElementById('activity-box').src = path_img + 'box_case_on.png';
                document.getElementById('enterprise-name-box').src = path_img + 'box_case_off.png';
                document.getElementById('brand-box').src = path_img + 'box_case_off.png';
                document.getElementById('choice').value = 'PS';
        }else{
                document.getElementById('box-step-1').src = path + 'box_step_1_keyword-trans.png';
                document.getElementById('box-step-1').alt = '1 - Introduce la palabra clave :';
                document.getElementById('activity-box').src = path_img + 'box_case_off.png';
                document.getElementById('enterprise-name-box').src = path_img + 'box_case_off.png';
                document.getElementById('brand-box').src = path_img + 'box_case_off.png';
                document.getElementById('choice').value = '';
        }
}

// FONCTION POUR LA RECHERCHE PAR RAISON SOCIALE
function box_enterprise_name(path){

        if(document.getElementById('choice').value != 'CN'){
                document.getElementById('box-step-1').src = path + 'box_step_1_enterprise_name-trans.png';
                document.getElementById('box-step-1').alt = '1 - Introduce la razón social :';
                document.getElementById('activity-box').src = path_img + 'box_case_off.png';
                document.getElementById('enterprise-name-box').src = path_img + 'box_case_on.png';
                document.getElementById('brand-box').src = path_img + 'box_case_off.png';
                document.getElementById('choice').value = 'CN';
        }else{
                document.getElementById('box-step-1').src = path + 'box_step_1_keyword-trans.png';
                document.getElementById('box-step-1').alt = '1 - Introduce la palabra clave :';
                document.getElementById('activity-box').src = path_img + 'box_case_off.png';
                document.getElementById('enterprise-name-box').src = path_img + 'box_case_off.png';
                document.getElementById('brand-box').src = path_img + 'box_case_off.png';
                document.getElementById('choice').value = '';
        }
}

// FONCTION POUR LA RECHERCHE PAR MARQUE
function box_brand(path){
        if(document.getElementById('choice').value != 'TN'){
                document.getElementById('box-step-1').src = path + 'box_step_1_brand-trans.png';
                document.getElementById('box-step-1').alt = '1 - Introduce la marca :';
                document.getElementById('activity-box').src = path_img + 'box_case_off.png';
                document.getElementById('enterprise-name-box').src = path_img + 'box_case_off.png';
                document.getElementById('brand-box').src = path_img + 'box_case_on.png';
                document.getElementById('choice').value = 'TN';
        }else{
                document.getElementById('box-step-1').src = path + 'box_step_1_keyword-trans.png';
                document.getElementById('box-step-1').alt = '1 - Introduce la palabra clave :';
                document.getElementById('activity-box').src = path_img + 'box_case_off.png';
                document.getElementById('enterprise-name-box').src = path_img + 'box_case_off.png';
                document.getElementById('brand-box').src = path_img + 'box_case_off.png';
                document.getElementById('choice').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('choice').value==''){
		ouvre('http://www.kompass.es/busqueda_incorrecta.php?msg=1', 'busqueda_incorrecta', 390, 250, 'scrollbars=no');
		return false;
	}

	if(document.getElementById('choice').value!='' && !checkString(formulaire._Keyword.value)){
		formulaire._Keyword.focus();
		ouvre('http://www.kompass.es/busqueda_incorrecta.php?msg=2', 'busqueda_incorrecta', 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);
}

/***************************************************************************************************/

// 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();
}

/***************************************************************************************************/
