var erros;

function add_error(msg) {
	erros = erros + "\n" + "- " + msg
}

function add_error2(msg, campo) {
	alert(msg)
	campo.focus()
}

function tem_erros() {
	return (erros.length != 0)
}

function mostra_erros() {
	alert("Erros no formulário: \n" + erros);
}

function vazio(texto) {
	var formato_correto = "([ ])*[a-zA-Z0-9\\-\\.]+([ ])*";
	var correto = new RegExp(formato_correto);
	var vazio
	vazio = false
	if (texto.length == 0) {
		vazio = true
	}
	return ((!correto.test(texto)) || vazio)
}

function data_br_valida(data) {
	var formato = "[0-3][0-9]/[0-1][0-9]/[0-9][0-9][0-9][0-9]";
	var reg = new RegExp(formato);
	var formato_ok = reg.test(data);
	var dia = data.substring(0,2);
	var mes = data.substring(3,5);
	var ano = data.substring(6,10);
	var nova_data = new Date(ano, mes - 1, dia);
	var dia_ok = (nova_data.getDate() == dia);
	var mes_ok = (nova_data.getMonth() + 1 == mes);
	return (formato_ok && dia_ok && mes_ok)
}

function data_br_valida_mes_ano(data) {
	var formato = "[0-1][0-9]/[0-9][0-9][0-9][0-9]";
	var reg = new RegExp(formato);
	var formato_ok = reg.test(data);
	var mes = data.substring(0,2);
	var ano = data.substring(3,7);
	var nova_data = new Date(ano, mes - 1);
	var mes_ok = (nova_data.getMonth() + 1 == mes);
	return (formato_ok && mes_ok)
}

function inteiro_valido(numero) {
	var validos = "0123456789";
	if (numero.length == 0)
		 return (false);
	for (j = 0; j < numero.length; j++)  {
		if (validos.indexOf(numero.charAt(j)) == -1)
			return (false)
	}
	return (true)
}

function menor_4000(texto) {
	if (texto.length > 4000)
		return false
	else
		return true
}

function menor_96(texto) {
	if (texto.length > 95)
		return false
	else
		return true
}


function decimal_valido(numero) {
	var validos = "0123456789.";
	if (numero.length == 0)
		 return (false);
	for (i = 0; i < numero.length; i++)  {
		if (validos.indexOf(numero.charAt(i)) == -1)
			return (false)
	}
	if (numero.indexOf(".") == -1)
		return (false);
		
	if (numero.indexOf(".") != numero.lastIndexOf("."))
		return (false);
		
	return (true)
}

function hora_valida(hora) {
	var formato = "[0-2][0-9]:[0-5][0-9]";
	var reg = new RegExp(formato);
	var formato_ok = reg.test(hora);
	var h = hora.substring(0,2);
	var m = hora.substring(3,5);
	var nova_hora = new Date(2000, 1, 1, h, m);
	var h_ok = (nova_hora.getHours() == h);
	var m_ok = (nova_hora.getMinutes() == m);
	return (formato_ok && h_ok && m_ok)
}

function email_valido(email) {
	var formato_errado = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
	var formato_certo = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
	var errado = new RegExp(formato_errado);
	var certo = new RegExp(formato_certo);
	return (!errado.test(email) && certo.test(email))
}
	
function Abrir_Pop_Up (href_pagina, NomeJanela, width_w, height_w, top_t, left_l, toolbar_t, location_l, directories_d, status_s, menubar_m, scrollbars_s, resizable_r) {
	window.open (href_pagina , NomeJanela, "width=" + width_w + ", height=" + height_w + ", top=" + top_t + ", left=" + left_l + ", toolbar=" + toolbar_t + ", location=" + location_l + ", directories=" + directories_d + ", status=" + status_s + ", menubar=" + menubar_m + ", scrollbars=" + scrollbars_s + ", resizable=" + resizable_r);
}
//<a href="javascript: Abrir_Pop_Up('/htmls/pesquisa_tarifas.htm', 'Detalhe', '550', '250', '30', '30', 'no', 'no', 'no', 'no', 'no', 'no', 'no')">Abre Pop Up</a>