var fondDiv = false;
var dataDiv = false;
// Ajout a la newsletter
function addNewsletter(idForm) {
	
	if(!fondDiv){
		fondDiv = document.createElement('div');
		fondDiv.style.position = 'absolute';
		document.body.appendChild(fondDiv);
	}
	fondDiv.innerHTML = '';
	//alert(getHeight());

	$(fondDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '100%',
	   height: getScrollHeight(),
	   position: 'absolute',
	   opacity: '0.5',
	   overflow: 'hidden',
	   top: '0px',
	   left: '0px',
	   zIndex: '1500',
	   visibility: 'hidden'
	});

	if(!dataDiv){
		dataDiv = document.createElement('div');
		dataDiv.style.position = 'absolute';
		document.body.appendChild(dataDiv);
	}

	$(dataDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '300px',
	   height: '300px',
	   position: 'absolute',
	   border: '1px solid #000',
	   top: '50%',
	   left: '50%',	   
	   marginLeft: '-150px',	   
	   marginTop: (getScrollTop()-150) + 'px',	   	   	   
	   zIndex: '1600',
	   visibility: 'hidden'
	});	

	new Ajax(
		'/js/ajax/newsletter.php',
		{
			update: dataDiv,
			data:$(idForm).toQueryString(),
			onSuccess: function(req) {

					$$(fondDiv).setStyles({visibility: 'visible' });
					$$('select').setStyles({visibility: 'hidden' });
					$$(dataDiv).setStyles({visibility: 'visible' });
	
			},
			evalScripts: true
		}
	).request();		
	
	
	
}

function checkamis(on) {
	new Ajax(
		'/js/ajax/sendAmis.php',
		{
			method:'post',
			update: dataDiv,
			data:$('formamis').toQueryString(),
			onSuccess: function(req) {
				update:$('arrDebug')
			},
			evalScripts: true
		}
	).request();		
	

}


function sendAmisProduit(id) {

	if(!fondDiv){
		fondDiv = document.createElement('div');
		fondDiv.style.position = 'absolute';
		document.body.appendChild(fondDiv);
	}
	fondDiv.innerHTML = '';
	//alert(getHeight());
	$(fondDiv).onclick = function() { removeDiv(); };
	$(fondDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '100%',
	   height: getScrollHeight(),
	   position: 'absolute',
	   opacity: '0.5',
	   overflow: 'hidden',
	   top: '0px',
	   left: '0px',
	   zIndex: '1500',
	   visibility: 'hidden'
	});

	if(!dataDiv){
		dataDiv = document.createElement('div');
		dataDiv.style.position = 'absolute';
		document.body.appendChild(dataDiv);
	}

	$(dataDiv).setStyles({
	   backgroundColor: '#fff',
	   width: '400px',
	   height: '480px',
	   position: 'absolute',
	   border: '1px solid #000',
	   top: '50%',
	   left: '50%',	   
	   marginLeft: '-200px',	   
	   marginTop: (getScrollTop()-240) + 'px',	   	   	   
	   zIndex: '1600',
	   visibility: 'hidden'
	});	

	new Ajax(
		'/js/ajax/sendAmis.php',
		{
			update: dataDiv,
			data:"produit_id="+id,
			onSuccess: function(req) {

					$$(fondDiv).setStyles({visibility: 'visible' });
					$$('select').setStyles({visibility: 'hidden' });
					$$(dataDiv).setStyles({visibility: 'visible' });
	
			},
			evalScripts: true
		}
	).request();

}



function addLogin(idForm) {
	
	if(!fondDiv){
		fondDiv = document.createElement('div');
		fondDiv.style.position = 'absolute';
		document.body.appendChild(fondDiv);
	}
	fondDiv.innerHTML = '';
	//alert(getHeight());

	$(fondDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '100%',
	   height: getScrollHeight(),
	   position: 'absolute',
	   opacity: '0.5',
	   overflow: 'hidden',
	   top: '0px',
	   left: '0px',
	   zIndex: '1500',
	   visibility: 'hidden'
	});

	if(!dataDiv){
		dataDiv = document.createElement('div');
		dataDiv.style.position = 'absolute';
		document.body.appendChild(dataDiv);
	}

	$(dataDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '300px',
	   height: '300px',
	   position: 'absolute',
	   border: '1px solid #000',
	   top: '50%',
	   left: '50%',	   
	   marginLeft: '-150px',	   
	   marginTop: (getScrollTop()-150) + 'px',	   	   	   
	   zIndex: '1600',
	   visibility: 'hidden'
	});	

	new Ajax(
		'/js/ajax/login.php',
		{
			update: dataDiv,
			data:$(idForm).toQueryString(),
			onSuccess: function(req) {

					$$(fondDiv).setStyles({visibility: 'visible' });
					$$('select').setStyles({visibility: 'hidden' });
					$$(dataDiv).setStyles({visibility: 'visible' });
	
			},
			evalScripts: true
		}
	).request();		
	
	
	
}



function removeDiv()
{
	if(fondDiv){
		$(fondDiv).remove();
		fondDiv = false;
	}	
	if(dataDiv){
		$(dataDiv).remove();
		dataDiv = false;
	}
	$$('select').setStyles({visibility: 'visible' });		
}

function changeMenu(menu_id) {
	

	// On réinitialise tous les menus
	var main_menu_items = $$(".grandmenu");

	main_menu_items.each(function(item){
		var old_id = item.id;		
		
		$(old_id).style.backgroundColor="transparent";
		$(old_id).style.backgroundImage="url(/styles/images/header/onglet.png)";
		$(old_id).style.backgroundRepeat="no-repeat";
		$(old_id).style.backgroundPosition="bottom left";
		$(old_id).style.color="#55b0db";
		
		data = item.id.split('_');
		$("supermenu_a_"+data[1]).style.color="#55b0db";
	})
	

	// On active que celui qui nous interesse	
	if($("supermenu_"+menu_id)) {
		$("supermenu_"+menu_id).style.backgroundColor="transparent";
		$("supermenu_"+menu_id).style.backgroundImage="url(/styles/images/header/onglet_hover.png)";
		$("supermenu_"+menu_id).style.backgroundRepeat="no-repeat";
		$("supermenu_"+menu_id).style.backgroundPosition="bottom left";		
		
		$("supermenu_a_"+menu_id).style.color="#dfdfdf";
	}
	
	
	// Cas des sous menus
	// On initialise
	var main_menu_items = $$('.niveau2');
	
	main_menu_items.each(function(item){
		var old_id = item.id;		
		$(old_id).style.display="none";
	})		
	if($("sub_"+menu_id)) {
		$('noss').style.display="none";
		$('sub_'+menu_id).style.display="block";
	}else{
		$('noss').style.display="none";
	}
}

function change_reference(obj, etat) {
	if(etat==1) {
		$(obj).style.backgroundColor="#fff";
		$(obj).style.backgroundImage="url(/styles/images/reference/bordure.png)";
		$(obj).style.backgroundRepeat="no-repeat";
		$(obj).style.backgroundPosition="top left";			
	}else{
		$(obj).style.background="none";
	}
}




 

function infobulle(id, event){ 

		  if( window.event)
		    event = window.event;
			
			var x = event.clientX;
			var y = event.clientY;


document.getElementById('bulle').style.visibility = 'visible'; 
document.getElementById('bulle').style.left = (x+10)+"px"; 
document.getElementById('bulle').style.top = (y+20+getScrollTop())+"px"; 

txt = $("txt_"+id).innerHTML;
document.getElementById('bulle').innerHTML = txt;


//

} 

function infobulle_cache(){
	document.getElementById('bulle').style.visibility = 'hidden';
}


function changebordertext(name,etat) {
	if(etat) {
		name.style.border="green 1px solid";
	}else{
		name.style.border="red 1px solid";
	}
}

function VerifMail(value)
	{
	a = value;
	valide1 = false;
	
	for(var j=1;j<(a.length);j++){
		if(a.charAt(j)=='@'){
			if(j<(a.length-4)){
				for(var k=j;k<(a.length-2);k++){
					if(a.charAt(k)=='.') valide1=true;
				}
			}
		}
	}
	if(valide1==false) return false;
	return true;
	}




function verifForm(name, type, length) {	
	// TEXT
	if(type=="text") {		
		if(length==0 && name.value.length != 0) {
			changebordertext(name,true);
		}else{
			if(length > name.value.length || name.value.length == 0) {
				changebordertext(name,false);
			}else{
				changebordertext(name,true);
			}
		}
	}
	
	// MAIL
	if(type=="email") {		
		if(length==0 && name.value.length != 0) {
			if(VerifMail(name.value)) {
				changebordertext(name,true);
			}else{
				changebordertext(name,false);
			}
		}else{
			if(length > name.value.length || name.value.length == 0) {
				if(VerifMail(name.value)) {
					changebordertext(name,true);
				}else{
					changebordertext(name,false);
				}
			}else{
				changebordertext(name,true);
			}
		}		
	}
	
	
}




function init_menu(selected_section){
	
	var main_menu_items = $$('.sousmenu');
	//console.log(main_menu_items.length);
	
	main_menu_items.each(function(item){
			
			//console.log(item.id);		
			data = item.id.split('_');	
			
			if($('sub_' + data[1]))
			{
				submenu = $('sub_' + data[1]);
				
				var height_fx = new Fx.Style($('sub_' + data[1]),'height')
				var nb = $('sub_' + data[1]).getChildren().length
				
				//var Pos = $('supermenu_' + data[1]).getPosition();
				//$('submenuw_' + data[1]).style.left = Pos.x - 2 + 'px';
				
				//console.log('nb = ' + nb);		

			

				//--deb
				item.addEvent('mouseenter',function(e){
					//$$('input').setStyles({visibility: 'hidden' });
					item.addClass('active');


					e = new Event(e)
					
					// calculate the submenu new item
					height_fx.stop()
					height_fx.start(nb*27)
					//console.log('sdsd'+submenu.id);
					submenu.getChildren().each(function(submenu_item){
						//console.log('pwet');
						submenu_item.addEvent('mouseover',function(e){
							// change color
							//submenu_item.addClass('active');
							// end of submenu_item.addEvent('mouseover')
						})
						submenu_item.addEvent('mouseout',function(e){
							// change color
							//submenu_item.removeClass('active');
							// end of submenu_item.addEvent('mouseout')
						})
					})

					e.stop()
					// end of item.addEvent('mouseenter')
				})
				//--deb

				
				//--deb
				item.addEvent('mouseleave',function(e){
					item.removeClass('active');

					
					e = new Event(e)
					height_fx.stop()
					height_fx.start(0)
					// change color
					e.stop()

					//$$('input').setStyles({visibility: 'visible' });
					
					// end of item.addEvent('mouseleave')
				})
				//--deb


			} //ifsubmenu


			
		


	// end of each
	})
	
// end of function
}

function valider()
{
	a = confirm("Notre site est actuellement en construction, cliquez sur OK pour nous contacter");
	if(a)
		document.location.href='/contactez-nous.html';
}

function open_radio() {
	window.open("/radio.html","Ontours","menubar=no, status=no, scrollbars=no, menubar=no");
}


function loadphoto(urgi) {
	$('photoprod').src=urgi;
}






var fondDiv = false;
var dataDiv = false;
// Ajout au panier
function addPanier(idForm)
{
	if(!fondDiv){
		fondDiv = document.createElement('div');
		fondDiv.style.position = 'absolute';
		document.body.appendChild(fondDiv);
	}
	fondDiv.innerHTML = '';
	//alert(getHeight());

	$(fondDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '100%',
	   height: getScrollHeight(),
	   position: 'absolute',
	   opacity: '0.5',
	   overflow: 'hidden',
	   top: '0px',
	   left: '0px',
	   zIndex: '999999',
	   visibility: 'hidden'
	});

	if(!dataDiv){
		dataDiv = document.createElement('div');
		dataDiv.style.position = 'absolute';
		document.body.appendChild(dataDiv);
	}

	$(dataDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '395px',
	   height: '330px',
	   position: 'absolute',
	   border: '1px solid #000',
	   top: '50%',
	   left: '50%',	   
	   marginLeft: '-150px',	   
	   marginTop: (getScrollTop()-150) + 'px',	   	   	   
	   zIndex: '9999991',
	   visibility: 'hidden'
	});

	//alert($(idForm).toQueryString());

	new Ajax(
		'/js/ajax/panier-change.php',
		{
			update: dataDiv,
			data:$(idForm).toQueryString(),
			onSuccess: function(req) {

					$$(fondDiv).setStyles({visibility: 'visible' });
					$$('select').setStyles({visibility: 'hidden' });
					$$(dataDiv).setStyles({visibility: 'visible' });
	
					//new Ajax(
					//	'/js/ajax/updatePanier.php',
					//	{
					//		update: $('header_panier')
					//	}
					//).request();
					
			},
			evalScripts: true
		}
	).request();
}

function removeDivPanier()
{
	if(fondDiv){
		$(fondDiv).remove();
		fondDiv = false;
	}	
	if(dataDiv){
		$(dataDiv).remove();
		dataDiv = false;
	}
	$$('select').setStyles({visibility: 'visible' });		
}



function delParticipant(id) {
	new Ajax(
		'/js/ajax/delParticipant.php',
		{
			data:"id="+id,
			onSuccess: function(req) {
				location.href="/reservation_amis.html";
			},
			evalScripts: true
		}
	).request();
}

/*
function checkHebergement( num_id ,produit_hebergement_id ,obj) {
	//alert(produit_hebergement_id);

	
	new Ajax(
		'/js/ajax/addHebergement.php',
		{
			update: $('frais_hebergement'),
			data:"id="+num_id+"&produit_hebergement_id="+produit_hebergement_id+"&value="+obj.value,
			onSuccess: function(req) {
				
					new Ajax(
						'/js/ajax/updateprix.php',
						{
							update: $('prix_total')
						}
					).request();
								
				
			},
			evalScripts: true
		}
	).request();	
}


function checkAssurance( num_id ,produit_assurance_id ,obj) {
	//alert(produit_hebergement_id);
	new Ajax(
		'/js/ajax/addAssurance.php',
		{
			update: $('frais_assurance'),
			data:"id="+num_id+"&produit_assurance_id="+produit_assurance_id+"&value="+obj.value,
			onSuccess: function(req) {
					new Ajax(
						'/js/ajax/updateprix.php',
						{
							update: $('prix_total')
						}
					).request();				
			},
			evalScripts: true
		}
	).request();	
	
	
	
	
}

*/

function checkOptions( num_id ,produit_option_valeur2_id ,  produit_option_nom2 ,obj, produit_id) {


	new Ajax(
		'/js/ajax/addOptions.php',
		{
			update: $('prix_total'),
			data:"id="+num_id+"&produit_option_valeur2_id="+produit_option_valeur2_id+"&value="+obj.value+"&produit_option_nom2="+produit_option_nom2+"&produit_id="+produit_id,
			onSuccess: function(req) {
								
			},
			evalScripts: true
		}
	).request();	

	
}


function checkAssurance(num_id, etat) {

	new Ajax(
		'/js/ajax/checkAssurance.php',
		{
			update: $('prix_total'),
			data:"id="+num_id+"&etat="+etat,
			onSuccess: function(req) {
								
			},
			evalScripts: true
		}
	).request();	
	
}

var Interval;
//window.onload = wl;
var iScroll=0;

function diapoHome(param_scroll) {

	if(param_scroll==1 || param_scroll==2)	iScroll=param_scroll;
	if(iScroll>0)
	{
		pos_left = $('divs_prods').offsetLeft;
		//pos_left = pos_left.replace('px','');
		//pos_left=parseInt(pos_left);
		//if(pos_left=="NaN")	pos_left=0;
		
		if(iScroll==1)	pos_left-=2;
		else if(iScroll==2)	pos_left+=2;
		
		if(pos_left<0)
			$('divs_prods').style.left=pos_left + "px";
		
		setTimeout(diapoHome, 5);
	}
}

function stopdiapoHome()
{
	iScroll=0;
}

function changeOnglet(obj, name, etat) {
	
	var arr = obj.className.split(" ");
	
	if(arr[1]!="ongl_lock") {
		var varname="";
		
		varname=name;

		obj.className=varname;
	}
				
}

function loadOptions(produit_id, onglet_id, i){
	//alert(produit_id + " - " + onglet_id + " - " + i);
	
	// Traitement option ajax
	new Ajax(
		'/js/ajax/loadOptions.php',
		{
			update: $('table_option_'+i),
			data:"produit_id="+produit_id+"&onglet_id="+onglet_id,
			onSuccess: function(req) {
				
			},
			evalScripts: true
		}
	).request();		
}


var Interval;
//window.onload = wl;
var iScroll=0;
function defilegauche(param_scroll) {
	
	
	if(param_scroll==1)	iScroll=param_scroll;
	if(iScroll)
	{
		$('index_bloc_gris').scrollLeft+=100;
		setTimeout(defilegauche, 10);
	}
}

function defiledroite(param_scroll) {
	if(param_scroll==1)	iScroll=param_scroll;
	if(iScroll)
	{
		$('index_bloc_gris').scrollRight-=100;
		setTimeout(defiledroite, 10);
	}	
}



function showonglet(id) {

	for(i=1;i<=10;i++) {
		if($("onglet"+i))
			$("onglet"+i).className = "ongletgris ongl_unlock";
		
		if($('onglethide'+i))	$('onglethide'+i).style.display='none';
	}
	
	$("onglet"+id).className = "onglet ongl_lock";
	//var contenu = $('desconglet'+id).innerHTML;
	
	//contenu = contenu.replace("arrDebug","arrDebug2");
	//contenu = contenu.replace('contact_form','contact_form2');


	//$('resa_content').innerHTML = "";
	//$('resa_content').innerHTML = contenu;

	
	$('onglethide'+id).style.display='block';
	
}


function sendspecial(on) {
	new Ajax(
		'/js/ajax/sendSpecial.php',
		{
			method:'post',
			update:$('arrDebug'),
			data:$('contact_form').toQueryString(),
			onSuccess: function(req) {
			},
			evalScripts: true
		}
	).request();			

}

function showPrevisu(evenement_date, day) {
	new Ajax(
		'/js/ajax/showPrevisu.php',
		{
			method:'post',
			data:"evenement_date="+evenement_date,
			onSuccess: function(req) {
				if(req!="error") {
					$('previsu_calendrier').innerHTML = req;
					var xs = $('case'+day).offsetLeft;
					var ys = $('case'+day).offsetTop;
					xs = (xs-220);
					ys = (ys+108);
					
					$('previsu_calendrier').style.position = "absolute";

					$('previsu_calendrier').style.left = xs + "px";
					$('previsu_calendrier').style.top = ys + "px";
					
					$('previsu_calendrier').style.display="block";
					
					
				}
			},
			evalScripts: true
		}
	).request();			
}

function hidePrevisu() {
	$('previsu_calendrier').style.display="none";	
	$('previsu_calendrier').innerHTML = "";
}

function questionnaire(val) {
	if(val==0) {
		$('client_connaissance2').value="";
		$('pques').style.display = "none";
	}else if(val==1){
		$('client_connaissance2').value="";
		$('pques').style.display = "block";		
	}else if(val==2){
		$('client_connaissance2').value="";
		$('pques').style.display = "block";		
	}else if(val==3){
		$('client_connaissance2').value="";
		$('pques').style.display = "block";		
	}else if(val==4){
		$('client_connaissance2').value="";
		$('pques').style.display = "block";		
	}else if(val==5){
		$('client_connaissance2').value="";
		$('pques').style.display = "none";		
	}else if(val==6){
		$('client_connaissance2').value="";
		$('pques').style.display = "block";		
	}
}