$(document).ready(function() {

	// Промяна на избора от списъка с типове
	$('#type').change( function() {
		var id = $(this).val();
		
		$('#yard_area').css('display', 'none');
		$('#yard').val('');
		
		$('#act16').css('display', 'none');
		$('#act16_stamp').css('display', 'none');
		$('#act16_box').attr('checked', '');
		
		$('#floor').css('display', 'none');
		$('#floor_input').val('');
		$('#total_floors').val('');
		
		$('#construction').css('display', 'none');
		$('#construction_select').attr('selectedIndex', '');
		
		$('#month').attr('selectedIndex', '');
		$('#year').attr('selectedIndex', '');
		
		$('#thickness').css('display', 'none');
		$('#kint').css('display', 'none');
		$('#kota').css('display', 'none');
		
		// етаж от къща
		if (id==12) {
			$('#yard_area').css('display', '');
			$('#floor').css('display', '');
			$('#construction').css('display', '');
			$('#act16').css('display', '');
			
		// парцел
		} else if (id==13) {
			$('#thickness').css('display', '');
			$('#kint').css('display', '');
			$('#kota').css('display', '');
		// вила, къща, магазин, заведение, хотел, склад, пром. помещение, бензиностанция, фабрика
		} else if (id==10 || id==11 || id==14 || id==15 || id==16 || id==17 || id==18 || id==19 || id==23) {
			$('#yard_area').css('display', '');
			$('#construction').css('display', '');
			$('#act16').css('display', '');
		// гараж показваме само тип стройтелство
		}  else if (id==20) {
			$('#construction').css('display', '');
		// всичко освен земеделски имот , гора
		} else if (id!=21 && id!=22 && id!='') {
			$('#act16').css('display', '');
			$('#floor').css('display', '');
			$('#construction').css('display', '');
		}
		
		$('#extras').load('/?mod=ajax&resource=extras&id='+id);
	});
	
	// клик върху checkbox-а за "Без акт 16"
	$('#act16_box').click( function() {
		
		if ($(this).attr('checked')) {
			$('#act16_stamp').css('display', '');
		} else {
			$('#act16_stamp').css('display', 'none');
		}
		
	});
	
	// първоначално зареждане на екстрите
	if ($('#type') && $('#type').val()>0) {
		var id = $('#type').val();
		
		$('#yard_area').css('display', 'none');
		$('#act16').css('display', 'none');
		$('#floor').css('display', 'none');
		$('#construction').css('display', 'none');
		$('#thickness').css('display', 'none');
		$('#kint').css('display', 'none');
		$('#kota').css('display', 'none');
		
		// вила, къща, етаж от къща
		if (id==10 || id==11 || id==12) {
			$('#yard_area').css('display', '');
			$('#floor').css('display', '');
			$('#construction').css('display', '');
			$('#act16').css('display', '');
			
		// парцел
		} else if (id==13) {
			$('#thickness').css('display', '');
			$('#kint').css('display', '');
			$('#kota').css('display', '');
		// всичко освен земеделски имот , гора
		} else if (id!=21 && id!=22 && id!='') {
			$('#act16').css('display', '');
			$('#floor').css('display', '');
			$('#construction').css('display', '');
		}
		
		if ($('#act16_box').attr('checked')) {
			$('#act16_stamp').css('display', '');
		}
		
		
		var eid = new Array();
		$("input[@id^=extra_]").each(function() {
			eid.push($(this).val());
		});
		
		$.post('/?mod=ajax&resource=extras&id='+$('#type').val(), {'eid[]':eid}, function(data){
			$('#extras').append(data);
		});
		
	}
	
	
	$('.gallery').click( function() {
		window.open($(this).attr('href'), 'gallery', 'location=0,status=0,scrollbars=1,width=525,height=580');
		return false;
	});
	
	$('#toggle_bbcode').click( function() {
		tinyMCE.execCommand('mceToggleEditor',false,'html_description');
		return false;
	});
	
	
	var menuBgColor = '';
	$('ul#list > li').hover(
		function() {
			menuBgColor = $(this).attr('class');
			$(this).attr('class', 'yellow');
			$(this).find('div.cell').css('border-right', '1px solid #cccccc');
		},
		function() {
			$(this).attr('class', '');
			$(this).find('div.cell').css('border-right', '1px solid #ffffff');
			
		}
	);
	
	
	$("input[id='toggle_other_region']").click(function () {
		
		if ($(this).attr('checked')) {
			$('#other_region_block').css('display', '');
		} else {
			$('#other_region').val('');
			$('#other_region_block').css('display', 'none');
		}
		
	});
	
	
	
	$('#currency').change( function() {
		
		$.ajax({
			type: 'POST',
			url: '/?mod=ajax&resource=price-convert',
			data: 'currency=' + $('#currency').val() + '&price=' + $('#hidden_price').val() + '&area=' + $('#hidden_area').val(),
			dataType: 'script'
		});

	});
	
	$('input[@name^=default]').click( function() {
		$.ajax({
			type: 'POST',
			url: $(this).val()
		});
	});
		
});
