/** COMO UTILIZAR: onkeypress="evita_letra(event)"
 * N?o permite digitar letras em um input type=text
 */
function isNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   if (sText == ""){
         IsNumber = false;
   }
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


function evita_letra(tecla) {
	if (tecla.keyCode < 48 || tecla.keyCode > 57) 
		tecla.returnValue = false;
}



/**
 * Fun??o b?sica para submeter o formul?rio
 */

function frmSubmit(vlr) {
  if (checkData()) {
    return document.frmData.submit();	
  } else {
    return false;
  }
} 

/**
 * Valida??es
 */ 

function isEmpty(texto){
	if (texto == "") return false
	return true;
}

/**
 * Valida??o de Email
 *   . precisa existir uma arroba 
 *   . precisa existir um ponto depois da arroba
 */

function chkEmail(email){
	if (email.indexOf("@") < 3) return false
	if (email.charAt(email.indexOf("@")-1) == ".") return false;
	if (email.lastIndexOf(".") <= email.indexOf("@")) return false;
	if (email.lastIndexOf(".")  == (email.length-1)) return false; 
	return true;
}
/**
 * Valida??o de datas v?lidas
 */
function chkDate (mydata) {
	dia = (mydata.substring(0,2));
	mes = (mydata.substring(3,5));
	ano = (mydata.substring(6,10));
	situacao = "";
	// verifica o dia valido para cada mes
	if ((dia < 1)||(dia < 1 || dia > 30) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) || dia > 31) {
		situacao = "falsa";
	} 
	// verifica se o mes e valido
	if (mes < 1 || mes > 12 ) {
		situacao = "falsa";
	}
	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}
	if (mydata == "") {
		situacao = "falsa";
	}
	return situacao
}
function chkHora(campo){
	hrs = (campo.value.substring(0,2));
	min = (campo.value.substring(3,5));
	situacao = "";
	if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59)){
		situacao = "falsa";
	}
	if (campo.value == "") {
		situacao = "falsa";
	}

	if (situacao == "falsa") {
		alert("Hora inv?lida!");
		campo.focus();
	}
} 



/**
 * M?scara de Data
 */

function mskData(campo){
	var mydata = campo.value;
	
	if (mydata.length == 2){
		mydata = mydata + '/';
		campo.value = mydata;
	}
	if (mydata.length == 5){
		mydata = mydata + '/';
		campo.value = mydata;
	}
	if (mydata.length == 10){
		verifica_data(mydata);
	}
}
	  


function mskHora(campo){
	var myhora = '';
	myhora = myhora + campo.value;
	if (myhora.length == 2){
		myhora = myhora + ':';
		campo.value = myhora;
	}
	if (myhora.length == 5){
		verifica_hora(campo);
	}
}
/*
function mascara(valor, formato){
	var myhora = '';
	myhora = myhora + campo.value;
	
	if (myhora.length == 2){
		myhora = myhora + ':';
		campo.value = myhora;
	}
	if (myhora.length == 5){
		verifica_hora(campo);
	}
}
*/
	  


function addElement(elemento, id, valor){
	newOption = document.createElement("option");
	newOption.value = id;
	newOption.text=	valor;
	elemento.appendChild(newOption);
//	window.opener.document.frmData.idGrupo.appendChild(newOption); 
}

function checkAll(campo, ini, fim) { 
	for (var j=ini; j < fim; j++) {
//		alert(campo+'['+j+']');
		for (var i=0; i < document.frmDel.elements.length; i++) {
			var x = document.frmDel.elements[i];
			if (x.name == campo) {  
				if (x.checked == true)
					x.checked = false;
				else 
					x.checked = true;

			} 
		} 
	}
} 

function hideElement(idVisible, idShow ){
//	alert("Opa");
//	document.getElementById(id).style.visibility = "visible";
	if (document.getElementById(idVisible).style.display == "none"){
		document.getElementById(idVisible).style.display = "block";
		document.getElementById(idShow).style.display = "none";
	}else   {
		document.getElementById(idVisible).style.display = "none";
		document.getElementById(idShow).style.display = "block";
	}
}
function hideElement(idVisible){
	if (document.getElementById(idVisible).style.display == "none"){
		document.getElementById(idVisible).style.display = "block";
	}else   {
		document.getElementById(idVisible).style.display = "none";
	}
}
function getValueFromRadio(campo){
	value = false;
//	alert("length interno: "+campo.length)
	for (var i = 0; i < campo.length; i++) {
		if (campo[i].checked==true){
//			alert(campo[i].value);
			value=campo[i].value;
		}
	}
	return value;
}

/**
 * Rel?gio
 */

var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();
   var hora;
   
   var hrs = tDate.getHours();
   var min = tDate.getMinutes(); 

   if (hrs<10){
      hrs = "0"+hrs;
   }
   hora = hrs;   
   if (hrs<10){
      hrs = "0"+hrs;
   } else {
      hrs = hrs;
   }

   if (min<10){
      min = "0"+min;
   } else {
      min = min;
   }

   document.theClock.theTime.value = hora + ":" + min;
   
   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
	if (document.theClock){
		clockID = setTimeout("UpdateClock()", 500);
	}
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}


