$(document).ready(function(){
	var URL = "/admin/imoveis/proprietario/";
        $('#detalhe_proprietario').hide();
        function ver_detalhes(){
		if($('#id_proprietario').val() == ""){
                $('#detalhe_proprietario').hide();
            }
            else{
                $('#detalhe_proprietario').show();
                $('#detalhe_proprietario').attr('href', (URL+$('#id_proprietario').val()));    
            }
		
	}
	ver_detalhes();
	$('#id_proprietario').bind('change', function(){
            ver_detalhes();
	});
	function marcar_proposta(){
		var status = $('#id_proposta').attr('checked');
		var cor = status? '#f18585':'#fff'
		$('.proposta').css({background:cor});
	}
	marcar_proposta();
	$('#id_proposta').bind('click', function(){
		marcar_proposta();
	});
	
	$('.descricao-2').hide();
	$('h3').toggle(function(){
		var txt = $(this).text();
		$(this).text("-" + txt.substring(1,txt.length));
		$(this).next().slideDown();
	},
	function(){
		var txt = $(this).text();
		$(this).text("+" + txt.substring(1,txt.length)); 
		$(this).next().slideUp();
	});
	
});

function dismissAddAnotherPopup(win, newId, newRepr) {
    // newId and newRepr are expected to have previously been escaped by
    // django.utils.html.escape.
    newId = html_unescape(newId);
    newRepr = html_unescape(newRepr);
    var name = windowname_to_id(win.name);
    var elem = document.getElementById(name);
    if (elem) {
        if (elem.nodeName == 'SELECT') {
            var o = new Option(newRepr, newId);
            elem.options[elem.options.length] = o;
            o.selected = true;
        } else if (elem.nodeName == 'INPUT') {
            if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
                elem.value += ',' + newId;
            } else {
                elem.value = newId;
            }
        }
    } else {
        var toId = name + "_to";
        elem = document.getElementById(toId);
        var o = new Option(newRepr, newId);
        SelectBox.add_to_cache(toId, o);
        SelectBox.redisplay(toId);
    }
    window.location.reload();
    win.close();
}

