nb_fois = 0;
arreter = 0;
nbStartPromo = 1;

timeOut = "";

//var baseHrefJava = 'http://localhost/alpharegul/';
var baseHrefJava = 'http://www.alpharegul.telordesign.com/';
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 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');
}
