

function refresh_ajax(typesTab, typesCheckedTab, nightsTab)
{
	
	$.ajax({
	    url: 'get_clubs_ajax.php',
	    type: 'POST',	  
	    data: "types="+typesTab+"&typesChecked="+typesCheckedTab+"&nights="+nightsTab,  
	    dataType: "html",
	    timeout: 3000,	    
	    error: function(){	    	
	        refresh_ajax(typesTab, typesCheckedTab, nightsTab);
	    },
	    success: function(result){	    
	        $('.body_left_wrap').html(result);
	    }
	});		
}


function refresh_type(id)
{	
	var id_num = id[3]+id[4];
	
	//on affiche le loading
	$('#clubs_filter_result').html('<br /><img src="/images/interface_clubaxs/indicator.gif" width="10px" height="10px" /> Loading...');
	
	//------------------------------- REFRESH TYPES
	
	// on bloque tous les checkbox de types
	$('#box29').attr('disabled',1);
	$('#box30').attr('disabled',1);
	$('#box31').attr('disabled',1);
	$('#box32').attr('disabled',1);
	$('#box33').attr('disabled',1);
	$('#box34').attr('disabled',1);
	$('#box35').attr('disabled',1);
	$('#box36').attr('disabled',1);
	$('#box37').attr('disabled',1);
			
	var typesTab = [];
	var typesCheckedTab = [];
		
	// on decoche la case All si on vient de decocher un club		
	if( ! $(id).attr('checked')  && id != 'auto' && id_num <= 37) {

		$('#box36').attr('checked',0);
	}
	
	// on coche All si tous les clubs sont cochés
	if( $('#box29').attr('checked') && $('#box30').attr('checked') && $('#box31').attr('checked') && $('#box32').attr('checked') && $('#box33').attr('checked') && $('#box34').attr('checked') && $('#box35').attr('checked') && $('#box37').attr('checked') ) {
		
		$('#box36').attr('checked',1);
		typesTab.push('all');		
		
	}
		
	if( $('#box29').attr('checked') ) {typesTab.push('nightclub'); typesCheckedTab.push(29); }
	if( $('#box30').attr('checked') ) {typesTab.push('lounge'); typesCheckedTab.push(30); }
	if( $('#box31').attr('checked') ) {typesTab.push('after-hours'); typesCheckedTab.push(31); }
	if( $('#box32').attr('checked') ) {typesTab.push('dayclub'); typesCheckedTab.push(32); }
	if( $('#box33').attr('checked') ) {typesTab.push('supper club'); typesCheckedTab.push(33); }
	if( $('#box34').attr('checked') ) {typesTab.push('private club'); typesCheckedTab.push(34); }
	if( $('#box35').attr('checked') ) {typesTab.push('concert venue'); typesCheckedTab.push(35); }
	if( $('#box36').attr('checked') ) {typesCheckedTab.push(36); }
	if( $('#box37').attr('checked') ) {typesTab.push('bar'); typesCheckedTab.push(37); }			
	
	//------------------------------- END REFRESH TYPES
	
	//------------------------------- REFRESH NIGHTS
	
	var nightsTab = [];
	// on bloque tous les checkbox de types
	$('#box52').attr('disabled',1);
	$('#box53').attr('disabled',1);
	$('#box54').attr('disabled',1);
	$('#box55').attr('disabled',1);
	$('#box56').attr('disabled',1);
	$('#box57').attr('disabled',1);
	$('#box58').attr('disabled',1);
	$('#box59').attr('disabled',1);
	
	// on decoche la case All si on vient de decocher une night
	if( ! $(id).attr('checked') && id != 'auto' && id_num >=52 ) {
		$('#box57').attr('checked',0);
	}
	
	// on envoie 'all' si toutes les nights sont cochés
	if( $('#box52').attr('checked') && $('#box53').attr('checked') && $('#box54').attr('checked') && $('#box55').attr('checked') && $('#box56').attr('checked') && $('#box58').attr('checked') && $('#box59').attr('checked') ) {
		
		nightsTab.push('all');		
		
	}
	
	else{
		
		if( $('#box52').attr('checked') ){ nightsTab.push('monday');}
		if( $('#box53').attr('checked') ){ nightsTab.push('saturday');}
		if( $('#box54').attr('checked') ){ nightsTab.push('tuesday');}
		if( $('#box55').attr('checked') ){ nightsTab.push('sunday');}
		if( $('#box56').attr('checked') ){ nightsTab.push('wednesday');}
		if( $('#box57').attr('checked') ){ nightsTab.push('all-none');}
		if( $('#box58').attr('checked') ){ nightsTab.push('thursday');}
		if( $('#box59').attr('checked') ){ nightsTab.push('friday');}
	}
	
	//------------------------------- END REFRESH NIGHTS
	
	refresh_ajax(typesTab, typesCheckedTab, nightsTab);
		                
}

function all_types()
{
	if($('#box36').attr('checked')) {
		
		$('#box29').attr('checked',1);
		$('#box30').attr('checked',1);
		$('#box31').attr('checked',1);
		$('#box32').attr('checked',1);
		$('#box33').attr('checked',1);
		$('#box34').attr('checked',1);
		$('#box35').attr('checked',1);
		$('#box37').attr('checked',1);
		
		refresh_type('auto');
		
	} else {
		
		$('#box29').attr('checked',0);
		$('#box30').attr('checked',0);
		$('#box31').attr('checked',0);
		$('#box32').attr('checked',0);
		$('#box33').attr('checked',0);
		$('#box34').attr('checked',0);
		$('#box35').attr('checked',0);
		$('#box37').attr('checked',0);		
		
		refresh_type('auto');	
	}
}

function all_nights()
{	
	
	if( $('#box57').attr('checked')) {									
	
		$('#box52').attr('checked',0);
		$('#box53').attr('checked',0);
		$('#box54').attr('checked',0);
		$('#box55').attr('checked',0);
		$('#box56').attr('checked',0);
		$('#box58').attr('checked',0);
		$('#box59').attr('checked',0);					
		
	}	
	refresh_type('auto');		
}


