$(document).ready(function(){
    $('#extButt').click(function(){
        var className = $(this).attr('class');
        if (className == 'close') {
            $(this).attr('class', '');
            $('#rozsirenyFilter').attr('class', '');
            $('#rozsirenyFilter').slideDown();
        }
        else {
            $(this).attr('class', 'close');
            $('#rozsirenyFilter').attr('class', '');
            $('#rozsirenyFilter').slideUp();
            $('#sForm #rozsirenyFilter .input').val('');
            $('#sForm #rozsirenyFilter .checkbox').attr('checked', '');
        }
        return false;
    })
	$('#sFormKraj').change(function(){
		var id = $(this).val();
		ajax('getOkresyByKrajCheckbox',{
			kraj: id
		},function(data) {
			$('#okresWrap').html(data);
		})
	})
    $('#typNehnutelnostiWrap .checkbox').click(function(){
        var stav = $(this).attr('checked');
        var id = $(this).attr('value');
        var callFunction = 'closeFilterSet';
        var className = '';
        if (stav) {
            callFunction = 'openFilterSet';
        }
        if (id == '1') {
        	className = 'byt';
        }
		if (id == '2' || id == '5') {
        	className = 'dom';
        }
		if (id == '3') {
        	className = 'poz';
        }
		if (id == '4') {
        	className = 'kom';
        }
		eval (callFunction+"('"+className+"');");
    })
	$('#sForm .input').attr('maxlength',8);
	$('#sForm .input').keyup(function(){
		$(this).val(intReplaceFnc($(this).val()));
	})
	$('#pi1 input').click(function(){
		var objs = $('#pi1 input');
		var array = new Array ();
		$.each(objs,function(){
			array.push($(this).attr('checked'));
		})
		var objs = $('#pi2 input');
		var poc = 0;
		$.each(objs,function(){
			$(this).attr('checked',array[poc]);
			poc++;
		})
	})
	$('#pi2 input').click(function(){
		var objs = $('#pi2 input');
		var array = new Array ();
		$.each(objs,function(){
			array.push($(this).attr('checked'));
		})
		var objs = $('#pi1 input');
		var poc = 0;
		$.each(objs,function(){
			$(this).attr('checked',array[poc]);
			poc++;
		})
	})
	$('#novostavbyChck').click(function(){
		if ($(this).attr('checked')) {
			$('.novostavba4').attr('checked',true);
		} else {
			$('.novostavba4').attr('checked',false);
		}
	})
	$('#sForm form').submit(function(){
		var checkBoxs = $('#sForm .checkbox');
		var inputs = $('#sForm .input');
		var selects = $('#sForm select');
		$.each(checkBoxs,function(){
			if (!$(this).attr('checked')) {
				$(this).attr('disabled',true);
			}
		})
		$.each(inputs,function(){
			if (!$(this).val()) {
				$(this).attr('disabled',true);
			}
		})
		$.each(selects,function(){
			if (!$(this).val() || $(this).val() == '0') {
				$(this).attr('disabled',true);
			}
		})
	})
})
function intReplaceFnc(value){
    var value = value.split('', 255);
    var newValue = new Array();
    jQuery.each(value, function(){
        if (this != '0' && this != '1' && this != '2' && this != '3' && this != '4' && this != '5' && this != '6' && this != '7' && this != '8' && this != '9') {
            return ''
        }
        else {
            newValue.push(this);
        }
    });
    return newValue.join('');
}
function openFilterSet(setClassName){
    if (setClassName) {
        $('#sForm .set.' + setClassName).slideDown();
    }
}
function closeFilterSet(setClassName){
    if (setClassName) {
        $('#sForm .set.' + setClassName).slideUp();
    }
}
