function showSearchNumberDiv( div_id_number, form_name )
{
	switch( div_id_number )
	{
		case 'first':
		
			if ( $( 'second_search_label' ).className != 'search_label_blocked' )
				clearSecondTab(form_name);
						
			clearThirdTab();
			
			$( 'first_search_label' ).className = 'search_label_active_opened';
			show_node( 'first_search_cont' );
			
			
			break;
			
		case 'second':
		
			if ( $( 'second_search_label' ).className == 'search_label_blocked' )
				break;
		
			clearFirstTab();
			clearThirdTab();
			
			$( 'second_search_label' ).className = 'search_label_active_opened';
			show_node( 'second_search_cont' );
			
			break;
			
		case 'third':
			
			if ( $( 'third_search_label' ).className == 'search_label_blocked' )
				break;
			
			if ( $( 'second_search_label' ).className != 'search_label_blocked' )
				clearSecondTab(form_name);
				
			clearFirstTab();
			
			$( 'third_search_label' ).className = 'search_label_active_opened';
			show_node( 'third_search_cont' );
			
			$( 'location_radius_third' ).value = '';
						
			break;
 	}
}

function displayCountryCont( region_id )
{
	switch ( $( 'region_'+region_id ).className )
	{
		case 'country_region_closed_selected':

			$( 'region_'+region_id ).className = 'country_region_opened_selected';
			show_node( 'country_cont_'+region_id );
			break;
		
		case 'country_region_closed_unselected':
		
			$( 'region_'+region_id ).className = 'country_region_opened_unselected';
			show_node( 'country_cont_'+region_id );
			break;
			
		case 'country_region_opened_selected':

			$( 'region_'+region_id ).className = 'country_region_closed_selected';
			hide_node( 'country_cont_'+region_id );
			break;
		
		case 'country_region_opened_unselected':
		
			$( 'region_'+region_id ).className = 'country_region_closed_unselected';
			hide_node( 'country_cont_'+region_id );
			break;		
	}	
}

function setRegionDiv( region_id, total_countries )
{
	if ( checkSelectedCountries( region_id, total_countries ) )
		$( 'region_'+region_id ).className = 'country_region_opened_selected';
	else
		$( 'region_'+region_id ).className = 'country_region_opened_unselected';
}

function checkSelectedCountries( region_id, total_countries )
{
	for( var key = 1; key <= total_countries; key++ )
		if ( $( 'country_'+region_id+'_'+key ).checked )
			return true;
			
	return false;
}

function clearSecondTab( form_name )
{
	for( var k in $( 'second_search_cont' ).childNodes )
	{
		if ( !$( 'second_search_cont' ).childNodes[k].className )
			continue;
	
		if( /^country_region_.*/gi.exec( $( 'second_search_cont' ).childNodes[k].className ) )
		{
			$( 'second_search_cont' ).childNodes[k].className = 'country_region_closed_unselected';
		}
		else if ( $( 'second_search_cont' ).childNodes[k].className == 'region_country_cont_closed' )
		{
			$( 'second_search_cont' ).childNodes[k].style.display = 'none';
			$( 'second_search_cont' ).childNodes[k].style.opacity = 0;
		}
	}
	
	field = document.forms[form_name].elements['mcheck_country[]']

	for (var i = 0; i < field.length; i++ )
	{
		field[i].checked = false;
	}
	
	$( 'second_search_label' ).className = 'search_label_passive_closed';
	
	hide_node( 'second_search_cont' );
}

function clearFirstTab()
{
	$( 'first_search_label' ).className = 'search_label_passive_closed';
	
	hide_node( 'first_search_cont' );
	
	$( 'location_country_id' ).value = '';
	$( 'location_state_cont' ).className = 'location_unit_hide';
	$( 'location_state_id' ).value = '';
	$( 'location_city_cont' ).className = 'location_unit_hide';
	$( 'location_city_id' ).value = '';
	$( 'location_zip_cont' ).className = 'location_unit_hide';
	$( 'location_zip_first' ).value = '';
	$( 'location_radius_cont' ).className = 'location_unit_hide';
	$( 'location_radius_first' ).value = '';
	$( 'location_custom_location_cont' ).className = 'location_unit_hide';
	$( 'location_custom_location' ).value = '';
}

function clearThirdTab()
{
	$( 'third_search_label' ).className = ( $( 'third_search_label' ).className == 'search_label_blocked' ) ? 'search_label_blocked' :'search_label_passive_closed';
	
	hide_node( 'third_search_cont' );
	
	$( 'location_zip_third' ).value = '';
	$( 'location_radius_third' ).value = '';	
}

function hideTab( number )
{
	hide_node( number+'_search_cont' );
	$( number+'_search_label' ).className = 'search_label_active_closed';
}
