var niveau = 0
var pathRacine = ""
if($("#crouzetJs")){

	var srcJs = $("#crouzetJs").attr("src");
	var temp = srcJs.split("../");
	niveau = (temp.length - 1);

	if(niveau != 0){
		for(var iNiveau = 0; iNiveau < parseInt(niveau) ; iNiveau++){
			pathRacine += "../";
		}
	}
	
}

//FONCTION PERMETTANT DE REDIMENSIONNER DEUX BLOCS
function ResizeColonne(idGauche, idDroite, plus_gauche, plus_droite){
	// HEIGHT
	var height_gauche 			= $("#" + idGauche).height();
	var height_droite 			= $("#" + idDroite).height();
	
	// Taille complète gauche
	if (plus_gauche != ""){
		height_gauche= height_gauche + parseInt(plus_gauche);
	}else{
		plus_gauche = 0
	}

	// Taille complète droite
	if (plus_droite != ""){
		height_droite= height_droite + parseInt(plus_droite);
	}else{
		plus_droite =0;
	}
				
	// comparaison des tailles
	if(height_gauche > height_droite){ // Le bloc de gauche est plus grand
		$("#" + idDroite).height(height_gauche - parseInt(plus_droite));
	}else{
		$("#" + idGauche).height(height_droite - parseInt(plus_gauche));
	}
}

function rss()
{
	lg = codeLangue;
	window.open(pathRacine + "_inc/genrss.asp?lg=" + lg);
}

function afficheImagesApplications(marche, vehicule, application, zone)
{
	//alert("lg=" + codeLangue + "&marche=" + marche + "&vehicule=" + vehicule + "&application=" + application + "&zone=" + zone);
	// on va chercher les images de la zone
	$.ajax({
		type: "POST",
		url: "../../_inc/getzones.asp",
		data: "lg=" + codeLangue + "&marche=" + encodeURIComponent(marche) + "&vehicule=" + encodeURIComponent(vehicule) + "&application=" + encodeURIComponent(application) + "&zone=" + zone,
		success: function(imagesapplication)
		{
			$("#zonesImages").html(imagesapplication);
		},
		error: function(retour)
		{
		   alert(retour.responseText);
		}
	});	
}

function changeLangue(lg)
{
	alert(codePage + " > "  + lg);

	// on va chercher la page équivalente dans la nouvelle langue
	$.ajax({
		type: "get",
		url: "../_inc/ip.asp",
		success: function(codePays)
		{
			$("#localisation2").val(codePays);
		},
		/*error: function(retour)
		{
		   alert("Erreur, veuillez recommencer");
		}*/
	});
	
	//window.location.href = "";
}

function localise()
{
	// on va chercher le pays en fonction de l'IP
	$.ajax({
		type: "get",
		url: "../_inc/ip.asp",
		success: function(codePays)
		{
			$("#localisation2").val(codePays);
		},
		/*error: function(retour)
		{
		   alert("Erreur, veuillez recommencer");
		}*/
	});
}

function getCodePays()
{
	// on va chercher le pays en fonction de l'IP
	$.ajax({
		type: "get",
		url: "../_inc/ip.asp",
		success: function(codePays)
		{
		},
		/*error: function(retour)
		{
		   alert("Erreur, veuillez recommencer");
		}*/
	});
}



function loadApplication(iAppli)
{
	$(".menuapplicationitem").css("background-color", "");
	$(".menuapplicationitem").eq(iAppli-1).css("background-color", "#f3982f");

	$(".menuapplicationitem a").css("color", "#005aa1");
	$(".menuapplicationitem a").eq(iAppli-1).css("color", "#FFFFFF");
	
	$(".menuapplicationitemfl").css("display", "none");
	$(".menuapplicationitemfl").eq(iAppli-1).css("display", "block");
	
	$(".applicationFlash").css("display", "none");
	$(".applicationFlash").eq(iAppli-1).css("display", "block");
	
	$(".applicationProduits").css("display", "none");
	$(".applicationProduits").eq(iAppli-1).css("display", "block");

	afficheImagesApplications("", "", "", "");
}

function loadProductCarac(iAppli)
{
	$(".menudescriptifitem").css("background-color", "");
	$(".menudescriptifitem").eq(iAppli-1).css("background-color", "#2f9dce");

	$(".menudescriptifitem a").css("color", "#005aa1");
	$(".menudescriptifitem a").eq(iAppli-1).css("color", "#FFFFFF");
	
	$(".menudescriptifitemfl").css("display", "none");
	$(".menudescriptifitemfl").eq(iAppli-1).css("display", "block");
	
}

function GetDownload(CookieName,lg,activite){
		
		
		if(lg == "" || lg == null )
			lg = "fr"
		
		var sData = "lang="+lg+"&activite="+activite
		
		
		var ids = "";
		if(CookieName != "notDefined"){
			ids  = getIdsInCookie(CookieName); 
			sData += "&ids="+ids;
		}

		if(CookieName == "notDefined" || ids != ""){

			$.ajax({
					type: "POST",   
					url: pathRacine + "_ajax/get_download.asp",        
					data: sData,
					success: function(msg){  
					tb_remove();					
					if(msg != ""){

						$("#hiddenModalContent").html(msg);
						tb_show($("#hiddenModalContent").attr("title"),"#TB_inline?height=200&width=400&inlineId=hiddenModalContent"  ,false);				
					}
									   
				},
				error:function(msg){       
					alert(msg.ResponseText);
				},
				beforeSend:function(){
					 tb_show_mask(); 
				}
			});  
		}
}


function ReloadSelecRegion(SelectName, SelectId, CodePays, lg){
			
			if(lg == "" || lg == null)
			 lg = "fr";
		
			 
			$.ajax({
					type: "POST",   
					url: pathRacine + "_ajax/get_RenderRegion.asp",        
					data: "SelectName="+ SelectName+"&SelectId="+SelectId+"&CodePays="+CodePays+"&Lang="+lg,
					success: function(msg){   
						if(msg != ""){
							$("#" + SelectId +"").html(msg);
							$("#" + SelectId +"").show();
						}else{
							$("#" + SelectId +"").html("<option value=\"all\" selected>all</option>");
							$("#" + SelectId +"").hide();
							
							SearchDistrib();
						}
									   
					},
					error:function(msg){       
						alert(msg.ResponseText);
					},
					beforeSend:function(){
						   
					}
				});  
}

function LoadFormContact(Lang){


	if($("#profession").val() != "" && $("#typeDemande").val() != "" && $("#client").val() != ""){
		$.ajax({
			type: "POST",   
			url: pathRacine + "_ajax/load_formContact.asp",        
			data: "lang="+ Lang +"&profession="+ $("#profession").val()+"&Activite="+ $("#Activite").val()+"&typeDemande="+ $("#typeDemande").val()+"&client="+ $("#client").val()+"&formAction="+ $("#FormAction").val()+"&postAjax="+ $("#PostAjax").val()+"&UrlReferrer="+document.referrer +"&UrlPage="+document.URL +"&CssName="+ $("#CssName").val(),
			success: function(msg){   
			if(msg != ""){
				$("#ResultContact").html(msg);
				$("#ResultContact").show();               
			}else{
				$("#ResultContact").hide();                                     
			}		   
			},
			error:function(msg)
			{       
				alert(msg.ResponseText);
			},
			beforeSend:function(){
				$("#ResultContact").hide();     
			}
	}); 
	}
}


function SaveFormContact(CookieName,Lang){

		if(verifForm()){
			var sData = "action=dlDoc&lang="+ Lang;

			$("#TB_ajaxContent input").each(function(){
				sData += "&"+$(this).attr("name")+"="+$(this).val();
			});
			$("#TB_ajaxContent select").each(function(){
				sData += "&"+$(this).attr("name")+"="+$(this).val();
			});


			$.ajax({
				type: "POST",   
				url: pathRacine + "_ajax/save_contact.asp",        
				data: sData,
				success: function(msg){  
					if(msg != "")
						eval(msg)
				},
				error:function(msg)
				{       
					alert(msg.ResponseText);
				},
				beforeSend:function(){ 
				}
			}); 
	}

}

function SendUrl(lg){

		if(verifForm()){
			var sData = "action=SendUrl&lang="+ lg;

			$("#TB_ajaxContent input").each(function(){
				sData += "&"+$(this).attr("name")+"="+$(this).val();
			});


			$.ajax({
				type: "POST",   
				url: pathRacine + "_ajax/send_url.asp",        
				data: sData,
				success: function(msg){  
					if(msg != "")
						$("#TB_ajaxContent").html(msg);
				},
				error:function(msg)
				{       
					alert(msg.ResponseText);
				},
				beforeSend:function(){ 
				}
			}); 
	}

}

function SendUrlToFriend(lg){

		if(lg == "" || lg == null )
			lg = "fr";
		
		var sData = "Lang="+lg+"&Url="+document.URL;

		$.ajax({
				type: "POST",   
				url: pathRacine + "_ajax/send_url.asp",        
				data: sData,
				success: function(msg){  
					tb_remove();					
					if(msg != ""){

						$("#hiddenModalContentUrl").html(msg);
						tb_show($("#hiddenModalContentUrl").attr("title"),"#TB_inline?height=200&width=400&inlineId=hiddenModalContentUrl"  ,false);				
					}
								   
				},
				error:function(msg){       
					alert("Erreur, veuillez recommencer");
				},
				beforeSend:function(){
					 //tb_show_mask(); 
					 $("#hiddenModalContentUrl").html("<div id='TB_load'><img src='"+ pathRacine + +"_images/loading.gif' /></div>");
				}
			});  

}


function tb_show_mask(){
	if(document.getElementById("TB_window"))
	{
		document.getElementById("TB_window").style.display = "none";
	}
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		$("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
		}
	}
	
	if(tb_detectMacXFF()){
		$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}


	$("body").append("<div id='TB_load'><img src='"+ pathRacine +"_images/loading.gif' /></div>");//add loader to the page
	$('#TB_load').show();//show loader
	
}

function verifForm(){

	var bOk = true
	$(".required[@title]").each(function(){
		var defaultValue = trim($(this).attr("title"));
		var presentValue = trim($(this).val());
		
		if(defaultValue == presentValue || presentValue == ""){
			$(this).css("background-color","#ff0000");
			bOk = false;
			$(".infoForm").show();
		}
		if($(this).attr("name").toLowerCase().indexOf("mail") > 0){
			if(!isMailValid(presentValue)){
				$(this).css("background-color","#ff0000");
				bOk = false;
				$(".infoForm").show();
			}
		}		
		
	});
	
	//si form ok on remplace les valeur par defaut encore existant par vide
	if(bOk == true){
		$("input[@title]").each(function(){	
			var defaultValue = trim($(this).attr("title"));
			var presentValue = trim($(this).val());		
			if(defaultValue == presentValue){
				$(this).val("")
			}
		});
	}

	return bOk;
	
}

function trim(string){
	return string.replace(/(^\s*)|(\s*$)/g,'');
} 

function isMailValid(email){
	 var verif = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/;
	 if (verif.exec(email) == null)
		return false; //mail incorrect
	 else
		return true; //mail correct
} 

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}


