<!--
// funções de Javascript





//AJAX_________________________________________

function cria_ajax()
	{
	var xmlhttp;
	try
		{
		xmlhttp = new XMLHttpRequest();
		}
	catch(ee)
		{
		try
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch(e)
			{
			try
				{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(E)
				{
				xmlhttp = false;
				}
			}
		}
	return xmlhttp;
	}
	
	



function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function






function checar(formulario)
{
for(var i=0;i<formulario.elements.length;i++)
     {
	 
	 var campo=formulario.elements[i];
	 
	 if(campo.type=="text" || campo.type=="hidden" || campo.type=="select" || campo.type=="select-one" || campo.type=="password" || campo.type=="file" || campo.type=="textarea" || campo.type=="radio")
	      {
	 	  var obriga=campo.getAttribute('obrigatorio');
	 	  var nomecampoatual=campo.getAttribute('nomecampo');
		  
		  if(campo.type=="radio" && obriga==1)
		       {
			   var meuradio=document.getElementsByName(campo.getAttribute('name'));
			   var preencheu = false;
			   for (var k=0; k<meuradio.length; k++) 
			             {
						 //alert(k + "- teste: " + meuradio[k].value + " está " + meuradio[k].checked);
						 
						 if (meuradio[k].checked)
						           {
								   preencheu = true;
								   }
  						 }
			  if (preencheu==false)
			            {
						alert("Ao menos uma das opções do campo '" + nomecampoatual + "' deve ser selecionada.");
			   			return false;
						break;
						}
			   }
		  else if(obriga==1 && trim(campo.value)=="")
		       {
			   alert("O campo '" + nomecampoatual + "' não pode ficar vazio.");
			   campo.focus();
			   return false;
			   break;
			   }
		  }
	 }
return true;
}



function limita_texto(field, countfield, maxlimit) 
     {
	 if (field.value.length > maxlimit) // if too long...trim it!
	      {
		  field.value = field.value.substring(0, maxlimit);
		  }
     else 
	      {
		  countfield.innerHTML = maxlimit - field.value.length;
		  }
     }




function checkAll(theForm, nome_classe) {
	for (i=0,n=theForm.elements.length;i<n;i++) 
		if (theForm.elements[i].className.indexOf(nome_classe) !=-1) 
			theForm.elements[i].checked = !theForm.elements[i].checked;
}





function toggle_contato() { //alert('toggle_contato');
	//$('link_toggle').innerHTML='';
	if($('contato').style.display=='none')	{
		Effect.BlindDown('contato');
		nova_frase='FECHAR';
	} else {
		Effect.BlindUp('contato');
		nova_frase='ABRIR';
	}
	//setTimeout(function() {$('link_toggle').innerHTML=nova_frase;}, 1000);
}


function submete(formulario) {
	if(checar(formulario)) {
		//alert('submeteria o formulário');
		$('bt_ok').hide();
		var quadro=$('mensagem_form');
			quadro.innerHTML="Enviando dados...";
		
		toggle_mensagem_form();
		
		var xmlhttp=cria_ajax();
		xmlhttp.open("GET", "ferramentas/ajax_envia_email.php?nome=" + $('nome').value + "&email=" + $('email').value + "&mensagem=" + $('mensagem').value, true);
		xmlhttp.onreadystatechange=function()
			{
			if(xmlhttp.readyState==4)
				{
				var texto=xmlhttp.responseText;
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);
				var dados=eval(texto);
				var erro=dados[0];
				var mensagem_retorno=dados[1];

				quadro.innerHTML=mensagem_retorno;
				
				if(erro==0)
					{
					//___mostra a mensagem de sucesso por 2 segundos e depois fecha o FORM
					setTimeout(function() {reseta_form();}, 2000);
					}
				else
					{
					$('bt_ok').show();
					}
				}
			}
		xmlhttp.send(null);
		delete xmlhttp;
		
	}
	return false;
}


function toggle_mensagem_form() { //alert('toggle_mensagem_form');
	Effect.toggle('quadro_mensagem', 'appear', {duration: 0.5});
	Effect.toggle('formulario', 'appear', {duration: 0.5});
}

function reseta_form() { //alert('reseta_form');
	$('bt_ok').hide();
	toggle_contato();
	$('nome').value='';
	$('email').value='';
	$('mensagem').value='';
	toggle_mensagem_form();
}



function muda_css(titulo_css) { //alert('nova cor: ' + titulo_css);
	var c, i, t;
	if(!(c = document.styleSheets)) {return;}
	i = c.length;
	while(i--) {
		if((t = c[i].title)) {
			c[i].disabled = (titulo_css != t);
		}
	}
	ajax_muda_cor(titulo_css);
	muda_css_folhinha(titulo_css);
}


function muda_css_folhinha(titulo_css) { //alert('nova cor: ' + titulo_css);
	var c, i, t, janela, pagina;
	janela = document.getElementById("folhinha");
	if(!janela) {return;}
    pagina = janela.contentWindow || janela.contentDocument;

	if(!(c = pagina.document.styleSheets)) {return;}
	i = c.length;
	while(i--) {
		if((t = c[i].title)) {
			c[i].disabled = (titulo_css != t);
		}
	}
}

function muda_mes(mes, ano) {
	formdados.mes.value=mes;
	formdados.ano.value=ano;
	formdados.submit();
}


function ajax_muda_cor(nome_cor) {
	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "ferramentas/ajax_muda_cor.php?nome_cor=" + nome_cor, true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			//alert('mudou para ID: ' + texto);
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
}





function loadAccordions() { //alert('load accordions');
	var bottomAccordion = new accordion('vertical_container');
	//var vetor_itens = $$('#vertical_container .accordion_toggle');
	
	// Se quiser abrir o primeiro conteúdo (casa "0" do vetor)...
	//bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
}


function load_prestadores(id_aberto) { //alert('load accordions');
	var bottomAccordion = new accordion('container_prestadores');

	if(id_aberto>=0) {
		bottomAccordion.activate($$('#container_prestadores .accordion_toggle')[id_aberto]);
	}
}


function validardecimal(e)
{
var tecla=codigo_tecla(e);
var valor=String.fromCharCode(tecla);

if (parseInt(valor)!=valor && valor!="-" && valor!="." && e.keyCode!="13")
	{
	e.returnValue=false;
	}
}


function codigo_tecla(e)
	{
	var tecla; 
	if(e && e.which)
		{
		e = e;
		tecla = e.which;
		}
	else
		{
		tecla = e.keyCode;
		}
	return tecla;	
	}


function enter_submete(e, formulario)
	{
	if(codigo_tecla(e) == 13)
		{
		//alert('pressionou ENTER');
		if(checar(formulario))
			{
			formulario.submit();
			}
		}
	else
		{
		return true;
		}
	}


function toggle_tipo_pessoa(tipo) {
	if(tipo=="PF")	{
		$('cnpj').value=$('empresa').value=$('ramo_atividade').value='';

		$('cnpj').setAttribute('obrigatorio',0);
		$('empresa').setAttribute('obrigatorio',0);
		$('ramo_atividade').setAttribute('obrigatorio',0);

		$('cpf').setAttribute('obrigatorio',1);
		$('nome').setAttribute('obrigatorio',1);
		$('dia_nascimento').setAttribute('obrigatorio',1);
		$('mes_nascimento').setAttribute('obrigatorio',1);
		$('ano_nascimento').setAttribute('obrigatorio',1);
		
		$('fields_pj').style.display='none';
		$('fields_pf').style.display='block';
	} else {
		$('cpf').value=$('nome').value=$('dia_nascimento').value=$('mes_nascimento').value=$('ano_nascimento').value='';

		$('cnpj').setAttribute('obrigatorio',1);
		$('empresa').setAttribute('obrigatorio',1);
		$('ramo_atividade').setAttribute('obrigatorio',1);

		$('cpf').setAttribute('obrigatorio',0);
		$('nome').setAttribute('obrigatorio',0);
		$('dia_nascimento').setAttribute('obrigatorio',0);
		$('mes_nascimento').setAttribute('obrigatorio',0);
		$('ano_nascimento').setAttribute('obrigatorio',0);

		$('fields_pj').style.display='block';
		$('fields_pf').style.display='none';
	}
}





-->