Cufon.replace('.main_menu a', {'hover': true, fontFamily: 'Bodoni BE'}); 

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

timeOut = "";


  // plain JavaScript example
  function jsonpCallback(data) { 
    return data.address.country; 
  }

	
var canDo = false;

        /** plugin @author: http://www.webinventif.fr/wslide-plugin/ */
//var clone = $("#promo_flash").clone(true);
//alert(clone.attr('id'));

$(document).ready(function(){

	$('.box_selection #color').change(function(){
		lenum = $(this).val();
		if($('.img_'+lenum).length)
		{
			$('.item_left div:not(.autres_images,.autres_images *)').css('display','none');
			
			$('.img_'+lenum+":first").fadeIn(500, function() {
			// Animation complete
		  });
		}
		
	});
		
	  $('.promo_thumb a').click(function(){
		canDo = true;
		
			if($("#promo_flash").is("object"))
			{
				
				setTimeout(function() {
				 $("#promo_flash").remove();
				 $(".promo_flash_holder").append($("#promo_flash_tmp").removeClass("hide"));
				}, 500);

			}
		})/*.mouseout(function(){
			canDo = true;
		});*/

		$("#promo_images").wslide({
			width: 707,
			height: 309,
			autolink: false,
			fade: true,
			duration: 400
		});
		
		$.timer(6000, function (timer) {
			if(canDo){
				if($('.promo_thumb a#last').hasClass('wactive')){
					$('.promo_thumb a#first').click();
					//$(".promo_flash_holder").html(clone);
					
				}else{
					//alert($('.promo_thumb a.wactive').next().attr('href'));
					$('.promo_thumb a.wactive').next().click();
					//alert(clone);
				}
			}
		 });
	});


//var baseHrefJava = 'http://localhost/kollontai/';
var baseHrefJava = 'http://www.kollontai.net/';
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 checkQte(color,grandeur,inforepeat)
{
	
	var laqte = eval("color"+inforepeat+color)[grandeur];
	//alert(inforepeat);
	if(laqte<=0)
	{
		laqte=0;
	}
	window["actualQte"+inforepeat] = laqte;
	validQte(document.getElementById("qte"+inforepeat).value,inforepeat);
}
function validQte(qte,inforepeat)
{
	//alert(window["actualQte"+inforepeat]+"test");
	if(qte>window["actualQte"+inforepeat])
	{
		document.getElementById("qte"+inforepeat).value = window["actualQte"+inforepeat];
		alert("La quantité maximale est "+window["actualQte"+inforepeat]);
	}
}
function showDims(colorID,inforepeat)
{
	for(a=1; a<=100; a++)
	{
		if(document.getElementById("dimension"+inforepeat+a))
		{
			document.getElementById("dimension"+inforepeat+a).style.display="none";
		}
	}
	//alert(colorID);
	document.getElementById("dimension"+inforepeat+colorID).style.display="inline";
}
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='inline-block';
	}
	else
	{
		document.getElementById('province').style.display='inline-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++)
			{
				alert("id"+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)
	{
		$('.item_left div:not(.autres_images,.autres_images *)').css('display','none');
		//document.getElementById("id"+id).style.display = 'block';
		$('#id'+id).fadeIn(500, function() {
        // Animation complete
      });

	};
	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(totalItems)
	{
		document.getElementById("chaletstart").style.display = 'none';
		for (var a=1; a<=totalItems; a++)
			{				
				document.getElementById("chalet"+a).style.display = 'none';
			}
	}
	function aff_hebergement(id,totalItems)
	{
		clearAllDivs(totalItems);
		document.getElementById(id).style.display = 'inline';
	}
	function hebergement_img(image,alt,num)
	{			
		image_src = base + "gros_img_chalet/" + image + ".jpg";
		document.getElementById('heb_big_img'+num).src = image_src;		
		document.getElementById('heb_big_img'+num).alt = alt;
		document.getElementById('heb_big_img'+num).title = alt;
	}
	function isset(varname){
  return(typeof(window[varname])!='undefined');
}
