nb_fois = 0;
arreter = 0;
var baseHrefJava = 'http://localhost/pique/';
//var baseHrefJava = 'http://pique.lempreintedutemps.com/';
	
// Create a directions object and register a map and DIV to hold the 
// resulting computed directions

function getDistance(pointB, itemid){
		// For this example I'll assume pointA and pointB are freeform addresses.
		var pointA = document.getElementById('codePostal'+itemid).value;
		var directions = "from: "+pointA+" to: "+pointB;

		// Initialize the GDirections class, load the directions
		gd = new GDirections(null,null);

		loader = gd.load(directions, {"locale" : "en_US"});

		// event listener
		GEvent.addListener(gd, "load", function(gd){

		// Grab the distance between point A and point B
		var distance = gd.getDistance().meters;
		distance = distance/1000;
		distance = distance.toFixed(1);

		var duration = gd.getDuration().html;
		var prixLivraison = (distance*0.70) + 10;
		prixLivraison = roundNumber(prixLivraison,2);
	   	document.getElementById('livraison'+itemid).value=prixLivraison+"$";
		//alert(distance + " " + duration);		
 
  		}
		)
}

//function onLoader
function roundNumber(rnum, rlength) {
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber;
}
	
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
return str;
}
/* CountDown Inversé */
timeOut = 0;
function countdown_clock(year, month, day, hour, minute, format, langue)
 {
 //I chose a div as the container for the timer, but
 //it can be an input tag inside a form, or anything
 //who's displayed content can be changed through
 //client-side scripting.
 html_code = '<div id="countdown" class="countdown"></div>';
 
 document.write(html_code);
 
 countdown(year, month, day, hour, minute, format, langue);                
 }
         
function countdown(year, month, day, hour, minute, format, langue)
 {
	 Today = new Date();
	 Todays_Year = Today.getFullYear() - 2000;
	 Todays_Month = Today.getMonth();                  
	 
	 //Convert both today's date and the target date into miliseconds.                           
	 Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
							 Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
	 Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
	 
	 //Find their difference, and convert that into seconds.                  
	 Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
	 
	 if(Time_Left <= 0)
	 {
		Time_Left = 0;
		window.location.reload();
		timeOut = 1;
	 }
		
	 
	 switch(format)
		   {
		   case 0:
				//The simplest way to display the time left.
				document.getElementById('countdown').innerHTML = Time_Left + ' seconds';
				break;
		   case 1:
				//More datailed.
				days = Math.floor(Time_Left / (60 * 60 * 24));
				Time_Left %= (60 * 60 * 24);
				hours = Math.floor(Time_Left / (60 * 60));
				Time_Left %= (60 * 60);
				minutes = Math.floor(Time_Left / 60);
				Time_Left %= 60;
				seconds = Time_Left;
				
				dps = 's'; hps = 's'; mps = 's'; sps = 's';
				//ps is short for plural suffix.
				if(days == 1) dps ='';
				if(hours == 1) hps ='';
				if(minutes == 1) mps ='';
				if(seconds == 1) sps ='';
				
				
				if(hours <= 9)
				{hours = '0'+hours;	}
				if(minutes <= 9)
				{minutes = '0'+minutes;	}
				if(seconds <= 9)
				{seconds = '0'+seconds;	}
				
				jours = "jours";
				if(langue == 'en')
				{
					jours = "days";
				}
				//alert(langue);
				document.getElementById('countdown').innerHTML = '<b>'+ days + '</b>' + jours + ' &nbsp; ';
				document.getElementById('countdown').innerHTML += '<b>'+hours + '</b> : ';
				document.getElementById('countdown').innerHTML += '<b>'+minutes + '</b> : ';
				document.getElementById('countdown').innerHTML += '<b>'+seconds + '</b>';
				break;
		   default: 
				document.getElementById('countdown').innerHTML = Time_Left + ' seconds';
		   }
		   
	 //Recursive call, keeps the clock ticking.
	if(timeOut<=0)
	{
		setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ',"' + langue + '");', 1000);
	}
 }

function getVars()
	{
		var info ="";
		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 );
			//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 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,itemID)
	{
		for (var a=1; a<=totalImages; a++)
			{
				document.getElementById("id"+itemID+a).style.display = 'none';
			}
	}
	function afficherImage(id,totalImages,itemID)
	{
		clearAllImgs(totalImages,itemID);		
		document.getElementById("id"+itemID+id).style.display = 'block';
		/*document.getElementById('img_centre').src = image;
		document.getElementById('img_centre').alt = imageName;
		document.getElementById('img_centre').title = imageName;
		*/
	}
	function changeImg(id,totalImages,itemID)
	{
		clearAllImgs(totalImages,itemID);
		document.getElementById("id"+itemID+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(id,fin)
	{	
		var lafleche = id + "_" +fin;
		//alert(lafleche);
		if(document.getElementById(id).style.display == 'block')
		{
			document.getElementById(lafleche).src=baseHrefJava+"images/"+fin+"-bas.gif";
			document.getElementById(id).style.display = 'none';
			
			
		}
		else
		{			//document.getElementById(lafleche).style.backgroundimage.src='images/fleche_haut.gif';

			document.getElementById(lafleche).src=baseHrefJava+"images/"+fin+"-haut.gif";
			document.getElementById(id).style.display = 'block';
			//alert(document.getElementById(lafleche).src);
		}
	}
	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;
	}
	