var class_sous_cat_displayed='categories sous_categories';var class_sous_cat_hidden=class_sous_cat_displayed+' hide';var picto_delete=new Image(14,14);var current_localisation=new Array();var default_localisation='ex: Nice, Var, Rhône Alpes, 13 ...';var current_level1='';var current_level2='';var nb_ville_selected=0;picto_delete.src="images/supprimer.jpg";window.onload=init;var parcours_length=0;function positionAuto(element,entry){setTimeout(function(){Element.clonePosition('localisation_propositions','localisation',{'setWidth':false,'setHeight':false,'offsetTop':document.getElementById('localisation').offsetHeight});},200);return entry;}
function init()
{new Ajax.Autocompleter('localisation','localisation_propositions','controler.php',{parameters:'action=tools-getlocalisations',paramName:'localisation',minChars:2,afterUpdateElement:setCurrentLocalisation,indicator:'localisation_loader',select:'localisation_texte',callback:positionAuto});}
function sendForm()
{var ul_parent=document.getElementById('geo_selection');var childs=ul_parent.childNodes;if(childs.length>0)
{var geo_criteres='';for(var i=0;i<childs.length;i++)
{if(i==0)
geo_criteres+=childs[i].id;else
geo_criteres+='-'+childs[i].id;if(document.getElementById('extend_'+childs[i].id)&&document.getElementById('extend_'+childs[i].id).checked)
{geo_criteres+='*'+document.getElementById('extend_km').options[document.getElementById('extend_km').selectedIndex].value;}}
document.getElementById('localisations').value=geo_criteres;document.getElementById('form_search').submit();}
else
{messageBox('Pour rechercher des activités, veuillez au préalable spécifier une zone géographique de recherche.')}}
function addLocalisationFromSavedCriteres(id,libelle,extend)
{var ul_parent=document.getElementById('geo_selection');document.getElementById('no_geo_selected').style.display='none';ul_parent.style.display='block';document.getElementById('div_extend').style.display='block';var elem=document.createElement('li');var txt=document.createTextNode('');elem.appendChild(txt);elem.id=id;var type=id.substr(0,4);if(type=='vill')
{nb_ville_selected++;document.getElementById('fields_extend').style.display='block';elem.className='localisation_ville';}
if(type=='dept')
elem.className='localisation_dept';if(type=='regi')
elem.className='localisation_region';if(extend)
elem.title=extend;ul_parent.appendChild(elem);if(type=='vill')
{var content='<div style="width:200px"><a href="javascript:removeLocalisation(\''+id+'\');"><img src="images/supprimer.jpg"/></a>'+libelle+'</div>';content+='<div style="display:inline;float:right;margin-top:-18px;"><input type="checkbox" style="vertical-align:middle;" name="extend_'+id+'" id="extend_'+id+'" value="1" onclick="checkExtend(this);" ';if(extend>0)
{content+='checked="checked"';document.getElementById('extend_km').disabled="";for(var i=0;i<document.getElementById('extend_km').options.length;i++)
{if(document.getElementById('extend_km').options[i].value==extend)
{document.getElementById('extend_km').selectedIndex=i;break;}}}
content+='/></div>';elem.innerHTML=content;}
else
elem.innerHTML='<a href="javascript:removeLocalisation(\''+id+'\');"><img src="images/supprimer.jpg"/></a>'+libelle;}
function addLocalisation()
{if(current_localisation['id']&&current_localisation['id']!='')
{var extend='';var extend_libelle='';var ul_parent=document.getElementById('geo_selection');var childs=ul_parent.childNodes;for(var i=0;i<childs.length;i++)
{if(current_localisation['id']==childs[i].id)
{removeLocalisation(current_localisation['id']);break;}}
document.getElementById('no_geo_selected').style.display='none';ul_parent.style.display='block';document.getElementById('div_extend').style.display='block';var elem=document.createElement('li');var txt=document.createTextNode('');elem.appendChild(txt);elem.id=current_localisation['id'];var type=current_localisation['id'].substr(0,4);if(type=='vill')
{nb_ville_selected++;document.getElementById('fields_extend').style.display='block';elem.className='localisation_ville';}
if(type=='dept')
elem.className='localisation_dept';if(type=='regi')
elem.className='localisation_region';elem.title=extend;if(childs.length>0)
ul_parent.insertBefore(elem,childs[0])
else
ul_parent.appendChild(elem);if(type=='vill')
{var content='<div style="width:200px"><a href="javascript:removeLocalisation(\''+current_localisation['id']+'\');"><img src="images/supprimer.jpg"/></a>'+current_localisation['libelle']+'</div>';content+='<div style="display:inline;float:right;margin-top:-18px;"><input type="checkbox" style="vertical-align:middle;" name="extend_'+current_localisation['id']+'" id="extend_'+current_localisation['id']+'" value="1" onclick="checkExtend(this);"/></div>';elem.innerHTML=content;}
else
elem.innerHTML='<a href="javascript:removeLocalisation(\''+current_localisation['id']+'\');"><img src="images/supprimer.jpg"/></a>'+current_localisation['libelle']+extend_libelle;trackEvent('HomePage','AddLocalisation');trackEvent('SearchedLocalisation',current_localisation['libelle']);current_localisation=new Array();document.getElementById('localisation').value='';flash('bloc_droit_destinations');}
else
{alert('Tapez le début d\'un nom de ville, de département ou de région, sélectionnez l\'élément souhaité dans la liste affichée, puis cliquez sur le bouton "Ajouter".');}}
function addDept(id)
{full_id='dept_'+id;var ul_parent=document.getElementById('geo_selection');var childs=ul_parent.childNodes;for(var i=0;i<childs.length;i++)
{if(full_id==childs[i].id)
{removeLocalisation(full_id);break;}}
document.getElementById('no_geo_selected').style.display='none';ul_parent.style.display='block';document.getElementById('div_extend').style.display='block';var elem=document.createElement('li');var txt=document.createTextNode('');elem.className='localisation_dept';elem.appendChild(txt);elem.id=full_id;var childs=ul_parent.childNodes;if(childs.length>0)
ul_parent.insertBefore(elem,childs[0])
else
ul_parent.appendChild(elem);elem.innerHTML='<a href="javascript:removeLocalisation(\''+full_id+'\');"><img src="images/supprimer.jpg"/></a>'+document.getElementById('map_dpt_'+id).title;flash('bloc_droit_destinations');trackEvent('HomePage','AddDepartement');trackEvent('SearchedDepartement',document.getElementById('map_dpt_'+id).title);}
function debug(elem)
{var ul_parent=document.getElementById(elem);var nb_childs=ul_parent.childNodes;var chaine='';for(var i=1;i<nb_childs.length;i++)
{chaine+=(i+' : '+nb_childs[i].id+'\n');}
alert(chaine);}
function removeLocalisation(id)
{var ul_parent=document.getElementById('geo_selection');var list_childs=ul_parent.childNodes;for(var i=0;i<list_childs.length;i++)
{if(list_childs[i].id==id)
{if(list_childs[i].id.substr(0,4)=='vill')
{nb_ville_selected--;if(nb_ville_selected==0)
{document.getElementById('fields_extend').style.display='none';document.getElementById('extend_km').disabled="disabled";}}
ul_parent.removeChild(list_childs[i]);}}
trackEvent('HomePage','RemoveDestination');var nb_childs=ul_parent.childNodes;if(nb_childs.length==0)
{document.getElementById('geo_selection').style.display='none';document.getElementById('div_extend').style.display='none';document.getElementById('fields_extend').style.display='none';document.getElementById('no_geo_selected').style.display='block';}}
function setCurrentLocalisation(dest_field,li_selected)
{current_localisation['id']=li_selected.id;current_localisation['libelle']=document.getElementById('localisation').value;addLocalisation();}
function checkExtend(objet)
{if(objet.checked)
{document.getElementById('extend_km').disabled="";var extendsList=document.getElementById('geo_selection').getElementsByTagName('input');for(var i=0;i<extendsList.length;i++)
{if(extendsList[i].id!=objet.id)
extendsList[i].checked=false;}
trackEvent('HomePage','SetKmExtension');}
else
document.getElementById('extend_km').disabled="disabled";}
function purgeDests()
{var ul_parent=document.getElementById('geo_selection');var list_childs=ul_parent.childNodes;for(var i=list_childs.length-1;i>=0;i--)
ul_parent.removeChild(list_childs[i]);trackEvent('HomePage','PurgeDestinations');document.getElementById('geo_selection').style.display='none';document.getElementById('no_geo_selected').style.display='block';document.getElementById('div_extend').style.display='none';document.getElementById('fields_extend').style.display='none';document.getElementById('extend_km').disabled="disabled";}
function showLevel1Detail(level1)
{document.getElementById('no_souscat_displayed').style.display='none';if(current_level2!='')
{current_cat_lv2=document.getElementById('cat_lv2_'+current_level2);if(current_cat_lv2)
current_cat_lv2.className=class_sous_cat_hidden;}
if(current_level1!='')
{current_cat_lv1=document.getElementById('cat_lv1_'+current_level1);if(current_cat_lv1)
current_cat_lv1.className=class_sous_cat_hidden;}
document.getElementById('cat_lv1_'+level1).className=class_sous_cat_displayed;current_level1=level1;}
function showLevel2Detail(level2)
{if(current_level2.value!='')
{current_cat_lv2=document.getElementById('cat_lv2_'+current_level2);if(current_cat_lv2)
current_cat_lv2.className=class_sous_cat_hidden;}
document.getElementById('cat_lv2_'+level2).className=class_sous_cat_displayed;current_level2=level2;}
function changeCheckCat(level1,level2,level3,checked)
{if(!checked)
{if(level3)
{document.getElementById('check_lv3_'+level1+'_'+level3).checked=false;document.getElementById('lb_check_all_'+level1+'_'+level2).innerHTML='Tout cocher';}
else
document.getElementById('check_lv2_'+level2).checked=false;if(level3)
deleteSelection(level3);else
deleteSelection(level2);}
else
{if(level3)
{var liste_elems=document.getElementById('cat_lv2_'+level1+'_'+level2).getElementsByTagName('input');var allCheck=true;for(var j=0;j<liste_elems.length;j++)
{if(!liste_elems[j].checked)
{allCheck=false;break;}}
if(allCheck)
document.getElementById('lb_check_all_'+level1+'_'+level2).innerHTML='Tout décocher';}
addSelection(level1,level2,level3);}}
function addSelection(level1,level2,level3)
{document.getElementById('no_cat_selected').style.display='none';document.getElementById('cats_selection').style.display='block';var ul_parent=document.getElementById('cats_selection');var libelle='';if(level3)
libelle=document.getElementById('check_lv3_'+level1+'_'+level3).title
else
libelle=document.getElementById('check_lv2_'+level2).title
var elem=document.createElement('li');var txt=document.createTextNode('');elem.appendChild(txt);if(level3)
elem.id='selection_'+level3;else
elem.id='selection_'+level2;elem.className='categorie_'+level1;var childs=ul_parent.childNodes;if(childs.length>0)
ul_parent.insertBefore(elem,childs[0])
else
ul_parent.appendChild(elem);if(level3)
elem.innerHTML='<a href="javascript:changeCheckCat(\''+level1+'\',\''+level2+'\',\''+level3+'\', false);"><img src="images/supprimer.jpg"/></a>'+libelle;else
elem.innerHTML='<a href="javascript:changeCheckCat(\''+level1+'\',\''+level2+'\','+level3+', false);"><img src="images/supprimer.jpg"/></a>'+libelle;trackEvent('HomePage','addCategorie_'+level1);trackEvent('SearchedCategories',libelle);}
function deleteSelection(level_id)
{var ul_parent=document.getElementById('cats_selection');var li_selected=document.getElementById('selection_'+level_id);if(li_selected)
{ul_parent.removeChild(li_selected);li_selected=null;}
trackEvent('HomePage','removeCategorie');var nb_childs=ul_parent.childNodes;if(nb_childs.length==0)
{document.getElementById('cats_selection').style.display='none';document.getElementById('no_cat_selected').style.display='block';}}
function purgeCats()
{var checksList=document.getElementById('bloc_categories').getElementsByTagName('input');for(var i=checksList.length-1;i>=0;i--)
{checksList[i].checked=false;checksList[i].onclick();}
var ul_parent=document.getElementById('cats_selection');var list_childs=ul_parent.childNodes;for(var i=list_childs.length-1;i>=0;i--)
ul_parent.removeChild(list_childs[i]);trackEvent('HomePage','PurgeCategories');document.getElementById('cats_selection').style.display='none';document.getElementById('no_cat_selected').style.display='block';}
function checkAllLevel2childs(level1,level2)
{var liste_checkboxes=document.getElementById('cat_lv2_'+level1+'_'+level2).getElementsByTagName('input');var allCheck=true;for(i=0;i<liste_checkboxes.length;i++)
{if(!liste_checkboxes[i].checked)
{allCheck=false;break;}}
if(allCheck)
{for(var i=0;i<liste_checkboxes.length;i++)
{liste_checkboxes[i].checked=false;var check_level3_name=liste_checkboxes[i].id;var reg=new RegExp("_","gi");var tab_name=check_level3_name.split(reg);changeCheckCat(level1,level2,tab_name[3],false);}
document.getElementById('lb_check_all_'+level1+'_'+level2).innerHTML='Tout cocher';}
else
{for(var i=0;i<liste_checkboxes.length;i++)
{if(!liste_checkboxes[i].checked)
{liste_checkboxes[i].checked=true;var check_level3_name=liste_checkboxes[i].id;var reg=new RegExp("_","gi");var tab_name=check_level3_name.split(reg);changeCheckCat(level1,level2,tab_name[3],true);}}
document.getElementById('lb_check_all_'+level1+'_'+level2).innerHTML='Tout décocher';}}
function goStep3()
{if(parcours_length>0)
goToPage('controler.php','step3-step3');else
messageBox('Veuillez ajouter des activités à votre parcours touristique avant d\'accéder <br/>à l\'étape 3 : la visualisation de votre parcours sur une carte !');}
function goStep4()
{if(parcours_length>0)
goToPage('controler.php','step4-step4');else
messageBox('Votre parcours ne comporte aucune activité !');}
