$(function() {
    $('#slider_container').show();
    $('#slider').orbit({
        bullets: true,			 // true or false to activate the bullet navigation
        bulletThumbs: true,		 // thumbnails for the bullets
        directionalNav: false
    });
    set_judet_after_search();
	if($('#txtOras').val() == ''){
		$('#txtOras').val(80);
		$('#txtOras').change();
	}
    $('#slider_container').css('top',0);
    $('div#add_lstTipAnunts').html($('select#add_lstTipAnunt option:selected').text());
    $('div#lstTips').html($('select#lstTip option:selected').text());
    $('div#txtJudets').html($('select#txtJudet option:selected').text());
    $('div#txtOrass').html($('select#txtOras option:selected').text());
    $('div#txtCartiers').html($('select#txtCartier option:selected').text());
    $('select#add_lstTipAnunt').change(function(){
        $('div#add_lstTipAnunts').html($('select#add_lstTipAnunt option:selected').text());
    });
    $('select#lstTip').change(function(){
        $('div#lstTips').html($('select#lstTip option:selected').text());
    });
    $('select#txtJudet').change(function(){
        $('div#txtJudets').html($('select#txtJudet option:selected').text());
    });
    $('select#txtOras').change(function(){
        $('div#txtOrass').html($('select#txtOras option:selected').text());
    });
    $('select#txtCartier').change(function(){
        $('div#txtCartiers').html($('select#txtCartier option:selected').text());
    });
});

function set_judet_after_search(){
    if($('#txtJudet').val().length){
        $('#txtJudet').change();
    }
}

function set_cartier_after_search(){
    //if($('#hidIdOras').val().length){
    $('#txtOras').change();
    $('#txtCartier').val($('#hidIdCartier').val());
//}
}

function get_orase_combo(){
    var judet_id = $('#txtJudet').val();
	
    $.ajax({
        type: "POST",
        url: 'common.ajax.php',
        data: {
            op: 'get_orase_combo',
            judet_id:judet_id
        },
        cache:false,
        dataType: 'html',
        success: function(response){
            $('#txtOras').html(response);
            get_cartier_combo();
            if(!is_empty($('#hidIdOras').val())){
                $('#txtOras').val($('#hidIdOras').val());
                $('#txtOras').change();
            }
        },
        error:function(){
            alert('Ajax error!');
        }
    });
}

function get_cartier_combo(){
    var oras_id = $('#txtOras').val();
	
    $.ajax({
        type: "POST",
        url: 'common.ajax.php',
        data: {
            op: 'get_cartier_combo',
            oras_id:oras_id
        },
        cache:false,
        dataType: 'html',
        success: function(response){
            $('#txtCartier').html(response);
            if(!is_empty($('#hidIdCartier').val())){
                $('#txtCartier').val($('#hidIdCartier').val());
            }
        },
        error:function(){
            alert('Ajax error!');
        }
    });
}

function reset_search_form(){
    $('select#add_lstTipAnunt').val('');
    $('div#add_lstTipAnunts').html('');
    $('select#lstTip').val('');
    $('div#lstTips').html('');
    $('select#txtJudet').val('');
    $('div#txtJudets').html('');
    $('select#txtOras').val('');
    $('div#txtOrass').html('');
    $('select#txtCartier').val('');
    $('div#txtCartiers').html('');
    $('#txtPriceMax').val('');
    $('#txtSuprafataMin').val('');
    $('#txtSuprafataMax').val('');
    $('#chkPhoto').attr('checked',false);
    $('#txtPage1').val('1');
}

function predefined_search(offer_type_id, tipimobil_id){
    reset_search_form();
    $('select#add_lstTipAnunt').val(offer_type_id);
    $('div#add_lstTipAnunts').html(offer_type_id);
    $('select#lstTip').val(tipimobil_id);
    $('select#lstTip').val(tipimobil_id);
    DoSearch();
}

function apartamente_search(){
    $('#type').val('apartamente');
    DoSearch();
}
function case_search(){
    $('#type').val('case');
    DoSearch();
}
function terenuri_search(){
    $('#type').val('terenuri');
    DoSearch();
}
