
	var isAncestor = function(parent,child) {
        if(typeof(parent) != "undefined" && typeof(child) != "undefined" /*&& walker != null && child != null*/)
        {
			var walker = child;
			while (walker != document.body) 
            {
				if(walker == null){
					return false;
				}
					walker = walker.parentNode;
					if (parent == walker) 
                    	return true;		
			
			}
		}
        return false;
	}	
	
	
	
	
	
$(function () {
			
/* =============================================================================
									BLOCK CONNEXION
* ===========================================================================*/		
	$('#btn_connexion').click(function() {	
								  
			if ($('#form_connexion_global').css('display') == 'none') {				
				$('#form_connexion_global').slideDown(600);
			}
			else {
				$('#form_connexion_global').slideUp(400);			
			}
			
	});
	

	$(document).bind('click',function(event) {
		var tgt = $(event.target)[0];
		var parent1 = $('#form_connexion_global')[0];
		var parent2 = $('#btn_connexion')[0];
		var parent3 = $('#gestion_club .content_choice')[0];
		var parent4 = $('#gestion_club .content_choice')[1];
		var parent5 = $('#gestion_content_supplier .content_choice')[0];
		var parent6 = $('#gestion_content_supplier .content_choice')[1];
		var parent7 = $('#gestion_compte .content_choice')[0];
		var parent8 = $('#gestion_compte .content_choice')[1];
		var tgtId = $(event.target)[0].id;
		
		//espaceAnnonceursTxt - espaceAnnonceurs - annonceurLogin
		if($('#form_connexion_global:visible').length && tgtId!='form_connexion_global' && tgtId!='btn_connexion' && !isAncestor(parent1,tgt) && !isAncestor(parent2,tgt)) {
			$('#form_connexion_global').fadeOut(400);	
		}
		
		if( !isAncestor(parent3,tgt) &&  !isAncestor(parent4,tgt))
		{
			$(this).find('#gestion_club .select_open').slideUp(250);
		}
		
		if( !isAncestor(parent5,tgt) &&  !isAncestor(parent6,tgt))
		{
			$(this).find('#gestion_content_supplier .select_open').slideUp(250);
		}
		
		if( !isAncestor(parent7,tgt) &&  !isAncestor(parent8,tgt))
		{
			$(this).find('#gestion_compte .select_open').slideUp(250);
		}		
	});
/* =============================================================================
* ===========================================================================*/
	
	
	
/* =============================================================================
										MENU
* ===========================================================================*/


	function menu_resize () {
		//$('#debugBox').remove();
		
		if($('#mainNav').length == 0){
			return;	
		}
		
		var m_menu_h = $('#mainNav').height(); //Hauteur du menu
		var m_menu_top = parseInt($('#mainNav').css('top').replace("px", "")); //Distance du menu par rapport au haut de page
		var m_menu_h_g = m_menu_h + m_menu_top; //Hauteur total du menu dans la page
		var m_html_h = $(window).height(); //Hauteur du site
		var m_menu_out = m_html_h - m_menu_h_g;//Distance entre le bas du menu et le bas du html pour voir si le menu sort
		
		if((m_html_h < m_menu_h_g) || (m_html_h < m_menu_h + 220)) {
			m_menu_top = m_menu_top + m_menu_out - 50;
			$('#mainNav').animate({top: m_menu_top+'px'}, {queue: false, duration: 600, easing: 'easeInOutCirc'});
		}else{
			m_menu_top = 220;
			$('#mainNav').animate({top: m_menu_top+'px'}, {queue: false, duration: 600, easing: 'easeInOutCirc'});
		}		
		//$("body").append("<div id='debugBox'>"+m_menu_out+"</div>");
	}
	
	menu_resize();

	$(window).resize(function () {
		menu_resize();
	});

	$('ul.menuContent li .menu').hover(function(){											
			$(this).parent().find('.menuTitleGlobal').css('display', 'block');
			$(this).parent().find('.menuTitleGlobal').css('opacity', 1);
			$(this).parent().find('.menuTitleGlobal').css('width', '200px');
		},
		function(){
			$(this).parent().find('.menuTitleGlobal').stop().animate({opacity: 0}, {queue:false, duration:300});
			setTimeout("$(this).parent().find('.menuTitleGlobal').css('display', 'none');$(this).parent().find('.menuTitleGlobal').css('width', '0px');",300);
	});
/* =============================================================================
* ===========================================================================*/



/* =============================================================================
								HAUT DE PAGE
* ===========================================================================*/
$(function() {		   
	$('#back_top').click(function() {
		if($.browser.opera){$('html').animate({ scrollTop: $('#headerGlobal').offset().top }, 1200, 'easeInOutCirc');}
		else{$('html,body').animate({ scrollTop: $('#headerGlobal').offset().top }, 1200, 'easeInOutCirc');}
	});
 });
/* =============================================================================
* ===========================================================================*/



/* =============================================================================
								ALBUM PHOTOS
* ===========================================================================*/
	$('.apercu_photo').hover(function(){											
			$(this).find('.desc_photo').stop().animate({opacity: 1}, {queue:false, duration:100});
			$(this).find('.photo_membre').stop().animate({opacity: 1}, {queue:false, duration:100});
		},
		function(){
			$(this).find('.photo_membre').stop().animate({opacity: 0}, {queue:false, duration:300});
			$(this).find('.desc_photo').stop().animate({opacity: 0}, {queue:false, duration:300});
			
	});
/* =============================================================================
* ===========================================================================*/




/* =============================================================================
								SLIDER HOME + ACTUS
* ===========================================================================*/	
	$('#sentiers').tabs({fx:{opacity: 'toggle'}, selected: 3});
/* =============================================================================
* ===========================================================================*/




/* =============================================================================
							ANIMATION DES BOUTONS
* ===========================================================================*/	
	$('.anim_btn').hover(function(){	
			this._width = $(this).css('width');
			$(this).stop().animate({paddingLeft: '30px', width:'-=20'}, {queue:false, duration:250});
		},
		function(){
			$(this).stop().animate({paddingLeft: '10px', width:this._width}, {queue:false, duration:100});
	});
	
	
	$('.anim_btn_no_padding').hover(function(){	
			$(this).stop().animate({paddingLeft: '20px'}, {queue:false, duration:250});
		},
		function(){
			$(this).stop().animate({paddingLeft: '0px'}, {queue:false, duration:100});
	});
/* =============================================================================
* ===========================================================================*/


/* =============================================================================
							DESCRIPTION FICHE PARCOURS
* ===========================================================================*/	
	$('.descritpion_parcours').hover(function(){
			$(this).find('.full_desc').show('fast');
			/*if( $('div#description div.content p').outerHeight(true) > 55 ){											  
				$(this).find('.full_desc').show('fast');
			}*/
		},
		function(){
			$(this).find('.full_desc').hide('fast');
			/*if( $('div#description div.content p').outerHeight(true) > 55 ){											  
				$(this).find('.full_desc').hide('fast');
			}*/
	});
	
	
	$('.desc_small').hover(function(){
			if( $(this).find('p').outerHeight(true) > 55 ){											  
				$(this).find('div.more').show('fast');
			}
		},
		function(){
			if( $(this).find('p').outerHeight(true) > 55 ){											  
				$(this).find('div.more').hide('fast');
			}
	});
/* ======	
/* =============================================================================
* ===========================================================================*/


/* =============================================================================
							AFFICHER + DE COMMENTAIRES
* ===========================================================================*/	
	/*$('#see_all_comments').click(function() {
		$(this).fadeOut("slow");
		$('#more_comments').slideDown("slow");
		return false;
	});*/
/* =============================================================================
* ===========================================================================*/




});



/* =============================================================================
								ACTUALITES HOME
* ===========================================================================*/	
		var cur_el = 1;
	  function change_parcours_push_home(_n, _l)
	  {
		 if(_n == cur_el)
		 	return;
			
	  	for(var i=1;i<=4;i++){
			$('#parcours_push_'+i).css('display', 'none');	
			if(i==_n){
				$('#div_btn_parcours_push_home_'+i).attr('class', 'select_article activ');
			}
			else{
				$('#div_btn_parcours_push_home_'+i).attr('class', 'select_article');
			}
		}
		$('#parcours_push_'+_n).fadeIn('slow');
		cur_el = _n;
		$('a#goto_blog')[0].onclick = function(){$(this).attr('href', _l); return true;};
	  }

/* =============================================================================
								SLIDER HOME + ACTUS + CAROUSEL PARTENAIRES
* ===========================================================================*/

var timer_slider = null;
var timer_slider_delay = 7000;
var total_slider_element;

function init_home()
{
	$('#slider').slideView({toolTip: true, ttOpacity: 0.7});
	
	timer_slider = window.setTimeout('display_next_home_slider_title();',timer_slider_delay);
	
	
	$('#carousel_partenaires').jcarousel({
		scroll: 1,
		animation: 1500,
		auto: 2,
		wrap: 'circular'
	});
	
	
	/*if($('#map_flash_content').length != 0)
	{
		//alert('ok');
		swfobject.embedSWF("http://www.sentiers-debattus.com/swf/mapHome.swf?kik", "map_flash_content", "610", "250", "9.0.0","http://www.sentiers-debattus.com/swf/expressInstall.swf", {}, {wmode:"transparent",quality:"high"}, {id:"flashCarte",style:""});	
	}*/
	
	
}

function display_next_home_slider_title() {
	var next = parseInt(curent_week_parcours)+1;
	if(next > total_slider_element) {
		next = 1;
	}
	$('div#tpl_home div#slider_global .stripTransmitter a:eq('+(next-1)+')').trigger('click');
}

function display_home_slider_title(_el, _total)
{
	if(timer_slider!=null) {
		window.clearTimeout(timer_slider);
	}
	curent_week_parcours = _el;
	
	for(var i=1;i<=_total;i++)
	{
		$('#weekParcours'+i).fadeOut('slow');
		$('#weekParcoursBtn'+i).fadeOut('slow');
		$('#weekParcoursBtn'+_el+' #btn_week_parcours').hide();
	}
	$('#weekParcours'+_el).fadeIn('slow');
	$('#weekParcoursBtn'+_el).fadeIn('slow');
	$('#weekParcoursBtn'+_el+' #btn_week_parcours').show();
	//$('#btn_week_parcours'+_el).fadeIn('slow');
	
	timer_slider = window.setTimeout('display_next_home_slider_title();',timer_slider_delay);
}

var curent_week_parcours = 1;
function go_to_week_parcours()
{
	document.location.replace(t_week_parcours[curent_week_parcours]);
}


/* =============================================================================
* ===========================================================================*/


/* =============================================================================
							TOOLTIP MEMBRES
* ===========================================================================*/	
	this.tooltip = function(){    
	
			/* position par rapport au curseur */
			xOffset = $.browser.msie?50:45;
			yOffset = 0;
			
		$(".tooltip2").hover(function(e){                                              
			this.t = this.title;
			this.title = "";                                      
			$("body").append("<div id='tooltipMembres'><div id='tooltipMembresLeft'></div><div id='tooltipMembresRight'></div><div id='tooltipMembresBottom'></div><span>"+ this.t +"</span></div>");
			yOffset = Math.floor( ( $('#tooltipMembres').width() )/2 )+6;
			$("#tooltipMembres")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX - yOffset) + "px")
				.css("display", "block");        
		},
		function(){
			this.title = $('div#tooltipMembres span')[0].innerHTML;        
			$("#tooltipMembres").remove();
		});    
		$(".tooltip2").mousemove(function(e){
			$("#tooltipMembres")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX - yOffset) + "px");
		});            
	};	
	$(function() {tooltip();});
/* =============================================================================
* ===========================================================================*/



/* =============================================================================
							TOOLTIP COMPTE
* ===========================================================================*/	
	this.tooltip_compte = function(){
		
		var _timer;
		//<img src='/sd_img/integre/compte/links_ico.png' alt='link' />
			
		$(".tooltip_compte").hover(function(){
			clearTimeout(_timer);
			this.t = this.title;
			this.title = "";		

			if($("#tooltipCompte_global").length > 0){
				$("#tooltipCompte").html( "<img id='tooltipCompte_img' src='/sd_img/integre/compte/links_ico.png' alt='link' /> <span>"+ this.t +"<span>" );
			}
			else{
				$("body").append("<div id='tooltipCompte_global'><div id='tooltipCompte'><img id='tooltipCompte_img' src='/sd_img/integre/compte/links_ico.png' alt='link' /> <span>"+ this.t +"<span></div></div>");
			}

			$("#tooltipCompte_global").animate({bottom: '0px'}, {queue:false, duration:450});
			$("#tooltipCompte_global").animate({opacity: 1}, {queue:false, duration:800});
		},
		function(){
			this.title = $('#tooltipCompte span').html();
			_timer = setTimeout("$('#tooltipCompte_global').stop().animate({bottom: '-43px', opacity: 0}, {queue:false, duration:700});",500);
			
		});
	};
	$(function() {tooltip_compte();});
/* =============================================================================
* ===========================================================================*/





/* =============================================================================
							TOOLTIP CREATION SORTIE
* ===========================================================================*/	
	this.tooltipParcours = function(){    
	
			/* position par rapport au curseur */
			xOffset3 = 121;
			yOffset3 = 15;
			
		$(".list-item").hover(function(e){   
			this.t = this.title;
			this.title = "";                                      
			$("body").append("<div id='tooltipParcours'>"+ this.t +"</div>");
			$("#tooltipParcours")
				.css("top",(e.pageY - xOffset3) + "px")
				.css("left",(e.pageX - yOffset3) + "px")
				.css("display", "block");        
		},
		function(){			
			this.title = document.getElementById('tooltipParcours').innerHTML;
			//alert(this.title);
			$("#tooltipParcours").remove();
		});    
		$(".list-item").mousemove(function(e){
			$("#tooltipParcours")
				.css("top",(e.pageY - xOffset3) + "px")
				.css("left",(e.pageX - yOffset3) + "px");
		});          
	};	
	$(function() {tooltipParcours();});
/* =============================================================================
* ===========================================================================*/



/* =============================================================================
							BOUTON RADIO + CHECKBOX
* ===========================================================================*/	

	function checkboxCustom(element){
		$(element).children('div').css('display', (($(element).children('div').css('display') == 'block')?'none':'block'));
		(($(element).css('display') == 'block')?$(element).children('input[type=radio]').attr('checked',true):$(element).children('input[type=radio]').attr('checked',false))	
	}
	
	
	function InputRadioNotation(id){
		if( $(id).children("input[type='radio']").attr('checked') != true ){
			$(".bg_btn_input_radio > .btn_input_radio").fadeOut(500);
			$(id).children(".btn_input_radio").fadeIn(500);
			$(id).children("input[type='radio']").attr('checked',true);
			if(typeof($(id).children("input[type='radio']")[0].onchange) == 'function'){
				$(id).children("input[type='radio']")[0].onchange();	
			}			
		}
	}
	
	
	function InputRadioNotation2(id){
		if( $(id).children("input[type='radio']").attr('checked') != true ){
			$(".bg_btn_input_radio1 > .btn_input_radio1").fadeOut(500);
			$(id).children(".btn_input_radio1").fadeIn(500);
			$(id).children("input[type='radio']").attr('checked',true);
			if(typeof($(id).children("input[type='radio']")[0].onchange) == 'function'){
				$(id).children("input[type='radio']")[0].onchange();	
			}			
		}
	}
	
	function radioCustom(_cont)
	{
		$(_cont).click(function(){ 
			if( !$(this).children("input[type='radio']:checked").length ){
				$(_cont+" .btn_input_radio").fadeOut(500);
				$(this).children(".btn_input_radio").fadeIn(500);
				$(this).children("input[type='radio']").attr('checked',true);
				if(typeof($(this).children("input[type='radio']")[0].onchange) == 'function'){
					$(this).children("input[type='radio']")[0].onchange();	
				}			
			}			
		});
	}
	
	$(function(){
		checkbox_it();
	});
	
	function checkbox_it()
	{
		$('.bg_btn_input_checkbox').click( function () { 
			var _el_check;            
			if ($(this).find('.btn_input_checkbox:visible').length != 1) {
				$(this).find('.btn_input_checkbox').fadeIn(400);            
				_el_check = true;
			}
			else {
				$(this).find('.btn_input_checkbox').fadeOut(400);
				_el_check = false;
			}
			$(this).find('input').attr("checked", _el_check);
			if(typeof($(this).find('input')[0].onchange) == 'function'){
				$(this).find('input')[0].onchange();	
			}
		});		
	}
/* =============================================================================
* ===========================================================================*/



/* =============================================================================
							ANIMATION MAP
* ===========================================================================*/		
	$(function(){
		_height_interets = ($('#centre_interets').height()) - ($('#centre_interets_title').height())-4;
		$('#centre_interets_title').click( function () {
			if($('#centre_interets').css('bottom')=='0px') {
								
				$(this).parent().stop().animate({bottom: '-'+_height_interets+'px'}, {queue:false, duration:300});
				$("#centre_interets_title").css('backgroundImage', 'url(/sd_img/integre/fiche_parcours/map_interets_titre_up.png)');
				
			}else{
				
				$(this).parent().stop().animate({bottom: '0px'}, {queue:false, duration:300});
				$("#centre_interets_title").css('backgroundImage', 'url(/sd_img/integre/fiche_parcours/map_interets_titre_down.png)');
				
			}
		});
	});
/* =============================================================================
* ===========================================================================*/



/* =============================================================================
							RECHERCHE
* ===========================================================================*/		
	$(function(){
		/*Slide Up slide Down*/
		$('#searchBar_content .search_more_top span').click( function () {
			if ($(this).parent().next('.search_more_content:visible').length != 1) {
				$(this).parent().next('.search_more_content').slideDown(600);
				$(this).css('background-image', 'url(/sd_img/integre/recherche/block_search_detail_arrow_top.png)');
				$(this).html('MASQUER');
                
                if( $(this).parent().parent().attr('id') == 'div_search_club' ){
                    $('input[name=club]').attr('checked', true);  
                    $('input[name=club]').prev().fadeIn();
                    toggle_results({name:'club',checked:true});
                }
                else if( $(this).parent().parent().attr('id') == 'div_search_customer' ){
                    $('input[name=customer]').attr('checked', true);  
                    $('input[name=customer]').prev().fadeIn();
                    toggle_results({name:'customer',checked:true});
                }
                else if( $(this).parent().parent().attr('id') == 'div_search_parcours_event' ){
                    $('input[name=parcours]').attr('checked', true);  
                    $('input[name=event]').attr('checked', true);  
                    $('input[name=parcours]').prev().fadeIn();
                    $('input[name=event]').prev().fadeIn();
                    toggle_results({name:'parcours',checked:true});
                    toggle_results({name:'event',checked:true});
                }
			}
			else {
				$(this).parent().next('.search_more_content').slideUp(300);
				$(this).css('background-image', 'url(/sd_img/integre/recherche/block_search_detail_arrow_bottom.png)');
				$(this).html('AFFICHER');

                if( $(this).parent().parent().attr('id') == 'div_search_club' ){
                    $('input[name=club]').attr('checked', false);  
                    $('input[name=club]').prev().fadeOut();          
                    toggle_results({name:'club',checked:false});            
                }
                else if( $(this).parent().parent().attr('id') == 'div_search_customer' ){
                    $('input[name=customer]').attr('checked', false);  
                    $('input[name=customer]').prev().fadeOut();   
                    toggle_results({name:'customer',checked:false});                   
                }                       
                else if( $(this).parent().parent().attr('id') == 'div_search_parcours_event' ){
                    $('input[name=parcours]').attr('checked', false);  
                    $('input[name=event]').attr('checked', false);  
                    $('input[name=parcours]').prev().fadeOut();
                    $('input[name=event]').prev().fadeOut();  
                    toggle_results({name:'parcours',checked:false});  
                    toggle_results({name:'event',checked:false});                    
                }                
			}
		});
			   
	});
/* =============================================================================
* ===========================================================================*/

function check_and_save()
{
	if( parseInt( $('#parcours_type').css('top')  ) == 0)
	{	
		$('#parcours_type_mask').find('img').animate({rotate: '+=180deg'}, {queue:false, duration:400});	
		$('#parcours_type_mask').find('img').animate({scale: '0.5'}, {queue:false, duration:200, complete: function() {
			$(this).animate({scale: '1'}, {queue:false, duration:200});
		}});			             
		
		$('#parcours_type_mask').parent().animate({top: '-213px'}, {queue:false, duration:800, easing: 'easeInOutCirc'});				
	}
}
/* =============================================================================
							COMPTE
* ===========================================================================*/		
	$(function(){
		$('#status .photo').hover(function(){                                       
			$(this).find('.over').animate({opacity: 1}, {queue:false, duration:250});    
		},
		function(){
			$(this).find('.over').animate({opacity: 0}, {queue:false, duration:400});   
		}); 
			   
	});
	
	$(function(){
		$('#status h2').hover(function(){                                       
			$(this).find('.delete').animate({opacity: 1}, {queue:false, duration:250});    
		},
		function(){
			$(this).find('.delete').animate({opacity: 0}, {queue:false, duration:400});   
		}); 
			   
	});
	
	$(function(){
		$('.show_detail_compte').hover(function(){                                       
			$(this).find('.detail_compte').animate({opacity: 1}, {queue:false, duration:250});    
		},
		function(){
			$(this).find('.detail_compte').animate({opacity: 0}, {queue:false, duration:400});   
		}); 
			   
	});
	
	$(function(){
		
		window.setTimeout("if( $('#parcours_type').length ){$('#parcours_type_mask').find('img').animate({rotate: '+=180deg'}, {queue:false, duration:400});$('#parcours_type_mask').parent().animate({top: '0px'}, {queue:false, duration:1200, easing: 'easeInOutCirc'});$('#parcours_type_mask').find('img').animate({scale: '0.5'}, {queue:false, duration:200, complete: function() {$(this).animate({scale: '1'}, {queue:false, duration:200});}});}",2500);
		
		
		$('#parcours_type_mask').click(function(){
			if($(this).parent().css('top') == '0px') {	
				$(this).find('img').animate({rotate: '+=180deg'}, {queue:false, duration:400});	
				$(this).find('img').animate({scale: '0.5'}, {queue:false, duration:200, complete: function() {
      				$(this).animate({scale: '1'}, {queue:false, duration:200});
    			}});			             
				$(this).parent().animate({top: '-213px'}, {queue:false, duration:800, easing: 'easeInOutCirc'});				
				/*var _img = '<img src="/sd_img/integre/compte/arrow_toolbox_bottom.png" alt="bottom" />';
				$(this).html(_img);*/
			}else{
				$(this).find('img').animate({rotate: '+=180deg'}, {queue:false, duration:400});
				$(this).find('img').animate({scale: '0.5'}, {queue:false, duration:200, complete: function() {
      				$(this).animate({scale: '1'}, {queue:false, duration:200});
    			}});	
				$(this).parent().animate({top: '0px'}, {queue:false, duration:1200, easing: 'easeInOutCirc'});				
				/*var _img = '<img src="/sd_img/integre/compte/arrow_toolbox_top.png" alt="top" />';
				$(this).html(_img);*/
			}
		});
		
			
		
		$('#sortie_list_parcours_mask').click(function(){
			if($(this).parent().css('bottom') == '0px') {	
				$(this).find('img').animate({rotate: '+=180deg'}, {queue:false, duration:400});	
				$(this).find('img').animate({scale: '0.5'}, {queue:false, duration:200, complete: function() {
      				$(this).animate({scale: '1'}, {queue:false, duration:200});
    			}});			             
				$(this).parent().animate({bottom: '-275px'}, {queue:false, duration:800, easing: 'easeInOutCirc'});				
				/*var _img = '<img src="/sd_img/integre/compte/arrow_toolbox_bottom.png" alt="bottom" />';
				$(this).html(_img);*/
			}else{
				$(this).find('img').animate({rotate: '+=180deg'}, {queue:false, duration:400});
				$(this).find('img').animate({scale: '0.5'}, {queue:false, duration:200, complete: function() {
      				$(this).animate({scale: '1'}, {queue:false, duration:200});
    			}});	
				$(this).parent().animate({bottom: '0px'}, {queue:false, duration:1200, easing: 'easeInOutCirc'});				
				/*var _img = '<img src="/sd_img/integre/compte/arrow_toolbox_top.png" alt="top" />';
				$(this).html(_img);*/
			}
		});
		
			   
	});
/* =============================================================================
* ===========================================================================*/



/* =============================================================================
							NOTIFICATION COMPTE
* ===========================================================================*/	
	$(function() {
		
		$('.notification .close').click(function() {
			$(this).parent().fadeOut(800);
		});
		
	});
/* =============================================================================
* ===========================================================================*/




function ajax_form(form, _url) {
	
	if(typeof(_url) == 'undefined'){
		_url = $(form).attr("action");
	}
	
    $.ajax({
		type: $(form).attr("method"),
		url: _url ,
		data: $(form).serialize(),
		success: function (data) {
			eval(data);
		}
	});
}

function ajax_form2(form) {
    $.ajax({
		type: $(form).attr("method"),
		url:  $(form).attr("action"),
		data: $(form).serialize(),
		contentType:'multipart/form-data',
		success: function (data) {
			eval(data);
		}
	});
} 

function alert(message){
	 guest_message(message, null);
}

function guest_message(_msg, _function)
{
	var boxe_alert = new DOMAlert({
		title: 'Title',
		text: 'Alert Message',
		skin: 'default',
		width:350,
		ok: {value: true, text: 'Yes', onclick: null},
		cancel: {value: true, text: 'X', onclick: null}
	});

	
	boxe_alert.show("", _msg.replace(/\n/g, '<br/>') );
		
	if( typeof(_function) == 'function' ){
		boxe_alert.settings.ok.onclick = _function;
	}
	/*if( typeof(_function) == 'function' ){
		_function();	
	*/
}


function scroll_to_element(_el)
{
	$('html,body').animate({scrollTop:$(_el).offset().top},'normal');	
}


function wall_add(_form)
{
	if( $(_form).find('textarea[name=msg]').val() != '' && $(_form).find('textarea[name=msg]').val() != default_wall_value ){
		t_wall_call[_form] = true;
		ajax_form(_form);
	}
}

var t_wall_call = new Array();
function wall_get(_form)
{
	if(typeof(t_wall_call[_form]) == 'undefined'){
		t_wall_call[_form] = false;
	}
	
	if(!t_wall_call[_form])
	{
		t_wall_call[_form] = true;
		$.ajax({type: 'post', url: '/sd-ajax/get-wall-message.php', data: 'token='+$(_form).find('input[name=token]').val()+'&id_item='+$(_form).find('input[name=id_item]').val()+'&entity='+$(_form).find('input[name=entity]').val()+'&older_id_message='+$(_form).find('input[name=older_id_message]').val()+'&form=' + _form , success: function (data) {eval(data);}});
	}
}

function wall_get_callback(_content, _form, _id_message, b_append, _el, b_no_other_message)
{
	if(b_append){
		$('#comment_content').append(_content);
		$(_form).find('input[name=older_id_message]').val(_id_message);
	}
	else{
		$('#comment_content').prepend(_content);
		$(_form).find('input[name=newest_id_message]').val(_id_message);
	}
	
	if(b_no_other_message){
		$("#see_all_comments").css('display', 'none');	
	}

	$("#commentaires>p").css('display', 'none');	

	$(_form).find('textarea[name=msg]').val('');
	$(_el).slideDown("slow");
	
	t_wall_call[_form] = false;
}

function wall_delete(_form, _id)
{
	$.ajax({type: 'post', url: '/sd-ajax/del-wall-message.php', data: 'token='+$(_form).find('input[name=token]').val()+'&id_item='+$(_form).find('input[name=id_item]').val()+'&entity='+$(_form).find('input[name=entity]').val()+'&id_message='+_id+'&form=' + _form , success: function (data) {eval(data);}});	
}

function wall_delete_callback(_id)
{
	$('div#com_' + _id ).slideUp("slow");
}



function ajax_search(_url, _type) {
	var form = '#form_search';
	$.ajax({type: $(form).attr("method"), url: _url , cache:false, data: $(form).serialize(), success: function (data) {display_search_data(data, _type);}});
}	
	
var timer_location = null;
function call_location()
{
	if(timer_location){
		window.clearTimeout(timer_location);
	}
	timer_location = window.setTimeout('search_resolve_addr()', 500);
}	


function search_resolve_addr(_d) 
{
	geocoder.getLatLng(
		$('#form_search input[name=place1]').val()+', fr',
		function(point) 
		{
			if(point){
				$('#form_search input[name=lat]').val( point.lat() );
				$('#form_search input[name=lng]').val( point.lng() );
				$('#form_search div#radius').css('display', 'block');
				$('#form_search input[name=place]').val( $('#form_search input[name=place1]').val() );
			}
			else{
				$('#form_search input[name=lat]').val('0');
				$('#form_search input[name=lng]').val('0');		
				$('#form_search div#radius').css('display', 'none');							
				$('#form_search input[name=place]').val( $('#form_search input[name=place1]').val() );
			}
		}
	);		
}

function search_resolve_coord() 
{
	geocoder.getLocations(new GLatLng(customer_coord.lat, customer_coord.lng) , function(response){
		if (response && response.Status.code == 200) {
			var place = response.Placemark[0];
			$('input[name=place1]').val(place.address);
			$('#form_search input[name=lat]').val( customer_coord.lat );
			$('#form_search input[name=lng]').val( customer_coord.lng );			
		}						   
	});
}

String.prototype.strip_tags = function(){
	tags = this;
	stripped = tags.replace(/[\<\>]/gi, "");
	return stripped;
}

String.prototype.is_mail = function(){
	var filter_email=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return filter_email.test(this);
}

String.prototype.is_postcode = function(){
	var filter_postcode=/^\d{5}$/i;
	return filter_postcode.test(this);
}

String.prototype.is_phone = function(){
	var filter_phone=/^\d{10}$/i;
	return filter_phone.test(this);
}

String.prototype.is_formatted_date = function(){
    var filter_phone=/^\d{2}\/\d{2}\/\d{4}$/i;
    return filter_phone.test(this);
}

function is_mail(mail){
    var filter_email=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    return filter_email.test(mail);
}

function PopupCentrer(page,name,largeur,hauteur,options) 
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	
	window.open(page,"_blank","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
		
function display_search_data(_data , _type)
{
	t_xml[_type] = _data;
	t_index[_type] = 0;
	sort_and_display(_type,  t_sort_select[_type], true );		
}

function getElementByTagName(_node, _s)
{
	if( _node.getElementsByTagName(_s)[0].childNodes.length > 0 )
	 	return _node.getElementsByTagName(_s)[0].childNodes[0].nodeValue;
	else	
		return '';
}

function getAttributeByTagName(_node, _tagName, _attrName)
{
	return  _node.getElementsByTagName(_tagName)[0].getAttribute(_attrName);
}
	
var t_carousel = new Array();
function nq_carousel(_el_content_name, _el_left_name, _el_right_name)
{
	var _length = $(_el_content_name+' li').length;
	t_carousel[_el_content_name]= {cur:0,max:_length};
	var _ul_width = 0;
	var _li_outer_width = $(_el_content_name+' li').outerWidth(true);
	var _ul_left_pos = -parseInt($(_el_content_name).css('left'));
	
	$(_el_content_name+' li').each(function(){_ul_width+=$(this).outerWidth(true)});

	if( _length > 2 ){
		$(_el_left_name).css('display', 'block');
		$(_el_right_name).css('display', 'block');			
	}		
	$(_el_content_name).width(_ul_width);
	
	$(_el_left_name).bind('click', function() {
		if( t_carousel[_el_content_name].cur>0 ){
			t_carousel[_el_content_name].cur--;
			$(_el_content_name).animate({left:'+='+_li_outer_width}, 500);
		}
	});
	
	$(_el_right_name).bind('click', function() {												 
		if( t_carousel[_el_content_name].cur<t_carousel[_el_content_name].max - 2 ){
			t_carousel[_el_content_name].cur++;
			$(_el_content_name).animate({left:'-='+_li_outer_width}, 500);
		}
	});																														
}

function d(_s)
{
    if( typeof(console.log) != 'undefined' && typeof(_s) != 'undefined' ){
        console.log(_s);
    }
}

function sendFriendRequest(id_customer, token, context)
{
    s = '';
    if( typeof(context) != 'undefined' ){
        s = '&context='+context;   
    }
	$.ajax({type: "POST", url: '/sd-ajax/send-friend-request.php' , data: 'id_customer='+id_customer+'&token='+token+s, success: function (data) {eval(data);}});
}
     

function hide_on_blur()
{
    $('#form_search input[name=lat]').val('0');
    $('#form_search input[name=lng]').val('0');        
    $('#form_search div#radius').css('display', 'none');                            
    $('#form_search input[name=place]').val( $('#form_search input[name=place1]').val() );        
}
            
function search_go_prev(_type)
{
    sort_and_display(_type, t_sort_select[_type], false, t_index[_type] - res_per_page);
}

function search_go_next(_type)
{
    sort_and_display(_type, t_sort_select[_type], false, t_index[_type] + res_per_page);
}         

    
function automation_change(_id)
{
    switch(_id)
    {
        case 1:
            break;
            
        case 2:
            break;
            
        case 3:
            break;
            
        case 4:
            break;                                                
    }
}

function init_carte(){
    init_gmap();
    $('#afficher_recherche').click(toogleCarte);
    importNQ.init_regroupement('background-color: rgb(255, 0, 0);height:10px;line-height:10px;padding-left:2px;padding-right:2px;padding-top:0px;padding-bottom:0px;',[-5,20],'#FFFFFF');
    
    
}

var deplacementSlider = false;
function toogleCarte(){
    if(!deplacementSlider){
        deplacementSlider = true;
        
        if($("#res").scrollLeft() == 0){
            montreCarte();
        } else{
            cacheCarte();
        }
    }
}

function montreCarte(){

    $('#res').animate({
        scrollLeft: 610
        }, 1000, function() {
        deplacementSlider = false;
        $("#textAfficheResultSousForme").html("texte");
    });
}

function cacheCarte(){
    $('#res').animate({
        scrollLeft: 0
        }, 1000, function() {
        deplacementSlider = false;
        $("#textAfficheResultSousForme").html("carte");
    });
}
  
    
function toggle_results(_el)
{
    if(_el.checked){
        display_div_result(_el.name);
    }
    else{
        hide_div_result(_el.name);
    }    
}

function display_div_result(_name)
{        
    $('div.'+ _name).slideDown('slow');
    
    //importNQ.toogleIconeHide(_name, false);    
    if(_name == 'parcours'){
        //importNQ.toogleMarker('2_regroup');
        importNQ.montreParcours();
    }
    
    if(_name == 'event'){
        //importNQ.toogleMarker('3_regroup');
        importNQ.montreEvent();
    }
    
    if(_name == 'customer'){
        importNQ.montreMembre();
    }
    
    if(_name == 'club'){
        //importNQ.toogleMarker('0_regroup');
        importNQ.montreClub();
    }

}
function hide_div_result(_name)
{
    $('div.'+ _name).slideUp('slow');
    
    //importNQ.toogleIconeHide(_name, true);
    if(_name == 'parcours'){
        //importNQ.toogleMarker('2_regroup');
        importNQ.cacheParcours();
    }
    
    if(_name == 'event'){
        //importNQ.toogleMarker('3_regroup');
        importNQ.montreEvent();
    }
    
    if(_name == 'customer'){
        importNQ.cacheMembre();
    }
    
    if(_name == 'club'){
        //importNQ.toogleMarker('0_regroup');
        importNQ.cacheClub();
    }
}


/* =============================================================================
									BLOCK MATERIEL NECESSAIRE
* ===========================================================================*/	

function open_materiel(a){
	if($(a).hasClass("materiel_necessaire_ouvert")){
		$(a).removeClass().addClass("materiel_necessaire");
		$(a).next(".contenu").fadeOut();
	}
	else {
		$(a).removeClass().addClass("materiel_necessaire_ouvert");
		$(a).next(".contenu").fadeIn();
	}
}
