function RTRIM(texto) {
	var re = / +$/;
	texto = texto.replace(re, "");
	return texto;
}
function LTRIM(texto) {
	var re = /^ +/;
	texto = texto.replace(re, "");
	return texto;
}
function TRIM(texto) {
	return LTRIM(RTRIM(texto));
}

function novo_captcha() {
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("captcha").src;
		thesrc = thesrc.substring(0, thesrc.lastIndexOf(".") + 4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("captcha").src = thesrc + "?" + Math.round(Math.random()*100000);
	} else {
		alert("Desculpe, não foi possível recarrecar automaticamente o Código de Confirmação\nEnvie o formulário e irá carregar um novo Código de Confirmação");
	}
}

function EmailValido(email) {
	var re = /^[a-z0-9][a-z0-9_\.\-]*[a-z0-9]\@(([a-z0-9][a-z0-9\-]*[a-z0-9])\.)+(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|[a-z]{2})$/;
	return re.test(email);
}

function URLValida(url) {
	var re = /^https?:\/\/[a-z0-9]+(\.[a-z0-9]+)+(\/.*)?$/;
	return re.test(url);
}

function DataValida(dia, mes, ano) {
	dia = TRIM(dia);
	mes = TRIM(mes);
	ano = TRIM(ano);
	
	re_dia = /^[0-9]{1,2}$/;
	re_mes = /^[0-9]{1,2}$/;
	re_ano = /^[0-9]{4}$/;
	
	if (!re_dia.test(dia) || !re_mes.test(mes) || !re_ano.test(ano)) {
		return false;
	} else if ((dia < 1 || dia > 31) || (mes < 1 || mes > 12) || (ano < 1000 || ano > 2999)) {
		return false;
	} else if ((mes == 4 || mes == 6 || mes == 9 || mes == 11) && dia > 30)  {
		return false;
	} else if (mes == 2 && dia > (ano % 4 == 0 ? 29 : 28)) {
		return false;
	}
	
	return true;
}

function SiteClique(a, i, u) {
	try {
		if (a === window)
			for (a = window.event.srcElement; a;) {
				if (a.href)
					break;
				a = a.parentNode;
			}
		var e;
		e = a.href;
		e = a.getAttribute("href", 2);
		var g;
		if (a.href == u) {
			a.href = [ "/", "siteclique", ".", "html", "?" + "id=", i, "&", "url", "=", u].join("");
		} else {
			a.href = u;
			a.onmousedown = "";
		}
	} catch (t) {
	}
	return true;
}
