<!--
// funções de Javascript





//_____________________________________________


//função para pré-carregar imagens no documento. Basta digitar a URL das imagens, separadas por vírgula
//Não importa o número de argumentos. Cada argumento é uma imagem.

function carregar()
{
var imagens=new Array();

for (i=0; i<arguments.length; i++)
     {
     imagens[i]=new Image();
     imagens[i].src=arguments[i];
     }
}




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 confirma(destino, mensagem)
{

var quero;

quero=window.confirm(mensagem);

if(quero)
     {
	 window.location.href=destino;
	 }
}


function hide_and_seek(id_item)
     {
	 var elemento=document.getElementById(id_item);

	 if(elemento.style.display=='block')
	      {
	 	  elemento.style.display='none';
		  }
	 else
	      {
	 	  elemento.style.display='block';
		  }
     }
	 


function checkAll(theForm, cName) {
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements[i].className.indexOf(cName) !=-1)
if (theForm.elements[i].checked == true) {
theForm.elements[i].checked = false;
} else {
theForm.elements[i].checked = true;
}
}



//______________________________________________


function ativa_aba(id_aba)
	{
	//alert("aba ativa: " + id_aba);
	
	for(var i=1;i<6;i++)
		{
		aba=document.getElementById('aba' + i);
		submenu=document.getElementById('submenu' + i);
		
		if(i==id_aba)
			{
			aba.style.display='block';
			submenu.style.display='block';
			}
		else
			{
			aba.style.display='none';
			submenu.style.display='none';
			}
		}
	}



//______________________________________________



function init()
	{
	vetor_elementos=$$('a.entenda');
	for(i=0; i<vetor_elementos.length; i++)
		{
		Event.observe(vetor_elementos[i], 'click', toggle_acao);
		}
	}


//___funções do banner

function init_banner() {
	$('frame_folhinha').style.visibility='hidden';
	Effect.Appear('banner', {to:0.8});
	Effect.Appear('banner_cont', {to:1});
}

function fechar_banner() {
	Effect.Fade('banner');
	Effect.Fade('banner_cont');
	$('frame_folhinha').style.visibility='visible';
}









function toggle_acao(e)
	{
	var acao_clicada=Event.element(e);
	acao_clicada.toggleClassName('entenda_on');
	var id_acao=acao_clicada.readAttribute('id_acao');
	var paragrafo='parag_' + id_acao;
	//$(paragrafo).toggle();
	if(acao_clicada.hasClassName('entenda_on'))
		{
		//alert('abre');
		Effect.SlideDown(paragrafo, {duration: 0.2});
		//$(paragrafo).show();
		}
	else
		{
		//alert('fecha');
		Effect.SlideUp(paragrafo, {duration: 0.5});
		//$(paragrafo).hide();
		}
	}


function imprime_aulas(id_turma)
	{
	var destino = 'aulas_print.php?id_turma=' + id_turma;
	
	var altura=500;
	var largura=700;
	var esquerda=(screen.availWidth-largura)/2;
	var topo=(screen.availHeight-altura)/2;;
	
	window.open(destino, '','toolbar=yes, scrollbars=yes, left=' + esquerda + ', top=' + topo + ', width=' + largura + ', height= ' + altura + ''); 
	}


-->