Cufon.replace('#menu a, h1, h2, .fleche, .niveau_item .bloc1 h2, .content_realisations .right h2, .content_service-conseil .right, .cufon_text, .header_product .right a, .ref_principales table th', {'hover': true, fontFamily: 'DIN-Regular'}); 

ie7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
ie8 = (navigator.appVersion.indexOf("MSIE 8.")==-1) ? false : true;

nb_fois = 0;
arreter = 0;
nbStartPromo = 1;

timeOut = "";

$(window).resize(function() {
	ecran = $(window).height();
	resizeContent(ecran);					  
});
$(function(){
	
	if(mode=="")
	{
		ecran = $(window).height();
		resizeContent(ecran);
		//alert($(".content_produits .bloc").width());
		
		if(!ie7 && (laCat<14 || laCat>16))
		{
			//alert('test');
			$(".content_accueil	.bloc, .cat_0 .bloc").css({"float":"none"});
			//alert($(".content_accueil .bloc").css('float'));
		}
		$(".menu_produits a").hover(
			function(){
			$("#id"+$(this).attr('id')).addClass("fleche_hover");
			Cufon.refresh();
		},
		function(){
			$("#id"+$(this).attr('id')).removeClass("fleche_hover");
			Cufon.refresh();
		}
		
		);
		//alert('test');
		$('.content_produits:not(.cat_0), .content_liens-utiles, .content_telechargement').children().masonry({
			singleMode: false,
			itemSelector: '.bloc',
			columnWidth: 1,
			isFitWidth: false,
			isAnimated: true,
			//cornerMaskSelector: '.corner-mask',
			animate:true
		});
		
		leText=" ";
		$("#contact_pays").change(function(){
			//alert($(this).attr('value'));							  
			lavalue = $(this).attr('value');
			$(".resultats_fournisseurs div").fadeTo(300, 0).css({"display":"none"});
			$(".departements select").fadeTo(300, 0).css({"display":"none"});
			
			if(lavalue=="france" || lavalue=="allemagne")
			{
				$(".departements #"+lavalue+"_departements").fadeTo(300, 1);
			}
			else
			{
				$(".departements select").fadeTo(300, 0).css({"display":"none"});
				$(".resultats_fournisseurs #"+lavalue+"_fournisseur").fadeTo(300, 1);
			}
			
		});
		$(".pays_departement").change(function(){
			
			lavalue=$("#contact_pays").attr('value');
			if(lavalue=="france")
			{
				//alert('test');
				arrayPays=new Array(new Array(75,77,78,91,92,93,94,95), new Array(3,15,19,23,43,63,87), new Array(22,29,35,44,49,53,56,72,79,85,86), new Array(16,17,24,33,40,47,64), new Array(25,52,54,55,57,67,68,88,90),new Array(9,11,12,31,32,46,48,65,66,81,82),
				new Array(2,8,51,59,60,62,80),new Array(4,5,6,13,20,30,34,83,84),new Array(1,7,26,38,42,69,73,74),new Array(14,27,50,61,76),new Array(18,28,36,37,41,45),new Array(10,21,39,58,70,71,89));
				//alert($("#contact_departement").attr('value'));
			}
			else if(lavalue=="allemagne")
			{
				arrayPays=new Array(new Array(70,71,72,73,74,75,77,78,79,88,89),new Array(1,2,3,4,5,6,7,8,9,10,12,13,14,15,98,99),new Array(34,35,36,60,61,63,64,65),new Array(40,41,42,44,45,46,47,48,49,50,51,52,53,56,57,58,59),new Array(54,55,66,67,68,69,76),new Array(16,17,18,26,27,28,29,30,31,32,33,37,38,39,80,81,82,83,84,85,86,87,90,91,92,93,94,95,96,97),new Array(19,20,21,22,23,24,25));			
			}
				
			$("#"+$("#contact_pays").attr('value')+"_fournisseur div").fadeTo(300, 0).css({"display":"none"});
			$(".resultats_fournisseurs div").css({"display":"none"});
			$(".resultats_fournisseurs #"+lavalue+"_fournisseur").fadeTo(0, 1).css({"display":"inline"});
			
			for (key in arrayPays)
			{
				//alert(arrayFrance[key].length);
				countArray = arrayPays[key].length;
				for(d=0;d<countArray;d++)
				{
					if(arrayPays[key][d]==$("#"+$("#contact_pays").attr('value')+"_departements").attr('value'))
					{
						
						lenum = key*1+1;
						//alert("#"+$("#contact_pays").attr('value')+"_fournisseur #dep"+lenum);
						$("#"+$("#contact_pays").attr('value')+"_fournisseur #dep"+lenum).fadeTo(300, 1);
					}
				}
				
			}
			
			
			
		});
		
		if (document.images)
		{
		  preload_image_object = new Image();
		  // set image url
		  image_url = new Array("images/home/home-1.jpg","images/home/home-2.jpg","images/home/home-3.jpg","images/home/home-4.jpg","images/home/home-5.jpg","images/home/home-6.jpg","images/home/home-7.jpg"
								,"images/home/home-8.jpg");
		   var i = 0;
		   nummax = image_url.length;
		   for(i=0; i<=nummax; i++) 
			 preload_image_object.src = image_url[i];
		}
	
		
		
		$('.slide').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,
		transitionSpeed:750,
		displayProgressBar:0,
		displayThumbnails:1,
		displayThumbnailBackground:0
		});
			
		if(leType==1)
		{
			$("#thumb_1").addClass('active');	
		}
		//alert(ecran);
		ecran =  $(window).width();
		//alert(ecran);

		
		
	}
	//alert($(".text .bloc").width());
});
function resizeContent(ecran)
{
	if(mode=="")
	{
		
	pos = $(".main").offset(); 
	//alert(pos.top);
	//alert(ecran+" - "+pos.top+" - "+$('.footer').height());
	//alert(paddings);
	leHeight = ecran-pos.top-$('.footer').height()-paddings;
	
	/*
	if($('.text').innerHeight()<=leHeight)
	{
		*/
		if(!ie7 && !ie8)
		{
			
			if((leType==5 && laCat!=0) || leType==10)
			{
				$('.text').css('min-height',leHeight+'px');
			}
			else if(leType == 5 && laCat==0)
			{
				leHeight += 17;
				$('.main').css('height',leHeight+'px');		
			}
			else
			{
				$('.main').css('height',leHeight+'px');	
				
			}
			
		}
		else
		{
			leHeight = leHeight-15;
			if(leType==1 || (leType==5 && laCat==0))
			{
				
				$('.main .text .bloc').css('height',leHeight+'px');	
			}
			$('.text').css('min-height',leHeight+'px');
			//alert ($('.main').css('min-height'));
		}

		
	}		
	//}
	//$('.main').css('min-height',$('.text').height()+'px');
	
	
}
function selected(leid,lavalue)
{
	var formSelect = document.getElementById(leid);
	total = formSelect.length;
	//alert();
	
	for(var a=0; a<total; a++)
	{
		if(formSelect.options[a].value == lavalue)
		{
			formSelect.selectedIndex = a;
			//formSelect.options[a].selected = true;
		}
	}
}
function qsValue(findName) {
  var name = new String();
  var value = new String();
  var querystring = document.location.href;

  if(querystring.indexOf("?")==-1) {
    return "null";
  }

  querystring = querystring.split("?");
  querystring = querystring[1].split("&");

  for(q=0; q<querystring.length; q++) {
    var pair = querystring[q].split("=");
    name = pair[0].toLowerCase();
    value = pair[1].toLowerCase();

    if(findName.toLowerCase() == name) {
      return value;
    }

  }
}

function checkLivraison(radioObj)
{
	if(radioObj.value != '')
	{
		num = "prix_livraison"+radioObj.value;
		document.getElementById('final_livraison_prix').value=document.getElementById(num).value ;
	}	
}

function submitForm(f)
{
	//https://www.paypal.com/ca/cgi-bin/webscr
	f.action = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
	f.submit();

}
function submitBothForms(f)
{
	//https://www.paypal.com/ca/cgi-bin/webscr
	formFinal = document.forms[f];
	formFinal.submit();
/*
	formFinal.action = lien2;
	formFinal.submit();
	*/
}
function afficherDiv(leid,lename)
{
	nbPaysProvince = 3; /* Comprenant le champ input */
	document.getElementById("CA").style.display = 'none';
	document.getElementById("US").style.display = 'none';
	document.getElementById("province").style.display = 'none';
	
	document.getElementById("CA").name = 'none';
	document.getElementById("US").name = 'none';
	document.getElementById('province').name="none";
	
	if(document.getElementById(leid))
	{
		document.getElementById(leid).name=lename;
		document.getElementById(leid).style.display='block';
	}
	else
	{
		document.getElementById('province').style.display='block';
		document.getElementById('province').name=lename;
	}
	
}
function Attendre()
{									

	var string="yeah();";		
	var duree= (12000);
	timeOut = setTimeout(string,duree);												
}

function yeah(temp)
{					

	clearTimeout(timeOut);
	if(arreter<=0)
	{
		//alert(totalImages);
		//alert(nbStartPromo);
		
		if(nbStartPromo>nbPromo)
		{
			nbStartPromo=1;
		}
			
		//alert(nb_fois);
		for (var a=1; a<=nbPromo; a++)
		{				
			//alert(document.getElementById("id"+a).style.display);
			document.getElementById("id"+a).style.display = 'none';
			if(document.getElementById("id_info"+a) != null)
			{
			document.getElementById("id_info"+a).style.display = 'none';
			}
		}
		
		document.getElementById("id"+nbStartPromo).style.display = 'block';
		if(document.getElementById("id_info"+a) != null)
			{
		document.getElementById("id_info"+nbStartPromo).style.display = 'block';
			}
		nbStartPromo +=1;	
		Attendre();										
	}		

}


function position(select_type)
{
	leType = 'positionType'+select_type;	
	leChangedType = document.getElementById(leType).value;
	if(leChangedType > leType)
	{
		for (a=1; a<=leChangedType; a++)
		{
			newSelect_type = document.getElementById('positionType'+a).value - 1;
			document.getElementById('positionType'+a).options[newSelect_type-1].selected = true;
		}		
	}
	else if(leChangedType < leType)
	{
		for (a=1; a<=leChangedType; a++)
		{
			newSelect_type = document.getElementById('positionType'+a).value - 1;
			document.getElementById('positionType'+a).options[newSelect_type-1].selected = true;
		}		
	}
	
}

function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
return str;
}
function bouclePromo()
{
		
}
function promo(leNum)
{

	for (var a=1; a<=nbPromo; a++)
	{				
		document.getElementById("promo"+a).style.display = 'none';
	}
	clearTimeout(timeOut); 
	document.getElementById("promo"+leNum).style.display = 'block';
	nbStartPromo = leNum;
	yeah();
}
function getVars()
	{
		var info ="";
		
		if(location.href.indexOf('?Erreur=') != -1 || location.href.indexOf('&Erreur=') != -1)
		{
			
			if(location.href.indexOf('?Erreur=') != -1)
			{
				var laVar = location.href.substring(location.href.indexOf('?Erreur=') +8, location.href.length);
				var laLangue = location.href.substring(baseHrefJava.length, baseHrefJava.length + 2 );
			}
			else
			{
				var laVar = location.href.substring(location.href.indexOf('&Erreur=') +8, location.href.length);
				var laLangue = location.href.substring(location.href.indexOf('?lang=') +6, location.href.indexOf('?lang=') +8);
			}

			//alert(laLangue);
			//alert(laLangue);
			if(laLangue == "fr")
			{
				if(laVar == "login")
				{
					info = "Problème de connexion: mot de passe ou utilisateur incorrect";
				}
				if(laVar == "exp")
				{
					info = "Vous avez tentez d'accèder à l'administration et le temps est écoulé";
				}
				if(laVar == "vide")
				{
					info = "Vous devez entrer votre nom d'utilisateur et votre mot de passe";
				}
			}
			else
			{
				if(laVar == "login")
				{
					info = "Connexion problem: incorrect password or user";
				}
				if(laVar == "exp")
				{
					info = "You tried to access to the administration section but the time as expired";
				}
				if(laVar == "vide")
				{
					info = "You have to enter your user and password";
				}
			}
		}
		return info;
	}
function pages(adress){
	
		window.open(adress,"_self");	
	}
	function clearAllImgs(totalImages)
	{
		for (var a=1; a<=totalImages; a++)
			{
				document.getElementById("id"+a).style.display = 'none';
				if(document.getElementById("id_info"+a) != null)
				{
				document.getElementById("id_info"+a).style.display = 'none';
				}
			}
	}
	function afficherImage(id,totalImages,itemID)
	{
		
		clearAllImgs(totalImages);
		clearTimeout(timeOut); 
		document.getElementById("id"+id).style.display = 'block';
		if(document.getElementById("id_info"+id) != null)
		{
			document.getElementById("id_info"+nbStartPromo).style.display = 'block';
		}
		nbStartPromo = id;
		yeah();
	}
	function changeImg(id,totalImages,itemID)
	{
		clearAllImgs(totalImages);
		document.getElementById("id"+id).style.display = 'block';
	};
	function retourneImage()
	{
		/* Retourne le NOM de l'image dans le URL 
		
		if(location.href.indexOf('#') != -1 && location.href.indexOf('&') != -1 && location.href.indexOf('#id') == -1)
		{
		var lesrc = location.href.substring(location.href.indexOf('#') +1, location.href.indexOf('&'));
		var leEt = location.href.substring(location.href.indexOf('&') +1, location.href.length);
		var lesrc = lesrc.toString();

		clearAllImgs(leEt,lesrc);	
		

		var leId = "id"+document.images[lesrc].id;
		document.getElementById(leId).style.display = 'block';
		}
		*/
		/* Retourne le ID de l'image dans le URL */
		/*
		if(location.href.indexOf('#id') != -1)
		{
			var leId = location.href.substring(location.href.indexOf('#') +1, location.href.indexOf('&'));
			var itemID = location.href.substring(location.href.indexOf('#') +3, location.href.indexOf('&')-1);
			var leEt = location.href.substring(location.href.indexOf('&') +1, location.href.length);

			clearAllImgs(leEt,itemID);	
			document.getElementById(leId).style.display = 'block';
		}
		else if(location.href.indexOf('photos') != -1)
		{
			//document.getElementById("id1").style.display = 'block';
		}
		*/
	}
	function openFormLog(laBase)
	{
		if(document.getElementById('formlog').style.display=='inline')
		{
			document.getElementById('formlog').style.display='none';
		}
		else
		{
			document.getElementById('formlog').style.display='inline';
		}		
		
		var newImg = '';
		if(document.getElementById('imgLog').src==laBase+'images/fleche_bas_right.gif')
		{
			newImg =laBase+'images/fleche_haut_right.gif';
		}
		else
		{
			newImg =laBase+'images/fleche_bas_right.gif';
		}
		document.getElementById('imgLog').src = newImg;
	}
	
	function openDesc(base,id)
	{	
		var lacolor="black";
		var lafleche = id + "_fleche";
		//alert(document.getElementById(lafleche).src);
		if(document.getElementById(id).style.display == 'block')
		{

			document.getElementById('show_hide_'+id).style.backgroundImage="url('"+base+"images/"+lacolor+"_arrow_show.png')";
			document.getElementById(id).style.display = 'none';
		}
		else
		{
			document.getElementById('show_hide_'+id).style.backgroundImage="url('"+base+"images/"+lacolor+"_arrow_hide.png')";
			document.getElementById(id).style.display = 'block';
		}
	}
	function openId(id)
	{	
		if(document.getElementById(id).style.display == 'block')
		{
			document.getElementById(id).style.display = 'none';
		}
		else
		{
			//document.getElementById(lafleche).style.backgroundimage.src='images/fleche_haut.gif';
			document.getElementById(id).style.display = 'block';
		}
	}
	
	
	/* Hébergement */
	//var total_hebergement = 21;
	var base = "http://localhost/chezrainville/photos/";

	
	function clearAllDivs(name,totalItems)
	{
		for (var a=1; a<=totalItems; a++)
		{				
			document.getElementById(name+a).style.display = 'none';
		}
	}
	function nextBloc(id,name,totalItems)
	{
		valid=true;
		if(name=='bloc')
		{
			etape= id-1;
			if(etape>=1)
			{
				valid = valid_consultation(etape);
			}
			//alert(valid);
		}
		if(valid==true)
		{
			clearAllDivs(name,totalItems);
			document.getElementById(name+id).style.display = 'block';
		}
	}
	
	function isset(varname){
  return(typeof(window[varname])!='undefined');
}
