	// omniture 
	s_account="opodofrprod";
	s.pageName="Op:FR:MoteurVoituresHP:Search";
	s.channel="HOMEPAGE";
	s.campaign=s.getQueryParam('CMP');
  
  //decalage jours entre aller et retour
	var dpDelay = 3;
	var volDelay=7;
		
	$(document).ready(function() {
        
		// initialisation des date du moteur,    
  	    var today = new Date ();
		
			// ajouter les divs pour afficher le calendar
	   $('.calContainer').remove();
	   $('#contenu').after('<div id="cal5Container" name="cal5Container" class="calContainer" ></div><div id="cal6Container" name="cal6Container" class="calContainer" ></div>');
	   		
  	   
       //vol
        var departDate = new Date();
		    departDate.setDate(today.getDate() + 1);
  	    var returnDate = new Date();
		    returnDate.setDate(today.getDate() + volDelay +1);
  	      
        var departMonth=(departDate.getMonth()+1).toString();
        var departDay=departDate.getDate().toString();
        
        var returnMonth=(returnDate.getMonth()+1).toString();
        var returnDay=returnDate.getDate().toString();
        
        
        if(departMonth.length==1)
          departMonth = "0"+departMonth;
        
        if(departDay.length==1)
            departDay= "0"+departDay;
                   
        if(returnMonth.length==1)
          returnMonth = "0"+returnMonth;
        
        if(returnDay.length==1)
            returnDay= "0"+returnDay;
                
        var dateDepartText = departDay+"/"+departMonth+"/"+departDate.getFullYear();
  	    var dateRetournText = returnDay+"/"+returnMonth+"/"+returnDate.getFullYear();
  	    
        $('#DATE_DCARText').val(dateDepartText);
  	    $('#DATE_RCARText').val(dateRetournText);
  	    
		$("#pickUpDateForm").val(departDate.getFullYear()+""+departMonth+""+departDay+$("#pickHour").val()+'00');
        $("#dropOffDateForm").val(returnDate.getFullYear()+""+returnMonth+""+returnDay+$("#dropHour").val()+'00');
        
      	// call  yahoo calendars via nput
		
		initDoubleCalendier("DATE_DCARText", "cal5Container", "calendar5","DATE_DCARText",12,"","updateReturnDate('DATE_DCARText','DATE_RCARText','formVoiture')","DD","YYYYMM");
		initDoubleCalendier("DATE_RCARText", "cal6Container", "calendar6","DATE_RCARText",18, "","updateDepartureDate('DATE_RCARText','formVoiture')","DD","YYYYMM");	
	
		var villeDepInit ='Ville ou aéroport'
		//$("#searchString").val(villeDepInit);
			
		$("#searchString").click(function () {
			
			if ($("#searchString").val()==villeDepInit) $("#searchString").val('');
	
		});
		
		
		$("#searchStringDrop").click(function () {
		
			if ($("#searchStringDrop").val()=='Identique à la prise en charge') $("#searchStringDrop").val('');
	
		});
		
			
	
	// On gère l'envoi du  formulaire voiture 
	
		$('#formVoiture').submit(function() {
			
			tracking(document.getElementById("rechercheVoiture"),'Op:FR:Homepage:Search_CarSubmitButton');return submitCarSearch();
			return false;
		
		});
		
	 
  });
    
	// Onsubmit Vols
	function submitCarSearch() {
		
		var departureDateTab = $("#DATE_DCARText").val().split("/");
		var returnDateTab = $("#DATE_RCARText").val().split("/");
		var error_=false;
		var html="<img id='errorIcon' src='./img/pictoAttention.jpg' alt='error' />Attention!<div class='errMsg11v'>Merci de lire le(s) message(s) suivant(s)</div> ";
			
		
		if($("#formVoiture select[@name=age]").val()==0){
		 
			html="<p><img class='alert' src='/img_opodo/homepageV2/alert3.gif' align='ATTENTION' />Veuillez saisir l'âge du conducteur.<img id='closeError' class ='closeError' border='0' alt='Fermer' src='/img_opodo/headfoot/icon-close.gif' /></p>";
			$("#errorVoiture").html(html);
			$("#errorVoiture").show();
		
			$('.closeError').click(function() {
				$("#errorVoiture").hide();
			});
			return false;
						
		}
		
		
		if ($("#searchString").val() == '' || $("#searchString").val() == 'Ville ou aéroport' ) {
					
			html="<p><img class='alert' src='/img_opodo/homepageV2/alert3.gif' align='ATTENTION' />Veuillez saisir un lieu de prise en charge.<img id='closeError' class ='closeError' border='0' alt='Fermer' src='/img_opodo/headfoot/icon-close.gif' /></p>";
			$("#errorVoiture").html(html);
			$("#errorVoiture").show();
		
			$('.closeError').click(function() {
				$("#errorVoiture").hide();
			});
			return false;
					
		}
		
				
		// erreur sur les dates
		if(!validRegexDate($('#DATE_DCARText').val())  || !isDateValid($('#DATE_DCARText').val())) {
	      
			html="<p><img class='alert' src='/img_opodo/homepageV2/alert3.gif' align='ATTENTION' />Veuillez entrer une date de départ valide<br/>(format jj/mm/aaaa).<img id='closeError' class ='closeError' border='0' alt='Fermer' src='/img_opodo/headfoot/icon-close.gif' /></p>";
			$("#errorVoiture").html(html);
			$("#errorVoiture").show();
		
			$('.closeError').click(function() {
				$("#errorVoiture").hide();
			});
			return false;
						
		}
	       
		if(!validRegexDate($('#DATE_RCARText').val()) || !isDateValid($('#DATE_RCARText').val())) {
	      
			html="<p><img class='alert' src='/img_opodo/homepageV2/alert3.gif' align='ATTENTION' />Veuillez entrer une date de retour valide<br/>(format jj/mm/aaaa).<img id='closeError' class ='closeError' border='0' alt='Fermer' src='/img_opodo/headfoot/icon-close.gif' /></p>";
			$("#errorVoiture").html(html);
			$("#errorVoiture").show();
		
			$('.closeError').click(function() {
				$("#errorVoiture").hide();
			});
			return false;
			
			
		}
				
		var status = validateDates("errorVoiture","formVoiture", departureDateTab, returnDateTab, "pickHour", "dropHour");
			if(status==false)
				return false;
			
			
		// submit ok
		
		$("#formVoiture").attr('action', 'http://voitures.opodo.fr/opodo/StrutsServlet/CarSearch');	
		$("#destination1").val($("#searchString").val());
		$("#destination2").val($("#searchString").val());
			
		if($("#searchStringDrop").val()!='' && $("#searchStringDrop").val() != 'Identique à la prise en charge')
			$("#destination2").val($("#searchStringDrop").val());
	
		$("#pickUpDateForm").val(departureDateTab[2]+departureDateTab[1]+departureDateTab[0]+$("#pickHour").val()+'00');
		$("#dropOffDateForm").val(returnDateTab[2]+returnDateTab[1]+returnDateTab[0]+$("#dropHour").val()+'00'); 
		return true;
		
				
		
	}