﻿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 += "../";
		}
	}
	
}

function getDistriStock(sDistri)
{
}

function distriStock()
{
	sVal = $("#distristock").val();
	var tmpPathRacine = pathRacine.replace("../", "");
	window.location.href = tmpPathRacine + "distributor-stock.htm?ref=" + sVal;
}

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 style=\"color:#FFF; margin:10px 0 0 0;\">...</div></div>");//add loader to the page
	$('#TB_load').show();//show loader
}

//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)
{

	// on va chercher la page équivalente dans la nouvelle langue
	$.ajax({
		type: "get",
		url: pathRacine + "_inc/ip.asp",
		success: function(codePays)
		{
			$("#localisation2").val(codePays);
		},
		error: function(retour)
		{
		   //alert("Erreur, veuillez recommencer");
		}
	});
	
	//window.location.href = "";
}

function changeSite(sUrl)
{
	sUrl2 = sUrl;

	sUrl2 = sUrl2.replace("../../../../../francais/", "http://www.crouzet.com/francais/");
	sUrl2 = sUrl2.replace("../../../../../english/", "http://www.crouzet.com/english/");
	sUrl2 = sUrl2.replace("../../../../../deutsch/", "http://www.crouzet.de/deutsch/");
	sUrl2 = sUrl2.replace("../../../../../espanol/", "http://www.crouzet.es/espanol/");

	sUrl2 = sUrl2.replace("../../../../francais/", "http://www.crouzet.com/francais/");
	sUrl2 = sUrl2.replace("../../../../english/", "http://www.crouzet.com/english/");
	sUrl2 = sUrl2.replace("../../../../deutsch/", "http://www.crouzet.de/deutsch/");
	sUrl2 = sUrl2.replace("../../../../espanol/", "http://www.crouzet.es/espanol/");
	
	sUrl2 = sUrl2.replace("../../../francais/", "http://www.crouzet.com/francais/");
	sUrl2 = sUrl2.replace("../../../english/", "http://www.crouzet.com/english/");
	sUrl2 = sUrl2.replace("../../../deutsch/", "http://www.crouzet.de/deutsch/");
	sUrl2 = sUrl2.replace("../../../espanol/", "http://www.crouzet.es/espanol/");

	sUrl2 = sUrl2.replace("../../francais/", "http://www.crouzet.com/francais/");
	sUrl2 = sUrl2.replace("../../english/", "http://www.crouzet.com/english/");
	sUrl2 = sUrl2.replace("../../deutsch/", "http://www.crouzet.de/deutsch/");
	sUrl2 = sUrl2.replace("../../espanol/", "http://www.crouzet.es/espanol/");

	sUrl2 = sUrl2.replace("../francais/", "http://www.crouzet.com/francais/");
	sUrl2 = sUrl2.replace("../english/", "http://www.crouzet.com/english/");
	sUrl2 = sUrl2.replace("../deutsch/", "http://www.crouzet.de/deutsch/");
	sUrl2 = sUrl2.replace("../espanol/", "http://www.crouzet.es/espanol/");
	
	window.location.href = sUrl2;
}

function localise()
{
	
	// on va chercher le pays en fonction de l'IP
	$.ajax({
		type: "get",
		url: pathRacine + "_inc/ip.asp",
		success: function(codePays)
		{
			$("#localisation2").val(codePays);
			
			//alert(codePays);

			switch(codePays) 
			{ 
				//case "US", "FR": 
				case "US": 
				
					// OUTILS US
					$("#haut1Droit1").css("width", "305px");
					$("#haut1Droit2").css("background", "none");
					$("#haut1Droit2").css("padding-left", "5px");
					$("#haut1Droit2").html("");

					sHTML = "<div style=\"width:316px;\">";
					sHTML += "<div style=\"padding-left:28px;padding-top:5px;float:left;width:130px;height:19px;background-image:url(" + pathRacine + "_images/extranet.png);\"><a style=\"font-size:12px;\" target=\"_blank\" href=\"https://www.extra.crouzet.com\">Extranet login</a></div>";
					sHTML += "<div style=\"padding-left:28px;padding-top:5px;float:left;width:130px;height:19px;background-image:url(" + pathRacine + "_images/noextranet.png);\"><a style=\"font-size:12px;\" target=\"_blank\" href=\"http://storefront.crouzet-usa.com\">Eportal</a></div>";
					sHTML += "</div>";
					
					sHTML += "<div style=\"width:316px;\">";
					sHTML += "<div style=\"padding-left:28px;padding-top:5px;float:left;width:130px;height:19px;background-image:url(" + pathRacine + "_images/distristock.png);\">";
					
						sHTML += "<input type=\"text\" id=\"distristock\" name=\"PartNo\" value=\"Enter Part No:\" onclick=\"this.select();\" style=\"color:#FFFFFF; width:105px;background:none;\" />&nbsp;";
						sHTML += "<input type=\"image\" src=\"" + pathRacine + "_images/fleche-blancheForm.png\" name=\"btnInventory\" value=\"Go\" onclick=\"distriStock();\">";
						//sHTML += "<a style=\"font-family:arial;font-size:11px;text-decoration:none;\" href=\"http://www.mectronic.net\" target=\"_blank\" class=\"menusmall\">Powered by Mectronic.net</a>";
						
					sHTML += "</div>";
					
					sHTML += "<div style=\"padding-left:28px;padding-top:5px;float:left;width:130px;height:19px;background-image:url(" + pathRacine + "_images/noextranet.png);\"><a style=\"font-size:12px;\" target=\"_blank\" href=\"http://www.crouzet-usa.com/techtalk/\">TechTalk Forums</a></div>";
					sHTML += "</div>";
					$("#haut1Droit2").html(sHTML);
					
					// RSS > FORUM TECH TALK
					$("#centre2gauche2droite").css("background-image", "url(" + pathRacine + "_images/techtalk.png)");
					$("#centre2gauche2droite").css("padding-right", "5px");
					$("#centre2gauche2droite").css("width", "221px");
					$("#rsstitre").html("<a href='#' target='_blank'>TechTalk forums</a>");
					$("#rsstitre a").css("color", "#035aa7");
					$("#rsstexte").html("<a href='#'>Interact with the team of Crouzet experts and other engineers to ask questions and share knowledge on our forums</a>");
					$("#doctitre a").html("Technical documents");
					$("#doctexte").css("width", "195px");
					$("#doctexte a").html("Click here to download technical documents, manuals, product information brochures and catalogs");
					
					break;
				
				default: 
				
						// on cache les elements US du menu
						$("#menuproduits .catMenu .libelle_chapitre1 .txtMenuCat").eq(9).css("display","none");
						$("#menuproduits .catMenu .libelle_chapitre4 .txtMenuCat").eq(4).css("display","none");
						$("#menuproduits .catMenu .libelle_chapitre4 .txtMenuCat").eq(5).css("display","none");
						$("#menuproduits .catMenu .libelle_chapitre4 .txtMenuCat").eq(6).css("display","none");
						
						
						// on cache les elements US des pages catalogues
						var sLoc = document.location.toString();
						var aSlash = sLoc.split("/");
						filename= aSlash[aSlash.length-1];
						
						if (filename == "micro-control.htm")
						{
							$(".blocfamille").eq(9).css("display","none");
						}
						
						if (filename == "position-sensors.htm")
						{
							$(".blocfamille").eq(4).css("display","none");
							$(".blocfamille").eq(5).css("display","none");
							$(".blocfamille").eq(6).css("display","none");
						}
						

					break;
					
			}
			
			
			// on va chercher le pays en fonction de l'IP
			$.ajax({
				type: "get",
				url: pathRacine + "_ajax/get_contact2.asp",
				data: "codeActivite=MCT&codePays=" + codePays + "&lang=" + codeLangue,
				success: function(sContact)
				{
					$.ajax({
						type: "POST",   
						url: pathRacine + "_ajax/get_expression.asp",        
						data: "lang="+ codeLangue +"&marqueur=contact_local",
						success: function(msg){   
							$("#contact1 div div div.textBleu").html(msg + "<br />" + sContact);
						},
						error:function(msg){       
							alert(msg.ResponseText);
						}
					}); 
				},
				error: function(retour)
				{
				   //alert("Erreur, veuillez recommencer");
				}
			});
			
		},
		error: function(retour)
		{
		   //alert("Erreur, veuillez recommencer");
		}
	});
}

function localiseMaps()
{
	
	// on va chercher le pays en fonction de l'IP
	$.ajax({
		type: "get",
		url: pathRacine + "_inc/ip_lib.asp",
		success: function(nomPays)
		{
			return nomPays;
		},
		error: function(retour)
		{
			return "France";
		}
	});
}

function getCodePays()
{
	// on va chercher le pays en fonction de l'IP
	$.ajax({
		type: "get",
		url: pathRacine + "_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, codeCouleur)
{
	$(".menudescriptifitem").css("background-color", "");
	$(".menudescriptifitem").eq(iAppli-1).css("background-color", codeCouleur);

	$(".menudescriptifitem a").css("color", codeCouleur);
	$(".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";
		if (codeLangue  != "" && codeLangue != null ) lg = codeLangue;
	}
		
	
	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 != ""){
					if (msg.indexOf("<div") > -1)
					{
						// on affiche le formulaire d'authentification
						$("#hiddenModalContent").html(msg);
						tb_show($("#hiddenModalContent").attr("title"),"#TB_inline?height=250&width=450&inlineId=hiddenModalContent", false);
					}
					else
					{
						// on renvoie le fichier
						parent.location.href = msg;

					}
				}
			},
			error:function(msg){       
				alert(msg.ResponseText);
			},
			beforeSend:function(){
				 tb_show_mask();
			}
		});  
	}
}


function ReloadSelecRegion(SelectName, SelectId, CodePays, lg, selectedValue)
	{

	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();
					if (selectedValue != ""){
						$("#" + SelectId +"").val(selectedValue);
						SearchDistrib();
					}
				}else{
					$("#" + SelectId +"").html("<option value=\"all\" selected>all</option>");
					$("#" + SelectId +"").hide();
					

					
					SearchDistrib();
				}
							   
			},
			error:function(msg){       
				alert(msg.ResponseText);
			},
			beforeSend:function(){
				   
			}
		});  
}

function LoadFormContact(Lang){

	if($("#typeDemande").val() == "newsletter"){
		return;
	}
	
	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 != ""){
				$("#ResultContact2").html(msg);
				$("#ResultContact2").show();               
			}else{
				$("#ResultContact2").hide();                                     
			}		   
			},
			error:function(msg)
			{       
				alert(msg.ResponseText);
			},
			beforeSend:function(){
				$("#ResultContact2").hide();     
			}
		}); 
	}
	$("#retourContact").hide();
}

function LoadFormNewsletter(Lang, email){
	
	$.ajax({
		type: "POST",   
		url: pathRacine + "_ajax/load_formNewsletter.asp",        
		data: "lang="+ Lang + "&email=" + encodeURIComponent(email),
		success: function(msg){   
		if(msg != ""){
			$("#ResultContact2").html(msg);
			$("#ResultContact2").show();
			if(email != "" && email != null){
				$("#news_email").val(unescape(email));
			}
		}		   
		},
		error:function(msg)
		{       
			alert(msg.ResponseText);
		},
		beforeSend:function(){
			$("#ResultContact2").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();
			});
			
			$("#TB_ajaxContent select").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 != ""){
						document.getElementById("hiddenModalContentUrl").innerHTML = 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 getExpression(lg, marqueur)
{
	$.ajax({
		type: "POST",   
		url: pathRacine + "_ajax/get_expression.asp",        
		data: "lang="+ lg +"&marqueur="+ marqueur,
		success: function(msg){   
			return msg;
		},
		error:function(msg){       
			alert(msg.ResponseText);
		}
	}); 	
}

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();
			}
		}		
		
	});
	
	$("select.required").each(function(){
		var presentValue = trim($(this).val());
		if(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];
    }
  } 
}

