function getPackagesSide()
{
	gets = '&';
	destinations = '';
	check_plane = document.getElementById('packs_filter_plane');
	check_ship = document.getElementById('packs_filter_ship');
	check_car = document.getElementById('packs_filter_car');
	continents = $('#packs_destination_1').val();
	countries = $('#packs_destination_2').val();
	totalStates = $('#total_states_side').val();
	
	if(continents != '')
		destinations = continents;
	if(countries != '')
		destinations = countries;
	if(totalStates > 0)
	{	
		o = 0;
		for(i=0; i<totalStates; i++)
		{
			check = document.getElementById('states_'+i+'_side');
			
			
			if(check)
			{
				if(check.checked)
					{
						if(o == 0)
							{
							o = 1;
							destinations = '';
							}
						destinations += check.value+',';
					}
			}
		}
		if(o == 1)
			destinations = destinations.substring(0,(destinations.length -1));
	}
	if(check_plane.checked)
		gets += 'has_plane=1&';
	if(check_ship.checked)
		gets += 'has_ship=1&';
	if(check_car.checked)
		gets += 'has_car=1&';
	if(destinations != 'x' && gets != '&')
		document.location = '/web/packages.php?'+gets+'destinations='+destinations;
	else if(gets == '&' && destinations != 'x') 
		document.location = '/web/packages.php?destinations='+destinations;
	else if(destinations == 'x' && gets != '&') 
		document.location = '/web/packages.php?'+gets;
	else 
		document.location = '/web/packages.php?show_all=true';
}

function setSelect(child_select)
	{	
	switch(child_select)
		{
		case 'packs_destination_2':
			father_id = $('#packs_destination_1 option:selected').val();
			child_code = '<select name="packs_destination_2" id="packs_destination_2" onchange="triggerFilterSelection(\'packs_destination_2\');">';
			default_child_code = '<select name="packs_destination_2" id="packs_destination_2" disabled="disabled"><option value="x">País (Todos)</option></select>';

			if(father_id != 'x')
				{
				$.ajax({
					type: "POST",
					url: "/ok/getter.php?part=index_search_select&child_select="+child_select+"&father_id="+father_id,
					data: "",
					async: false,
					success: function(html){
						$('#'+child_select).replaceWith(child_code+html+'</select>');
						}
					});

				setFilterSelection(father_id);
				}
			else
				{
				$('#'+child_select).replaceWith(default_child_code);
		
				$('#index_top_packages_all_layer').show();
				$('#index_top_packages_car_layer').hide();
				$('#index_top_packages_plane_layer').hide();
				$('#index_top_packages_ship_layer').hide();
				}
		break;

		case 'articles_destination_2':
			father_select = 'articles_destination_1';
			father_id = $('#articles_destination_1 option:selected').val();
			child_code = '<select name="articles_destination_2" id="articles_destination_2" onchange="setSelect(\'articles_destination_3\');">';
			default_child_code = '<select name="articles_destination_2" id="articles_destination_2" disabled="disabled"><option value="x">País (Todos)</option></select>';
			default_child_code_lv2 = '<select name="articles_destination_3" id="articles_destination_3" disabled="disabled"><option value="x">Destino (Todos)</option></select>';

			if(father_id != 'x')
				{
				$.ajax({
					type: "POST",
					url: "/ok/getter.php?part=index_search_select&child_select="+child_select+"&father_id="+father_id,
					data: "",
					async: false,
					success: function(html){
						$('#'+child_select).replaceWith(child_code+html+'</select>');
						$('#articles_destination_3').replaceWith(default_child_code_lv2);
						setAuthorSelect(father_select);
						}
					});
				}
			else
				{
				$('#articles_destination_2').replaceWith(default_child_code);
				$('#articles_destination_3').replaceWith(default_child_code_lv2);
				setAuthorSelect('all');
				}
		break;

		case 'articles_destination_3':
			grand_father_select = 'articles_destination_1';
			father_select = 'articles_destination_2';
			father_id = $('#articles_destination_2 option:selected').val();
			child_code = '<select name="articles_destination_3" id="articles_destination_3" onchange="setSelect(\'articles_author\');">';
			default_child_code = '<select name="articles_destination_3" id="articles_destination_3" disabled="disabled"><option value="x">Destino (Todos)</option></select>';

			if(father_id != 'x')
				{
				$.ajax({
					type: "POST",
					url: "/ok/getter.php?part=index_search_select&child_select="+child_select+"&father_id="+father_id,
					data: "",
					async: false,
					success: function(html){
						$('#'+child_select).replaceWith(child_code+html+'</select>');
						setAuthorSelect(father_select);
						}
					});
				}
			else
				{
				$('#'+child_select).replaceWith(default_child_code);
				setAuthorSelect(grand_father_select);
				}
		break;
		
		case 'articles_author':
			grand_father_select = 'articles_destination_2';
			father_select = 'articles_destination_3';
			father_id = $('#articles_destination_3 option:selected').val();
			child_code = '<select name="articles_destination_3" id="articles_destination_3" onchange="setSelect(\'articles_author\');">';
			default_child_code = '<select name="articles_destination_3" id="articles_destination_3" disabled="disabled"><option value="x">País (Todos)</option></select>';

			if(father_id != 'x')
				{
				setAuthorSelect(father_select);
				}
			else
				{
				setAuthorSelect(grand_father_select);
				}
		break;
		}

	}

function setAuthorSelect(source_select)
	{
	father_id = $('#'+source_select+' option:selected').val();

	if(source_select == 'all')
		father_id = 'all';
		
	$.ajax({
		type: "POST",
		url: "/ok/getter.php?part=index_search_select&child_select=articles_author&father_id="+father_id,
		data: "",
		async: false,
		success: function(html){
			$('#articles_author').replaceWith('<select id="articles_author" name="articles_author">'+html+'</select>');
			}
		});
	}


function triggerFilterSelection(father_id)
	{
	setFilterSelection($('#'+father_id+' option:selected').val());
	}

function setFilterSelection(father_id)
	{
	/*Chekear si hay paquetes con auto*/
	$.ajax({
		type: "POST",
		url: "/ok/returner.php?test=index_search_packages&father_id="+father_id+"&has=car",
		data: "",
		async: false,
		success: function(html){
			if(html == '1')
				{
				$('#index_top_packages_car_layer').hide();
				$('#result_has_car').val('1');
				}
			else
				{
				$('#index_top_packages_car_layer').show();
				$('#result_has_car').val('0');
				}
			}
		});
	
	/*Chekear si hay paquetes con aéreo*/
	$.ajax({
		type: "POST",
		url: "/ok/returner.php?test=index_search_packages&father_id="+father_id+"&has=plane",
		data: "",
		async: false,
		success: function(html){
			if(html == '1')
				{
				$('#index_top_packages_plane_layer').hide();
				$('#result_has_plane').val('1');
				}
			else
				{
				$('#index_top_packages_plane_layer').show();
				$('#result_has_plane').val('0');
				}
			}
		});
	
	/*Chekear si hay paquetes con crucero*/
	$.ajax({
		type: "POST",
		url: "/ok/returner.php?test=index_search_packages&father_id="+father_id+"&has=ship",
		data: "",
		async: false,
		success: function(html){
			if(html == '1')
				{
				$('#index_top_packages_ship_layer').hide();
				$('#result_has_ship').val('1');
				}
			else
				{
				$('#index_top_packages_ship_layer').show();
				$('#result_has_ship').val('0');
				}
			}
		});
	
	if($('#result_has_car').val() == 0 &&
	   $('#result_has_plane').val() == 0 &&
	   $('#result_has_ship').val() == 0)
		{
		$('#index_top_packages_all_layer').show();
		$('#index_top_packages_car_layer').hide();
		$('#index_top_packages_plane_layer').hide();
		$('#index_top_packages_ship_layer').hide();
		}
	else
		$('#index_top_packages_all_layer').hide();
	}
	
function setFilters(action)
	{
	if(action == 'on')
		{
		$('#packs_filter_car').attr('disabled', '');
		$('#packs_filter_plane').attr('disabled', '');
		$('#packs_filter_ship').attr('disabled', '');
		}
	else
		{
		$('#packs_filter_car').attr('disabled', 'disabled');
		$('#packs_filter_plane').attr('disabled', 'disabled');
		$('#packs_filter_ship').attr('disabled', 'disabled');
		}
	}
