<div class="index_search_widget" id="index_search_widget">
	<div class="search_widget_qs_form float_left">
		<div class="search_block">
			<h2>{$lang.section.q_search}</h2>
			<form id="search_widget_form" action="{$server}/{$seo.quick_search}" method="POST">
				<div class="block">	
					<div class="lookingfor_im">
						<div class="looking_for">
							{$lang.profile.looking_for}<br />
							<select name="id_looking_user_type[]" id="id_looking_user_type" style="width:100%">
								{foreach name=user_type item=item from=$user_types}
									<option value="{$item.id}" {if $id_looking_user_type && $id_looking_user_type eq $item.id}selected="selected"{/if}>{$item.name}</option>
								{/foreach}
							</select>
						</div>
					</div>
				</div>
				<div class="block">
					<div class="birthday">	
						{$lang.home_page.between_the_ages_of}:<br />	
						<select style="width:42px;" name="age_min" id="age_min" class="index_select">
							{section name=a loop=$age_min}
								<option value="{$age_min[a]}" {if $form.age_min eq $age_min[a]}selected="selected"{/if}>{$age_min[a]}</option>
							{/section}
						</select>						
						<span style="line-height: 2.5">{$lang.users.to}</span>
						<select style="width:43px;" name="age_max" id="age_max" class="index_select">
							{section name=a loop=$age_max}
								<option value="{$age_max[a]}" {if $form.age_max eq $age_max[a]}selected="selected"{/if}>{$age_max[a]}</option>
							{/section}
						</select>
						
					</div>
				</div>
				<div class="block location_block" id="location_block">
					{$lang.sub_par.location}:<br />
					<div id="country_div">
						<select style="width:100%;" onchange="ChangeLocation(this, 'sw');" name="id_country" id="country" class="index_select">
							<option value="0" >{$header.choose_country}</option>
							{section name=a loop=$country}                                            
								<option value="{$country[a].id}">{$country[a].name}</option>
							{/section}
						</select>
					</div>
					<div id="region_div">
						<select style="width:100%;" onchange="ChangeLocation(this, 'sw');" name="id_region" id="region" class="index_select">
							<option value="0" >{$header.choose_region}</option>
						</select>
					</div>
					<div id="city_div">
						<select style="width:100%;" onchange="ChangeLocation(this, 'sw');" name="id_city" id="city" class="index_select">
							<option value="0" >{$header.choose_city}</option>
						</select>
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="search_widget_result float_left"></div>
</div>

{literal}
<script>
	var search_widget_count = 0;
	widgetSearch();
	
	$('#index_search_widget').on('change', 'select', function(){
		widgetSearch();
	}).on('mouseenter', '.search_widget_thumb', function(){
		$(this).find('.search_widget_result_info').fadeIn(100);
	}).on('mouseleave', '.search_widget_thumb', function(){
		$(this).find('.search_widget_result_info').fadeOut(100);
	});
	
	function widgetSearch(){
		var form_arr = $('#search_widget_form').serializeArray();
		var form_obj = {};
		for(var i in form_arr){
			form_obj[form_arr[i].name] = form_arr[i].value;
		}
		form_obj.foto_only = 1;
		form_obj.sel = 'search_widget';

		$.ajax({
			type: 'POST',
			url: '{/literal}{$server}/{$seo.quick_search}{literal}',
			data: form_obj,
			success: function(data, textStatus, jqXHR){
				if(jqXHR.count === search_widget_count && data){
					$('#index_search_widget').find('.search_widget_result').html(data);
				}
			},
			error: function(jqXHR, textStatus, errorThrown){
				if(typeof(console)!=='undefined'){
					console.log(errorThrown);
				}
			},
			beforeSend: function(jqXHR, settings){
				jqXHR.count = ++search_widget_count;
			},
			dataType: 'html',
			backend: 0
		});
	}
	
	function goSearchFromWidget(search_type){
		search_type = search_type || 'full';
		if(search_type == 'new'){
			location.href = $('#search_widget_form').attr('action') + '?sel=search&from_search=1&search_type=1&id_looking_user_type='+$('#id_looking_user_type').val();;
		}else{
			$('#search_widget_form').append('<input type="hidden" name="sel" value="search">')
				.append('<input type="hidden" name="from_search" value="1">')
				.append('<input type="hidden" name="foto_only" value="1">')
				.append('<input type="hidden" name="search_type" value="1">')
				.submit();
		}
	}
</script>
{/literal}
