$(document).ready(function()
{
    $("#loading").bind("ajaxSend", 
		function (){
			$("#loading").fadeIn();
		}).bind("ajaxComplete", 
			function (){
				$("#loading").fadeOut();
			});
    
	$("#loading").hide();
});

function loadContent(p, s, id, vars)
{
	if(vars == undefined)
		vars = '';
	
	var x;
	var y = 0;
	
	//alert(p+", "+s+", "+id+", "+vars);
	
	if(id!="div#noticias")
	{
		//menu "selected"
		x = s;
		if(s=="produits")
		{
			x = s+"_"+vars.replace("padre=", "");	
			y = 1;
		}

		$('li.menu_selec').removeClass("menu_selec");	
		$('li#m_'+x).addClass("menu_selec");
		//alert(x);
		
		
		//cambia el titulo de top right
		if(y==1)
			$("div#title_right").load("top_right/produits.php");
		else if(s=="realisations")
			$("div#title_right").load("top_right/realisations.php");
		else
			$("div#title_right").load("top_right/actualites.php");
		
	}	
	$(id).load(p+"/"+s+".php?"+vars);
}

function toggleContent(id)
{
	$(id).toggle();	
}

function hideContent(id)
{
	$(id).hide();	
}

function showContent(id)
{
	$(id).show();	
}

function toggleImage()
{
	$('#thick_img_1').toggle();
	$('#thick_img_2').toggle();
}

function sendContact(f)
{
	var email = f.email.value;
	var message = f.message.value;
	var nom = f.nom.value;	
	var entreprise = f.entreprise.value;
	
	var error = 0;
	
	if(email=="")
	{
		alert(LANG_MAIL + LANG_ERR);
		error++;	
	}
	if(message=="")
	{
		alert(LANG_MESS + LANG_ERR);
		error++;	
	}	
	if(entreprise=="")
	{
		alert(LANG_ENT + LANG_ERR);
		error++;	
	}	
	if(nom=="")
	{
		alert(LANG_NOM + LANG_ERR);
		error++;	
	}	
	
	if(error==0)
	{
		$("div#dos").load("sys/contact.php?email="+email+"&message="+message+"&entreprise="+entreprise+"&nom="+nom);
		//alert("mandamos");
	}
}

function sendConseil(f)
{
	var email = f.email.value;
	var message = f.message.value;
	var ref = f.ref.value;
	var tlf = f.tlf.value;
	if(email=="")
		alert(LANG_MAIL + LANG_ERR);
	else
		$("div#conseils_form").load("sys/conseils.php?email="+email+"&message="+message+"&ref="+ref+"&tlf="+tlf);
}

function sendRecommend(f)
{
	var email = f.email.value;
	var message = f.message.value;
	var id = f.id.value;	
	if(email=="")
		alert(LANG_MAIL + LANG_ERR);
	else
		$("div#recommend").load("sys/recommend.php?email="+email+"&message="+message+"&id="+id);
}

function sendNewsletter(f)
{	
	var nom = f.nom.value;
	var fonction = f.fonction.value;
	var email = f.email.value;
	var adresse = f.adresse.value;
	var cp = f.cp.value;
	var tlf = f.tlf.value;
	var fax = f.fax.value;
	//$("div#TB_ajaxContent").load("sys/newsletter.php?nom="+nom+"&fonction="+fonction+"&email="+email+"&adresse="+adresse+"&cp="+cp+"&tlf="+tlf+"&fax="+fax);
	//$("div#TB_ajaxContent").
	$.ajax({
		type: "POST",
		url: "mailing/index.php/outer/newsletter",
		data: "&nom="+nom+"&fonction="+fonction+"&email="+email+"&adresse="+adresse+"&cp="+cp+"&tlf="+tlf+"&fax="+fax
		});
}

function imprimir()
{
	tb_remove();	
	setTimeout('window.print()', 1000);		
}