//
// ==========================================================
// TOUTES les pages utilisant ce script doivent prealablement
// valoriser les variables suivantes:
// langue, ci, model_loc, session.
// ==========================================================
//
if(typeof(langue) == "undefined")
	alert(must_define_lang+document.location);
//
// ==========================================================
// Le nom de la fenetre commence par "SITE" si on vient du site
// de l'heberge. Il faut donc tester ce nom a chaque fois que
// l'on veut en deduire le nom du repertoire.
// ==========================================================
//
var editeur_ci = "AGGMgraphimat";
var wwroot = "http://www.whatwhere.com";
var nomclient;
var from_ww;
if(window.name.substr(0,4) == "SITE") {
	nomclient = window.name.substr(4).split("_").join("-");
	from_ww = false;
} else if(window.name.substr(0,4) == "SOUS") {
	// sous-fenetre d'une fenetre SITE: le nom de fenetre differe pour
	// pouvoir afficher deux fenetres, mais le traitement est identique
	// a la fenetre SITE. En particulier on ferme toujours en sortant.
	// Ceci interdit le retour intermediaire depuis une sous-sous-fenetre.
	nomclient = window.name.substr(4).split("_").join("-");
	from_ww = false;
} else {
	nomclient = window.name.split("_").join("-");
	if(nomclient == "principal") nomclient = editeur_ci.substr(4);
	from_ww = true;
}

function exitcons(loc)
{
	if(from_ww) {
		loc.href = model_loc + "/var/" + ci + "/" + langue + "/";
		return true;
	} else {
		self.close();
		return false;
	}
}
function exitww()
{
	self.close();
}
// fenetre site -> sous-fenetre thesaurus -> sous-sous-fenetre btn fiche finale
var curwin;	// sous-fenetre a passer en avant-plan
curwin = null;
function soussite(client,page) {
	if(client == "") client = nomclient; // possible si sous-sous-fenetre
	model = (client == editeur_ci.substr(4)) ? "public" : "cistandard";
	return winopen(
		model_loc+"/../"+model+"/var/"+client+"/"+langue+"/index.php",
		"SOUS"+client.split("-").join("_"));
}
function sousthes(client,thesaurus,fonc) {
	return thesopen(client,thesaurus,fonc,"SOUS");
}
function sitethes(client,thesaurus,fonc) {
	return thesopen(client,thesaurus,fonc,"SITE");
}
function thesopen(client,thesaurus,fonc,prefixe) {
	if(client == "") client = nomclient; // possible si sous-sous-fenetre
	return winopen(wwroot + "/cgi-bin/CGI_POLYCLES?" +
		"POLYCLES_USERDATA=whatwhere&THESAURUS=" + thesaurus +
		"&CI=" + editeur_ci.substr(0,4) + client +
		"&LANG=" + langue + "&AC=CN&FONC=" + fonc,
		prefixe + client.split("-").join("_"));
}
function winopen(url,nomfen) {
	if(curwin != null && !curwin.closed) {
		curwin.close();
		curwin = null;
	}
	curwin = window.open(url, nomfen,
		"scrollbars=yes,toolbar=no,"+
		"directories=no,menubar=no,resizable=yes,"+
		"height=598,outerHeight=610,width=788,outerWidth=800,"+
		"left=0,screenX=0,top=0,screenY=0");
	return false;
}
function gohelp(fichier,niveau) {
	if(document.all && fichier.charAt(0) != '/') {
		var x = document.all.tags('BASE')[0].href;
		fichier = x.substring(0,x.lastIndexOf('/')+1) + fichier;
	}
	window.open(fichier + ".htm#" + niveau,
		"fen_aide",
		"scrollbars=yes,toolbar=no,directories=no,menubar=no,"+
		"resizable=1,width=500,height=300");
	return false;
}
function info(niveau) {
	return gohelp(model_loc+'/var/'+ci+'/'+langue+'/info',niveau);
}

function LoadImg(dir,nom,indice,pale) {
	var i = 3*indice;
	Tab_img[i+0] = new Image();
	Tab_img[i+0].src=dir+nom+"_on.gif";
	Tab_img[i+1] = new Image();
	Tab_img[i+1].src=dir+nom+"_of.gif";
	if(pale) {
		Tab_img[i+2] = new Image();
		Tab_img[i+2].src=dir+nom+"_pal.gif";
	}
}

// prechargement des boutons
var Tab_img=new Array();
var icons="../../";
if(typeof(ww_subdir_level) != "undefined")
	while(ww_subdir_level > 0) {
		icons="../" + icons;
		ww_subdir_level--;
	}
var textes=icons+langue+'/cmn/';
icons=icons+'cmn/';

LoadImg(icons,"btn_aide",0,0);
LoadImg(icons,"btn_info",1,0);
LoadImg(icons,"btn_home",2,0);
LoadImg(icons,"btn_retour",8,0);
LoadImg(textes,"onglet_ajout",3,0);
LoadImg(textes,"onglet_recherche",4,0);
LoadImg(textes,"onglet_reponse",5,0);
LoadImg(textes,"onglet_comparer",6,0);
LoadImg(textes,"onglet_annonce",7,0);
LoadImg(icons,"flech_g",10,0);
LoadImg(icons,"flech_d",11,0);
LoadImg(icons,"flech_h",12,0);
LoadImg(icons,"btn_accu",13,0);

function aff(loc, img, on_of_pal) {
	if (document.images)
		document.images[loc].src=Tab_img[img*3+on_of_pal].src;
}

// code pour executer les liens dans les listes deroulantes
function go(which)
{
	var i = which.selectedIndex;
	var point = which.options[i].value;
	if(point=="-1")
		alert(noselect);
	else
		cango(session + "&FONC=ATTRIBUTE&POINTER=" + point);
}

// code pour generer les liens sur l'image
function pmap(forme,pointer,desc,alt)
{
	document.write("<AREA SHAPE=\"" + forme +
		"\" href=\"#\" onclick=\"return cango('" + session +
		"&POINTER=" + pointer +
		"&FONC=ATTVALS')\" coords=\"" + desc +
		"\" alt=\"" + alt + "\">")
}

function histo(n,ann,ptr) {
	var i;
	var label=histo_label.split("%1").join(ann.toString());
	document.write("<tr><td width=50");
	if(n<1) n = 1;
	document.write(" bgcolor=#D90550");
	document.write("><font color=\"#FFFFFF\" size=\"2\">");
	document.write("<center>"+label+"</center></font>");
	for(i=1; i<n; i++) {
		document.write("<tr><td width=50 bgcolor=#D90550>");
		document.write("<font size=\"-1\">&nbsp;</font></td></tr>");
	}
}

var let_us_go = true;	// on va interdire de cliquer deux fois sur le meme lien
function cango(url){	// renvoie true si appele la 1ere fois sur cette page
	var gonow = let_us_go;
	let_us_go = false;
	if(!gonow)
		alert(wait_load);
	else {
		window.location.replace(url);	// commenter ce 2 lignes pour
		gonow = false;			// reactiver precedent/suivant
	}
	return gonow;
}

// lien vers la gestion de la fiche
function gestfiche(ucle) {
	var url;
	url = '/ww_std/'+langue+'/admin/gestfiche.php?' +
		'FONC=MENU&REC=' + ucle + '&' +
		session.substring(session.indexOf('?')+1) +
		'&WIN=' + window.name +
		'&BACK=' + escape(session+'&BUTTON=UP&FONC=RET_GESTION');
/*
	window.open(url, 'wwgestfiche',
		'scrollbars=yes,toolbar=no,directories=no,menubar=no,'+
		'resizable=1,width=550,height=400');
*/
	window.location = url;
	return false;
}
