    /**********************GOOGLE MAP JAVASCRIPT************************/

var deptnum=new Array; 
deptnum[""] = 0; deptnum["Ain"] = 01; deptnum["Aisne"] = 02;
deptnum["Allier"] = 03; deptnum["Alpes-de-Haute-Provence"] = 04; deptnum["Hautes-Alpes"] = 05;
deptnum["Alpes-Maritimes"] = 06; deptnum["Ardèche"] = 07; deptnum["Ardennes"] = 08;
deptnum["Ariège"] = 09; deptnum["Aube"] = 10; deptnum["Aude"] = 11;
deptnum["Aveyron"] = 12; deptnum["Bouches-du-Rhône"] = 13; deptnum["Calvados"] = 14;
deptnum["Cantal"] = 15; deptnum["Charente"] = 16; deptnum["Charente Maritime"] = 17;
deptnum["Cher"] = 18; deptnum["Correze"] = 19; deptnum["Corse-du-Sud"] = "2A";
deptnum["Haute-Corse"] = "2B"; deptnum["Côte-d'Or"] = 21; deptnum["Côtes-d'Armor"] = 22;
deptnum["Creuse"] = 23; deptnum["Dordogne"] = 24; deptnum["Doubs"] = 25; 
deptnum["Drôme"] = 26; deptnum["Eure"] = 27; deptnum["Eure-et-Loir"] = 28;
deptnum["Finistère"] = 29; deptnum["Gard"] = 30; deptnum["Haute-Garonne"] = 31;
deptnum["Gers"] = 32; deptnum["Gironde"] = 33; deptnum["Hérault"] = 34;
deptnum["Ille-et-Vilaine"] = 35; deptnum["Indre"] = 36; deptnum["Indre-et-Loire"] = 37;
deptnum["Isère"] = 38; deptnum["Jura"] = 39; deptnum["Landes"] = 40;
deptnum["Loir-et-Cher"] = 41; deptnum["Loire"] = 42; deptnum["Haute-Loire"] = 43;
deptnum["Loire-Atlantique"] = 44; deptnum["Loiret"] = 45; deptnum["Lot"] = 46;
deptnum["Lot-et-Garonne"] = 47; deptnum["Lozère"] = 48; deptnum["Maine-et-Loire"] = 49; 
deptnum["Manche"] = 50; deptnum["Marne"] = 51; deptnum["Haute Marne"] = 52;
deptnum["Mayenne"] = 53; deptnum["Meurthe-et-Moselle"] = 54; deptnum["Meuse"] = 55;
deptnum["Morbihan"] = 56; deptnum["Moselle"] = 57; deptnum["Nièvre"] = 58;
deptnum["Nord"] = 59; deptnum["Oise"] = 60; deptnum["Orne"] = 61;
deptnum["Pas-de-Calais"] = 62; deptnum["Puy-de-Dôme"] = 63; deptnum["Pyrénées-Atlantiques"] = 64;
deptnum["Hautes-Pyrénées"] = 65; deptnum["Pyrénées-Orientales"] = 66; deptnum["Bas-Rhin"] = 67;
deptnum["Haut-Rhin"] = 68; deptnum["Rhône"] = 69; deptnum["Haute-Saône"] = 70;
deptnum["Saône-et-Loire"] = 71; deptnum["Sarthe"] = 72; deptnum["Savoie"] = 73;
deptnum["Haute-Savoie"] = 74; deptnum["Paris"] = 75; deptnum["Seine-Maritime"] = 76;
deptnum["Seine-et-Marne"] = 77; deptnum["Yvelines"] = 78; deptnum["Deux-Sèvres"] = 79;
deptnum["Somme"] = 80; deptnum["Tarn"] = 81; deptnum["Tarn-et-Garonne"] = 82;
deptnum["Var"] = 83; deptnum["Vaucluse"] = 84; deptnum["Vendée"] = 85;
deptnum["Vienne"] = 86; deptnum["Haute-Vienne"] = 87; deptnum["Vosges"] = 88;
deptnum["Yonne"] = 89; deptnum["Territoire de Belfort"] = 90; deptnum["Essonne"] = 91;
deptnum["Hauts-de-Seine"] = 92; deptnum["Seine-Saint-Denis"] = 93; deptnum["Val-de-Marne"] = 94; deptnum["Val-d'Oise"] = 95;


    var map = null;
    var geocoder = null;

    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(45.890, 1.933), 4);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();
        geocoder.setBaseCountryCode('fr');
  }
    }

    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) {
      map.clearOverlays();
      document.getElementById('v_country').innerHTML = ""; document.getElementById('vp_country').value = "";
      document.getElementById('v_dept').innerHTML = ""; document.getElementById('vp_dept').value = "";
      document.getElementById('v_street').value = "";
      document.getElementById('v_town').innerHTML = ""; document.getElementById('vp_town').value = "";


      if (!response || response.Status.code != 200) {
        alert("D&eacute;sol&eacute;, adresse non reconue");
      }
      else
      {
        place = response.Placemark[0];

        //Stockage Longitude & latitude pour la carte
        document.getElementById('vp_lat').value = place.Point.coordinates[1];
        document.getElementById('vp_lng').value = place.Point.coordinates[0];

        if (place.AddressDetails.Country)
        {
          var Country = place.AddressDetails.Country;
          // Remplissage pour affichage
          document.getElementById('v_country').innerHTML = Country.CountryNameCode;
          document.getElementById('vp_country').value = Country.CountryNameCode;

          if (Country.AdministrativeArea)
          {
            var administrativeArea = place.AddressDetails.Country.AdministrativeArea;

            if (administrativeArea.SubAdministrativeArea)
            {
              var subAdministrativeArea = administrativeArea.SubAdministrativeArea;
              // Remplissage pour affichage
              //document.getElementById('v_dept').selectedIndex = deptnum[subAdministrativeArea.SubAdministrativeAreaName];
              document.getElementById('v_dept').innerHTML = deptnum[subAdministrativeArea.SubAdministrativeAreaName] + " - " + subAdministrativeArea.SubAdministrativeAreaName;
              document.getElementById('vp_dept').value = deptnum[subAdministrativeArea.SubAdministrativeAreaName];

              if (subAdministrativeArea.Locality)
              {
                var locality = subAdministrativeArea.Locality;
                // Remplissage pour affichage
                //document.getElementById('v_town').value = locality.LocalityName;
                document.getElementById('v_town').innerHTML = locality.LocalityName;
                document.getElementById('vp_town').value = locality.LocalityName;

                //if (locality.PostalCode)
                //{
                  //Remplissage pour affichage
                //  document.getElementById('v_cp').value = locality.PostalCode.PostalCodeNumber;
				//}
                if (locality.DependentLocality)
                {
                  //html += '<br />';
                  //html += '<b> Lieu dit : </b>' + locality.DependentLocality.DependentLocalityName;
                }
                if (locality.Thoroughfare)
                {
                  // Remplissage pour affichage
                  document.getElementById('v_street').value = locality.Thoroughfare.ThoroughfareName;
                }

                var html = '<b> ' + document.getElementById('v_locname').value + ',<br>' + document.getElementById('v_street').value  + ',<br>' + document.getElementById('vp_town').value + ' (' + document.getElementById('vp_dept').value + ')' + '<br>' + document.getElementById('vp_country').value + '</b>';

                //Affichage sur la carte
                point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
                map.setCenter(point, 14);
                marker = new GMarker(point);
                map.addOverlay(marker);
                marker.openInfoWindowHtml(html);
              } else { alert("Precisez au moins la ville"); } //locality
            } else { alert("Le département n'a pu être trouvé"); }//subAdministrativeArea
          } else { alert("La région n'a pu être trouvée"); }//AdministrativeArea
        } else { alert("Le pays n'a pu être trouvé"); }//Country
      } //Response & statuscode
    } //Function

    function showAddressOnMap(lat, lng, locname, street, town, dept, country) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.clearOverlays();
        var html = '<b> ' + locname + ',<br>' + street  + ',<br>' + town + ' (' + dept + ')' + '<br>' + country + '</b>';

        //Affichage sur la carte
        point = new GLatLng(lat, lng);
        map.setCenter(point, 14);
        marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(html);
	  }
    } //Function

    function UpdateMap() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.clearOverlays();
//        var html = '<b> ' + document.getElementById('v_locname').value + ' </b><p>';
        var html = '<b> ' + document.getElementById('v_locname').value + ',<br>' + document.getElementById('v_street').value  + ',<br>' + document.getElementById('vp_town').value + ' (' + document.getElementById('vp_dept').value + ')' + '<br>' + document.getElementById('vp_country').value + '</b>';

        //Affichage sur la carte
        point = new GLatLng(document.getElementById('vp_lat').value, document.getElementById('vp_lng').value);
        map.setCenter(point, 14);
        marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(html);
	  }
    } //Function

    function updateLocation(address) {
      if (address != "") {
        //initialize();
        geocoder.getLocations(address, addAddressToMap);
        //showAddress(address);
        //xajax_gettowns(document.getElementById('locateaddress').value);
      }
	  else
	  {
        alert("Veuillez entrer une adresse ! \nExemple : 5 rue des artistes Musiqueville");
	  }
    }

    function selectLocation(listid) {
      if (document.getElementById('addrlist').value != "") {
        xajax_selectlocation(document.getElementById('addrlist').value);

        setTimeout("UpdateMap();",2000);
      }
	  else
	  {
        alert("Veuillez entrer une adresse ! \nExemple : 5 rue des artistes Musiqueville");
	  }
    }

/**********************COMMON JAVASCRIPT************************/

/* Limits content char input to charlimit characters */
function CharLimiter(curField, charleftField, charlimit, okclass, errorclass) {
  var maxCharCount = charlimit;
  var charCount = curField.value.length;
  if (charCount >= charlimit) {
    if (errorclass != "") {
     curField.className = errorclass;
    }
  }
  else if (okclass != "") {
    curField.className = okclass;
  }
  var charleftContent = document.getElementById(charleftField);
  var charleftHtml = charleftContent.innerHTML;
  charleftHtml = charleftHtml.replace(/(\d+)\/(\d+)/, "$2");
  charleftHtml = charleftHtml.replace(/(\d+)/,(((charCount > maxCharCount ) ? maxCharCount : charCount)));
  charleftContent.innerHTML = charleftHtml;
}

/* Checks the coherency of the date in the input form */
function CheckRepeat(val)
{
  var len = document.agenda_item_form.elements.length;
  var i = 0;
  for (i = 0; i < len; i++)
  {
    if (document.agenda_item_form.elements[i].name == 'datetype')
    {
      if (document.agenda_item_form.elements[i].value == '1')
        document.agenda_item_form.elements[i].checked = (val == 1);
      if (document.agenda_item_form.elements[i].value == '2')
        document.agenda_item_form.elements[i].checked = (val == 2);
    }
  }
}

/* Checks the completeness of the input form */
function submitAgendaForm(f) {
	if (f.type.value == '') {
		alert("Vous n'avez pas indiqué le type d'événement !");
		f.type.focus();
		return false;
	}
	if (f.evtstyle.value == '') {
		alert("Vous n'avez pas indiqué le style d'événement !");
		f.evtstyle.focus();
		return false;
	}
	if (f.attractivity.value == '') {
		alert("Vous n'avez pas indiqué l'attractivité; de l'événement !");
		f.attractivity.focus();
		return false;
	}
	else if (f.title.value == '') {
		alert("Vous n'avez pas indiqué de titre pour l'événement !");
		f.title.focus();
		return false;
	}
	else if (f.content.value == '') {
		alert("La description de l'événement est vide !");
		f.content.focus();
		return false;
	}
	//else if ((f.vp_town.value == '') || (f.vp_dept.value == '') /*|| (f.vp_country.value == '')*/) {
	else if (f.v_locname.value == '') {
		alert("Veuillez préciser le nom du lieu de l'événement !");
		f.v_locname.focus();
		return false;
	}
	else if (f.datelist.value == '') {
		alert("Aucune date n'est associée à votre événement !");
		f.datestartday.focus();
		return false;
	}
	else {
		f.submit();
	}
}

/**********************FACEBOOK JAVASCRIPT********************************/
function fbs_click_url()
{
  u=location.href;
  t=document.title;
  window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}

function fbs_click_set(u)
{
  t=document.title;
  window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}

/**********************DATES GENERATION JAVASCRIPT************************/
function getdates()
{
  xajax_getdates(xajax.getFormValues("agenda_item_form" , 1, "date"));

/*Radio buttons management (for memory)*/
  /*var len = document.agenda_item_form.elements.length;
  var i = 0;
  for (i = 0; i < len; i++)
  {
    if ((document.agenda_item_form.elements[i].name == 'datetype') && (document.agenda_item_form.elements[i].checked == true))
    {
      if (document.agenda_item_form.elements[i].value == '0')
        xajax_getdates_single(xajax.getFormValues("agenda_item_form" , 1, "date"));
      if (document.agenda_item_form.elements[i].value == '1')
        xajax_getdates_interval(xajax.getFormValues("agenda_item_form" , 1, "date"));
      if (document.agenda_item_form.elements[i].value == '2')
        xajax_getdates_daybased(xajax.getFormValues("agenda_item_form" , 1, "date"));
    }
  }*/
}

function remdate(datetorem)
{
  document.getElementById('daterem').value = datetorem;
  xajax_remdate(xajax.getFormValues("agenda_item_form" , 1, "date"));
}

function ToggleDate(entrynum)
{
/*  var len = document.agenda_item_form.elements.length;
  var i = 0;
  for (i = 0; i < len; i++)
  {
    if ((document.agenda_item_form.elements[i].name == 'remdate['+ entrynum +']'))
    {
document.getElementById('linktext['+ entrynum +']').innerHTML = "Ajouter"
if (document.agenda_item_form.elements[i].value == '0')
        xajax_getdates_single(xajax.getFormValues("agenda_item_form" , 1, "date"));
      if (document.agenda_item_form.elements[i].value == '1')
        xajax_getdates_interval(xajax.getFormValues("agenda_item_form" , 1, "date"));
      if (document.agenda_item_form.elements[i].value == '2')
        xajax_getdates_daybased(xajax.getFormValues("agenda_item_form" , 1, "date"));
    }
  }*/


  //if (document.getElementById('linktext['+ entrynum +']').innerHTML == "Retirer")
  if (document.getElementById('toggleimg['+ entrynum +']').className == "addrem_btn retirer")
  {
    //document.getElementById('linktext['+ entrynum +']').innerHTML = "Ajouter";
    document.getElementById('toggleimg['+ entrynum +']').className = "addrem_btn ajouter";
    document.getElementById('datetext['+ entrynum +']').style.color = "#BBBBBB";
  }
  //else if (document.getElementById('linktext['+ entrynum +']').innerHTML == "Ajouter")
  else if (document.getElementById('toggleimg['+ entrynum +']').className == "addrem_btn ajouter")
  {
    //document.getElementById('linktext['+ entrynum +']').innerHTML = "Retirer";
    document.getElementById('toggleimg['+ entrynum +']').className = "addrem_btn retirer";
    document.getElementById('datetext['+ entrynum +']').style.color = "#7C0B0B";
  }
}

/*Update input dates for agenda selection*/
function updatedateselection(writeid, inputdate, startdate, enddate)
{

  if (writeid == 'startcalendar')
  {
    document.getElementById('endcalendar').innerHTML = "";
    document.getElementById('startarrow').style.display = "inline";
    document.getElementById('endarrow').style.display = "none";
    xajax_writecalendar('startcalendar', inputdate, startdate, enddate);
    setTimeout("xajax_updatedateselection('startdate');",300); //Wait 300ms to allow writecalendar to update the SESSION variables before updating the date selection
    //setTimeout("document.getElementById('enddate').style.backgroundColor = \"#FFCC00\"; \
    //document.getElementById('startdate').style.backgroundColor = \"#EEEEEE\";", 1000);
  }
  if (writeid == 'endcalendar')
  {
    document.getElementById('startcalendar').innerHTML = "";
    document.getElementById('startarrow').style.display = "none";
    document.getElementById('endarrow').style.display = "inline";
    xajax_writecalendar('endcalendar', inputdate, startdate, enddate);
    setTimeout("xajax_updatedateselection('enddate');",300); //Wait 300ms to allow writecalendar to update the SESSION variables before updating the date selection
    //setTimeout("document.getElementById('startdate').style.backgroundColor = \"#FFCC00\"; \
    //document.getElementById('enddate').style.backgroundColor = \"#EEEEEE\";", 1000);
  }
}
