$(document).ready(function() {
	
	// Gestion du slide d'informations
	if ($('#msg_slide').size() > 0) {
		$('<div>', { html: $('#msg_slide').detach().html() }).slide();
	}
	
	// pop-up pour l'abonnement à la newsletter
	$('#callme').click(function() {
		loadPopUp('ctn_callme','form_callme');
	});
	
	// fonction de remplissage de la popup
	function loadPopUp(id_contenu, load_file) {
		var load_file_protect = load_file.replace('..','');
		load_file_protect = load_file_protect.replace('/','');
		$('<div>', {
			'class': 'ctn_popup',
			'id': id_contenu	
		}).slide({ 'border_color': '#808080' });
		$('#'+id_contenu).load('./pages/'+load_file_protect+'.php', function(response, status, xhr) {
			if(status == 'error') {
				var msg = "<p>Une erreur a été rencontrée : "+xhr.status+" "+xhr.statusText+'</p>';
				$('#'+id_contenu).html(msg);
			}
		});
	}
	
	$('#bandeau_head').innerfade({ speed: 'slow', timeout: 8000, type: 'sequence', containerheight: '145px' });
	mainmenu();
	
	$('.ref_web_site').attr('target','_blank');

	function mainmenu(){
		$("ul#subnav_sol").parent().append("<span class=\"png_bg\"></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
		$("<span class=\"png_bg\"></span>").insertBefore("h2#sec_h"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
		
		$("ul.topnav li span").click(function() { //When trigger is clicked...
			
			//Following events are applied to the subnav itself (moving subnav up and down)
			$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
	
			$(this).parent().hover(function() {
			}, function(){	
				$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			});
	
			//Following events are applied to the trigger (Hover events for the trigger)
			}).hover(function() { 
				$(this).addClass("subhover"); //On hover over, add class "subhover"
			}, function(){	//On Hover Out
				$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		});
	}	
});

var externalLinks=function(){
	if( !document.getElementsByTagName ){
		return;
	}
	var anchorList=document.getElementById('div_logo').getElementsByTagName('A');
	for(var i=0,anchor;anchor=anchorList[i];i++){
		if( anchor.href != 'javascript:void(0);'){
			anchor.target='_blank';
		}
	}
};
window.onload=externalLinks;

/*function montre(id_elt) {
	var ssm = getElementsByClassName('detail_menu');
	if(ssm) {
		var nb_ssm = ssm.length;
		for (var i = 0; i<nb_ssm; i++) {
			if(ssm[i].id != id_elt) {
				$('#'+ssm[i].id).hide('slow');
			}
		}
	}
	$('#'+id_elt).show('slow');
}*/

function mref(obj) {
	var div1=document.getElementById(obj);
	if(div1) {
		div1.style.visibility='visible';
	}
}

function cref(obj) {
	var div1=document.getElementById(obj);
	if(div1) {
		div1.style.visibility='hidden';
	}
}

function montre(id) {
var d = document.getElementById(id);
if (d) {
	d.style.visibility='visible';
	d.style.display = 'block';
	d.style.zIndex = 40;
	}
}


function cache(id) {
var d = document.getElementById(id);
if (d) {
	d.style.visibility='hidden';
	d.style.display = 'none';
	d.style.zIndex = 10;
	}
}

function montre_actu(id_elt) {
	var d = document.getElementById(id_elt);
	if (d) {
		d.style.display = 'block';
		d.style.zIndex='40';
	}
}


function cache_actu(id_elt) {
	var d = document.getElementById(id_elt);
	if (d) {
		d.style.display = 'none';
	}
}

function verif_contact()
{
var strTexte=" Veuillez remplir tout les champs\n";
var good="1";

if (document.form_contact.nom_contact.value=="")
{
document.form_contact.nom_contact.style.border="solid 2px red";
document.form_contact.nom_contact.style.color="#FFFFFF";
document.form_contact.nom_contact.style.backgroundColor="#CCCCCC";
good="0";
}
else
{
document.form_contact.nom_contact.style.border="solid 1px gray";
document.form_contact.nom_contact.style.color="black";
document.form_contact.nom_contact.style.backgroundColor="#FFFFFF";
}

if (document.form_contact.prenom_contact.value=="")
{
document.form_contact.prenom_contact.style.border="solid 2px red";
document.form_contact.prenom_contact.style.color="#FFFFFF";
document.form_contact.prenom_contact.style.backgroundColor="#CCCCCC";
good="0";
}
else
{
document.form_contact.prenom_contact.style.border="solid 1px gray";
document.form_contact.prenom_contact.style.color="black";
document.form_contact.prenom_contact.style.backgroundColor="#FFFFFF";
}

if (document.form_contact.email_contact.value=="")
{
document.form_contact.email_contact.style.border="solid 2px red";
document.form_contact.email_contact.style.color="#FFFFFF";
document.form_contact.email_contact.style.backgroundColor="#CCCCCC";
good="0";
}
else
{
	var email = document.form_contact.email_contact.value; 
	if (email.search(/^[_a-z0-9-]+(.[_a-z0-9-]+)*[^._-]@[a-z0-9-]+(.[a-z0-9]{2,4})*[^._-].[a-z0-9-]+(.[a-z0-9]{2,4})*$/) == -1)
	{ 
		document.form_contact.email_contact.style.border="solid 2px red";
		document.form_contact.email_contact.style.color="#FFFFFF";
		document.form_contact.email_contact.style.backgroundColor="#CCCCCC";
		good="0";
		strTexte=" Veuillez indiquer une adresse email valide.\n";
	}
	else
	{
		document.form_contact.email_contact.style.border="solid 1px gray";
		document.form_contact.email_contact.style.color="black";
		document.form_contact.email_contact.style.backgroundColor="#FFFFFF";
	}

}

if (good=="0")
{
alert(strTexte);
return false;
}
else
{
return true;
}
}
