var ongletAffiche=0;
var affinageAffiche=0;

function oninit1(){ 
    setLinkVisuCarto();
    setActionSurOnglet();  
    setCalendrierGeneral("","1","","","calendrierMoteurAffine",clicCalendJsAffine,"inpt_dateDebAffine","","","lst_nbjAffine","1","");
}

function clicCalendJsAffine(evt,jour,mois,annee,etat){
  $("inpt_dateDebAffine").value=jour+"/"+mois+"/"+annee;
  afficheEffaceCalendJs("calendrierMoteurAffine");
}

function setLinkVisuCarto(){
    if (window.iteaGMAP_setElemDeListeClickToVisuCarte)
    iteaGMAP_setElemDeListeClickToVisuCarte({
        callback:function(){
            afficheOngletCarte();
            $("li_ongletCarte").scrollTo();
        },
        imgPicto:"/img/punaise_on.png",
        zoom:10} 
    );
}

function afficheOngletListe1(){
    ongletAffiche=0;
    $("div_liste1").style.display="block";
    effaceCarto();
    $("div_liste_navigListeQuePageAjxBas").style.display="block";
    $("div_listeTriEtPage").style.display="block";

    setClassForObj($("li_ongletListe1"),"listeOngletOn");
    setClassForObj($("li_ongletCarte"),"listeOnglet");
}

function afficheOngletCarte(){
    ongletAffiche=1;
    $("div_liste1").style.display="none";
    $("div_liste_navigListeQuePageAjxBas").style.display="none";
    $("div_listeTriEtPage").style.display="none";     
    if(window.gmap)window.gmap.checkResize();    
    if(window.gmap)window.gmap.resetCentre();

    setClassForObj($("li_ongletListe1"),"listeOnglet");
    setClassForObj($("li_ongletCarte"),"listeOngletOn");  
    
    afficheCarte();
}

function setActionSurOnglet(){
   $("li_ongletListe1").onclick=function (evt){afficheOngletListe1();}
   $("li_ongletCarte").onclick=function (evt){afficheOngletCarte();}
   
   if (ongletAffiche==0)afficheOngletListe1();
   if (ongletAffiche==1)afficheOngletCarte();
}

function effaceCarto(){
    if($("div_liste_carto")){$("div_liste_carto").style.display="none";}
}
function afficheCarte(){
    document.getElementById("div_liste_carto").style.display="block";
    if(window.gmap)window.gmap.checkResize();    
    if(window.gmap)window.gmap.resetCentre();
}

function onRefreshList(){
    initMoteurAccueil();
    setActionSurOnglet()
    traiteGMap();
    if(affinageAffiche==1) afficheAffinage();
}
function onRefreshListChgtTriEtPage(){
	traiteGMap();
}
function traiteGMap(){
  if (window.gmap){
     gmap.reload();
  	 setLinkVisuCarto();
  }
}

function rechercheCarto(){
  afficheEffaceCalendJs("div_moteurAffinage");
  afficheOngletCarte();
}


function setActionScrollingMoteur(){
	function setForScroll(evt){
		var yscroll=document.body.scrollTop;
		if (!yscroll)yscroll=document.documentElement.scrollTop;
		var divGene=$("div_moteurFixe");
		divGene.style.top=yscroll+"px";
		
		//divGene.style.marginTop=null;
		//divMsg.style.top=parseInt(yscroll+50)+"px";
	}
		
	document.onmousewheel=setForScroll;
	window.onscroll=setForScroll;
}


function afficheAffinage(){
  if(document.body.clientWidth>=1240){ 
    if($("div_moteurFixe").style.width=="0px"){
      if(!$("div_moteurFixe").innerHTML) $("div_moteurFixe").innerHTML=$("div_moteurAffinage").innerHTML;
      $("div_moteurFixe").morph("width:244px;");
      initMoteurAccueil();
      setActionScrollingMoteur();
      if($("div_moteurAffinage").showing==true) afficheEffaceCalendJs("div_moteurAffinage");
    }
    else {
	   $("div_moteurFixe").morph("width:0px;");
	  }
  }
  else{
    //if($("div_moteurFixe").style.width=="244px") $("div_moteurFixe").morph("width:0px;");
    if(!$("div_moteurAffinage").innerHTML) $("div_moteurAffinage").innerHTML=$("div_moteurFixe").innerHTML;
    $("div_moteurFixe").innerHTML="";
    afficheEffaceCalendJs("div_moteurAffinage");
    initMoteurAccueil();
  }
  affinageAffiche=1;  
}

function effaceAffinage(){
  if(document.body.clientWidth>=1240){
    $("div_moteurFixe").morph("width:0px;");
  }
  else{
    Effect.BlindUp("div_moteurAffinage");       
    $("div_moteurAffinage").showing=false;
  }
}

function initEffaceAffinage(){
  if(document.body.clientWidth>=1240) $("div_moteurAffinage").style.display="none";
  else $("div_moteurFixe").style.display="none";
}

function reinitRecherche(){
  setListByForm($('frm_newSearch'));
  affinageAffiche=1
}

