// JavaScript Document

var champs=['nom_usuel','commune','lieu_dit','commune','nom_antique','departement','region','pays','civitas','superficie','topographie','nombre_de_phases','rempart','nombre_portes','nombre_portes_fouillees','occupation_interne','environnement_de_l_oppidum','datation_de_l_oppidum','occupation_du_site','methode_chronologie_absolue','gestion_mise_en_valeur'];

function chargerFichier(fichier,args,methode) {
	if(window.XMLHttpRequest) xhr_object=new XMLHttpRequest(); // FIREFOX
	else if(window.ActiveXObject) xhr_object=new ActiveXObject("Microsoft.XMLHTTP"); // IE
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return(false);
	}
	if(methode=='POST') {
		xhr_object.open(methode,fichier,false);
		xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr_object.send(args);
	}
	else {
		xhr_object.open(methode,fichier+'?'+args,false);
		xhr_object.send(null);
	}
	if(xhr_object.readyState==4) return(xhr_object.responseText);
	else return(false);
}

function visuelExpo(id) {
	return document.getElementById('visuel_'+id).value;
}

function initialiserExpo(id,lg,pg) {
	var args='lg='+lg+'&id_theme='+id+'&pg='+pg;
	var texte=chargerFichier("include/dyn_exposition.php",args,"POST");
	document.getElementById("exposition").innerHTML=texte;
	var intro=chargerFichier("include/dyn_intro.php",args,"POST");
	document.getElementById("intro").innerHTML=intro;
	if(document.getElementById("sui").value==0) document.getElementById("asui").style.display='none';
	else document.getElementById("asui").style.display='';
	if(document.getElementById("pre").value==0) document.getElementById("apre").style.display='none';
	else document.getElementById("apre").style.display='';
	return document.getElementById("visuel").value;
}

function presuiExpo(action,lg) {
	if(action=="+") var pg=document.getElementById("sui").value;
	else if(action=="-") var pg=document.getElementById("pre").value;
	initialiserExpo(document.getElementById("expo").value,lg,pg);
	js2swf('jsMajImage',document.getElementById("visuelencours").value);
}

function initialiserPage() {
	afficherListe("defaut","");
	afficherRecherche();
}

function inscrireNewsletter(email) {
	var args='email='+email;
	texte=chargerFichier("include/dyn_newsletter.php",args,"POST");
	document.getElementById("newsletter").innerHTML=texte;
}

function afficherFiche(id_ville,carto) {
	var fiche;
	var id_carto;
	var args="lg="+document.getElementById("lg").value+"&";
	
	args+="id_ville="+id_ville;
	fiche=chargerFichier("include/dyn_fiche.php",args,"POST");
	document.getElementById("fiche").innerHTML=fiche;
	id_carto=chargerFichier("include/dyn_point.php",args,"POST");
	if(carto) js2swf('jsMajPoints','swf/carto.php?id_carto='+id_carto);
}

function afficherListe(type,args) {
	var date=new Date();
	var liste;
	if(args!='') args+="&";
	args+="lg="+document.getElementById("lg").value+"&";
	
	if(type=="libre") {
		args+="mot="+document.getElementById("find").value;
	}
	else if(type=="defaut") {
		document.getElementById("find").value='';
		recherche=chargerFichier("include/dyn_recherche.php",args,"POST");
		document.getElementById("rechercheav").innerHTML=recherche;
	}
	else if(type=="avancee") {
		for(var i=0;i<=champs.length;i++) {
			if(document.getElementById("ra_"+champs[i])) {
				if(args!="") args+="&";
				args+=champs[i]+"="+document.getElementById("ra_"+champs[i]).value;
			}
			else if(document.getElementById("cb_"+champs[i]+"_1")) {
				var c=1;
				var t=0;
				while(document.getElementById("cb_"+champs[i]+"_"+c)) {
					if(document.getElementById("cb_"+champs[i]+"_"+c).value!='' && document.getElementById("cb_"+champs[i]+"_"+c).checked==true) {
						if(args!="") args+="&";
						args+=champs[i]+"["+t+"]="+document.getElementById("cb_"+champs[i]+"_"+c).value;
						t++;
					}
					c++;
				}
			}
		}

	}
	
	liste=chargerFichier("include/dyn_liste.php",args,"POST");
	document.getElementById("liste").innerHTML=liste;
	
	id_carto=document.getElementById("carto_liste").value;
	if(id_carto>0) js2swf('jsMajPoints','swf/carto.php?time='+date.getTime()+'&id_carto='+id_carto);
}

function afficherRecherche(from) {
	var args="lg="+document.getElementById("lg").value+"&";

	for(var i=0;i<=champs.length;i++) {
		if(document.getElementById("ra_"+champs[i])) {
			if(args!="") args+="&";
			args+="ra_"+champs[i]+"="+document.getElementById("ra_"+champs[i]).value;
		}
	}
	if(args!="") args+="&from="+from;

	recherche=chargerFichier("include/dyn_recherche.php",args,"POST");
	document.getElementById("rechercheav").innerHTML=recherche;
}

function changerDisplay(id) {
	bloc=document.getElementById(id).style;
	if(bloc.display=="") bloc.display="none";
	else bloc.display="";
	if(id=="rechercheav") {
		if(bloc.display=="") document.getElementById("fleche").src="pics/fleche-orange-on.gif";
		else document.getElementById("fleche").src="pics/fleche-orange.gif";
	}
}



var InternetExplorer=navigator.appName.indexOf("Microsoft")!=-1;
function myFlash_DoFSCommand(command,args) {
	var myFlashObj = InternetExplorer ? myFlash : document.myFlash;
	if(command=="swfMajFiche") afficherFiche(args,0);
	else if(command=="swfMajHa") {
		var superficie=args.split(';');
		afficherListe('avancee','supmin='+superficie[0]+'&supmax='+superficie[1]);
	}
	//document.getElementById('sortieFlash').innerHTML = command+" / "+args;
}
if(navigator.appName && navigator.appName.indexOf("Microsoft")!=-1
  && navigator.userAgent.indexOf("Windows")!=-1
  && navigator.userAgent.indexOf("Windows 3.1")==-1)
{
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub myFlash_FSCommand(ByVal command, ByVal args)\n');
	document.write(' call myFlash_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}

function js2swf(nomVar,Var) {
	window.document.myFlash.SetVariable(nomVar,Var);
}

function intro() {
	var args="lg="+document.getElementById("lg").value;
	document.getElementById("fiche").innerHTML=chargerFichier('include/intro.php',args,"GET");
}