/* ---------------------------------------------------------------
	DEMO TEL
 --------------------------------------------------------------- */

function demoTel(cible){

	// Recuperation du contenu
	var myAjax = $.ajax({
		url: cible, 
		type: 'POST',
		success: function(retour){$("#demo_tel").html(retour);},
		complete: function(){
			$("#exemple").attr("style","top:88px;");
			$("#exemple").fadeIn(1500);
			setTimeout('$("div.affichage_cover").fadeOut("slow")', 3000);

			$('#nav_haut').click(function(){
				$('div.affichage_texte').scrollTo({top:'-=200px', left:'0px'}, 800, {axis:'y'});
			});
			$('#nav_bas').click(function(){
				$('div.affichage_texte').scrollTo({top:'+=200px', left:'0px'}, 800, {axis:'y'});
			});

		}
	});
	
}

/* ---------------------------------------------------------------
	TINY MCE
 --------------------------------------------------------------- */
function affichageTinyMce() {
	
	// TINYMCE
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		entity_encoding : "raw",
		//plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
		plugins : "paste,fullscreen,style",
theme_advanced_buttons1:"styleprops,bold,italic,underline,justifyleft,justifycenter,justifyright,justifyfull,formatselect,removeformat,undo,forecolor,fullscreen,code,link",
		theme_advanced_buttons2:"",
		theme_advanced_buttons3:"",
		theme_advanced_toolbar_location : "top"
	});
	// TINYMCE - ASTUCE IMPORTANTE
	$('#mySubmitButton').click(function() {
		var content = tinyMCE.activeEditor.getContent(); // get the content
		$('#contenu').val(content); // put it in the textarea
	});
	
}
/* ---------------------------------------------------------------
	GESTION DES FORMULAIRE
 --------------------------------------------------------------- */
function gestionFormulaire(idFormulaire) {
	// AFFICHAGE DU FORMULAIRE
	$("#" + idFormulaire).fadeIn('slow');
	
	// FOCUS SUR LE PREMIER ELEMENT
	$("#" + idFormulaire + " :text:visible:enabled:first").focus();
	
	// SURVOL DES BOUTONS des boutons
	$("#submit input").each(function(){ survolBouton(this); });			
}
/* ---------------------------------------------------------------
	REGLES FORMULAIRES
 --------------------------------------------------------------- */
function regleFormulaire() {
	
	var traitement = $('#traitement').attr('value');
	
	jQuery.validator.addMethod('verificationApple', function(id_apple) {
		   var postURL = "ajax/admin_roman/verification_apple.php";
		   $.ajax({
			   cache:false,
				async:false,
				type: "POST",
				data: "id_apple=" + id_apple + "&traitement=" + traitement,
				url: postURL, dataType: 'json',
				success: function(json) {
					result = (json.message_retour == '0') ? true : false;
				}//,
				//complete: function(json){
				//	var messageAlerte = json.message_alerte;
				//}
			});
			return result;
		}, 'Identifiant déjà utilisé !');

}
/* ---------------------------------------------------------------
	SURVOL DES BOUTONS
 --------------------------------------------------------------- */
function survolBouton(idBouton) {
	$(idBouton).hover(
		function(){
		// Affichage du fonds
			$(idBouton).attr("style","background-position: left bottom;");					
		},
		function(){
			$(idBouton).attr("style","background-position: left top;");					
		}
	);
}
/* ---------------------------------------------------------------
	BOUTONS DU MENU PRINCIPAL
 --------------------------------------------------------------- */
function boutonMenu(idBouton) {
	// Gestion du menu
	$('#menu_principal a').each( function(noeud){ $(this).removeAttr("style");	});
	$('#menu_principal li a span').each( function(noeud){ $(this).removeAttr("style");	});
	$('#menu_principal a').each( function(noeud){ $(this).focus(function() { $(this).blur(); } );	});
	$('#menu_' + idBouton).attr("style", "background-position: left bottom;color:#FFFFFF;");
	$('#menu_' + idBouton + ' span').attr("style", "top:65px;");
}
/* ---------------------------------------------------------------
	GESTION DES ANCRES
 --------------------------------------------------------------- */
function gestionAncre(idAncre) {
	$(idAncre).attr('onclick', 'return false');
	$(idAncre).focus(function() { $(idAncre).blur(); } );
}
/* ---------------------------------------------------------------
	MESSAGES
 --------------------------------------------------------------- */
function affichageMessage(statut , message){
	// Nettoyage de la zone
	$("#zone_message p").html('');
	$("#zone_message p").removeClass()
	// Insertion du message
	$("#zone_message p").html(message);
	// Affichage du message
	$("#zone_message p").fadeIn('normal');
	// Mise en forme css
	$("#zone_message p").addClass(statut);
	
	// Effacement du message le cas échéant
	if(statut == 'success') setTimeout('$("#zone_message p").fadeOut("slow")', 10000);
}
/* ---------------------------------------------------------------
	FONCTIONS A LANCER LORS DU CHARGEMENT DE LA PAGE
 --------------------------------------------------------------- */
$(document).ready(function(){

	// Gestion du formulaire d'abonnement
	$("#fml_abonnement").validate({
		debug: true,
		rules: {
			email: { required: true, email: true }
			},				
		messages: {
			email: { required: "E-mail obligatoire", email: "E-mail incorrect"}
			},				
		submitHandler: function(form) {
			var options = { 
				url: "ajax/sabonner/ouverture.php", type: 'post',	dataType: 'json',
				//beforeSubmit: function(){ affichageMessage('before' , 'traitement en cours'); },
				success: function(json){
					//$("#email").attr('value', '');
					//$("#txt_abonnement p").show();
					//$("#txt_abonnement p").html("La belle adele");
					$("#txt_abonnement p").html(json.message); 
				},
				complete: function(){ // A MODIFIER
					//alert('toto');
					//$("#txt_abonnement p").html("La belle adele");
				}
			}; 
			$("#fml_abonnement").ajaxSubmit(options); 
			return false; 
	   }
	});

	$("#email").click(
		function(){
			$(this).val("");
		}
	);

	$("#txt_abonnement").hover(
		function(){
			$("#txt_abonnement p").fadeIn('normal');					
		},
		function(){
			$("#txt_abonnement p").fadeOut('normal');					
		}
	);
	
	$("#fml_abonnement").hover(
		function(){
			$("#txt_abonnement p").fadeIn('normal');					
		},
		function(){
			$("#txt_abonnement p").fadeOut('normal');					
		}
	);


});
// -------------------------------------------------------------