	/* Permet d'afficher les message d'erreurs */
	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 error = {
				"Departure":"Veuillez saisir un lieu de d\xE9part.<br/>",
				"Destination":"Veuillez saisir un lieu de destination.<br/>",
				"Heure":"Veuillez choisir une heure d'arriv\xE9e post\xE9rieure \xE0 l'heure actuelle.<br/>",
				"Date":"Veuillez choisir une date valide entre le "+beginDay+"/"+beginMonth+"/"+beginYear+" et "+endDay+"/"+endMonth+"/"+endYear+".<br/>"
				};

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

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

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

			$('#DepartureLibelle').css("border-color","#CCCCCC");
			$('#DestinationLibelle').css("border-color","#CCCCCC");


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

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

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

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

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

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

			for(var i=0;i<id.length;i++)
			{
				$('#'+conteneur).append(error[id[i]]);
				if(id[i]=='Departure')
				{
					if(page=='viewroute')
					{
						$('#DepartureLibelle').css("border-color","red");
						$('#DepartureLibelle').css("color","red");
					}
					else if(page=='viewprecision')
					{
						$('#Departure').css("border-color","red");
						$('#edtDeparture').css("border-color","red");
						$('#Departure').css("color","red");
						$('#edtDeparture').css("color","red");
					}
				}

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

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

				if(id[i]=='Date')
				{
					$('#dateYearMonth').css("border-color","red");
					$('#dateDay').css("border-color","red");
					$('#dateYearMonth').css("color","red");
					$('#dateDay').css("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;

//		if($('#DepartureCityName').attr('rel')=="0" && $('#DepartureLibelle').attr('rel')=="0")
		if($('#DepartureLibelle').attr('rel')=="0")
		{
			testD=true;
		}
		else
		{
			testD = false;
		}
		//if($('#DestinationCityName').attr('rel')=="0" && $('#DestinationLibelle').attr('rel')=="0")
		if($('#DestinationLibelle').attr('rel')=="0")
		{
			testA = true;
		}
		else
		{
			testA = false;
		}

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

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

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

			if(testD)
				arrayError.push('Departure');
			if(testA)
				arrayError.push('Destination');
			if(testH)
				arrayError.push('Heure');
			if(testDate)
				arrayError.push('Date');

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

			return false;
		}
		else
		{
				if($('#DepartureLibelle').attr('rel')=="0")
				{
					$('#DepartureLibelle').val("");
				}
				else
				/*
				désactivation de ce test Mantis Client n°1962
				if($('#Departure').val()== '')
				*/
					$('#Departure').val($('#DepartureLibelle').val());

				if($('#DestinationLibelle').attr('rel')=="0")
				{
					$('#DestinationLibelle').val("");
				}
				else
				/*
				désactivation de ce test Mantis Client n°1962
				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("");

			var l_PanelRunning = document.getElementById("PnlRunning");
			l_PanelRunning.style.display = "block";

			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;


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

		if($('#edtDeparture').val() == "")
		{
			testDS = true;
		}
		else
		{
			testDS = false;
		}

		if($('#edtDestination').val() == "")
		{
			testAS = true;
		}
		else
		{
			testAS = false;
		}

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

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

		var arrayError = new Array();

		if(testD || testA)
		{
			if(testA)
				arrayError.push('Destination');
			if(testD)
				arrayError.push('Departure');
			if(testDate)
				arrayError.push('Date');
			if(testH)
				arrayError.push('Heure');



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

			return false;
		}
		else if(testDS || testAS)
		{
			if(testAS)
				arrayError.push('Destination');
			if(testDS)
				arrayError.push('Departure');
			if(testH)
				arrayError.push('Heure');
			if(testDate)
				arrayError.push('Date');

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

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

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

			var l_PanelRunning = document.getElementById("PnlRunning");
			l_PanelRunning.style.display = "block";

			return true;
		}
	};

	/* Verifie la validitÃ© 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!='')
		{
			//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 annÃ©e,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;
		}
	}

	/* VÃ©rifie la validitÃ© de l'heure */
	var checkHour = function()
	{
		var Hours = $('#hour').val();
		var Minutes = $('#minute').val();
		var sens = $('#sens').val();
		if(Hours!='' && Minutes!='')
		{
			var date = new Date();
			var myHours = date.getHours().toString();
			var myMinutes = date.getMinutes().toString();

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

			var concatMyHours = myHours.concat(myMinutes); concatMyHours = parseInt(concatMyHours);
			var concatHours = Hours.concat(Minutes); concatHours = parseInt(concatHours);
			/*if((sens == -1 && concatMyHours < concatHours )|| sens == 1)
			{
				return false;
			}
			else
			{
				return true;
			}*/
			return false;
		}
		else
		{
			return true;
		}
	}

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

	/* VÃ©frifie 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 Ã©tape */
	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');
		}
	};

	/* Affiche les formulaires de modification d'arrÃªts dans la partie Grille Horaires > template bandeauRecap.tpl */
	var ShowHideModifyStopArea = function()
	{
		$('#formHidden').slideToggle('show');
		return false;
	};

	var ShowHideModifyArrival = function()
	{
		$('#formArrivalHidden').slideToggle('show');
		return false;
	};

	var ValidateHoraire = function()
	{
		var error = {
				"Horaire":"Veuillez saisir le nom d'un arr\xEAt.<br/>"
				};

		if($('#stopAreaLibelle').attr('rel') == '0')
		{
			$('#stopAreaLibelle').css("border-color","red");
			$('#stopAreaLibelle').css("color","red");
			$('#msg_error').append(error['Horaire']);
			$('#msg_error').removeClass('hide');
			return false;
		}
		else
		{
			return true;
		}


	};

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