﻿function	changeImages	(	id	,	url	)	{
	if	(	document.getElementById(id)	)
		document.getElementById(id).src	=	url;
}
function	envoiMail	(formulaire)	{
	pref		=	(	formulaire	==	'recrut'	)	?
		'rec'	:	'com'	;	
	nombre		=	document.forms[formulaire].getElementsByTagName(	'input'	).length	-	4;
	stop		=	0;
	mailContent	=	new	Array();
	for	(	i	=	0	;	i	<	nombre	;	i++	)	{
		if	(	document.forms[formulaire].getElementsByTagName(	'input'	)[i].value	==	0	)	{
				alert(	'Veuillez remplir votre '	+	document.forms[formulaire].getElementsByTagName(	'input'	)[i].name.replace('rec','')	);
				document.forms[formulaire].getElementsByTagName(	'input'	)[i].focus();
				stop	=	1;
				break;
		}
		else
			mailContent[i]	=	document.forms[formulaire].getElementsByTagName(	'input'	)[i].name	+	'|'	+
				document.forms[formulaire].getElementsByTagName(	'input'	)[i].value;
		if	(	$('#'+pref+'Adresse').val() == 0	)	{
			alert(	'Veuillez remplir votre adresse '	);
			$('#'+pref+'Adresse').focus();
			stop	=	1;
			return	false;
		}
	}
	if	(document.forms[formulaire].getElementsByTagName(	'input'	)[nombre].checked == false && document.forms[formulaire].getElementsByTagName(	'input'	)[nombre+1].checked == false)	{
		alert(	'Sélectionnez au moins une case.'	);
		stop	=	1;
		return	false;
	}
	if	(	stop	!=	1	)	{
		mailContent[i]	=	'adresse|'	+	$(	'#'+pref+'Adresse'	).val();
		i++;
		if(document.forms[formulaire].getElementsByTagName(	'input'	)[nombre].checked == true)	{
			mailContent[i]	=	'recPart|on';
			i++
		}
		if(document.forms[formulaire].getElementsByTagName(	'input'	)[nombre+1].checked == true)	{
			mailContent[i]	=	'recComp|on';
			i++;
		}
		$.post(	'include/script/mail.php'	,	{
			type	:	pref,
			donnee	:	mailContent	,
		}	,
		function	success	(	data	)	{
			if	(	data	==	1	)
				alert(	'Votre message a \351t\351 envoy\351.'	);
			else
				alert(	data	);
		}	);
	}
}

function	envoiMail2	(formulaire)	{
	pref		=	"orga";	
	nombre		=	document.forms[formulaire].getElementsByTagName(	'input'	).length	-	4;
	stop		=	0;
	mailContent	=	new	Array();
	for	(	i	=	0	;	i	<	nombre	;	i++	)	{
		if	(	document.forms[formulaire].getElementsByTagName(	'input'	)[i].value	==	0	)	{
				alert(	'Veuillez remplir votre '	+	document.forms[formulaire].getElementsByTagName(	'input'	)[i].name.replace('rec','')	);
				document.forms[formulaire].getElementsByTagName(	'input'	)[i].focus();
				stop	=	1;
				break;
		}
		else
			mailContent[i]	=	document.forms[formulaire].getElementsByTagName(	'input'	)[i].name	+	'|'	+
				document.forms[formulaire].getElementsByTagName(	'input'	)[i].value;
		if	(	$('#'+pref+'Mes').val() == 0	)	{
			alert(	'Veuillez remplir votre message '	);
			$('#'+pref+'Mes').focus();
			stop	=	1;
			return	false;
		}
	}
	if	(	stop	!=	1	)	{
		mailContent[i]	=	pref+'Tel|'	+	$(	'#'+pref+'Tel'	).val();
		i++;
		mailContent[i]	=	pref+'Mail|'	+	$(	'#'+pref+'Mail'	).val();
		i++;

		mailContent[i]	=	pref+'Mes|'	+	$(	'#'+pref+'Mes'	).val();
		i++;

		$.post(	'include/script/mail.php'	,	{
			type	:	pref,
			donnee	:	mailContent	,
		}	,
		function	success	(	data	)	{
			if	(	data	==	1	)
				alert(	'Votre message a \351t\351 envoy\351.'	);
			else
				alert(	data	);
		}	);
	}
}


////////////////////////////////////////////////
//               POPUP AJAX
///////////////////////////////////////////////
function dialogBox(url,width,btclose,title){
	$('#dialogbox').css('width', width + 'px');
	$('#dialogbox_title').html(title);
	$('#dialogbox_content').html('<img height="11" src="/images/interface/ajax-loader.gif" width="43" alt="Chargement...">');
	
	if(btclose == "off")
		$("#dialogbox_btclose").hide();
	else
		$("#dialogbox_btclose").show();
	
//	var windowHeight = document.body.scrollHeight;
	var windowHeight	=	$('#centre').height();
	var windowWidth = document.body.scrollWidth;
	
	document.getElementById('dialogbox').style.marginLeft = "-" + (width/2) + "px";
//	$("#dialogbox").css({"top": document.body.scrollTop + 30});
	$("#dialogbox").css({"top": 30});
    
//	$("#global").css({"height": windowHeight,"width": windowWidth});
	$("#global").css({"height": windowHeight,"left":0});
	$("#global").fadeIn(400);
	setTimeout("$('#dialogbox').slideDown(400)",500);
	
	$("#global").click(function(){dialogbox_off();});
	
	/*
	$.get(url,{nocache : Math.random()},
    function success(data)
    { 
    	$('#dialogbox_content').html(data);
    });	
    */
    
    var myurl = url;
    
	$.ajax({
		type: "GET",
		url : myurl,
		cache: false,
		success: function(data) 
		{
			$('#dialogbox_content').html(data);
		}
	});
}

var timeout;

function dialogbox_off(){
	clearTimeout(timeout);
	$('#dialogbox').fadeOut(400);
	setTimeout("$('#global').fadeOut(400)",400);
}

function dialogbox_wait(){
	timeout = setTimeout("dialogbox_off()",5000); 
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
function	inscription	(	actId	)	{
	stopIt		=	0;
	form		=	document.forms[0];
	nombreInput	=	form.elements.length-2;
	for	(	i	=	0	;	i	<	nombreInput	;	i++	)	{
		if	(	form.elements[i].value	==	'')	{
			alert('Veuillez remplir tous les champs');
			stopIt	=	1;
			return false;
		}
	}
	if	(	stopIt	==	0)
		envoiForm(	actId	);
}

function	envoiForm(	id	)	{
     $(	'#inscription'	).ajaxForm();     
     $.post(	'include/ajax/validInscription.php'	,	{
     	actId	:	id,
     	data	:	$(	'#inscription'	).formSerialize() // sélection des champs à envoyer
     }	, 
     function	success	(	data	)	{     // callback en cas de succès
		$(	'#message'	).html(	data	);
		$(	'#message'	).show();
		alert(data);
		if	(	data	==	'Inscription effectu\351e.'	)
			setTimeout(	'location.reload()'	,	500	);
     }	);
}

