///////////////////////////////////////////////
// when 'true' prevents execution of callback
// functions in case of modifications of
// selections by another callback function
var program = true;

//variable pour la gestion des cartes
// 1 correspond a la carte des sites
var titre=1;



function addSelectPays( )
{
/*	if (document.cartes.pays.options[0].value != "")
	{
		document.cartes.pays.options[document.cartes.pays.length]
							= new Option( document.cartes.pays.options[0].text,
											document.cartes.pays[0].value, null, null);

		if (language == "FR")
			document.cartes.pays.options[0].text = "-- sélectionnez le pays --";
		else
			document.cartes.pays.options[0].text = "-- country selection --";
		document.cartes.pays.options[0].value = "";
		document.cartes.pays.selectedIndex = 0;
	}
*/
}

function eraseSelectPays( )
{
	if (document.cartes.pays.options[0].value == "")
	{
		document.cartes.pays.options[0] = null;
	}
}	

function addSelectRegion( )
{
	if (document.cartes.region.options[0].value != "")
	{
		document.cartes.region.options[document.cartes.region.length] =
												new Option( "", "", null, null);
		
		for (i = document.cartes.region.length - 1; i > 0; i--)
		{
			document.cartes.region.options[i].text = document.cartes.region.options[i - 1].text;
			document.cartes.region.options[i].value = document.cartes.region.options[i - 1].value;
		}

		if (language == "FR")
			document.cartes.region.options[0].text = "-- sélectionnez la région --";
		else
			document.cartes.region.options[0].text = "-- region selection --";
		document.cartes.region.options[0].value = "";
		document.cartes.region.selectedIndex = 0;
	}
}

function eraseSelectRegion( )
{
	if (document.cartes.region.options[0].value == "")
	{
		document.cartes.region.options[0] = null;
	}
}

function setSelectDepartement( numero)
{
	document.cartes.departement.options.length = 0;
	if (language == "FR")
		document.cartes.departement.options[0] =
							new Option( "TOUS", "", null, true);
	else
		document.cartes.departement.options[0] =
							new Option( "-- department selection --", "", null, true);

	// ajoute les départements de la région indiquée par le numéro
	addDepartments( numero);
}

function resetSelectDepartement( )
{
	document.cartes.departement.options.length = 0;

	if (language == "FR")
		document.cartes.departement.options[document.cartes.departement.length] =
									new Option( "-- pas de sélection --", "", null, true);
	else
		document.cartes.departement.options[document.cartes.departement.length] =
									new Option( "-- no selection --", "", null, true);
}

function eraseSelectDepartement( )
{
	if (document.cartes.departement.options[0].value == "")
	{
		document.cartes.departement.options[0] = null;
	}
}

function getPays( )
{	
	// eraseSelectPays( );
	// addSelectRegion( );
	resetSelectDepartement( );

	// update l'applet
	document.applets[0].setCarte( "P", "00");	
}

function getRegion( )
{

	if (document.applets[0] == null)
	{
		if (language == 0)
			alert( "Veuillez attendre l'initialisation des applets");
		else
			alert( "Please wait until applets are initialized");
			
		document.cartes.region.selectedIndex = 0;
		return;
	}	
	if(titre == 1)
	{	
	CodeRegion = document.cartes.region.options[document.cartes.region.selectedIndex].value ;	
	
	addSelectPays( );
	//eraseSelectRegion( );
	if (CodeRegion == "00")
		{
		getPays();
		}
	else
		{
		setSelectDepartement(CodeRegion);
		// update l'applet
		document.applets[0].setCarte( "R", CodeRegion);
		}
	}
}

function getDepartement( )
{
	addSelectPays( );
	// addSelectRegion( );
	//eraseSelectDepartement( );
	if (document.cartes.departement.options[document.cartes.departement.selectedIndex].value == "") {
		getRegion() ;
	}
	else{
		// update l'applet
		document.applets[0].setCarte( "D",document.cartes.departement.options[document.cartes.departement.selectedIndex].value);
	}
}


/////////////////////////////////////////////////
// making it out with images

function flipLanguage( toDo)
{
	if (toDo == "EN+")
	{
		document.images['language'].src = './Icones/English2.gif';
		window.setTimeout( 'window.status="Site en Anglais"', 1);
	}
		
	else if (toDo == "FR+")
	{
		document.images['language'].src = './Icones/Francais2.gif';
		window.setTimeout( 'window.status="French site"', 1);
	}
	
	else if (toDo == "EN-")
	{
		document.images['language'].src = './Icones/English1.gif';
		window.setTimeout( 'window.status=""', 1);
	}
		
	else if (toDo == "FR-")
	{
		document.images['language'].src = './Icones/Francais1.gif';
		window.setTimeout( 'window.status=""', 1);
	}
}

function resetSelectRegion( )
{
	document.cartes.region.options.length = 0;

	if (language == "FR")
		document.cartes.region.options[document.cartes.region.length] =
									new Option( "-- pas de sélection --", "", null, true);
	else
		document.cartes.region.options[document.cartes.region.length] =
									new Option( "-- no selection --", "", null, true);
}


function resetSelectPays( )
{
	document.cartes.pays.options.length = 0;

	document.cartes.pays.options[document.cartes.pays.length] =
									new Option( "France", "", null, true);
}


