function ShowError(id,conteneur,page) {
	var colorRed		= '#B74831';
	
	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 (page != 'viewprecision' && typeof(this.endDay) != 'undefined' && typeof(this.endMonth) != 'undefined' && typeof(this.endYear) != 'undefined') {
		endValDay   = this.endDay;
		endValMonth = this.endMonth;
		endValYear  = this.endYear;
	}
		
	var error = initMessageError(beginDay,beginMonth,beginYear,endValDay,endValMonth,endValYear);

    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","#000000").css("border-color","");
    	$('#DestinationCityName').css("color","#000000").css("border-color","");
    	$('#wayPointCityName').css("color","#000000").css("border-color","");

			if(conteneur != 'msg_error3') {
				$('#hour').css("color","#000000").css("border-color","");
				$('#minute').css("color","#000000").css("border-color","");
				$('#sens').css("color","#000000").css("border-color","");
			}

    	$('#dateYearMonth').css("color","#000000").css("border-color","");
    	$('#dateDay').css("color","#000000").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","#000000").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]=='WayPointCityName') {
					$('#wayPointCityName').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') {
					if(conteneur == 'msg_error2') {
						$('#dateYearMonth2').css("color","red").css("border-color","red");
						$('#dateDay2').css("color","red").css("border-color","red");
					} else if(conteneur == 'msg_error3') {
						$('#dateYearMonth3').css("color","red").css("border-color","red");
						$('#dateDay3').css("color","red").css("border-color","red");
					} else {
						$('#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");

		var testD = false;
    var testA = false;
    var testV = 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($('#wayPointCityName').length > 0) {
	    if($('#wayPointActiv').attr('checked') == true && $('#wayPointCityName').attr('rel')=="0" || $('#wayPointCityName').val().trim()=="") {
	      testV = true;
	    } else {
	      testV = 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 || testV) {
      var arrayError = new Array();

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

      ShowError(arrayError,'msg_error','viewroute');
			window.location.href = '#msg_error_container';

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

      return false;

    } else {
      
      $('#DepartureLibelle').val(deleteCityValue($('#DepartureLibelle').val()));
      $('#DestinationLibelle').val(deleteCityValue($('#DestinationLibelle').val()));
      $('#wayPoint').val(deleteCityValue($('#wayPoint').val()));
    	
      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' || $('#wayPointActiv').attr('checked') == false)
          $('#wayPoint').val("");

      if($('#wayPointCityName').attr('rel')=='0' || $('#wayPointActiv').attr('checked') == false)
          $('#wayPointCityName').val("");

      LogoWaitRunning();

      return true;
    }
  };

  var ValidatePrecision_ = function(select)
  {
	  var arrayError = new Array();
	  if(ValidatePattern('Departure')) {
		  if(select) {
				arrayError.push('DeparturePrecis');
			} else {
				arrayError.push('DepartureCityLibelle');
			}
	  }
	  if(ValidatePattern('Destination')) {
		  if(select) {
				arrayError.push('DestinationPrecis');
			} else {
				arrayError.push('DestinationCityLibelle');
			}
	  }
	  if(ValidatePattern('WayPoint')) {
		  arrayError.push('WayPointPrecis');
	  }

	  if(arrayError.length != 0) {
		  ShowError(arrayError,'msg_error','viewprecision');
			window.location.href = '#msg_error_container';

	    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("");

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

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

		  LogoWaitRunning();
		  return true;
	  }
  };

  var ValidatePattern = function(pattern)
  {
	  var inputList = $('input[name=edt' + pattern + ']');
	  if($('input[name=edt' + pattern + ']').attr('type') == 'hidden') {
		  return false;
	  } else if($('#' + pattern + 'CityName').attr('rel') == "0") {
		  return true;
	  }else if(inputList.length != 0) {
		  for(var i = 0; i < inputList.length; i++) {
			  var id = inputList[i].id;
			  if($('#' + id).attr('checked') == true) {
				  return false;
			  }
		  }
		  return true;
	  }
	  return false;
  };

  /* 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;
    }
  };

	var ValidateHoraireHome = function() {
		$("#cityLibelle").css("border-color", "#9EA4A8 #D5D5D5 #D5D5D5 #9EA4A8");
		$("#cityLibelle").css("color", "#000000");

		if($("#cityLibelle").val() == $("#cityLibelle").attr("rel")) {
			$("#cityLibelle").attr("value", "");
		}

		if($('#cityLibelle').attr('rel') == "0" || $('#cityLibelle').val().trim()=="") {
			$("#horaire_error_container").removeClass("hide");
			$("#horaire_error_container").show();
			//$("#cityLibelle").attr("value", $("#cityLibelle").attr("rel"));

			var arrayError = new Array();

      arrayError.push('CityLibelle');

			ShowError(arrayError,'horaire_error','mtkHoraire');
			$("#cityLibelle").css("border-color", "red");
			$("#cityLibelle").css("color", "red");

			window.location.href = '#horaire_error_container';

			return false;

		} else {
			$("#horaire_error_container").addClass("hide");

			if($('#stopAreaLibelle').attr('rel') == "0" || $('#stopAreaLibelle').val().trim()=="") {
				$("#stopAreaLibelle").attr("value","");
			}

      $("#stopAreaLibelle").val(deleteCityValue($("#stopAreaLibelle").val()));
      
			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
	 * On recupere en parametre la date de production
	 */
  var checkDate = function(endDay,endMonth,endYear,number) {
		if(typeof(number) == 'undefined') {
			number = '';
		}

  	var zero = '0';

    //on recupere la date de l'utilisateur
    var myDateDay = $('#dateDay' + number).val();
    var myDateMonth = $('#dateYearMonth' + number).val().slice(0,$('#dateYearMonth' + number).val().length-5);
    var myDateYear = $('#dateYearMonth' + number).val().slice(myDateMonth.length+1,$('#dateYearMonth' + number).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) {
			if(e.explicitOriginalTarget.nodeName=="#text") {
				$(this).value=e.explicitOriginalTarget.nodeValue;
			} else if(e.explicitOriginalTarget.localName=="TD") {
				$(this).value=e.explicitOriginalTarget.innerHTML;
			}
		}
  };

  /* 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 ########### */

	/**
	 * Validation du formulaire de recherche d'horaires à un arrêt
	 */
	var ValidateHoraire = function(libCityId) {
	  var libCity = $("#" + libCityId).val();
		var arrayError = new Array();
		var testCity = true;
		var testDate = true;

		$("#" + libCityId).css("border-color", "#9EA4A8 #D5D5D5 #D5D5D5 #9EA4A8");
		$("#" + libCityId).css("color", "#000000");

		$("#msg_error_container").addClass("hide");

		if(libCity == '') {
			testCity = false;
		}

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

		if(!testCity || !testDate) {
			if(!testCity) {
				arrayError.push('CityLibelle');
				$("#" + libCityId).css("border-color", "red");
				$("#" + libCityId).css("color", "red");
			}
			if(!testDate) {
				arrayError.push('Date')
			}

			ShowError(arrayError, 'msg_error1', 'mtkHoraire');
			window.location.href = '#msg_error1_container';

			return false;

		} else {
      $('#stopAreaLibelle_1').val(deleteCityValue($('#stopAreaLibelle_1').val()));
    
			LogoWaitRunning();
			return true;
		}
	};

	/**
	 * Validation du formulaire de recherche d'horaires entre deux arrêts
	 */
	var ValidateHoraireTwoStops = function(departureCityId, destinationCityId) {
	  var departureCity = $("#" + departureCityId).val();
		var destinationCity = $("#" + destinationCityId).val();
		var arrayError = new Array();
		var testDepartureCity = true;
		var testDestinationCity = true;
		var testDate = true;

		$("#" + departureCityId).css("border-color", "#9EA4A8 #D5D5D5 #D5D5D5 #9EA4A8");
		$("#" + departureCityId).css("color", "#000000");
		$("#" + destinationCityId).css("border-color", "#9EA4A8 #D5D5D5 #D5D5D5 #9EA4A8");
		$("#" + destinationCityId).css("color", "#000000");

		$("#msg_error2_container").addClass("hide");

	  if(departureCity == '') {
			testDepartureCity = false;
		}

		if(destinationCity == '') {
			testDestinationCity = false;
		}

		if(checkDate(endDay,endMonth,endYear, '2')) {
      testDate = false;
    }

		if(!testDepartureCity || !testDestinationCity || !testDate) {
			if(!testDepartureCity) {
				arrayError.push('DepartureCityLibelle');
				$("#" + departureCityId).css("border-color", "red");
				$("#" + departureCityId).css("color", "red");
			}
			if(!testDestinationCity) {
				arrayError.push('DestinationCityLibelle')
				$("#" + destinationCityId).css("border-color", "red");
				$("#" + destinationCityId).css("color", "red");
			}
			if(!testDate) {
				arrayError.push('Date')
			}

			ShowError(arrayError, 'msg_error2', 'mtkHoraire');

			window.location.href = '#msg_error2_container';

	  	return false;
		} else {
      $('#stopAreaLibelle_2').val(deleteCityValue($('#stopAreaLibelle_2').val()));
      $('#arrivalLibelle').val(deleteCityValue($('#arrivalLibelle').val()));
    
			LogoWaitRunning();
			return true;
		}
	};

	/**
	 * Validation du formulaire de précision de recherche d'horaire entre deux arrêts
	 */
	var ValidateHoraireTwoStopsPrecision = function(departureCityId, destinationCityId) {
		var departureCity = $("#" + departureCityId).val();
		var destinationCity = $("#" + destinationCityId).val();
		var arrayError = new Array();
		var testDepartureCity = true;
		var testDestinationCity = true;

		$("#" + departureCityId).css("border-color", "#9EA4A8 #D5D5D5 #D5D5D5 #9EA4A8");
		$("#" + departureCityId).css("color", "#000000");
		$("#" + destinationCityId).css("border-color", "#9EA4A8 #D5D5D5 #D5D5D5 #9EA4A8");
		$("#" + destinationCityId).css("color", "#000000");

		$("#msg_error_container").addClass("hide");

	  if(departureCity == '') {
			testDepartureCity = false;
		}

		if(destinationCity == '') {
			testDestinationCity = false;
		}

		if(!testDepartureCity || !testDestinationCity) {
			if(!testDepartureCity) {
				arrayError.push('DepartureCityLibelle');
				$("#" + departureCityId).css("border-color", "red");
				$("#" + departureCityId).css("color", "red");
			}
			if(!testDestinationCity) {
				arrayError.push('DestinationCityLibelle')
				$("#" + destinationCityId).css("border-color", "red");
				$("#" + destinationCityId).css("color", "red");
			}

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

			window.location.href = '#msg_error_container';

	  	return false;
		} else {
			LogoWaitRunning();
			return true;
		}
	};

	/**
	 * Validation du formulaire de recherche d'horaire d'une ligne
	 */
	var ValidateHoraireLine = function(networkListId, lineListId, sensId) {
	  var networkValue = $("#" + networkListId).val();
		var lineValue = $("#" + lineListId).val();
		var sensValue = $("#" + sensId).val();
		var arrayError = new Array();
		var testNetwork = true;
		var testLine = true;
		var testSens = true;
		var testDate = true;

		$("#" + networkListId).css("border", "auto");
		$("#" + networkListId).css("color", "#000000");
		$("#" + lineListId).css("border", "auto");
		$("#" + lineListId).css("color", "#000000");
		$("#" + sensId).css("border", "auto");
		$("#" + sensId).css("color", "#000000");

		$("#msg_error3_container").addClass("hide");

		if(networkValue == '') {
			testNetwork = false;
		}
		if(lineValue == '') {
			testLine = false;
		}
		if(sensValue == '') {
			testSens = false;
		}
		if(checkDate(endDay,endMonth,endYear, '3')) {
      testDate = false;
    }

		if(!testNetwork || !testLine || !testSens || !testDate) {
			if(!testNetwork) {
				arrayError.push('Network');
				$("#" + networkListId).css('border-color', 'red');
				$("#" + networkListId).css('color', 'red');
			}
			if(!testLine) {
				arrayError.push('Line');
				$("#" + lineListId).css('border-color', 'red');
				$("#" + lineListId).css('color', 'red');
			}
			if(!testSens) {
				arrayError.push('Sens');
				$("#" + sensId).css('border-color', 'red');
				$("#" + sensId).css('color', 'red');
			}
			if(!testDate) {
				arrayError.push('Date');
			}

			ShowError(arrayError, 'msg_error3', 'mtkHoraire');

			window.location.href = '#msg_error3_container';

	  	return false;
		} else {
			LogoWaitRunning();
			return true;
		}
	};

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

  function LogoWaitRunning() {
		$("#PnlRunning").css('display','block');
		$('#PnlRunning').css('z-index','2000');
		$('#lightbox-overlay').css('display','block');
		$('#lightbox-overlay').css('background-color','#C0C0C0');
		$('#lightbox-overlay').css('opacity','0');
		$('#lightbox-overlay').css('z-index','1000');
		$('#lightbox-overlay').animate({opacity: "0.7"}, 1500);
	};

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

	var Test = function()
    {
        alert('in');
    };


	// cette fonction permet de mettre à jour le nombre de jours
	// en conformité avec le mois de sélection.
	function changeMonth(selectMonthid,selectDayid)
	{
		if($("#"+selectMonthid)!= null && $("#"+selectDayid)!= null)
		{
			var selectMonth = $("#"+selectMonthid) ;
			var selectDay = document.getElementById(selectDayid);
			var selectedValue = selectMonth.val() ;
			var listValues =  selectedValue.split('|');
			var MaxDaysInMonth = 32 - new Date(listValues[1], listValues[0]-1, 32).getDate();
			var NumberOfDays = selectDay.length-1 ;// -1 pour tenir compte du libellé Jour dans DDL
			if(NumberOfDays != MaxDaysInMonth)
			{
				var _indice =  NumberOfDays ;
				if(NumberOfDays>MaxDaysInMonth)
				{
					while(_indice>MaxDaysInMonth)
					{
						selectDay.remove(_indice);
						_indice = _indice-1 ;
					}
				}
				else
				{
					while(_indice<MaxDaysInMonth)
					{
						var optn = document.createElement("OPTION");
						optn.text = _indice+1 ;
						optn.value = _indice+1;
						selectDay.options.add(optn);
						_indice = _indice +1 ;
					}
				}
			}
		}
	};
	
	function deleteCityValue(val)
	{
		if( typeof(val) == 'string' )
		{
			var indexOpenParenthese = val.lastIndexOf('(', val.length);
			if (indexOpenParenthese > 0)
			{
				val = val.substring(0,indexOpenParenthese);
			}
		}	
		return val; 
	};
