  /* Permet d'afficher les messages d'erreur */
  var ShowError = function(id,conteneur,page)
  {
  	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();
	var endValDay   = '';
	var endValMonth = '';
	var endValYear  = '';
	if(endDay !== undefined && endMonth !== undefined && endYear !== undefined)
	{
		endValDay   = endDay;
		endValMonth = endMonth;
		endValYear  = endYear;
	}
    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 d\'arriv\351e.<br />",
	           	 "Heure":"Veuillez choisir une heure d'arriv\351e post\351rieure \340 l'heure actuelle.<br />",
	           	 "Date":"Veuillez choisir une date valide entre le "+beginDay+"/"+beginMonth+"/"+beginYear+" et "+endValDay+"/"+endValMonth+"/"+endValYear+".<br />",
	           	 "Mode":"Vous devez s\351lectionner au moins un mode de transport.<br />"};

      var reg=document.URL.split('/');
      if ((page=='viewroute')&&((reg[reg.length-1].toLowerCase()=='destineo')||((reg[reg.length-1].toLowerCase()=='')&&(reg[reg.length-2].toLowerCase()=='destineo'))))
      {
    	    LogoWaitRunning();

      		if(!($('#'+conteneur+'_container').hasClass('hide')))
      			$('#'+conteneur+'_container').addClass('hide');
      		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("");
      		if (reg[reg.length-1].toLowerCase()=='')
      			var urltest = document.URL + "route/vuesearch?rappelDeparture=" + $('#DepartureCityName').val() + " -" + $('#DepartureLibelle').val() + "&rappelDestination=" + $('#DestinationCityName').val() + " -" + $('#DestinationLibelle').val() + "&dateDay=" + $('#dateDay').val() + "&selectedDate=" + $('#dateYearMonth').val() + "&hour=" + $('#hour').val() + "&minute=" + $('#minute').val() + "&sens=" + $('#sens').val() + "&Valid=1";
      		else
      			var urltest = document.URL + "/route/vuesearch?rappelDeparture=" + $('#DepartureCityName').val() + " -" + $('#DepartureLibelle').val() + "&rappelDestination=" + $('#DestinationCityName').val() + " -" + $('#DestinationLibelle').val() + "&dateDay=" + $('#dateDay').val() + "&selectedDate=" + $('#dateYearMonth').val() + "&hour=" + $('#hour').val() + "&minute=" + $('#minute').val() + "&sens=" + $('#sens').val() + "&Valid=1";
      		window.location=urltest;
      }
     else
     {
    	if($('#'+conteneur+'_container').hasClass('hide'))
      		$('#'+conteneur+'_container').removeClass('hide');

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

    	$('#DepartureCityName').css("color","#0B69AF").css("border-color","");
    	$('#DestinationCityName').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++)
    	{
	  		$('#'+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");
        		});
      		}
    	}
    	var ls_overlayDiv = document.getElementById("overlay");
    	if (ls_overlayDiv != null)
    	{
    		var visibleState = true;
    		if ($('#overlay').css("visibility")== 'hidden') visibleState = true ;
    		else visibleState = false;

    		$('#overlay').css("visibility",(visibleState ? "visible" : "hidden"));
    		$('#lightbox').css("visibility",(visibleState ? "visible" : "hidden"));
    	}
    }
  };

  /* viewRoute : Verifie si le formulaire est bien valide */
  var Validate = function()
  {
	var ls_overlayDiv = document.getElementById("overlay");
	var ls_hpSearch = document.getElementById("hp-search");
	var ls_lang = document.getElementById("lang");
	var ls_map = document.getElementById("hp-map");


	/*if(ls_hpSearch != null )
		$('#hp-search').attr('disabled', 'disabled');

	if(ls_lang != null )
	{
		$('#lang').attr('disabled', 'disabled');
		$('#lang').css("visibility","hidden");
	}

	if(ls_map != null )
	{
		$('#hp-map').attr('disabled', 'disabled');
		$('#hp-map').css("visibility","hidden");
	}

	if (ls_overlayDiv != null)
	{
		var visibleState = true;
		if ($('#overlay').css("visibility")== 'hidden')
		{
			visibleState = true ;
		}
		else
		{
			visibleState = false;
		}
		$('#overlay').css("visibility",(visibleState ? "visible" : "hidden"));
		$('#lightbox').css("visibility",(visibleState ? "visible" : "hidden"));
	}*/
	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())
	    {
	      //ticket Mantis client 2919
	      //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 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');
    }
  };

  var VerifInputBlur = function(e)
  {
    if($(this).val()=="")
    {
      $(this).val($(this).attr('rel'));
      $(this).attr('rel','0');
    }
    if(e.explicitOriginalTarget.nodeName=="#text")
    {
    	$(this).value=e.explicitOriginalTarget.nodeValue;
    }else if(e.explicitOriginalTarget.localName=="TD")
    {
    	$(this).value=e.explicitOriginalTarget.innerHTML;
    }else
    {
    	$('.mswfl').css('display','none');
    }
  };

  /* 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').toggleClass('show');
		return false;
	};

  var ShowHideModifyArrival = function()
	{
		$('#formArrivalHidden').toggleClass('show');
		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($('#map_form').css('display')=='none')
     {
       $('#map_form').show("normal");
       $('#map_form').css("width","800px").css("height","500px");
       map.ResizeMap();
       map.MapCenter(mapCenterX,mapCenterY,mapCenterZ);
     }
  };

  /* (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
  	   {
  		 var scrollX = 0;
  		 var scrollY = 0;
  		 // on récupère la position du scroll bar
         if (document.all)
         {
			if (!document.documentElement)
			      scrollX = document.body.scrollLeft;
			else
			      scrollX = document.documentElement.scrollLeft;
					               
			if (!document.documentElement)
			      scrollY = document.body.scrollTop;
			else
			      scrollY = document.documentElement.scrollTop;
		 }   
	     else
	     {
	                scrollX = window.pageXOffset;
	                scrollY = window.pageYOffset;
	      }
           scrollY=scrollY/2;
           // on récupère la taille de l'écran 
  		   var w;
		   var h;
		   var middleh = 0;
  		   if ($.browser.msie)
  		   {
  			   w = screen.width; 
	  		   h = screen.height;
	  		 middleh = h/2;
  		   }
  		   else
  		   {
	  		   w = screen.availWidth; 
	  		   h = screen.availHeight; 
	  		   middleh = h/2;
  		   }
  		   if(middleh != 0)
  			   $('#PnlRunning').css('top',middleh+scrollY);
  		   
	  	   $('#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;
	};