/************************************************************************/
/***  FONCTIONS JAVASCRIPT POUR LA GESTION DE LA RECHERCHE KOMPASS  *****/
/************************************************************************/

function initLogButton(){
	var name = getKompassCookie('LOGGED');
	var chemin = 'images/webdir_kompass/header/';

	if(name == '' || name == null){
		setLoginButton(chemin);
	}else{
		setLogoutButton(chemin, name);
	}
}

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

function getKompassCookie(name) {
	var search;
	search = name + '=';
	offset = document.cookie.indexOf(search);
	if (offset != -1) {
		offset += search.length;
		end = document.cookie.indexOf(';', offset);
		if (end == -1)
			end = document.cookie.length;
		return document.cookie.substring(offset, end);
	}else{
		return '';
	}
}

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

function setLoginButton(chemin){
	onglet_connexion = '<table width="140" border="0" cellpadding="0" cellspacing="0">';
		onglet_connexion += '<tr><td colspan="3"><img src="' + chemin + 'onglet_bordure_haut.gif" width="140" height="3" border="0"></td></tr>';
		onglet_connexion += '<tr>';
			onglet_connexion += '<td width="2" background="' + chemin + 'onglet_bordure_gauche.gif"><img src="' + chemin + 'p.gif" width="1" height="26" border="0"></td>';
			onglet_connexion += '<td width="136" align="center" bgcolor="#D7D8D2"><a href="http://fr04.kompass.com/compte.php?action=signin" target="kiDisplayFrame" class="txtNoir12"><img src="' + chemin + 'cadenas_connexion.gif" width="9" height="11" border="0" alt="Espace abonné" align="absmiddle" style="margin-right: 10px;">Espace abonnés</a></td>';
			onglet_connexion += '<td width="2" background="' + chemin + 'onglet_bordure_droit.gif"><img src="' + chemin + 'p.gif" width="1" height="26" border="0"></td>';
		onglet_connexion += '</tr>';
	onglet_connexion += '</table>';

	window.document.getElementById("onglets_abonne").innerHTML = onglet_connexion;

	//13/02/2007 : khai
	// on recharge le menu d�roulant qui concerne la localisation g�ographique lorsque l'on fait apparaitre le bouton de login
	set_restrict_geo('');

}

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

function boxRechercheAvanceeCalque(nature){
	if(nature == 'on'){

		// Affichage du calque de recherche avanc�e
		if(document.layers){
			document.layers['calque_recherche_avancee'].visibility = 'show';
		}
		if(document.all){
			document.all['calque_recherche_avancee'].style.visibility = 'visible';
		}else if(document.getElementById){
			document.getElementById('calque_recherche_avancee').style.visibility = 'visible';
		}

		document.getElementById('_Zone').disabled = true;
		document.getElementById('_Zone').style.visibility = 'hidden';

	}else{

		// Affichage de la box de recherche simple
		if(document.layers){
			document.layers['calque_recherche_avancee'].visibility = 'hide';
		}
		if(document.all){
			document.all['calque_recherche_avancee'].style.visibility = 'hidden';
		}else if(document.getElementById){
			document.getElementById('calque_recherche_avancee').style.visibility = 'hidden';
		}

		document.getElementById('_Zone').disabled = false;
		document.getElementById('_Zone').style.visibility = 'visible';

	}

}


function boxRechercheAvancee(nature){
	if(nature == 'on'){

		// Affichage du formulaire KI de recherche avanc�e
		parent.kiDisplayFrame.location.href = 'http://fr04.kompass.com/compte.php?action=advanced';

		boxRechercheAvanceeCalque('on');

	}else{

		// Affichage du formulaire KI de recherche avanc�e
		parent.kiDisplayFrame.location.href = 'http://fr04.kompass.com/vide.php';

		boxRechercheAvanceeCalque('off');

	}
}


function setLogoutButton(chemin, name){

	name = name.replace('%20', '&nbsp;');

	onglet_deconnexion = '<table width="420" border="0" cellpadding="0" cellspacing="0">';
		onglet_deconnexion += '<tr>';
			onglet_deconnexion += '<td colspan="3"><img src="' + chemin + 'onglet_bordure_haut.gif" width="140" height="3" border="0"></td>';
			onglet_deconnexion += '<td rowspan="3"><img src="' + chemin + 'p.gif" width="15" height="1" border="0"></td>';
			onglet_deconnexion += '<td colspan="3"><img src="' + chemin + 'onglet_bordure_haut.gif" width="140" height="3" border="0"></td>';
			onglet_deconnexion += '<td rowspan="3"><img src="' + chemin + 'p.gif" width="5" height="1" border="0"></td>';
			onglet_deconnexion += '<td colspan="3"><img src="' + chemin + 'onglet_bordure_haut.gif" width="120" height="3" border="0"></td>';
		onglet_deconnexion += '</tr>';
		onglet_deconnexion += '<tr>';
			onglet_deconnexion += '<td width="2" background="' + chemin + 'onglet_bordure_gauche.gif"><img src="' + chemin + 'p.gif" width="1" height="26" border="0"></td>';
			onglet_deconnexion += '<td width="136" align="center" bgcolor="#D7D8D2"><div id="onglet_recherche_avancee"></div></td>';
			onglet_deconnexion += '<td width="2" background="' + chemin + 'onglet_bordure_droit.gif"><img src="' + chemin + 'p.gif" width="1" height="26" border="0"></td>';
			onglet_deconnexion += '<td width="2" rowspan="2" background="' + chemin + 'onglet_bordure_gauche.gif"><img src="' + chemin + 'p.gif" width="1" height="26" border="0"></td>';
			onglet_deconnexion += '<td width="136" rowspan="3" align="center" bgcolor="#D7D8D2" class="txt">Compte :&nbsp; <a href="http://fr04.kompass.com/compte.php?action=memberAccount" target="kiDisplayFrame" class="txtRouge12bs">' + name + '</a></td>';
			onglet_deconnexion += '<td width="2" rowspan="2" background="' + chemin + 'onglet_bordure_droit.gif"><img src="' + chemin + 'p.gif" width="1" height="26" border="0"></td>';
			onglet_deconnexion += '<td width="2" background="' + chemin + 'onglet_bordure_gauche.gif"><img src="' + chemin + 'p.gif" width="1" height="26" border="0"></td>';

			// khai : rajout parent.kiTopFrame.location.reload();

			onglet_deconnexion += '<td width="116" align="center" bgcolor="#D7D8D2"><a href="http://fr04.kompass.com/compte.php?action=signout" target="kiDisplayFrame" onclick="boxRechercheAvanceeCalque(\'off\'); parent.kiTopFrame.location.reload(); " class="txtNoir12"><img src="' + chemin + 'cadenas_deconnexion.gif" width="9" height="11" border="0" alt="D�connexion" align="absmiddle" style="margin-right: 10px;">D�connexion</a></td>';

			onglet_deconnexion += '<td width="2" background="' + chemin + 'onglet_bordure_droit.gif"><img src="' + chemin + 'p.gif" width="1" height="26" border="0"></td>';
		onglet_deconnexion += '</tr>';
		onglet_deconnexion += '<tr>';
			onglet_deconnexion += '<td colspan="3" bgcolor="#FFFFFF"><img src="' + chemin + 'p.gif" width="140" height="1" border="0"></td>';
			onglet_deconnexion += '<td colspan="3" bgcolor="#FFFFFF"><img src="' + chemin + 'p.gif" width="120" height="1" border="0"></td>';
		onglet_deconnexion += '</tr>';
	onglet_deconnexion += '</table>';

	window.document.getElementById("onglets_abonne").innerHTML = onglet_deconnexion;

	// Changement du libell� de recherche simple en recherche avancée
	onglet_recherche_avancee_code = '<a href="Javascript:boxRechercheAvancee(\'on\');" class="txtNoir12">Recherche avanc�e</a>';
	window.document.getElementById('onglet_recherche_avancee').innerHTML = onglet_recherche_avancee_code;

}

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

function adjust_domain_name(){
	if(document.domain){
		var p = document.domain.lastIndexOf('.kompass');
		if(p > -1){
			document.domain = document.domain.substring(p+1);
		}
	}
}

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

function setKompassCookie(name, value){
	document.cookie = name + '=' + escape(value) + ';	path=/;	domain=kompass.com;';
}

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

function MajPub(url, version){

	complement = '';

	if(version==''){
		date = new Date();
		version = date.getFullYear() + date.getMonth() + date.getDate() + date.getHours() + date.getMinutes() + date.getSeconds();
	}

	if(url==''){
		url = 'http://www.kompass.com/kinl/T=FP&SWF=1&LG=' + page_language + '&S=' + version + '&loc=' + location.hostname + complement;

	}

	document.getElementById('sb_banner').width = 440;  // Ajout pour banni�re standard (hors KI)

	// ki_eid("_Version").value = version;
	frames['sb_banner'].location.href = url;

	return true;
}

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

function busy_mark(visible){
	if(visible){
		window.status = 'Recherche en cours...';
	}else{
		window.status = '';
	}
}

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

function set_member_data(id, name, units, language, country){

	// alert("set_member_data called !!\nid=" + id + "\nname=" + name + "\nunits=" + units + "\nlanguage=" + language + "\ncountry=" + country);

	var temp = '';
	busy_mark(false);

	// the id arg contains "out" when the user has just signed-in and "in" when just signed-out!
	// do nothing if there is no change in sign-in status.

	if((id > '') && (id != 'in')){		// ID should be changed from "in/out" to real member ID
		// user is signed in, change button to sign out!
		setLogoutButton('<?=$web_img?>', name);
		setKompassCookie('LOGGED', name);
	}else	if(id == "in"){
		// change button to sign-in (kps101) and clear cookie
		setLoginButton('<?=$web_img?>');
		setKompassCookie('LOGGED', '');
	}
	initLogButton();
	setKompassCookie('CREDITS', units);
}

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

/*
function lienEspaceAbonnes(){
	var name = getKompassCookie('LOGGED');

	alert('Cookie = ' + name);

	if(name == '' || name == null){
		top.window.location = 'compte.php?action=signin';
	}else{
		top.window.location = 'compte.php?action=memberAccount';
	}
}
*/

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

var original_domain = document.domain;
adjust_domain_name();
//alert(document.domain);
