var ROOT_HTML = "/";

function switch_product_categorie(categorie){
	for(i=0;i<=5;i++){
		if(i != categorie){
			$("categorie_produit_"+i).hide();
		}
	}

	$("categorie_produit_"+categorie).show();	
}


function load_product(cate,prod){
	

	switch_product_categorie(cate);
	
	if(prod != 0 && prod != "0"){
		var url = ROOT_HTML+'includes/pages/produits/produit_'+cate+'_'+prod+'.php';
				
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(result) {
		    $('fiche_produit').update(result.responseText + '<div class="clear"></div>');
		    $('fiche_produit').show();
		  }
		});
	}
}




function valid_form_login(){
		$('login').request({
		  method: 'post',
		  onSuccess: function(result){ 
		  		//alert(result.responseText)
				if(result.responseText != "true"){
					$('msgBox').update(result.responseText);
				}
				else{
					$('msgBox').update("");
					load_content(ROOT_HTML+"includes/header.php","header");
					window.open(ROOT_HTML+"livre_recettes.php");
					//myLightWindow.deactivate();
					window.location.href=window.location.href;
				}
			}
		})
}

function valid_form_mdp(){
	
		$('recup_mdp').request({
		  method: 'post',
		  onComplete: function(result){ 
		  		//alert(result.responseText)
				if(result.responseText != "true"){
					$('msgBox').update(result.responseText);
				}
				else{
					$('msgBox').update(result.responseText);
					open_window_mdp_end();
				}
			}
		})
}


function valid_form_inscription(){
		
			$('formulaire').request({
			  method: 'post',
			  onComplete: function(result){ 
					//alert(result.responseText)
					if(result.responseText != "true"){
						//open_window_login();
						$('msgBox').update(result.responseText);
						//alert("Cette adresse est déjà existante.");
						
					}
					else{
						//open_window_login();
						$('msgBox').update(result.responseText);
						open_window_inscription_end();
					}
				}
			})
		
}


function valid_form_contact(){

$('formulaire').request({
			  method: 'post',
			  onComplete: function(result){ 
					//alert(result.responseText)
					if(result.responseText != "true"){
						//open_window_login();
						$('msgBox').update(result.responseText);
					}
					else{
						//open_window_login();
						$('msgBox').update("");
						Effect.toggle('form_contact', 'slide');
						Effect.toggle('validation_mail', 'slide');
					}
				}
			})
	
}



function load_content(page,div){
	
	new Ajax.Request(page, {
	  method: 'get',
	  onSuccess: function(result) {
		$(div).update(result.responseText);
	  }
	});

		
}

function simple_call(page){	
	new Ajax.Request(page, {method: 'get'});		
}



function close_session(){
	new Ajax.Request(ROOT_HTML+'webServices.php?deconnexion=true', {
	  method: 'get',
	  onSuccess: function(result) {
		load_content(ROOT_HTML+"includes/header.php","header");
		window.location.href=window.location.href;
	  }
	});
	
}



// Ouverture !
function open_window_inscription_end(){
	myLightWindow.activateWindow({
		href: ROOT_HTML+'includes/form_inscription_end.php',
		type:'page',
		width:400,
		height:200
	});
}

function open_window_mdp(){
	myLightWindow.activateWindow({
		href: ROOT_HTML+'includes/form_mdp.php',
		type:'page',
		width:520,
		height:320
	});
}

function open_window_mdp_end(){
	myLightWindow.activateWindow({
		href: ROOT_HTML+'includes/form_mdp_end.php',
		type:'page',
		width:400,
		height:200
	});
}


function open_window_login(){
	myLightWindow.activateWindow({
		href: ROOT_HTML+'includes/form_login.php',
		type:'page',
		width:520,
		height:370
	});
}

function open_window_inscription(key){
	myLightWindow.activateWindow({
		href: ROOT_HTML+'includes/form_inscription.php?key_user='+key,
		type:'page',
		width:780,
		height:590
	});
}

//_____________ RECETTES _______________

function over_recette(num,key,vignette){
	$('recette_num_'+num).setStyle({backgroundColor: '#47adc9',color:'#FFFFFF'});
	if(vignette != "false"){
		new Tip('recette_num_'+num, '<img style="width:200px; height:161px;" src=\'/images/recettes_candia/vignettes/'+key+'.jpg\'/>',{delay: 0.3,effect: 'appear'});
	}	
}

function out_recette(num,key){
	bgColor = (num%2 == 1)?"#daeff4":"#ffffff";
	$('recette_num_'+num).setStyle({backgroundColor: bgColor,color:'#666666'});
	//new Tip('recette_num_'+num, '<img src=\'/images/recettes_candia/vignettes/'+key+'.jpg\'/>',{delay: 0.3});	
}

function click_recette(url){
	window.location.replace(url);
}



function showHide(){
	$('table_1').hide();
	$('table_2').show();	
}

function hideShow(){
	$('table_2').hide();
	$('table_1').show();	
}