var menuwidth='165px'; //default menu width
var menubgcolor='white'; //menu bgcolor
var disappeardelay=250;  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="no"; //hide menu when user clicks within menu?


var ie4=document.all;
var ns6=document.getElementById&&!document.all;

if (ie4||ns6)
	document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>');

function valida(referenciaElemento,validacao) {
	var valorCampo = referenciaElemento.value;
	var nomeCampo = referenciaElemento.name;
	var validacoes = new Array();

	// Declaracao das expressoes regulares
	validacoes.obrigatorio = /[^\s]+/i;
	validacoes.alfabetico = /[a-z]/i;
	validacoes.alfanumerico = /[a-z_0-9]/i;
	validacoes.texto = /[\w]/i;
	validacoes.numerico = /^\d*$/;
	validacoes.data = /^\d{2}\/\d{2}\/\d{4}$/;
	validacoes.email = /^[a-z]([a-z_.0-9]*)@[a-z-0-9]+(\.[a-z0-9]*)+$/i;
	validacoes.moeda = /^(R\$\s?)?\d{1,3}(\.?\d{3})*(\,\d{2})?$/;
	validacoes.telefone = /^\d{7,8}$/;
	validacoes.cep = /^\d{5}(-?\d{3})$/;
	validacoes.horario = /^([0-1][0-9]|[0-9]|2[0-3])[:,h][0-5]\d[:,m][0-5]\d[h,m,s]?$/i;
	validacoes.uf = /^AC$|^AL$|^AP$|^AM$|^BA$|^CE$|^DF$|^ES$|^GO$|^MA$|^MT$|^MS$|^MG$|^PA$|^PB$|^PR$|^PE$|^PI$|^RJ$|^RN$|^RS$|^RO$|^RR$|^SC$|^SP$|^SE$|^TO$/i;
	validacoes.sexo = /m|f/i;
	validacoes.cpf = /(\d{3}\.?){2}(\d{3}-?)\d{2}$/i;
	validacoes.cnpj = /(\d{8}\.?){2}(\d{3}-?)\d{2}$/i;
	validacoes.placa = /([a-zA-Z]{3})-?([0-9]{4})/i;

	// Aceita campo vazio se não for 'obrigatorio'
	if (valorCampo == null | valorCampo == "" && validacao != "obrigatorio") return true;
	if (referenciaElemento.length && validacao == "obrigatorio") {
		if(!verificaArray(referenciaElemento))	{
			return false;
		}
	}

	var expressao = validacoes[validacao];
	var validado = expressao.test(valorCampo);

	return validado;
}

function verificaArray(arr){
	var ok = false;
	if(arr)	{
		if(arr.length) {
			for(i=0;i<arr.length;i++) if(arr[i].checked) ok = true;
		}
		else if(arr.checked) ok = true;
	}
	return ok;
}
	
function trim(strValor)	 {
      // Retira Caracteres do Início
      var strData = "";
      var blnAchou = false;
      for(var i = 0 ; i < strValor.length ; i++) {
         if (strValor.substring(i,i+1) != ' ' | blnAchou ) {
            strData = strData + strValor.substring(i,i+1);
            blnAchou = true;
         }
      }
      
      // Retira Caracteres do Final
      strValor = strData;
      strData = "";
      blnAchou = false;
      for(var i = strValor.length ; i > 0 ; i--) {
         if (strValor.substring(i-1,i) != ' ' | blnAchou ) {
            strData = strValor.substring(i-1,i) + strData;
			blnAchou = true;
         }
      }
      return(strData);
}


function maskNumeric(obj, objEvent) {
	var Code = KeyPressAscCode(objEvent);
	var Char = KeyPressChar(objEvent);

	//obj.style.textAlign = 'right';

	if (Code == 8 || Code == 0 || objEvent.ctrlKey) {
		return true;
	} else {
		if (isNumeric(Char)) {
			return true;
		} else {
			return false;
		}
	}
}

function maskCurrency(obj, objEvent) {
	var Code, Letra, Valor, Milhar, Decimal;

	obj.style.textAlign = 'right';

	Code = KeyPressAscCode(objEvent);

	if (Code == 0 || Code == 8 || Code == 13) {
		return true;
	} else {
		Valor = obj.value;

		Valor = Valor.replace(/[^0-9]/g ,'');

		Letra = KeyPressChar(objEvent);

		if (Letra.search(/[^0-9]/g)) {
			Valor = Valor + Letra;

			if (Valor.length > 2) {
				Decimal = Math.floor(Valor%100).toString()//Valor.substr(-2, 2);
				//Valor = StringRevert(Valor);
				Milhar = Math.floor(Valor/100).toString();//Valor.substr(2);
				Milhar = StringRevert(Milhar);
				Milhar = StringChunk(Milhar, 3, '.');
				Milhar = StringRevert(Milhar);
				if (Math.floor(Decimal) < 10)
					Decimal = "0" + Decimal;
				Valor = Milhar + ',' + Decimal;
			}
			obj.value = Valor;
		}

		return false;
	}
}

function maskDate(obj, objEvent) {
	var Code = KeyPressAscCode(objEvent);

	//obj.style.textAlign = 'right';

	if (Code != 8 && !objEvent.ctrlKey){
		if ((obj.value.length == 2)||(obj.value.length == 5)){
			obj.value = obj.value + "/";
		}
	}
	
	return (maskNumeric(obj, objEvent));
}

function maskDecimal(obj, objEvent, numDecimais, separaMilhar) {
	var Code, Letra, Valor, Milhar, Decimal, defineDecimal;
	
	defineDecimal = Math.pow(10, numDecimais);
	
	//obj.style.textAlign = 'right';

	Code = KeyPressAscCode(objEvent);

	if (Code == 0 || Code == 8 || Code == 13) {
		return true;
	} else {
		Valor = obj.value;

		Valor = Valor.replace(/[^0-9]/g ,'');

		Letra = KeyPressChar(objEvent);

		if (Letra.search(/[^0-9]/g)) {
			Valor = Valor + Letra;

			if (Valor.length > numDecimais) {
				Decimal = Math.floor(Valor%defineDecimal).toString()//Valor.substr(-2, 2);
				//Valor = StringRevert(Valor);
				Milhar = Math.floor(Valor/defineDecimal).toString();//Valor.substr(2);
				if (separaMilhar) {
					Milhar = StringRevert(Milhar);
					Milhar = StringChunk(Milhar, 3, '.');
					Milhar = StringRevert(Milhar);
				}
				if (Math.floor(Decimal) < 10 && numDecimais == 2)
					Decimal = "0" + Decimal;
				Valor = Milhar;
				if (numDecimais > 0)
					Valor = Valor + ',' + Decimal;
			}
			obj.value = Valor;
		}

		return false;
	}
}

function maskDecimalOptional(obj, objEvent) {
	var Code = KeyPressAscCode(objEvent);
	var Char = KeyPressChar(objEvent);

	//obj.style.textAlign = 'right';

	if (Code == 8 || Code == 0 || objEvent.ctrlKey) {
		return true;
	} else {
		if (isNumeric(Char) || Char == "," || Char == ".") {
			return true;
		} else {
			return false;
		}
	}
}

function KeyPressAscCode(objEvent) {
	var Code;

	if (navigator.appName == 'Microsoft Internet Explorer') {
		Code = objEvent.keyCode;
	} else if (navigator.appName == 'Netscape') {
		Code = objEvent.which; 
	}

	return Code;
}

function KeyPressChar(objEvent) {
	var Letra;

	Letra = String.fromCharCode(KeyPressAscCode(objEvent));

	return Letra;
}

/* FUNÇÕES DO ARQUIVO FORM.JS - FIM */

/* FUNÇÕES DO ARQUIVO FUNCTIONS.JS - INÍCIO */

function isNumeric(value) {
	return stringValidation(value, "1234567890");
}

function stringValidation(value, validChars) {
	var rt = true;

	for (i = 0; i < value.length && rt == true; i++) {
		Char = value.charAt(i); 
		if (validChars.indexOf(Char) == -1) {
			rt = false;
		}
	}

	return rt;
}

function StringChunk (strTexto, intTamanho, strSeparador) {
	var Retorna, i;

	Retorna = '';

	for (i = 0; i <= strTexto.length; i++) {
		Retorna += strTexto.substr(i, 1);
		if ((i + 1) % intTamanho == 0 && i < strTexto.length - 1) {
			Retorna += strSeparador;
		}
	}

	return Retorna;
}

function StringRevert (strTexto) {
	var Retorna, i;

	Retorna = '';

	for (i = strTexto.length - 1; i >= 0; i--) {
		Retorna += strTexto.substr(i, 1);
	}

	return Retorna;
}

function cleanOptsSelect(strSelect){
	objSelect = document.getElementById(strSelect);
	for (i=0; i<objSelect.options.length; i++){
		objSelect.options[i] = null;
		i--;
	}
}

function emailCheck(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@*/|!=§#$%°ºª+,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	if (user.match(userPat)==null) {
	    //alert("The username doesn't seem to be valid.")
	    return false
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        //alert("Destination IP address is invalid!")
			return false
		    }
	    }
	    return true
	}
	
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
	    return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   //alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	
	if (len<2) {
	   /*var errStr="This address is missing a hostname!"
	   alert(errStr)*/
	   return false
	}
	
	return true;
}

function createFlashControl(idTarget, movie, wmode, bgcolor, height, width, flashvars) {
	var flashControl =  '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" height="' + height + '" width="' + width + '" align="middle">' +
						'<param name="allowScriptAccess" value="sameDomain" />' +
						'<param name="movie" value="' + movie + '" />' +
						'<param name="quality" value="high" />' + 
						'<param name="wmode" value="' + wmode + '" />' + 
						'<param name="bgcolor" value="' + bgcolor + '" />' +
						'<param name="flashvars" value="' + flashvars + '"/>' +
						'<embed src="' + movie + '" quality="high" wmode="' + wmode + '" bgcolor="' + bgcolor + '" height="' + height + '" width="' + width + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
						'</object>';
	document.getElementById(idTarget).innerHTML = flashControl;
}

function swapImage(imgName,newImg){
    if ((navigator.appName == 'Netscape' && parseFloat(navigator.appVersion) >= 3) || (parseFloat(navigator.appVersion) >= 4)){
        eval('document.' + imgName + '.src = "' + newImg + '"');
    }
}

function menu_competicao(){
document.write('<a href="index.html" onmouseover="swapImage(\'img01\',\'imagens/bt_comp01_on.gif\')" onmouseout="swapImage(\'img01\',\'imagens/bt_comp01_off.gif\');"> <img src="imagens/bt_comp01_off.gif" width="76" height="21" alt="" border="0" name="img01"></a> <a href="index.html" onmouseover="swapImage(\'img02\',\'imagens/bt_comp02_on.gif\')" onmouseout="swapImage(\'img02\',\'imagens/bt_comp02_off.gif\');"><img src="imagens/bt_comp02_off.gif" width="55" height="21" alt="" border="0" name="img02"></a> <a href="index.html" onmouseover="swapImage(\'img03\',\'imagens/bt_comp03_on.gif\')" onmouseout="swapImage(\'img03\',\'imagens/bt_comp03_off.gif\');"><img src="imagens/bt_comp03_off.gif" width="41" height="21" alt="" border="0" name="img03"></a> <a href="index.html" onmouseover="swapImage(\'img04\',\'imagens/bt_comp04_on.gif\')" onmouseout="swapImage(\'img04\',\'imagens/bt_comp04_off.gif\');"><img src="imagens/bt_comp04_off.gif" width="71" height="21" alt="" border="0" name="img04"></a> <a href="index.html" onmouseover="swapImage(\'img05\',\'imagens/bt_comp05_on.gif\')" onmouseout="swapImage(\'img05\',\'imagens/bt_comp05_off.gif\');"><img src="imagens/bt_comp05_off.gif" width="57" height="21" alt="" border="0" name="img05"></a> <a href="index.html" onmouseover="swapImage(\'img06\',\'imagens/bt_comp06_on.gif\')" onmouseout="swapImage(\'img06\',\'imagens/bt_comp06_off.gif\');"><img src="imagens/bt_comp06_off.gif" width="43" height="21" alt="" border="0" name="img06"></a>')
}


function pop(Url,winName,features) {
	window.open(Url,winName,features);
}


function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top="-500px"
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible
	else if (e.type=="click")
		obj.visibility=hidden
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	} else {
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
			if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
				edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
}

function populatemenu(what){
	if (ie4||ns6)
		dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	clearhidemenu()
	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
	populatemenu(menucontents)

	if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	}

	return clickreturnvalue()
}

function clickreturnvalue(){
	if (ie4||ns6) return false
	else return true
}

function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden"
	}
}

function delayhidemenu(){
	if (ie4||ns6)
		delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide)
}

function homeFindDiv(nomediv){
	escondedivs();
	var objdiv=document.getElementById(nomediv);
	if (objdiv.style.display!="block") {
		Effect.Appear(nomediv, {duration: 0.3});
	} else {
		Effect.Fade(nomediv, {duration: 0.3});
	}
}


function escondediv(nomediv){
	var objDiv = document.getElementById(nomediv);
	if(objDiv != null) { 
		Effect.Fade(nomediv, {duration: 0.3});
	}
}

if (hidemenu_onclick=="yes")
	document.onclick=hidemenu;

function escondedivs(){
	try { 
	document.getElementById('box01busca').style.display="none";
	document.getElementById('box02busca').style.display="none";
	document.getElementById('box03busca').style.display="none";
	document.getElementById('box04busca').style.display="none";
	}
	catch(e) {	
	}
	try {
	document.getElementById('box01busca_int').style.display="none";
	document.getElementById('box02busca_int').style.display="none";
	document.getElementById('box03busca_int').style.display="none";
	document.getElementById('box04busca_int').style.display="none";	
	}
	catch(e) {	
	}
}

 