// JavaScript Document

function completaCEP(campo)
 { 		
      qtdcaracteres = (campo.value).length;

      if(qtdcaracteres == 5)
	    campo.value = campo.value + "-";
 }
 

function completaFone(campo)
 { 	
 	qtdcaracteres = campo.value.length;

      if(qtdcaracteres == 0)
	    campo.value = campo.value + "(";
	  if(qtdcaracteres == 3)
	    campo.value = campo.value + ") "; 
	  if(qtdcaracteres == 9)
	    campo.value = campo.value + "-";   
	  else
	    campo.value = campo.value;   

 }
 
// ************************* FUNCOES DE DATA *************************** ///
function mascara_data(data)
{

	var mydata = '';
	mydata = mydata + data;
	if (mydata.length == 2){
	  mydata = mydata + '/';
	  document.forms[0].data.value = mydata;
	}
	if (mydata.length == 5){
	  mydata = mydata + '/';
	  document.forms[0].data.value = mydata;
	}
	if (mydata.length == 10){
	 // verifica_data();
	}
//	alert(document.forms[0].data.value);
}

//*********Funcoes Novas************************************************************
function validaData(str) { 

	dia = (str.value.substring(0,2)); 
    mes = (str.value.substring(3,5)); 
	ano = (str.value.substring(6,10)); 

	cons = true; 

	// verifica se foram digitados números
	if (isNaN(dia) || isNaN(mes) || isNaN(ano)){
		alert("Preencha a data somente com números."); 
		str.value = "";
		str.focus(); 
		return false;
	}
		
    // verifica o dia valido para cada mes 
    if ((dia < '01')||(dia < '01' || dia > '30') && 
		(mes == '04' || mes == '06' || mes == '09' || mes == '11' ) || dia > '31') { 
    	cons = false; 
	} 

	// verifica se o mes e valido 
	if (mes < 01 || mes > 12 ) { 
		cons = false; 
	} 

	// verifica se e ano bissexto 
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) 
	{ 
		cons = false; 
	} 
    
	if (cons == false) { 
		alert("A data inserida não é válida: " + str.value); 
		str.value = "";
		str.focus(); 
		return false;
	} 
}

function mascaraData(data,campo)
{
	var mydata = '';
	mydata = mydata + data;
	if (mydata.length == 2){
	  mydata = mydata + '/';
	  document.getElementById(campo).value = mydata;
	}
	if (mydata.length == 5){
	  mydata = mydata + '/';
	  document.getElementById(campo).value = mydata;
	}
	if (mydata.length == 10){
	 validaData(document.getElementById(campo));
	}
}
//****************************************************



	  
function mascara_hora(hora){
		  var myhora = '';
		  myhora = myhora + hora;
		  if (myhora.length == 2){
			  myhora = myhora + ':';
			  document.forms[0].hora.value = myhora;
		  }
		  if (myhora.length == 5){
			  verifica_hora();
		  }
	  }
         

/**********************************************************************************************/

function jumpMenu(form) 
{ 
	var newIndex = form.fieldname.selectedIndex; 
	if ( newIndex == 0 ) { 
		alert( "Selecione uma opção" ); 

	} else { 
		cururl = form.fieldname.options[ newIndex ].value; 
		window.location.assign( cururl ); 
	} 
} 

function submete(form) 
{             
		form.submit();
}

function confirmadel(form)
{

	if(confirm('Deseja realmente excluir esse registro'))
	{		
		form.submit();
	}
}
//*****************Retira espacos em branco*******************************
function trimAll(dados)
{
	while(''+dados.value.charAt(0)==' ')
		dados.value = dados.value.substring(1,dados.value.length);	
	return dados.value;			
}

function numerico(event) {
	var navegador = navigator.appName.toLowerCase(); 
	var mozilla = navegador.indexOf("netscape")+1;
	var tecla = mozilla ? event.which : event.keyCode;
	/* Vamos utilizar o objeto event para identificar quais teclas estão sendo pressionadas. */
	if( !((tecla >= 0 && tecla <= 43) || (tecla >= 48 && tecla <= 57) || tecla >= 127) ) {
			/* A propriedade keyCode revela o código ASCII da tecla pressionada. Sabemos que
			os números de 0 a 9 estão compreendidos entre os valores 48 e 57 da tabela referida.
			Então, caso os valores não estejam(!) neste intervalo, a função retorna falso
			para quem a chamou. */
			return false;
	}
}

function go(url) 
{ 
	location.href = url; 
}

function popUp(url,name,w,h,left,top,resizable,scrollbars,toolbar,status) 
{
	if(resizable == '') resizable = 'yes'; if(scrollbars == '')	scrollbars = 'yes'; if(toolbar == '') toolbar = 'no'; if(status == '') status = 'yes';
	eval("novajanela = window.open(url,name,'width="+w+",height="+h+",left="+left+",top="+top+",resizable="+resizable+",scrollbars="+scrollbars+",toolbar="+toolbar+",status="+status+"');");			
	if (window.focus) {
		novajanela.focus()
	}
}