$( function() {
    inputuf = 'uf';
    inputcidade = 'cidCod'
    $("#"+inputuf).change(function(){
        $("#"+inputcidade).attr("disabled","disabled");
        $.ajax({
            type: "GET",
            url: "/xmldata/" + $(this).val().toLowerCase() + ".xml",
            dataType: "xml",
            success: function(xml) {
                // limpa o combo de cidade
                $("#"+inputcidade+" option:not(:first)").remove();
                $(xml).find("cid").each(function(){
                    $("#"+inputcidade).append("<option value=\"" + $(this).attr('cod') + "\">" + $(this).text() + "</option>");
                }); //close each(
                $("#"+inputcidade).removeAttr("disabled");
            }
        }); //close $.ajax(
    });
});

function salvar( codigo ) {
    $.post(
        "/ajax/salvarveiculos.php",
        { acao: "inserir", codigo: codigo },
        function (data) {
            retorno = $.trim(data);
            switch(retorno) {
                case '0':
                    alert("Ocorreu um erro ao tentar executar está ação.");
                    break;
                case '1':
                    alert("Veículo salvo com sucesso!");
                    break;
                case '2':
                    alert("Veículo já salvo!");
                    break;
                case '3':
                    alert("Veículo inexistente!");
                    break;
                default:
                    alert("Ocorreu um erro interno.");
            }
        }
    );
}


function AmpliaFoto(anuncio, foto, tamanho) {
	wincarrofoto = window.open('/mostraanuncio-foto.php?cd='+anuncio+'&foto=' + foto + '&size=' + tamanho,'wincarrofoto','top=0,left=0,resizable=no,location=no,toolbar=no,width=640,height=520,scrollbars=no');
	if (wincarrofoto && wincarrofoto.open) { wincarrofoto.focus(); }
}

function MsgErro() {
	alert('Desculpe-nos. No momento este anúncio não possui foto maior.');
}

function AbreJanelaMarcados(cd) {
   winmar = window.open('/marcados-inc.php?cd=' + cd + '&act=inserir&back=1','winmar','top=0,left=0,resizable=yes,location=no,toolbar=no,width=300,height=100,scrollbars=yes');
   if (winmar && winmar.open) { winmar.focus(); }
}

function AbreJanelaIndicacao(cd) {
	window.open('/indica.php?tpindicacao=anuncio&cd=' + cd,'indicacao','top=0,left=0,resizable=yes,location=no,toolbar=no,width=400,height=300,scrollbars=yes');
}

function AbreJanelaImpressao(cd) {
	wincarroimpressao = window.open('/impressaoanuncio.php?cd=' + cd,'wincarroimpressao','top=0,left=0,resizable=yes,location=no,toolbar=yes,width=700,height=500,scrollbars=yes');
   if (wincarroimpressao && wincarroimpressao.open) { wincarroimpressao.focus(); }
}

function AbreJanelaMapa(cliente) {
	winsdfmapa = window.open('/localizacaogm.php?cdloja='+cliente,'winsdfmapa','top=0,left=0,resizable=no,location=no,toolbar=no,width=600,height=450,scrollbars=no');
	if (winsdfmapa && winsdfmapa.open) { winsdfmapa.focus(); }
}

function AbreJanelaFotoLoja(cliente,seq) {
	winsdffotoloja = window.open('/bannerfotoloja.php?cdloja='+cliente+'&seq='+seq,'winsdffotoloja','top=0,left=0,resizable=no,location=no,toolbar=no,width=640,height=480,scrollbars=no');
	if (winsdffotoloja && winsdffotoloja.open) { winsdffotoloja.focus(); }
}




VerTelefone = {
	fones: [],
	cliente: 0,
	anuncio: 0,
	addTelefone: function (fone) {
		nextidx = this.fones.length;
		this.fones[nextidx] = fone;
	},
	exibir: function (objbotao) {
		html = (this.fones.length==1) ? '<p style="padding-top:18px;height:27px;">' : '<p>';
		html+= this.fones.join('<br />')+'</p>';
		document.getElementById(objbotao).parentNode.innerHTML = html;
		if (this.anuncio>0) ajaxGetContent( '/ajax/vertelefone.php?clicod='+this.cliente+'&anucod='+this.anuncio, '' );
	}
}




