lCountryTab = new Array(); // Pays
lRegionTab = new Array();  // Villes
lDepartmentTab = new Array(); // Quartier

function lClearSelect(theSelect)
{
	var theSelectSize = theSelect.length;
  for (var i = 0; i < theSelectSize; i++)
  {
    theSelect.options[0] = null;
  }
}

function lCountryLoad(theSelect,selectedOption,defaultOption)
{
  lClearSelect(theSelect);
  theSelect.options[0] = new Option(defaultOption,"");
  theSelect.options[0].selected = true;
  for (var i = 0; i < lCountryTab.length; i++)
  {
    theSelect.options[i+1] = new Option(lCountryTab[i],lCountryTab[i]);
  	if (lCountryTab[i] == selectedOption)
  	{
      theSelect.options[0].selected = false;
  		theSelect.options[i+1].selected = true;
  	}
  }
}

function lRegionLoad(theSelect,country,selectedOption,defaultOption)
{
  lClearSelect(theSelect);
  theSelect.options[0] = new Option(defaultOption,"");
  theSelect.options[0].selected = true;
  var j = 1;
  for (var i = 0; i < lRegionTab.length; i++)
  {
    if (lRegionTab[i][0] == country)
    {
      theSelect.options[j] = new Option(lRegionTab[i][1],lRegionTab[i][1]);
     	if (lRegionTab[i][1] == selectedOption)
    	{
        theSelect.options[0].selected = false;
    		theSelect.options[j].selected = true;
  	  }
  	  j++;
    }
  }
}

function lRegionSelect(theSelect,country,department)
{
	var i = 0;
  var j = 0;
	var found = false;
  while (i < lRegionTab.length && !found)
  {
  	if (lDepartmentTab[i][0] == country && lDepartmentTab[i][2] == department)
    {
    	found = true;
    }
    else
    {
  	  i++;
    }
  }
  found = false; 
  while (j < theSelect.length && !found)
  {
    if (theSelect.options[j].value == lDepartmentTab[i][1])
    {
    	theSelect.options[j].selected = true;
    	found = true;
    }
    j++;
  }
} 

function lDepartmentLoad(theSelect,country,region,selectedOption,defaultOption)
{
  lClearSelect(theSelect);
  theSelect.options[0] = new Option(defaultOption,"");
  theSelect.options[0].selected = true;
  var j = 1;
  for (var i = 0; i < lDepartmentTab.length; i++)
  {
    if (lDepartmentTab[i][0] == country)
    {
    	if (region != "0")
    	{
    		if (lDepartmentTab[i][1] == region)
    		{
          theSelect.options[j] = new Option(lDepartmentTab[i][2],lDepartmentTab[i][2]);
  	      j++;
    		}
    	}
    	else
    	{
        theSelect.options[j] = new Option(lDepartmentTab[i][2],lDepartmentTab[i][2]);
  	    j++;
      }
     	if (lDepartmentTab[i][2] == selectedOption)
    	{
        theSelect.options[0].selected = false;
    		theSelect.options[j-1].selected = true;
  	  }
    }
  }
}

// lCountryAdd : ajout pays
function CA(country)
{
  lCountryTab[lCountryTab.length] = country;
}

// lRegionAdd: ajout ville
function RA(country,region)
{
  lRegionTab[lRegionTab.length] = new Array(country,region);
}

// lDepartmentAdd: ajout quartier
function DA(country,region,department)
{
  lDepartmentTab[lDepartmentTab.length] = new Array(country,region,department);
}