$(document).ready(function(){
    $("#shire").change(function(){
        getCities();
    });
    $("#shire_id").change(function(){
        getCitiesReg(0);
    });
    $("#shire_id_d").change(function(){
        getCitiesDetail();
    });
    $("#shire_h").change(function(){
        getCitiesH();
    });
    $("#shire_h2").change(function(){
        getCitiesH2();
    });
    $("#type_id").change(function(){
        getParams();
		cchangeSearchDetaileed();
    });
    $("#step1").click(function(){
        $("#formEmail").submit();
		return false;
    });
});

function cchangeSearchDetaileed() {
	if ($('#type_id').val() == 1 || $('#type_id').val() == '-' || $('#type_id').val() == 6 || $('#type_id').val() == 4 )	{
		$('#szoba_id').slideDown(300);
	} else {
		$('#szoba_id').slideUp(300);
	}

	if ($('#type_id').val() == 5) {
		replaceOpt('meretek', 'getsize2/ha');
	} else {
		replaceOpt('meretek', 'getsize2/m2');
	}
}

function changeSearch() {
	if ($('#type').val() == 1 || $('#type').val() == '-' || $('#type').val() == 6 || $('#type').val() == 4 )	{
		$('#szoba').slideDown(300);
	} else {
		$('#szoba').slideUp(300);
	}
	if ($('#type').val() == 5) {
		replaceOpt('meret', 'getsize/ha');
	} else {
		replaceOpt('meret', 'getsize/m2');
	}
}

function replaceOpt(obj, link) {
    $.ajax({
        url: '/ajax/'+link,
        success: function(msg){
            $("#"+obj).html(msg);
        }
    });
}

function changeType(type) {
var kereskedelmi = Array(3,8,2,5);
	$("#usetype option").remove();
	if (type == 3 || type == 8 ||type == 2 ||type == 5 ) {
		$("#usetype").append('<option value="3">Kereskedelmi</option>');
	} else {
		$("#usetype").append('<option value="1">Új</option>');
		$("#usetype").append('<option value="2">Használt</option>');
	}
}

function getCities() {
    $("#city").attr('disabled', 'disabled');
    $.ajax({
        url: '/ajax/getcities/'+ $("#shire").val(),
        success: function(msg){
            $("#cityContainer").html(msg);
        }
    });
}

function getCitiesDetail() {
    $("#city_id").attr('disabled', 'disabled');
    $.ajax({
        url: '/ajax/getcities/'+ $("#shire_id_d").val() + '/detail',
        success: function(msg){
            $("#cityContainerDetail").html(msg);
        }
    });
}

function getCitiesReg(city) {
    $("#city_id").attr('disabled', 'disabled');
    $("#ajax_loader_small_reg").show();
    $.ajax({
        url: '/ajax/getcities_reg/'+ $("#shire_id").val()+'/'+ city,
        success: function(msg){
			if (msg == 'ERR') {
	            $("#ajax_loader_small_reg").hide();
			} else {
				$("#cityContainerReg").html(msg);
				$("#ajax_loader_small_reg").hide();
			}
        }
    });
}

function getCitiesH() {
    $("#city_id").attr('disabled', 'disabled');
    $("#ajax_loader_small_reg").show();
    $.ajax({
        url: '/ajax/getcities_h/'+ $("#shire_h").val(),
        success: function(msg){
			if (msg == 'ERR') {
	            $("#ajax_loader_small_reg").hide();
			} else {
				$("#cityContainerReg").html(msg);
				$("#ajax_loader_small_reg").hide();
			}
        }
    });
}

function getCitiesH2() {
    $("#city_id").attr('disabled', 'disabled');
    $("#ajax_loader_small_reg").show();
    $.ajax({
        url: '/ajax/getcities_h2/'+ $("#shire_h2").val(),
        success: function(msg){
			if (msg == 'ERR') {
	            $("#ajax_loader_small_reg").hide();
			} else {
				$("#cityContainerReg").html(msg);
				$("#ajax_loader_small_reg").hide();
			}
        }
    });
}

function confirmMsg(msg) {
	var con = confirm(msg);
	if (con) return true;
	else return false;
}


function getParams() {
    $("#params").hide();
    $("#ajax_loader_small_reg").show();
    $.ajax({
        url: '/ajax/getparams/'+ $("#type_id").val(),
        success: function(msg){
			$("#ajax_loader_small_reg").hide();
			$("#params").html(msg);
		    $("#params").show();
		}
    });
}

/* IE6 bugix - a select kitakarasa - kezdete */

function disableSelect() {
    $('#property-search').hide();
    $('#property-search-false').show();
}

function enableSelect() {
    $('#property-search').show();
    $('#property-search-false').hide();
}

/* IE6 bugix - a select kitakarasa - vege */
