// +----------------------------------------------------------------------+
// | Desenvolvimento: Diego Lorena Delgado
// | Empresa: 				Infoxnet.com.br
// | Data da versão:	10/08/2006
// +----------------------------------------------------------------------+

// +----------------------------------------------------------------------+
// | Funções simples diversas
// +----------------------------------------------------------------------+
  // Link
	function Link(URL) {
 		 window.location = URL;
	}

	// Envio de formulário
	function Submit(URL) {
		 document.forms[0].action = URL;
		 document.forms[0].submit();
	}

	// Envio de formulario no caso de dois forms em uma mesma página
	function SubmitEspecial(URL) {
 		 document.forms[1].action = URL;
		 document.forms[1].submit();
	}

	// Envio de formulário com pergunta
	function SubmitDeleta(URL) {
		if(confirm('Deseja realmente apagar?')) {
	             document.forms[0].action = URL;
               document.forms[0].submit();
		}
	}

  // Envio de formulário com pergunta, para no caso de houver dois forms na mesma página
	function SubmitDeletaEspecial(URL) {
		if(confirm('Deseja realmente apagar?')) {
	             document.forms[1].action = URL;
               document.forms[1].submit();
		}
	}

  // Redirecionamento com pergunta
	function Deletar(URL) {
		if(confirm('Deseja realmente apagar?')) {
			 window.location = URL;
		}
	}

	// Repetido
	function SubmitNome(URL,ID) {
 		 document.getElementById(ID).action = URL;
		 document.getElementById(ID).submit();
	}    
	
	// Enviar dados do formulário quando apertar enter
	function onEnter(event) {
			if(event.keyCode==13) document.getElementById('entrar').submit();
	}

// +----------------------------------------------------------------------+
// | Muda botão marcar do cabeçalho
// +----------------------------------------------------------------------+
  var isInverse;
	function CheckTodos() {
		if(isInverse=="") isInverse = 0;
		var formObj = document.getElementById('formulario');

				   for (var i=0;i < formObj.length;i++) {
				      fldObj = formObj.elements[i];
				      if (fldObj.type == 'checkbox') {
				         if(isInverse) {
				            fldObj.checked = false;
				            //document.getElementById('bot_marcar').src = "../imagens/bot_marcar.gif";
				            document.getElementById('bot_marcar').value='  Marcar  ';
				         }else{
								 		fldObj.checked = true;
										//document.getElementById('bot_marcar').src = "../imagens/bot_desmarcar.gif";
										document.getElementById('bot_marcar').value='  Desmarcar  ';
								 }
				      }
				   }

				   if(isInverse) { isInverse = 0; }else{ isInverse = 1; }

	}
	
	
// +----------------------------------------------------------------------+
// | Muda botão marcar do cabeçalho
// +----------------------------------------------------------------------+
  var isInverse;
	function CheckTodos2() {
		if(isInverse=="") isInverse = 0;
		var formObj = document.getElementById('formulario');

				   for (var i=0;i < formObj.length;i++) {
				      fldObj = formObj.elements[i];
				      if (fldObj.type == 'checkbox') {
				         if(isInverse) {
				            fldObj.checked = false;
				            //document.getElementById('bot_marcar').src = "../imagens/bot_o_marcar.gif";
				            document.getElementById('bot_marcar').value='    Marcar    ';
				         }else{
								 		fldObj.checked = true;
										//document.getElementById('bot_marcar').src = "../imagens/bot_o_desmarcar.gif";
										document.getElementById('bot_marcar').value='  Desmarcar  ';
								 }
				      }
				   }

				   if(isInverse) { isInverse = 0; }else{ isInverse = 1; }

	}
	
// +----------------------------------------------------------------------+
// | Muda o ícone do som
// +----------------------------------------------------------------------+
				var somStatus = 1;
				
				function SomMudar() {
					 if(somStatus) {
					 	  document.getElementById('imgsom').src = "../imagens/bot_somd.gif";
					 	  document.getElementById('status').innerHTML = "Habilitar som";
					 	  somStatus = 0;
					 }else{
   		        document.getElementById('imgsom').src = "../imagens/bot_som.gif";
   		        document.getElementById('status').innerHTML = "Desabilitar som";
							somStatus = 1;
					 }
				}

// +----------------------------------------------------------------------+
// | Escreve no status o estado do som
// +----------------------------------------------------------------------+
				function Som() {
					 if(somStatus) {
					 	  document.getElementById('status').innerHTML = "Desabilitar som";
					 }else{
   		        document.getElementById('status').innerHTML = "Habilitar som";
					 }
				}

// +----------------------------------------------------------------------+
// | Toca o som
// +----------------------------------------------------------------------+
		   function playsom() {
				 	if(somStatus) {
				      if(navigator.userAgent.indexOf("MSIE") != -1) {
				         //document.write('<bgsound src=despertador.wav loop=1>');
				         document.getElementById('status').innerHTML = "<bgsound src=../despertador.wav loop=1>";
				      }else{
				         //document.write('<embed src=../despertador.wav loop=1 autostart=true hidden=true>');
				         document.getElementById('tocar_som').src = "../despertador.wav";
				         document.getElementById('tocar_som').play();
				      }
				      //alert('Tocou som');
	     		}
		   }


// +----------------------------------------------------------------------+
// | Escreve na div
// +----------------------------------------------------------------------+
				function Status(texto) {
           document.getElementById('status').innerHTML = texto;
				}

// +----------------------------------------------------------------------+
// | Insere uma TR na tabela dinâmica
// +----------------------------------------------------------------------+
				var count = 0;
				function insLinha(nome,texto)
				{
					var x=document.getElementById('papo').insertRow(count);
					var y=x.insertCell(0);
					var z=x.insertCell(1);
					y.innerHTML = nome;
					z.innerHTML = texto;
					alinhar = document.getElementById('papo').rows[count];
					alinhar.vAlign = "top";
					alinhar.cells[0].noWrap = "true";
					count++
				}

// +----------------------------------------------------------------------+
// | Insere uma TR na tabela dinâmica
// +----------------------------------------------------------------------+
				var count = 0;
				function insAnonima(texto)
				{
					var x=document.getElementById('papo').insertRow(count);
					var y=x.insertCell(0);
					y.innerHTML = texto;
					y.colSpan="2";
					alinhar = document.getElementById('papo').rows[count];
					alinhar.vAlign = "top";
					alinhar.cells[0].noWrap = "true";
					count++
				}

// +----------------------------------------------------------------------+
// | Mostra as DIV que contém as pré-mensagens
// +----------------------------------------------------------------------+
				var PreStatus = 0;
				function MostraPre() {
					if(!PreStatus) {
				    document.getElementById('pre').style.visibility = "visible";
				    document.getElementById('imgpre').src = "../imagens/bot_prev.gif";
            PreStatus = 1;
				  }else{
				    document.getElementById('pre').style.visibility = "hidden";
				    document.getElementById('imgpre').src = "../imagens/bot_pre.gif";
				    PreStatus = 0;
				  }
				}

// +----------------------------------------------------------------------+
// | Pergunta se deseja finalizar
// +----------------------------------------------------------------------+
	      function Pergunta(texto,caminho) {
						 if(confirm(texto)) {
							   window.location = caminho;
						 }
				}


// +----------------------------------------------------------------------+
// | Pergunta se deseja finalizar
// +----------------------------------------------------------------------+
				function historico(url) {

					window.open(url,'nome','height=00,width=100');

				}


// +----------------------------------------------------------------------+
// | Mostra a janela de avido que existe histórico
// +----------------------------------------------------------------------+
				function HistoricoWindows() {

			     document.getElementById('HistoricoWindows').style.visibility = 'visible';
			     setTimeout("document.getElementById('HistoricoWindows').style.visibility = 'hidden';",5000);

				}

// +----------------------------------------------------------------------+
// | Deixa digitar somente numeros no campo
// +----------------------------------------------------------------------+
  function SoNumero(evtKeyPress) {
      var nTecla = 0;

      if (document.all) {
  			 nTecla = evtKeyPress.keyCode;
      } else {
         nTecla = evtKeyPress.which;
      }

      if ((nTecla> 47 && nTecla <58) || nTecla == 8 || nTecla == 127 || nTecla == 0 || nTecla == 9 || nTecla == 13 || nTecla == 44) {
      	return true;
      } else {
      	return false;
      }

  }
  

// +----------------------------------------------------------------------+
// | Envia a mensagem pelo teclado
// +----------------------------------------------------------------------+
  function EnviaPeloTeclado(evento) {
			if(evento.shiftKey && evento.keyCode == 13) Registrar();
	}

	
// +----------------------------------------------------------------------+
// | Mascara as datas
// +----------------------------------------------------------------------+	
	function mascara_data(pthis){
		v_tam = pthis.value;
		if (v_tam.length == 2){
			 pthis.value += '/';
		}
		if (v_tam.length == 5){
			 pthis.value += '/';
		}
	}


// +----------------------------------------------------------------------+
// | Mascara as horas
// +----------------------------------------------------------------------+
	function FormataHora(hora,evento){

		v_tam = hora.value;
		if(evento.keyCode!='8') {
			if (v_tam.length == 2) hora.value += ':';
		}

    var valor = new String(hora.value);
    if(!(valor.substr(0, 1) >= 0 && valor.substr(0, 1) <= 2)) hora.value = '';
    if(!(valor.substr(3, 1) >= 0 && valor.substr(3, 1) <= 5)) hora.value = valor.substr(0,3);

	}
	

// +----------------------------------------------------------------------+
// | Contador de caracteres do campo
// +----------------------------------------------------------------------+
	function ContadorCarac(txarea,resposta) {

			total = 256;
			tam = txarea.value.length;
			str="";
			str=str+tam;
			//Digitado.innerHTML = str;
			resposta.innerHTML = total - str + " caracteres restantes";

			if (tam > total) {
				aux = txarea.value;
				txarea.value = aux.substring(0,total);
				//Digitado.innerHTML = total
				resposta.innerHTML = "Não é possível escrever acima de 256 caracteres!";
			}

	}
