function popup(file,width,height)
{
  var top,left ;
  top = (screen.height - height) / 2 ;
  left = (screen.width - width) / 2 ;

  window.open(file+".php","","top="+top+",left="+left+",width="+width+",height="+height+",toolbars=no,resizable=no,scrollbars=no,modal=yes") ;
  return null ;
}

function jsPopup(id,width,height)
{
  //calcul du milieu
  var top,left ;
  left = (screen.availWidth - width) / 2 ;
  top = (screen.availHeight - height) / 2 ;

  img = document.getElementById(id) ;
  img.style.width = width + "px" ;
  img.style.height = height + "px" ;
  img.style.top = (top-100) + "px" ;
  img.style.left = (left-20) + "px" ;
  img.style.display = "block" ;
}

function selectActivite()
{
  //ouvre la fenetre de selection d'activite en popup
  var  url = "/php/selection_activite.php" ;
  var width=640;
  var height=510;
  var top ;
  var left ;

  left = (screen.availWidth-width)/2 ;
  top = (screen.availHeight-height)/2 ;

  selection_window = window.open(url,"selection_window","width="+width+",height="+height+",left="+left+",top="+top+",modal=yes") ;
}

function submitme()
{
  selection = document.forms["listeActivite_form"].submit() ;
}

function blink()
{
    var spans = document.getElementById("blink");
     if(spans.style.visibility=="hidden")
         spans.style.visiblity="visible";
     else
         spans.style.visiblity="hidden";
     setTimeout("blink",1000);
      window.onload=blink;
 }

/********************************************************************
 * City Guide
 *******************************************************************/
function showCityGuide(){
  var city_cp = document.getElementById("city_cp") ;
  city_cp.value = "" ;

  var city_guide_box = document.getElementById("city_guide_box") ;
  city_guide_box.style.display="block" ;

  var city_guide_search_field = document.getElementById("city_guide_search_field");
  city_guide_search_field.focus() ;
}

function searchCityGuide(){

  //récupération du champ concerné
  var city_guide_search_field = document.getElementById("city_guide_search_field");

  //boite pop-up
  var city_guide_box = document.getElementById("city_guide_box") ;

  //boite de résultat
  var city_guide_result_box = document.getElementById("city_guide_result_box") ;

  //récupération de la valeur
  var city_guide_search_value = city_guide_search_field.value;

  var mesg = "Saisissez une ville...";
  //valeur non vide
  if (city_guide_search_value.length < 2 || city_guide_search_value == mesg) {
    city_guide_search_field.value = mesg;
    city_guide_search_field.select();
    return false;
  }

  //construction de la requete AJAX
  var sa = new SimpleAjax();
  sa.setVar("city_cp", city_guide_search_value);
  sa.requestFile = "/php/ajaxGetCity.php";
  sa.method = "post";
  sa.onLoading = function(){
    //gadget
    city_guide_search_field.style.background="#fff url(/images/ajax-loader.gif) 350px 50% no-repeat" ;
  }
  sa.onCompletion = function(){
    if (sa.responseText != "") {
      city_guide_box.style.marginTop = "-115px" ;
      city_guide_box.style.height = "290px" ;

      city_guide_result_box.innerHTML = sa.responseText ;
      city_guide_result_box.style.display = "block" ;
      city_guide_result_box.style.height = "150px" ;

      //assignation des fonctions oncliks
      var lis = city_guide_result_box.getElementsByTagName("li") ;
      for (var i = 0, j = lis.length; i < j; i++) {
        lis[i].onclick = function(){
          setCity(this.title);
        }
        lis[i].onmouseover = function(){
          this.style.color="#ff6e20";
        }
        lis[i].onmouseout = function(){
          this.style.color="#555555";
        }
      }

      city_guide_search_field.style.background="#fff !important" ;
    }
    else {
      alert("The request made a booboo !");
    }
  }
  sa.runAJAX();
  return false ;
}

function setCity(city){
  //récupération du champ city_cp du formulaire
  var city_cp = document.getElementById("city_cp") ;
  city_cp.value = city ;

  closeCityGuide() ;
}

function closeCityGuide(){
  with (document.getElementById("city_guide_box").style) {
    display = "none";
    //height = "100px";
    marginTop = "0";
  }
  with (document.getElementById("city_guide_result_box")) {
    innerHTML = "";
    style.height = "0";
    style.display = "none";
  }
  document.getElementById("city_guide_search_field").value="" ;
}