function validaContato(){
	
	var valido = validaForm('contato');
	
	if(valido){
		document.forms['contato'].submit();
	}
	
}

function replaceAll(string, token, newtoken) {
	while (string.indexOf(token) != -1) {
 		string = string.replace(token, newtoken);
	}
	return string;
}


function hideBloco(idDiv){
	document.getElementById(idDiv).style.display = 'none';
}


function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'toomuch';
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}





function getElementByIdInsideObj(obj,idToFind){
	var content = obj.getElementsByTagName('*');
	for(y = 0; y<content.length; y++){
		if(content[y].id == idToFind){
			return content[y];
		}
	}
	return null;
}


function confirmResetForm(fm){
	//alert(document.form.fm.action);
	//document.form.fm.reset();
	
	var formularios = document.getElementsByTagName("form");
	
	for(i = 0;i<formularios.length; i++ ){
		if(formularios[i].name == fm){
			formularios[i].reset();
		}
	} 
}


function filtraResultados(tipo_id){
	var data = tipo_id.split("#");
	if (data.length > 0) {
		var tipo = data[0];
		var id = data[1];
		window.location.href = site_url+'/resultado/index/'+id+'/'+tipo;
	} 	
}




function mostraOcultaDiv(id,status){
    var div = document.getElementById(id);
	if (!status) {
    	div.style.display = div.style.display == 'none' ? 'block' : 'none';
	}else{
		div.style.display  = status;
	}
}

function mostraOcultaTabela(id, status){
	var tabela = document.getElementById(id);
	if (!status) {
		tabela.style.display = tabela.style.display == 'none' ? 'table' : 'none';
	}else{
		tabela.style.display  = status;
	}
}





	
function trace(txt){
	
	document.getElementById("trace").innerHTML = document.getElementById("trace").innerHTML+"<br>"+ txt;

}
	
function addEvent(elm, strEvent, fnHandler)
{
	return ( elm.addEventListener
	? elm.addEventListener( strEvent, fnHandler, false)
	: elm.attachEvent( 'on'+strEvent, fnHandler)
	);
}