<!--
// 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');
		//Effect.toggle('bt_ok');
		//Effect.Fade('bt_ok', { duration: 0.1 });
		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)
					{
					Effect.Fade('bt_ok', { duration: 0.1 });
					//___mostra a mensagem de sucesso por 2 segundos e depois fecha o FORM
					setTimeout(function() {reseta_form();}, 2000);
					}
				else
					{
					//alert(mensagem_retorno);
					Effect.Appear('bt_ok', { duration: 0.1 });
					}
				}
			}
		xmlhttp.send(null);
		delete xmlhttp;
		
	}
	return false;
}


function submete_inscricao(formulario) {
	if(checar(formulario)) {
		//var check = document.getElementById('check_aceito');
		//if(check.checked) {
		if(true) {
			formulario.submit();
		} else {
			alert('Você precisa confirmar que leu e aceita o contrato para prosseguir com a inscrição.');
		}
	}
	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');
	Effect.Fade('bt_ok', { duration: 0.1 });
	toggle_contato();
	$('nome').value='';
	$('email').value='';
	$('mensagem').value='';
	toggle_mensagem_form();
}



//___funções do contrato

function abre_contrato() {//	alert('abriria o contrato');
	Effect.Appear('contrato', {to:0.8});
	Effect.Appear('contrato_cont', {to:1});
}

function fechar_contrato() {
	Effect.Fade('contrato');
	Effect.Fade('contrato_cont');
}






//___funções do banner da HOME

function init_banner() {
	Effect.Appear('banner', {to:0.8});
	Effect.Appear('banner_cont', {to:1});
}

function redirecionar() {
	//window.open('http://andersonbicicletas.com.br/?conteudo=proximos/andes_2009_programacao.php','_blank');
	location.href = 'andes_programacao.php';
	//location.href = 'california_programacao.php';
}
function visitar() {
	Effect.Fade('banner');
	Effect.Fade('banner_cont');
	setTimeout(redirecionar,1000);
}
function fechar() {
	Effect.Fade('banner');
	Effect.Fade('banner_cont');
}


-->
