$(document).ready(function() {
	$("a[rel='external']").each(function() {
		$(this).attr("target","_blank");  
	});
	
	$("#txt_nome").click(function() {
		if ($(this).val()=="Busca por nome...") {
			$(this).val("");
		}
	});	
	
	$("#txt_nome").blur(function() {
		if ($(this).val()=="") {
			$(this).val("Busca por nome...");
		}
	});
	
	$("#txt_cidade").click(function() {
		if ($(this).val()=="... e por cidade") {
			$(this).val("");
		}
	});	
	
	$("#txt_cidade").blur(function() {
		if ($(this).val()=="") {
			$(this).val("... e por cidade");
		}
	});
		
	
	$("input[type=text], textarea").blur(function() {
		if ($(this).val()=="") {
			$("#error_"+$(this).attr("id")).fadeIn("fast");
			$(this).addClass("input-error");				 
		} else {
			$("#error_"+$(this).attr("id")).hide();
			$(this).removeClass("input-error");
		}
		
		if ($(this).attr("id")=="txtcontatoemail") {
			if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#txtcontatoemail").val()))) {
				$("#error_txtcontatoemail").fadeIn("fast");
				$("#txtcontatoemail").addClass("input-error");
			}
		}
	});
	
	$("#frmContato").submit(function() {
		$("input[type=text], textarea").removeClass("input-error");
		$("#error_contato").hide("fast");
		if ($("#txtcontatonome").val()=="") {
			$("#error_txtcontatonome").fadeIn("fast");
			$("#txtcontatonome").addClass("input-error");
			return false;
		} else if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#txtcontatoemail").val()))) {
			$("#error_txtcontatoemail").fadeIn("fast");
			$("#txtcontatoemail").addClass("input-error");
			return false;
		} else if ($("#txtcontatomensagem").val()=="") {
			$("#error_txtcontatomensagem").fadeIn("fast");
			$("#txtcontatomensagem").addClass("input-error");
			return false;
		}  else {
			return true;
		}
	});

	$("#frmCadastraFoto").submit(function() {
		$("input[type=text], textarea").removeClass("input-error");
		$("#error_contato").hide("fast");
		if ($("#foto_tx_nome").val()=="") {
			$("#error_foto_tx_nome").fadeIn("fast");
			$("#foto_tx_nome").addClass("input-error");
			return false;
		} else if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#txtcontatoemail").val()))) {
			$("#error_txtcontatoemail").fadeIn("fast");
			$("#txtcontatoemail").addClass("input-error");
			return false;
		} else if ($("#foto_tx_cidade").val()=="") {
			$("#error_foto_tx_cidade").fadeIn("fast");
			$("#foto_tx_cidade").addClass("input-error");
			return false;
		}  else if ($("#foto_tx_imagem").val()=="") {
			$("#error_foto_tx_imagem").fadeIn("fast");
			$("#foto_tx_imagem").addClass("input-error");
			return false;
		}  else {
			return true;
		}
	});
	
});