
//var restriction = false;

/*
function set_restrict_geo(pays_restrict){
	return true;
}
*/


function set_restrict_geo(pays_restrict)
{

	var restriction = false;	// la restriction doit être toujours gérée lorsque cette fonction est appelée

	// rajoute les régions à un code 'pays_restrict' => FR
	if ( pays_restrict == 'FR' )
	{
		var codeRegionFr='';
		for( var cpt = 1 ; cpt < 23; cpt++ ) 
		{
			cpt_string = ''+ cpt;
			
			if (cpt_string.length<=1)
				codeRegionFr += 'FR'+'0'+cpt_string;
			else
				codeRegionFr += 'FR'+cpt_string;
				
			codeRegionFr += ',';	
		}
		codeRegionFr = codeRegionFr.substring(0, codeRegionFr.length-1);
		//alert(codeRegionFr);
		
		pays_restrict = codeRegionFr ;
	}
		
	if(!restriction)
	{
		if(pays_restrict.length!=0 && pays_restrict!="WW")
		{
			var i=0;
			var cpt=0;
			var trouve=0;
			var zonegeo=0;
			var id = "_Zone";
			var taille=document.getElementById(id).length;

			var reg=new RegExp("[ ,;]+", "g");
			var pays_tab = pays_restrict.split(reg);

						
			// on boucle sur la selection de pays choisis,
			// selection d'un continent?
			while(i<pays_tab.length)
			{
				if(pays_tab[i]=="Z1")
				{
					pays_restrict += ",DZ,MA,MU,ZA";
					zonegeo=1;
				}
				else if(pays_tab[i]=="Z2")
				{
					pays_restrict += ",CA,CL,MX,US";
					zonegeo=1;
				}
				else if(pays_tab[i]=="Z3")
				{
					pays_restrict += ",AU,CN,HK,IN,JP,KR,LK,MY,NZ,SG,TH,TW";
					zonegeo=1;
				}
				else if(pays_tab[i]=="Z4")
				{
					pays_restrict += ",KG,KZ,UZ";
					zonegeo=1;
				}
				else if(pays_tab[i]=="Z5")
				{
					pays_restrict += ",AM,AT,AZ,BG,BY,CS,CZ,EE,HR,HU,LT,LV,MD,PL,RO,RU,SI,SK,UA";
					zonegeo=1;
				}
				else if(pays_tab[i]=="Z6")
				{
					pays_restrict += ",AE,EG,IL,IR,LB,SA";
					zonegeo=1;
				}
				else if(pays_tab[i]=="Z7")
				{
					pays_restrict += ",BE,CH,DE,DK,ES,FI,FR,GB,GR,IE,IS,IT,LU,MC,MT,NL,NO,PT,SE,SM,TR";
					zonegeo=1;
				}
				i++;
			}
			pays_tab = pays_restrict.split(reg);

			
			cpt=0;
			// on boucle en comparant une occurrence du tableau des pays pays_'restrict' 
			// avec le fichier 'annuaire_localisations.inc' qui alimente la liste déroulante "Localisez" du formulaire
			while(cpt<taille && document.getElementById(id).options[cpt])
			{
				i=0;
				trouve=0;
				// le pays existe il dans la liste déroulante du formulaire?
				while(i<pays_tab.length && trouve==0)
				{
					if(pays_tab[i].length == 2)
					{
						if(document.getElementById(id).options[cpt].value == pays_tab[i] && pays_tab[i]!="WW")
							trouve=1;
					}
					else
					{
						if(pays_tab[i].substr(0,2) == "FR")
						{
							if(document.getElementById(id).options[cpt].value == pays_tab[i] || document.getElementById(id).options[cpt].value == "FR_"+pays_tab[i] || document.getElementById(id).options[cpt].value == pays_tab[i].substr(0,2))
								trouve=1;
						}
						else
						{
							if(document.getElementById(id).options[cpt].value == pays_tab[i].substr(0,2))
								trouve=1;
						}
					}
					i++;
				}

				// si le pays choisi existe dans la liste déroulante,
				// on l'efface
				if(trouve==0)
				{
					if(zonegeo==1 && document.getElementById(id).options[cpt].value=="-2")
						cpt++;
					else
						document.getElementById(id).options[cpt]=null;
				}
				else
					cpt++;
			}
		}
	restriction = true;
	}
	
}
