/************** CHARGEMENT PAGE *****************************/
jQuery(document).ready(function(){
    rollover_account();
	en_construction();
});
/************** CHARGEMENT PAGE *****************************/

var fondDiv = false;
var dataDiv = false;


// Ajout a la newsletter
function addNewsletter(idForm) {
	
	if(!fondDiv){
		fondDiv = document.createElement('div');
		fondDiv.style.position = 'absolute';
		document.body.appendChild(fondDiv);
	}
	fondDiv.innerHTML = '';
	//alert(getHeight());

	$(fondDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '100%',
	   height: getScrollHeight(),
	   position: 'absolute',
	   opacity: '0.9',
	   overflow: 'hidden',
	   top: '0px',
	   left: '0px',
	   zIndex: '1500',
	   visibility: 'hidden'
	});

	$(fondDiv).onclick = function() { removeDiv(); };

	if(!dataDiv){
		dataDiv = document.createElement('div');
		dataDiv.style.position = 'absolute';
		document.body.appendChild(dataDiv);
	}

	$(dataDiv).setStyles({
	   backgroundColor: 'transparent',
	   width: '500px',
	   height: '300px',
	   position: 'absolute',

	   top: '50%',
	   left: '44%',	   
	   marginLeft: '-150px',	   
	   marginTop: (getScrollTop()-150) + 'px',	   	   	   
	   zIndex: '1600',
	   visibility: 'hidden'
	});	

	new Ajax(
		'/js/ajax/newsletter.php',
		{
			update: dataDiv,
			data:$(idForm).toQueryString(),
			onSuccess: function(req) {

					$$(fondDiv).setStyles({visibility: 'visible' });
					$$('select').setStyles({visibility: 'hidden' });
					$$(dataDiv).setStyles({visibility: 'visible' });
	
			},
			evalScripts: true
		}
	).request();		
	
}


function removeDiv()
{
	if(fondDiv){
		$(fondDiv).remove();
		fondDiv = false;
	}	
	if(dataDiv){
		$(dataDiv).remove();
		dataDiv = false;
	}
	$$('select').setStyles({visibility: 'visible' });		
}


function checknewsletter(on) {
	new Ajax(
		'/js/ajax/newsletter.php',
		{
			method:'post',
			update: dataDiv,
			data:$('formnewsletter').toQueryString(),
			onSuccess: function(req) {
				update:$('arrDebug')
			},
			evalScripts: true
		}
	).request();		
	
}


function loadAddNewsletter(node){
    alterneText("#newsletter_email", 'Votre email');
		   
    jQuery(node).submit(function(){
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#close'
                }
            },
            ajax:'/js/ajax/newsletter.php',
            data:jQuery(node).serialize()
        });
        return false;
    });
}

function alterneText(id, text){
    jQuery(id).focus(function(){
        if (jQuery(this).attr('value') == text) {
            jQuery(this).attr('value', '');
        }
    });
    jQuery(id).blur(function(){
        if (jQuery(this).attr('value') == '') {
            jQuery(this).attr('value', text);
        }
    });
}

//Positionne les sous menus
function setPosition(){
	var gauche;
	var longueur;
	var my_id;
	
	jQuery(".onglet_contenant").each(function(){
		my_id = this.id.replace("onglet_","");

		switch(my_id){
			case "1":
				gauche = 115;
				longueur = 180;
			break;
			case "2":
				gauche = 294;
				longueur = 180;
			break;
			case "3":
				gauche = 461;
				longueur = 180;
			break;
			case "5":
				gauche = 694;
				longueur = 180;
			break;
			case "6":
				gauche = 817;
				longueur = 180;
			break;
		}
	
		jQuery("#ssmenu_"+my_id).css('left',gauche);
		jQuery("#ssmenu_"+my_id).css('width',longueur);		

	});
	
	//Mouse over : apparition du sous menu
	jQuery(".onglet_contenant").mouseover(function(){
		jQuery(".ssmenu").css('display','none');
		my_id = this.id.replace("onglet_","");
		jQuery("#ssmenu_"+my_id).css('display','block');
	});


	//Mouse out, disparition du sous menu
	if (getIE6and7()){
		jQuery("#conteneur").mouseleave(function(){
			jQuery(".ssmenu").css('display','none');
		});	
		
		jQuery("body").click(function(){
			jQuery(".ssmenu").css('display','none');
		});	

	} else {
		jQuery(".ssmenu").mouseleave(function(){
			jQuery(".ssmenu").css('display','none');
		});	
	}
	
}


//Renvoie true si on est sous IE 6 ou 7
function getIE6and7(){
	if (navigator.appName=='Microsoft Internet Explorer'){
	
		var strChUserAgent = navigator.userAgent;
		var intSplitStart = strChUserAgent.indexOf("(",0);
		var intSplitEnd = strChUserAgent.indexOf(")",0);
		var strChStart = strChUserAgent.substring(0,intSplitStart);
		var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
		
		if(strChMid.indexOf("MSIE 7") != -1 || strChMid.indexOf("MSIE 6") != -1){		
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
	
}


//Met en forme les éléments H2 des pages CMS
function addH2Elements(){
	var contenu;
	var new_contenu;
	jQuery("#conteneur #contenu .bloc_general .texte h2").each(function(){
		if(!jQuery(this).hasClass('no_design_auto')){
			contenu = jQuery(this).html();
			new_contenu = "<img src='/styles/images/contenu/h2_gauche.png' class='png img1' alt='' style='height:39px;width:18px;' />";
			new_contenu += "<p>"+contenu+"</p>";
			new_contenu += "<img src='/styles/images/contenu/h2_droite.png' class='png img2' alt='' style='height:30px;width:10px;' />";
			jQuery(this).html(new_contenu);
			jQuery(this).before("<div class='clear'></div>");
			jQuery(this).after("<div class='clear'></div>");
		}
	});
}


//Met en forme les éléments H3 des pages CMS
function addH3Elements(){
	var contenu;
	var new_contenu;
	jQuery("#conteneur #contenu .bloc_general .texte h3").each(function(){
		contenu = jQuery(this).html();
		new_contenu = "<img src='/styles/images/contenu/h3_gauche.png' class='png img1' alt='' style='height:39px;width:18px;' />";
		new_contenu += "<p>"+contenu+"</p>";
		new_contenu += "<img src='/styles/images/contenu/h3_droite.png' class='png img2' alt='' style='height:30px;width:10px;' />";
		jQuery(this).html(new_contenu);
		jQuery(this).before("<div class='clear'></div>");
		jQuery(this).after("<div class='clear'></div>");
	});
}

function affichage_bloc(p_this,bloc,p)
{
	document.getElementById(p_this).style.display='none';
	
	if(document.getElementById(bloc).style.display=='none')	document.getElementById(bloc).style.display='';
	else document.getElementById(bloc).style.display='none';
		
	document.getElementById(p).style.display='';
}


function affichage_bloc2(p_this,bloc_this,p,bloc)
{
	document.getElementById(p_this).style.display ='none';
	document.getElementById(bloc_this).style.display='none';	
	document.getElementById(p).style.display='block';
	document.getElementById(bloc).style.display='block';
}




function affichage_bloc_spe(bloc){ document.getElementById(bloc).style.display=''; }

function rollover_account() 
{
	jQuery("#espace_adherent").each(function(i){
    jQuery(this).mouseenter(function(event){
    		jQuery('#rollover_mon_compte').css('display','block');
    });
    jQuery(this).mouseleave(function(event){
    		jQuery('#rollover_mon_compte').css('display','none');
    });  	
  });  	
}

function en_construction() 
{
	jQuery(".construction").each(function(i){
    jQuery(this).mouseenter(function(event){
    		jQuery('.en_cours').css('display','block');
    });
    jQuery(this).mouseleave(function(event){
    		jQuery('.en_cours').css('display','none');
    });  	
  });  	
}

function confirm_suppr(idInt,suppr_ok,entite)
{ 
   if(suppr_ok==0)
   {	
      jQuery("body").popup({
          popup:{
              removeOnClick:{
                  0:'#btn_valider',
                  1:'#btn_retour'
              },
              css:{
				        'width':'450px',
				        'height':'100px'				        
				      }
          },
          ajax:'/js/ajax/suppr_intervenant.php',
       		data: 'idInt='+idInt+'&suppr_ok='+suppr_ok+'&entite='+entite      		    
      });
	 }
	 else
	 {
		 	jQuery.ajax({
        type: "POST",
        url: "/js/ajax/suppr_intervenant.php",
        data: 'idInt='+idInt+'&suppr_ok='+suppr_ok+'&entite='+entite,     
        success: function(msg){
               jQuery('#msg_chps_oblig').html(msg);
               jQuery('#msg_chps_oblig').css('display','block');
               jQuery('#msg_modif_chps').css('display','none');               
              }		   
    	});		 
		}
}
