  /* Permet d'afficher les messages d'erreur */
  var ShowError = function(id,conteneur,page)
  {
    var error = {"Departure":"Veuillez saisir un lieu de d\351part.<br />",
    			 "DeparturePrecis":"Veuillez choisir un point de d\351part dans la liste.<br />",
	           	 "Destination":"Veuillez saisir un lieu de destination.<br />",
	           	 "DestinationPrecis":"Veuillez choisir un point de destination dans la liste.<br />",
	           	 "DepartureCityName":"Veuillez saisir une commune de d\351part.<br />",
	           	 "DestinationCityName":"Veuillez saisir une commune de destination.<br />",
	           	 "Heure":"Veuillez choisir une heure d'arriv\351e post\351rieure \340 l'heure actuelle.<br />",
	           	 "Date":"Veuillez choisir une date valide et post\351rieure \340 la date actuelle.<br />",
	           	 "Mode":"Vous devez s\351lectionner au moins un mode de transport.<br />"};

    if($('#'+conteneur+'_container').hasClass('hide'))
      $('#'+conteneur+'_container').removeClass('hide');

    $('#'+conteneur).empty();

    //$('#DepartureLibelle').css("color","#0B69AF").css("border-color","");
    //$('#DestinationLibelle').css("color","#0B69AF").css("border-color","");

    $('#DepartureCityName').css("color","#0B69AF").css("border-color","");
    $('#DestinationCityName').css("color","#0B69AF").css("border-color","");

    //$('#edtDeparture').css("color","#0B69AF").css("border-color","");
    //$('#edtDestination').css("color","#0B69AF").css("border-color","");

    $('#hour').css("color","#0B69AF").css("border-color","");
    $('#minute').css("color","#0B69AF").css("border-color","");
    $('#sens').css("color","#0B69AF").css("border-color","");

    $('#dateYearMonth').css("color","#0B69AF").css("border-color","");
    $('#dateDay').css("color","#0B69AF").css("border-color","");

    $(".Mode:not(:checked)[name='Mode[]']").each(function(){
      $(this).parent().css("color","").css("border-color","");
    });

    $(".Mode:checked[name='Mode[]']").each(function(){
      $(this).parent().css("color","#0B69AF").css("border-color","");
    });

    for(var i=0;i<id.length;i++)
    {
      /*if(page=='viewprecision')
      {
		  if(id[i]=='DeparturePrecis' || id[i]=='DepartureCityName')
		  {
		  	$('#'+conteneur+'_dep').empty().append('<h4><strong>'+error[id[i]]+'</strong></h4>');
		  }
		  else if(id[i]=='DestinationPrecis' || id[i]=='DestinationCityName')
		  {
			$('#'+conteneur+'_dest').empty().append('<h4><strong>'+error[id[i]]+'</strong></h4>');
		  }
	  }
	  else $('#'+conteneur).append('<li>'+error[id[i]]+'</li>');*/

	  $('#'+conteneur).append('<li>'+error[id[i]]+'</li>');

      if(id[i]=='Departure')
      {
        if(page=='viewroute')
        {
          $('#DepartureLibelle').css("color","red").css("border-color","red");
        }
        else if(page=='viewprecision')
        {
          $('#edtDeparture').css("color","red").css("border-color","red");
        }
      }

	  if(id[i]=='DepartureCityName')
      {
        $('#DepartureCityName').css("color","red").css("border-color","red");
      }

      if(id[i]=='Destination')
      {
        if(page=='viewroute')
        {
          $('#DestinationLibelle').css("color","red").css("border-color","red");
        }
        else if(page=='viewprecision')
        {
          $('#edtDestination').css("color","red").css("border-color","red");
        }
      }

      if(id[i]=='DestinationCityName')
      {
        $('#DestinationCityName').css("color","red").css("border-color","red");
      }

      if(id[i]=='Heure')
      {
        $('#hour').css("color","red").css("border-color","red");
        $('#minute').css("color","red").css("border-color","red");
        $('#sens').css("color","red").css("border-color","red");
      }

      if(id[i]=='Date')
      {
        $('#dateYearMonth').css("color","red").css("border-color","red");
        $('#dateDay').css("color","red").css("border-color","red");
      }

      if(id[i]=='Mode')
      {
        $(".Mode:checkbox[name='Mode[]']").each(function(){
          $(this).parent().css("color","red").css("border-color","red");
        });
      }
    }
  };

  /* viewRoute : Verifie si le formulaire est bien valide */
  var Validate = function()
  {

    var testD = false;
    var testA = false;
    var testH = false;
    var testDate = false;
    var testMode = false;
	var ls_searchForm = document.getElementById("search-form");

	if (ls_searchForm!= null ) ls_searchForm.style.visibility="hidden";


    if($('#DepartureCityName').attr('rel')=="0" || $('#DepartureCityName').val().trim()=="")
    {
      testD = true;
    }
    else
    {
      testD = false;
    }
    if($('#DestinationCityName').attr('rel')=="0" || $('#DestinationCityName').val().trim()=="")
    {
      testA = true;
    }
    else
    {
      testA = false;
    }

    if(isToday())
    {
	    if(checkHour())
	    {
	      testH = true;
	    }
	}

    if(checkDate(endDay,endMonth,endYear))
    {
      testDate = true;
    }

    if(checkMode())
    {
      testMode = true;
    }

    if(testD || testA || testH || testDate || testMode)
    {
      var arrayError = new Array();

      if(testD)
        arrayError.push('DepartureCityName');
      if(testA)
        arrayError.push('DestinationCityName');
      if(testH)
        arrayError.push('Heure');
      if(testDate)
        arrayError.push('Date');
      if(testMode)
        arrayError.push('Mode');

      ShowError(arrayError,'msg_error','viewroute');

	  if ( ls_searchForm != null ) ls_searchForm.style.visibility = "";

      return false;
    }
    else
    {
      if($('#DepartureLibelle').attr('rel')=="0")
        $('#DepartureLibelle').val("");
      else if($('#Departure').val()== '')
      {
        $('#Departure').val($('#DepartureLibelle').val());
      }

      if($('#DestinationLibelle').attr('rel')=="0")
        $('#DestinationLibelle').val("");
      else if($('#Destination').val()== '')
        $('#Destination').val($('#DestinationLibelle').val());

      if($('#DepartureCityName').attr('rel')=="0")
        $('#DepartureCityName').val("");

      if($('#DestinationCityName').attr('rel')=="0")
        $('#DestinationCityName').val("");

      if($('#wayPoint').attr('rel')=='0')
          $('#wayPoint').val("");

      if($('#wayPointCityName').attr('rel')=='0')
          $('#wayPointCityName').val("");

      LogoWaitRunning();

      return true;
    }
  };

  /* viewPrecision : Verifie si le formulaire est bien valide */
  var ValidatePrecision = function()
  {
    var testD = false;
    var testA = false;
    var testDS = false;
    var testAS = false;
    var testH = false;
    var testDate = false;
    var testMode = false;

    if($('#DepartureCityName').attr('rel')=="0")
    {
      testD = true;
    }
    else
    {
      testD = false;
    }

    if($('#DestinationCityName').attr('rel')=="0")
    {
      testA = true;
    }
    else
    {
      testA = false;
    }

	if(checkEntryPoint('edtDeparture') == true)
    {
      testDS = true;
    }
    else
    {
      testDS = false;
    }

	if(checkEntryPoint('edtDestination') == true)
    {
      testAS = true;
    }
    else
    {
      testAS = false;
    }

    if(checkHour())
    {
      testH = true;
    }

    if(checkDate(endDay,endMonth,endYear))
    {
      testDate = true;
    }

    if(checkMode())
    {
      testMode = true;
    }

    var arrayError = new Array();

    if(testD || testA || testDS || testAS)
    {
   	  if(testD)
        arrayError.push('DepartureCityName');
      if(testDS)
        arrayError.push('DeparturePrecis');
      if(testA)
        arrayError.push('DestinationCityName');
      if(testAS)
        arrayError.push('DestinationPrecis');
      if(testH)
        arrayError.push('Heure');
      if(testDate)
        arrayError.push('Date');
      if(testMode)
        arrayError.push('Mode');

      ShowError(arrayError,'msg_error','viewprecision');

      return false;
    }
    else
    {
      if($('#Departure').attr('rel')=="0")
        $('#Departure').val("");

      if($('#Destination').attr('rel')=="0")
        $('#Destination').val("");

      if($('#DepartureCityName').attr('rel')=="0")
        $('#DepartureCityName').val("");

      if($('#DestinationCityName').attr('rel')=="0")
        $('#DestinationCityName').val("");

	  LogoWaitRunning();

      return true;
    }
  };

  /* viewResultChoice : Verifie si le formulaire est bien valide */
  var ValidateResultChoice = function()
  {
    var testMode = false;

    if(checkMode())
      testMode = true;

    var arrayError = new Array();

    if(testMode)
    {
      arrayError.push('Mode');
      ShowError(arrayError,'msg_error','viewresultchoice');
      return false;
    }
    else
    {
      LogoWaitRunning();
      return true;
    }
  };

  /* Verifie la saisie d'un point d'arret */
  var checkEntryPoint = function(radioName)
  {
  	var radioList = $('input[name='+radioName+']');

  	if ($('#'+radioName).attr('type') == "hidden" && $('#'+radioName).val() != "")
  	{
  		return false;
  	}

  	if (radioList.length > 0)
  	{
		for (var i=0;i<radioList.length;i++)
		{
			if ( radioList[i].checked ) return false;
		}
		return true
	}
	else return false;
  };

  var isToday =  function()
  {
    var zero = '0';
    //on recupere la date de l'utilisateur
    var myDateDay = $('#dateDay').val();
    var myDateMonth = $('#dateYearMonth').val().slice(0,$('#dateYearMonth').val().length-5);
    var myDateYear = $('#dateYearMonth').val().slice(myDateMonth.length+1,$('#dateYearMonth').val().length);

	if(myDateMonth.toString().length == 1)
		myDateMonth = zero.concat(myDateMonth);

	if(myDateDay.toString().length == 1)
		myDateDay = zero.concat(myDateDay);

	if(endMonth.toString().length == 1)
		endMonth = zero.concat(endMonth);

	if(endDay.toString().length == 1)
		endDay = zero.concat(endDay);

    if(myDateDay != '' && myDateMonth !='' && myDateYear!='')
    {

      //verifie la validite de la date
      var m = myDateMonth - 1;
      var d = new Date(myDateYear,m,myDateDay);
 	  if (d.getFullYear() != myDateYear || d.getMonth() != m)
 	  	return true;

      //on recupere la date de actuelle
      var DateDeb = new Date();
      var beginDay = DateDeb.getDate(); beginDay = beginDay.toString();
      var beginMonth = DateDeb.getMonth()+1; beginMonth = beginMonth.toString();
      var beginYear = DateDeb.getFullYear(); beginYear = beginYear.toString();

	  if(beginMonth.toString().length == 1)
		beginMonth = zero.concat(beginMonth);

	  if(beginDay.toString().length == 1)
		beginDay = zero.concat(beginDay);

      //on concatene les chaines sous la forme annee,mois,jour
      var concatMyDate = myDateYear.concat(myDateMonth); concatMyDate = concatMyDate.concat(myDateDay.toString());
      var concatBeginDate = beginYear.concat(beginMonth); concatBeginDate = concatBeginDate.concat(beginDay.toString());

      //on cast en int
      var concatMyDate = parseInt(concatMyDate);
      var concatBeginDate = parseInt(concatBeginDate);

      //et on verifie que la date est comprise dans la date de production.
      if(concatMyDate == concatBeginDate)
      {
        return true;
      }
      else
      {
        return false;
      }
    }
    else
    {
      return false;
    }
  };

  /* Verifie la validite de la date */
  var checkDate = function(endDay,endMonth,endYear)
  {
  	var zero = '0';
    //on recupere en parametre la date de production

    //on recupere la date de l'utilisateur
    var myDateDay = $('#dateDay').val();
    var myDateMonth = $('#dateYearMonth').val().slice(0,$('#dateYearMonth').val().length-5);
    var myDateYear = $('#dateYearMonth').val().slice(myDateMonth.length+1,$('#dateYearMonth').val().length);

	if(myDateMonth.toString().length == 1)
		myDateMonth = zero.concat(myDateMonth);

	if(myDateDay.toString().length == 1)
		myDateDay = zero.concat(myDateDay);

	if(endMonth.toString().length == 1)
		endMonth = zero.concat(endMonth);

	if(endDay.toString().length == 1)
		endDay = zero.concat(endDay);

    if(myDateDay != '' && myDateMonth !='' && myDateYear!='')
    {

      //verifie la validite de la date
      var m = myDateMonth - 1;
      var d = new Date(myDateYear,m,myDateDay);
 	  if (d.getFullYear() != myDateYear || d.getMonth() != m)
 	  	return true;

      //on recupere la date de actuelle
      var DateDeb = new Date();
      var beginDay = DateDeb.getDate(); beginDay = beginDay.toString();
      var beginMonth = DateDeb.getMonth()+1; beginMonth = beginMonth.toString();
      var beginYear = DateDeb.getFullYear(); beginYear = beginYear.toString();

	  if(beginMonth.toString().length == 1)
		beginMonth = zero.concat(beginMonth);

	  if(beginDay.toString().length == 1)
		beginDay = zero.concat(beginDay);

      //on concatene les chaines sous la forme annee,mois,jour
      var concatMyDate = myDateYear.concat(myDateMonth); concatMyDate = concatMyDate.concat(myDateDay.toString());
      var concatBeginDate = beginYear.concat(beginMonth); concatBeginDate = concatBeginDate.concat(beginDay.toString());
      var concatEndDate = endYear.toString().concat(endMonth.toString());	concatEndDate = concatEndDate.concat(endDay.toString());

      //on cast en int
      var concatMyDate = parseInt(concatMyDate);
      var concatBeginDate = parseInt(concatBeginDate);
      var concatEndDate = parseInt(concatEndDate);

      //et on verifie que la date est comprise dans la date de production.
      if(concatMyDate >= concatBeginDate && concatMyDate <= concatEndDate)
      {
        return false;
      }
      else
      {
        return true;
      }
    }
    else
    {
      return true;
    }
  };

  /* Verifie la validite de l'heure */
  var checkHour = function()
  {
    var Hours = $('#hour').val();
    var Minutes = $('#minute').val();
    var sens = $('#sens').val();

    if(Hours!='' && Minutes!='')
    {

   	  var obj = $("#sens option:selected");
      var sensText = obj.text();

      if ((sens == 1) && (sensText.indexOf("Partir apr") != -1 ))
      {
          Minutes = parseInt(Minutes)+10;
          if (Minutes >= 60)
          {
	  	     Hours = parseInt(Hours) + 1 ;
             Minutes = parseInt(Minutes) - 60 ;
          }
      }

      var date = new Date();
      var myHours = date.getHours().toString();
      var myMinutes = date.getMinutes().toString();

      if(myHours.length == 1)
        myHours="0"+myHours;
      if(myMinutes.length == 1)
        myMinutes="0"+myMinutes;

	  Hours = Hours.toString();
	  Minutes = Minutes.toString();

	  if(Hours.length == 1)
        Hours="0"+Hours;
      if(Minutes.length == 1)
        Minutes="0"+Minutes;

      /*var concatMyHours = myHours.concat(myMinutes); concatMyHours = parseInt(concatMyHours);
      var concatHours = Hours.concat(Minutes); concatHours = parseInt(concatHours);

      if(concatMyHours <= concatHours)
      {
        return false;
      }
      else
      {
        return true;
      }*/
    }
    else
    {
      return true;
    }
  };

  var checkMode = function()
  {
    if ($(".Mode:checked[name='Mode[]']").length == 0)
      return true;
    else
      return false;
  }

  /* Vide un input ou selectionne son contenu selon l'attribut rel */
  var ViderInput = function()
  {
    if($(this).attr('rel')=="0")
    {
      $(this).attr('rel',$(this).val());
      $(this).val("");
    }
    else
    {
      $(this).select();
    }
  };

  /* Verifie le contenu d'un input et stocke ou non son contenu dans l'attribut rel */
  var VerifInput = function()
  {
    if($(this).val()=="")
    {
      $(this).val($(this).attr('rel'));
      $(this).attr('rel','0');
    }
  };

  /* Affiche/Masque le champ etape */
  var ShowWayPoint = function()
  {
    $('#etape-area').slideToggle('slow');
    if($('#addwaypoint').hasClass('hide'))
    {
      $('#addwaypoint').removeClass('hide');
      $('#removewaypoint').addClass('hide');
    }
    else if($('#removewaypoint').hasClass('hide'))
    {
      $('#addwaypoint').addClass('hide');
      $('#removewaypoint').removeClass('hide');
    }
  };

  var ShowHideModifyStopArea = function()
  {
    $('.formHidden').show('slow');

    return false;
  };

  function ShowHideById(anchorId)
  {
    if(document.getElementById(anchorId).style.visibility == "visible")
    {
      document.getElementById(anchorId).style.visibility = "hidden";
    }else
    {
      document.getElementById(anchorId).style.visibility = "visible";
    }
  };

  /* Affiche/masque la carte de recherche d'itineraire (viewroute) */
  function selectForm()
  {
    if($('#itinerary_form') && $('#map_form'))
    {
      if($('#map_form').css('display')=='none')
      {
        //$('#itinerary_form').hide("normal");
        $('#map_form').show("normal");
        $('#map_form').css("width","800px").css("height","500px");
        map.ResizeMap();
        map.MapCenter(mapCenterX,mapCenterY,mapCenterZ);
      }/*
      else
      {
        //$('#itinerary_form').show("normal");
        $('#map_form').hide("normal");
      }*/
    }
  };

  /* (de)selectionne tous les checkbox a partir de leur nom */
  function selectAll(name,bool)
  {
    $(".Mode:checkbox[name='"+name+"']").each(function(){
      if(bool)
        $(this).attr("checked","checked");
      else
        $(this).removeAttr("checked");
    });
  };

  /* ######### vueHoraire ########### */

	var ValidateHoraire = function(libId,libCityId,alertMsg)
	{
		var lib = $("#" + libId).val();
	  	var libCity = $("#" + libCityId).val();

	  	if (lib == '' && libCity == '')
	  	{
	  		if (alertMsg != '') alert(alertMsg);
	  		return false;
		}
		else
		{
			LogoWaitRunning();
			return true;
		}
	};

	//fonction trim
	String.prototype.trim = function()
  	{
    	return this.replace(/(?:^\s+|\s+$)/g, "");
  	};


  	function LogoWaitRunning() {
  	   //gestion ie6
  	   if ($.browser.msie && $.browser.version.substr(0,1)<7) {
  	   }
  	   else
  	   {
  	   $('#lightbox-overlay').css('left','0px');
	   $('#lightbox-overlay').css('height','100%');
	   $('#lightbox-overlay').css('width','100%');
	   $('#lightbox-overlay').css('position','fixed');
	   $('#lightbox-overlay').css('z-index','90');
	   $('#lightbox-overlay').css('opacity','0')
	   $('#lightbox-overlay').css('background-color','black')
	   $('#lightbox-overlay').animate({opacity: "0.7"}, 1500);
	   $("#PnlRunning").css('display','inline');
	   window.setTimeout('LogoWaitRunningImage()', 250);
	   }
	   return false;
	 };

	function LogoWaitRunningImage()
	{
	   	var image = document.getElementById("PnlImage");
		image.src=image.src;
	};


