// JavaScript Document
$(document).ready(function() {
	$("#form_anunciar").change(function() {
		//alert('123');
	});
	$("#estado").change(function() {
		// Post de busca de cidade
		$.post("libraries/modules/cadastro.php", { estados: $(this).val() }, function(data){
			$("#cidade_").replaceWith(data);
			$("#cidade").removeAttr('disabled');
		});
	});
	$('#preco').priceFormat({
	prefix: '',
	centsSeparator: ',',
	thousandsSeparator: '.'
	});
	///
	var option = {
		success: function(data) {
			alert('Anúncio Realizado. Direcionando para a Home.'); 
			window.location = 'http://www.vtn.com.br/vtnimoveis';
        }
	}
	
	$("#form_anunciar").ajaxForm(option);
	
	$("#anunciar").click(function() {
		var error = 0;	
		$("#form_anunciar").find("input").each(function() {
			$(this).css( "background-color","" );
			if($(this).val() == '') {
			$(this).css( "background-color","#FFDDDD" );
			error++;
			}
		});
		$("#form_anunciar").find("select").each(function() {
			$(this).css( "background-color","" );
			if($(this).val() == '') {
			$(this).css( "background-color","#FFDDDD" );
			error++;
			}
		});
		if(error > 0) {
			alert('Todos os Campos são Obrigatórios');	
		}
		else
		{
		$("#form_anunciar").ajaxSubmit(option);
		//alert('123');
		}
	});
});
