/**fichier js*/
/*
* role: affiche le tarif dasn une thickbox
*/
function afficher_tarif(formule)
{
	tb_show("Lirus_axeimoto",chemin+"modeles/thickbox/thickbox_tarif.php?width=700&height=375&FORMULE="+formule);
} 

function afficher_formulaire_rapide()
{
	tb_show("Lirus_axeimoto",chemin+"modeles/thickbox/thickbox_form_rapide.php?width=750&height=500");
}        


/*
* affiche les villes
*/
function cpville(champ1,champ2)
{
	jQuery.ajax({
		type:"POST",
		data:"laville="+jQuery("select[name='"+champ1+"']").val(),
		url:chemin+"modeles/ajax/ajax_cpville.php",
		beforeSend:function()
		{
			jQuery("select[name='"+champ2+"']").html("");
		},
		success:function(http_requeste)
		{
			jQuery("select[name='"+champ2+"']").html(http_requeste);
		}
		});
} 


function tab_lieu(elem)
{
	//on determine quel bloc on veut effectuer l'effet	
	switch(elem.name)
	{
		case "aller_lieuD":
			var groupe="aller_trajet_D";
			var div1="#aller_adresse_D";
			var div2="#aller_aeroport_D";
		break;
		case "aller_lieuA":
			var groupe="aller_trajet_A";
			var div1="#aller_adresse_A";
			var div2="#aller_aeroport_A";
		break;
		case "retour_lieuD":
			var groupe="retour_trajet_D";
			var div1="#retour_adresse_D";
			var div2="#retour_aeroport_D";
		break;
		case "retour_lieuA":
			var groupe="retour_trajet_A";
			var div1="#retour_adresse_A";
			var div2="#retour_aeroport_A";
		break;
	}
	        
	//on efface les champs       
	jQuery("input[name^='"+groupe+"'],select[name^='"+groupe+"']").each(function()
	{
		jQuery(this).attr("value","");
	});
	
	//on cree les effets
	switch(elem.value)
	{
		case "1":		
			jQuery(div1).slideUp("slow",function()
			{
				jQuery(div2).slideDown("slow");
			});
		break;
		case "2":
			jQuery(div2).slideUp("slow",function()
			{
				jQuery(div1).slideDown("slow");
			});
		break;
	}
}    
/**
* function pour changer les caractères
**/ 
function ChangeCaractere(elem,val)
{
	switch (val)
	{
		case 1: //majuscule
			elem.value=elem.value.toUpperCase();
		break;
		case 2: //Premiere lettre en majuscule
			elem.value=elem.value.substr(0,1).toUpperCase() +elem.value.substr(1,elem.value.length);;
		break;
		case 3: //minuscule
			elem.value=elem.value.toLowerCase();
		break;	
	}
}
/**
* Cette function permet d'initialiser tout les objet du formulaire
**/
function init_formulaire()
{
	jQuery("select,input,textarea").each(function()
	{
		switch(jQuery(this).attr("type"))
		{
			case "select-one":
				if(jQuery(this).attr("name")!="form_1")
				{
					jQuery(this).attr("value","");
				}
			break
			case "text":
			case "textarea":
				jQuery(this).attr("value","");
			break;
			case "checkbox":
			case "radio":
				jQuery(this).attr("checked","");
				jQuery(this).attr("checked","");
			break;
		}
	});
}
/**
* Cette function permet d'initialiser tout les objet du block trajet
**/
function init_blocktrajet(block)
{
	jQuery("input[name^='"+block+"'],select[name^='"+block+"']").each(function()
	{
		switch(jQuery(this).attr("type"))
		{
			case "select-one":
				if(jQuery(this).attr("name")!="form_1")
				{
					jQuery(this).attr("value","");
				}
			break
			case "text":
				jQuery(this).attr("value","");
			break;
			case "radio":
				jQuery(this).attr("checked","");
			break;
		}
	});
}
/**
* function Afficher bloc 1 (Formulaire)
**/
function VisibleBloc_1()
{
		init_formulaire();
		jQuery("#trajet").slideUp("slow",function(){
		jQuery("#aller").slideUp("slow",function(){
		jQuery("#retour").slideUp("slow",function(){
		jQuery("#bagage").slideUp("slow",function(){		
		jQuery("#commentaire").slideUp("slow",function(){
		jQuery("#contact").slideUp("slow",function()
		{
			switch(jQuery("select[name='form_1']").attr("value"))
			{
				case "1":
					jQuery("#formulaire").slideUp("slow",function(){
						afficher_formulaire_rapide();
					});
				break;
				case "2":
					jQuery("#formulaire").slideDown("slow");
				break;
				default:
					jQuery("#formulaire").slideUp("slow");
				break;
			}	
		});
		});
		});
		});
		});
		});		
}
/**
* function Afficher bloc 2 (contact,trajet,bagages,commentaire)
**/
function VisibleBloc_2() 
{
	switch(jQuery("select[name='form_1']").attr("value")+"_"+jQuery("select[name='form_2']").attr("value"))
	{
		case "2_1": //Demande de pré reservation_particulier
			jQuery(".entreprise").css("visibility","hidden");
			jQuery("#contact").slideDown("slow",function(){
				jQuery("#trajet").slideDown("slow",function(){
					jQuery("#bagage").slideDown("slow",function(){
						jQuery("#commentaire").slideDown("slow",function(){
							
						});							
					});					
				});	
			});	
		break;
		case "2_2": //Demande de pré reservation_entreprise
			jQuery(".entreprise").css("visibility","visible");
			jQuery("#contact").slideDown("slow",function(){
				jQuery("#trajet").slideDown("slow",function(){
					jQuery("#bagage").slideDown("slow",function(){
						jQuery("#commentaire").slideDown("slow",function(){
							
						});						
					});					
				});				
			});	
		break;
		case "2_":
			VisibleBloc_1();
		break;
	}
}
/**
* function Afficher bloc 3 (aller/retour) 
**/
function VisibleBloc_3()  
{
	switch(jQuery("select[name='trajet_1']").attr("value"))
	{
		case "1": //Aller simple
			jQuery("#retour").slideUp("slow",function(){
				jQuery("#aller").slideDown("slow",function(){
					jQuery("#retour_aeroport_A,#retour_adresse_A,#retour_aeroport_D,#retour_adresse_D").css("display","none");
					init_blocktrajet("retour_");
			});
		});
		break;
		case "2": //aller retour
			jQuery("#aller").slideDown("slow",function(){
				jQuery("#retour").slideDown("slow",function(){
					
			});
		});
		break;
		default:
			jQuery("#aller").slideUp("slow",function(){
				jQuery("#retour").slideUp("slow",function(){
					init_blocktrajet("aller_");
					jQuery("#aller_aeroport_A,#aller_adresse_A,#aller_aeroport_D,#aller_adresse_D,#retour_aeroport_A,#retour_adresse_A,#retour_aeroport_D,#retour_adresse_D").css("display","none");
			});
		});		
		break;
	}
}

function test_form()
{
	if (jQuery("select[name='form_1']").attr("value")=="2")//formulaire pré reservation
	{
		if (!ctrl_contrat())
		{
			return false;
		}		
		if (!ctrl_trajet())
		{
			return false;
		}	
		if (!ctrl_bagage())
		{
			return false;
		}
		if (!ctrl_commentaire())
		{
			return  false;
		}		
	}	
	else //sinon contact rapide
	{
		if (!ctrl_contrat_rapide())
		{
			return false;
		}		
		if (!ctrl_commentaire_rapide())
		{
			return  false;
		}		
	}
	return true;
}  


function ctrl_form()
{
	if (test_form())
	{
		var html;
		var formulaire=(jQuery("select[name='form_1']").attr("value")=="2")?"#form_contact":"#form_contact_rapide";
		jQuery.ajax({
			type:"POST",
			data:jQuery(formulaire).serialize(),
			url:chemin+"modeles/ajax/ajax_formmail.php?AJAX=OUI",
			beforeSend:function()
			{
				html=jQuery(".submit").html();
				jQuery(".submit").html("<div class='loading'></div>");
			},
			success:function(httpRequeste)
			{
				jQuery(".submit").html(html);
				if (httpRequeste)
				{
					jAlert("Votre Demande a été transmise a notre société.<br/>Merci de votre confiance.","LirusAxeiMoto", function()
					{
					 	jQuery(location).attr('href',"contact.php");		 		 			
					});
				}
				else
				{
					jAlert("Une erreur est survenu lors de l'envoie du mail<br/>Veuillez nous contacter au 06 87 51 43 23 afin de valider votre demande.","LirusAxeiMoto")
				}
			}
			});
	}
}
/**
* Controle le block formulaire
*/
function ctrl_contrat_rapide()
{
	var bGood=true

	if (bGood && jQuery("input[name='contact_rapide_2']").attr("value")=="")
	{
		Search_Form(jQuery("input[name='contact_rapide_2']"),1);   
		bGood=false; 
	} 
	if (bGood && jQuery("input[name='contact_rapide_3']").attr("value")=="")
	{
		Search_Form(jQuery("input[name='contact_rapide_3']"),1);   
		bGood=false; 
	}
	if (bGood && jQuery("input[name='contact_rapide_4']").attr("value")=="")
	{
		Search_Form(jQuery("input[name='contact_rapide_4']"),1);   
		bGood=false; 
	}
	if (bGood && !ValideEmail(jQuery("input[name='contact_rapide_4']").attr("value")))
	{
		Search_Form(jQuery("input[name='contact_rapide_4']"),1);   
		bGood=false; 
	}		
	if (bGood && jQuery("input[name='contact_rapide_5']").attr("value")=="")
	{
		Search_Form(jQuery("input[name='contact_rapide_5']"),1);   
		bGood=false; 
	}
	return bGood;
} 

/**
* Controle le block formulaire
*/
function ctrl_contrat()
{
	var bGood=true
	if(bGood && jQuery("select[name='form_2']").attr("value")=="2")
	{
		if (bGood && jQuery("input[name='contact_1']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='contact_1']"),1);   
			bGood=false; 
		}
	}
	if (bGood && jQuery("input[name='contact_2']").attr("value")=="")
	{
		Search_Form(jQuery("input[name='contact_2']"),1);   
		bGood=false; 
	} 
	if (bGood && jQuery("input[name='contact_3']").attr("value")=="")
	{
		Search_Form(jQuery("input[name='contact_3']"),1);   
		bGood=false; 
	}
	if (bGood && jQuery("input[name='contact_4']").attr("value")=="")
	{
		Search_Form(jQuery("input[name='contact_4']"),1);   
		bGood=false; 
	}
	if (bGood && !ValideEmail(jQuery("input[name='contact_4']").attr("value")))
	{
		Search_Form(jQuery("input[name='contact_4']"),1);   
		bGood=false; 
	}		
	if (bGood && jQuery("input[name='contact_5']").attr("value")=="")
	{
		Search_Form(jQuery("input[name='contact_5']"),1);   
		bGood=false; 
	}
	return bGood;
} 
/**
*Controler block trajet
*/
function ctrl_trajet()
{
	var bGood=true;
	if(bGood && jQuery("select[name='trajet_1']").attr("value")=="")
	{
			Search_Form(jQuery("select[name='trajet_1']"),5);  
			bGood=false; 
	}
	//Partie Aller//
	if (bGood)
	{
		bGood=ctrl_aller_retour("aller_");
	}
	//Parie Retour
	if(jQuery("select[name='trajet_1']").attr("value")=="2")
	{
		if (bGood)
		{
			bGood=ctrl_aller_retour("retour_");
		}
	}
	return bGood;
}

function ctrl_aller_retour(typeblock)
{
	var bGood=true;
	if(bGood && jQuery("input[name='"+typeblock+"date']").attr("value")=="")
	{
			Search_Form(jQuery("input[name='"+typeblock+"date']"),1);
			bGood=false; 
	}
	if(bGood && jQuery("select[name='"+typeblock+"heure1']").attr("value")=="")
	{
			Search_Form(jQuery("select[name='"+typeblock+"heure1']"),6);
			bGood=false; 
	}
	if(bGood && jQuery("input[name='"+typeblock+"heure2']").attr("value")=="")
	{
			Search_Form(jQuery("input[name='"+typeblock+"heure2']"),1);
			bGood=false; 
	}
	if(bGood && jQuery("input[name='"+typeblock+"lieuD']:checked").length==0)
	{
			Search_Form(jQuery("input[name='"+typeblock+"lieuD']"),7);   
			bGood = false;	
	}
	if(bGood && jQuery("input[name='"+typeblock+"lieuD']:checked").attr("value")=="1")
	{
		if(bGood &&jQuery("input[name='"+typeblock+"aeroport_D1']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='"+typeblock+"aeroport_D1']"),1);   
			bGood = false;
		}
		if(bGood &&jQuery("input[name='"+typeblock+"aeroport_D2']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='"+typeblock+"aeroport_D2']"),1);   
			bGood = false;
		}
		if(bGood && jQuery("input[name='"+typeblock+"aeroport_D3']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='"+typeblock+"aeroport_D3']"),1);   
			bGood = false;
		}
	}	
	if(bGood && jQuery("input[name='"+typeblock+"lieuD']:checked").attr("value")=="2")
	{
		if(bGood && jQuery("input[name='"+typeblock+"adresse_D4']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='"+typeblock+"adresse_D4']"),1);   
			bGood = false;
		}
		if(bGood &&jQuery("select[name='"+typeblock+"adresse_D5']").attr("value")=="")
		{
			Search_Form(jQuery("select[name='"+typeblock+"adresse_D5']"),7);   
			bGood = false;
		}
		if(bGood &&jQuery("select[name='"+typeblock+"adresse_D6']").attr("value")=="")
		{
			Search_Form(jQuery("select[name='"+typeblock+"adresse_D6']"),7);   
			bGood = false;
		}
	}
	if(bGood && jQuery("input[name='"+typeblock+"lieuA']:checked").length==0)
	{
			Search_Form(jQuery("input[name='"+typeblock+"lieuD']"),7);   
			bGood = false;	
	}
	if(bGood && jQuery("input[name='"+typeblock+"lieuA']:checked").attr("value")=="1")
	{
		if(bGood &&jQuery("input[name='"+typeblock+"aeroport_A1']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='"+typeblock+"aeroport_A1']"),1);   
			bGood = false;
		}
		if(bGood &&jQuery("input[name='"+typeblock+"aeroport_A2']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='"+typeblock+"aeroport_A2']"),1);   
			bGood = false;
		}
		if(bGood && jQuery("input[name='"+typeblock+"aeroport_A3']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='"+typeblock+"aeroport_A3']"),1);   
			bGood = false;
		}
	}	
	if(bGood && jQuery("input[name='"+typeblock+"lieuA']:checked").attr("value")=="2")
	{
		if(bGood && jQuery("input[name='"+typeblock+"adresse_A4']").attr("value")=="")
		{
			Search_Form(jQuery("input[name='"+typeblock+"adresse_A4']"),1);   
			bGood = false;
		}
		if(bGood &&jQuery("select[name='"+typeblock+"adresse_A5']").attr("value")=="")
		{
			Search_Form(jQuery("select[name='"+typeblock+"adresse_A5']"),7);   
			bGood = false;
		}
		if(bGood &&jQuery("select[name='"+typeblock+"adresse_A6']").attr("value")=="")
		{
			Search_Form(jQuery("select[name='"+typeblock+"adresse_A6']"),7);   
			bGood = false;
		}
	}
	return bGood;
}


/**
* controle le block bagage
*/
function ctrl_bagage()
{
	var bGood=true;
	if (jQuery("input[id^='bagage_']:checked").length==0)
	{
		Search_Form(jQuery("input[id='bagage_1']"),4);   
		bGood=false;
	}
	return bGood;
}
function AucuneValise()
{
	if (jQuery("input[id='bagage_0']").attr("checked"))//si aucun bagage a été selectionné
	{
		if(jQuery("input[id^='bagage_']:checked").length == 2 ) //si nbre bagage ==2
		{
			jQuery("input[id^='bagage_']:checked").attr("checked","");
			Search_Form(jQuery("input[id='bagage_0']"),3);   
			return false;			
		}
	}
	else if(jQuery("input[id='bagage_4']:checked,input[id='bagage_5']:checked").length==2) //si le bagage 4 et 5 on été selectionné
	{
		jQuery("input[id='bagage_4']").attr("checked","");
		Search_Form(jQuery("input[id='bagage_4']"),2);   
		return false;
	}  
}
/*
* Block Commentaire
*/
function ctrl_commentaire()
{
	var bGood=true;
	if (jQuery("select[name='form_1']").attr("value")=="1")
	{
		if (bGood && jQuery("textarea[name='comm']").attr("value")=="")
		{
			Search_Form(jQuery("textarea[name='comm']"),1);   
			bGood = false;
		}
	}
	if(bGood && !(jQuery("input[name='question']").attr("checked")))
	{
			Search_Form(jQuery("input[name='question']"),8);   
			bGood = false;
	}
	return bGood;
}
function ctrl_commentaire_rapide()
{
	var bGood=true;

		if (bGood && jQuery("textarea[name='comm_rapide']").attr("value")=="")
		{
			Search_Form(jQuery("textarea[name='comm_rapide']"),1);   
			bGood = false;
		}
	if(bGood && !(jQuery("input[name='question_rapide']").attr("checked")))
	{
			Search_Form(jQuery("input[name='question_rapide']"),8);   
			bGood = false;
	}
	return bGood;
}

function Search_Form(elem,msg)
{
	switch (msg)
	{
		case 1: //contact
			var msg="Veuillez remplir ce champ correctement.";
		break;
		case 2: //bagage
			var msg="Vous ne pouvez choisir un seul des deux.";
		break;
		case 3: //bagage
			var msg="Vous ne pouvez pas selectionner ce bagage.";
		break;
		case 4: //bagage
			var msg="Veuillez selectionner votre type de bagage.";
		break;
		case 5: //trajet
			var msg="Veuillez selectionner votre type de trajet.";
		break;
		case 6://trajet
			var msg="Veuillez selectionner votre horaire."
		break; 
		case 7://trajet
			var msg="Veuillez selectionner votre lieu."
		break; 
 		case 8://commentaire
			var msg="Veuillez repondre a cette question<br/>Avez vous pris connaissance des conditions Générales de Vente Lirus-axe-i-moto.fr et les accepte?";
		break; 				
	}
	
jAlert(msg,"LirusAxeiMoto", function()
		{
		 	jQuery.scrollTo(elem,600,{axis:"y"});
 		 		elem.blur();	
 		 		elem.focus();		
 		 			
		});
} 

function gestion_info_pratique()
{
	location.reload(true);
} 
//Validation de l'email
function ValideEmail(champ)
{
	if (!champ.match(/^[\w\.\-\_]+@([\w\-]+\.)+[a-zA-Z]+$/)) 
	{
		return false;
	}
	else
	{
		return true;
	}
}      
                                             
