$(document).ajaxStop($.unblockUI); //.ajaxStart($.blockUI)
$(document).ready(function(){
	$('html').addClass('js');
	$('.tooltip').tooltip();
	$('.blockOverlay, .close-it').attr('title','Закрыть').live('click', function(){
		$.unblockUI();
	});
	
	$('#select-town').click(function(){
		
		$.blockUI({
			message: $('#towns'),
			css: {
				cursor: 'default',
				border: '0', 
				textAlign: 'left'
				//top:  ($(window).height() - 500) /2 + 'px'
			}
		});
		return false;
	});
	
	$('#towns li a').click(function(){
		
		$('#gorods').html($(this).text());
		//alert(0);
		getEstates();
		$.unblockUI();
		
	})
	
	
	$('#sender-order-link').click(function(){
	
		$('#orderform h2').html($('.position-title').text());
		
		$.blockUI({
			message: $('#orderform'),
			css: {
				cursor: 'default',
				border: '0', 
				textAlign: 'left',
				top:  ($(window).height() - 500) /2 + 'px'
			}
		});
		return false;
		
	});
	
	$('.orders li a').click(function(){
		
		if(!$(this).hasClass('li-3')) {
			$('#sender-order').show();
			$('#return-caller').hide();
			$('#sender-order .type-of-arenda').val($(this).text())
			
			$.blockUI({
				message: $('.popup'),
				css: {
					cursor: null,
					border: '0', 
					textAlign: 'left',
					top:  ($(window).height() - 500) /2 + 'px'
				}
			});
			return false;
			
		} else {
			return true;
		}
	});
	
	$('#rCall').click(function(){
	
		$('#sender-order').hide();
		$('#return-caller').show();
		$.blockUI({
			message: $('.popup'),
			css: {
				cursor: null,
				border: '0', 
				textAlign: 'left',
				top:  ($(window).height() - 500) /2 + 'px'
			}
		});
		return false;
	});
	/*
	$('.nums').click( function(){
	
		var whatIsClass = $(this).attr('id');
		
		if($(this).prev('input').val() == '0') {
			$(this).addClass(whatIsClass + '-active');
			$(this).prev('input').val(1);
			$(this).prev('input').attr('checked', 'checked');
		} else {
			$(this).removeClass(whatIsClass + '-active');
			$(this).prev('input').val(0);
			$(this).prev('input').attr('checked', '');
		};
		
		//getEstates();
	});
	*/

	
});

function sendOrderIt() {
	alert('hello world');
	$.unblockUI();
};

function sendOrder() {
	$('#sender-order').slideUp('fast');
	$('#ajaxer').slideDown('fast');
	
	$.ajax({
		type: 'post',
		url: '/ajax/feedback/',
		data: {
			'field_1': $('#field_3').val(),
			'field_2': $('#field_4').val(),
			'field_3': $('#field_5').val(),
			'field_4': $('#field_6').val(),
			'field_5': $('#field_7').val(),
			'field_6': $('#field_8').val(),
			'field_7[0]': ($('#field_9_0').attr('checked') ? '1' : ''),
			'field_7[1]': ($('#field_9_1').attr('checked') ? '2' : ''),
			'method': 'send',
			'posted': 1
		},
		success: function(response) {
			$('#sender-order').slideDown('fast');
			$('#ajaxer').slideUp('fast');
			//alert(response);
		}
	});
}

function requestCallback() {
	$('#return-caller').slideUp('fast');
	$('#ajaxer').slideDown('fast');
	
	$.ajax({
		type: 'post',
		url: '/ajax/feedback/',
		data: {
			field_8: $('#field_10').val(),
			method: 'send',
			posted: 1
		},
		success: function(response) {
			$('#return-caller').slideDown('fast');
			$('#ajaxer').slideUp('fast');
			//alert(response);
		}
	});
}

