
function showLoading(){

	if($('#wrapper')){
		$('#wrapper').hide();
	}
	if($('#content_wrap')){
		$('#content_wrap').hide();
	}
	if($('#city_content_center')){
		$('#city_content_center').hide();
	}
	if($('#left')){
		$('#left').hide();
	}
	if($('#right')){
		$('#right').hide();
	}
	if($('#advanced_form')){
		$('#advanced_form').hide();
	}
    $('#ajax_loader_search_form').show();
    
}

//languages display
function show_panel() {
    $('#outer_panel').css('display','block');
}
function hide_panel() {
    $('#outer_panel').css('display','none');
}
function language_dropdown() {
    show_panel();
}

//home page and advanced search - boxes
function toggle_box(id) {
	if ($('#box_button_'+id).attr('class')=='expand') {
		$('#box_button_'+id).attr('class','collapse');
		$('#box_content_'+id).show();
	} else {
		$('#box_button_'+id).attr('class','expand');
		$('#box_content_'+id).hide();
	}
}

//hide/display hiden properties
function show_left_box(id){
	$('#show_'+id).hide();
	$('#hide_'+id).show();
	$('#div_hidden_'+id).show();
}
function hide_left_box(id){
	$('#show_'+id).show();
	$('#hide_'+id).hide();
	$('#div_hidden_'+id).hide();
}

//submit advanced search-form
function advanced_form(){

	var cities = [];
	$('input[name=city]:checked').each(function() {
		if($(this).val() > 0){
			cities.push($(this).val());
		}
	});
	var regions = [];
	$('input[name=region]:checked').each(function() {
		if($(this).val() > 0){
			regions.push($(this).val());
		}
	});
	var countries = [];
	$('input[name=country]:checked').each(function() {
		if($(this).val() > 0){
			countries.push($(this).val());
		}
	});
	var types = [];
	$('input[name=types]:checked').each(function() {
		if($(this).val() > 0){
			types.push($(this).val());
		}
	});
	var websites = [];
	$('input[name=website]:checked').each(function() {
		if($(this).val() > 0){
			websites.push($(this).val());
		}
	});
	var properties = [];
	$('input[name=properties]:checked').each(function() {
		if($(this).val() > 0){
			properties.push($(this).val());
		}
	});
	var people = 0;
	if ($('#people').length > 0){
		people = $('#people').val();
	}
	var bedrooms = 0;
	if($('#bedrooms').length > 0){
		bedrooms = $('#bedrooms').val();
	}
	var bathrooms = 0;
	if($('#bathrooms').length > 0){
		bathrooms = $('#bathrooms').val();
	}
	var stars = 0;
	if($('#stars').length > 0){
		stars = $('#stars').val();
	}
	var price = 0;
	if($('#price').length > 0){
		price = $('#price').val();
	}
	var size = 0;
	if($('#size').length > 0){
		size = $('#size').val();
	}
	var words = '';
	if($('#words').length > 0){
		words = $('#words').val();
	}
	
	var link = '';
	var addS = '';
	
	if(cities.length > 0){
		link += 'ci';
		for (i=0; i < cities.length; i++){
			link += '-'+cities[i];
		}
	}
	if(regions.length > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'re';
		for (i=0; i < regions.length; i++){
			link += '-'+regions[i];
		}
	}
	if(countries.length > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'co';
		for (i=0; i < countries.length; i++){
			link += '-'+countries[i];
		}
	}
	
	if(websites.length > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'so';
		for (i=0; i < websites.length; i++){
			link += '-'+websites[i];
		}
	}
	if(types.length > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'ty';
		for (i=0; i < types.length; i++){
			link += '-'+types[i];
		}
	}
	if(properties.length > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'pp';
		for (i=0; i < properties.length; i++){
			link += '-'+properties[i];
		}
	}
	
	if(people > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'pe-'+people;
	}
	if(bedrooms > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'ro-'+bedrooms;
	}
	if(bathrooms > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'ba-'+bathrooms;
	}
	if(stars > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'st-'+stars;
	}
	if(price > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'pr-'+price;
	}
	if(size > 0){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'si-'+size;
	}
	if(words !== ''){
		addS = '';
		if(link !== ''){
			addS = '-'; 
		}
		link += addS+'wo-'+words;
	}
	
	if(link == ''){
		//showGeneralMessageDialog('Erorr', 'Add at least one filter.');
		do_search();
		return false;
	}else{
		showLoading();
		var url = $('#link').val();
		window.location =url+link+'/';
	}
	return false;
}

function fcity(id){
	var check = $('#city_'+id).attr('checked');
	if(check){
		$('#city_'+id).attr('checked', '');
	}else{
		$('#city_'+id).attr('checked', 'checked');
	}
}
function fregion(id){
	var check = $('#region_'+id).attr('checked');
	if(check){
		$('#region_'+id).attr('checked', '');
	}else{
		$('#region_'+id).attr('checked', 'checked');
	}
}
function fcountry(id){
	var check = $('#country_'+id).attr('checked');
	if(check){
		$('#country_'+id).attr('checked', '');
	}else{
		$('#country_'+id).attr('checked', 'checked');
	}
}
function fwebsite(id){
	var check = $('#website_'+id).attr('checked');
	if(check){
		$('#website_'+id).attr('checked', '');
	}else{
		$('#website_'+id).attr('checked', 'checked');
	}
}







function initGeneralMessageDialog(){ // de pus: $(document).ready(function() {  initDialog() });
	$("#general_messages_dialog").dialog({
		autoOpen: false,
		modal: true,
		closeText: ''
	});
}

function showGeneralMessageDialog(title, message){

	initGeneralMessageDialog();

	$("#general_messages_dialog")
		.html(message)
		.dialog("open");
	$('#general_messages_dialog').dialog('option', 'title', title);

	$('#general_messages_dialog').dialog('option', 'buttons', {
		"OK":function(){
			$(this).dialog("close");
		}
	});

	return false;
}

function dialog_waiter(title,html) {

	initGeneralMessageDialog();
	$('#general_messages_dialog').dialog('option', 'width', 640);
	$('#general_messages_dialog').dialog('option', 'title', title);
	$("#general_messages_dialog").html(html+'<div class="ajax_loader"></div>');
    $('#general_messages_dialog').dialog('open');

}

var isNavEnter, isIEEnter;
if (parseInt(navigator.appVersion)>=4) {
	if(navigator.appName == "Netscape")
	{
		isNavEnter = true;
	}
	else
	{
		isIEEnter = true;
	}
}
function checkEnter(evt, action) {
	var key;
	if (isNavEnter) {
		key = evt.which;
	} else {
		key = window.event.keyCode;
	}
	if (key==13) {
		eval(action);
	}
}


/**
http://blog.stevenlevithan.com/archives/faster-trim-javascript
*/
function trim12(str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

