// Coloca mascara no Telefone
function mascaratelefone (i)
 {


 var texto = i.value
//alert(event.keyCode) 
  
if (event.keyCode  == 46 || event.keyCode == 47 ) event.returnValue = false;
  
  if (event.keyCode  < 45 || event.keyCode > 57) event.returnValue = false;

 }

// Coloca mascara no CEP
function mascaracep (i)
 {
 var texto = i.value

	 if (i.value.length > 8)
		 event.returnValue = false;

   //if (event.keyCode  == 47 || event.keyCode == 46) event.returnValue = false;
  
  if (event.keyCode  < 48 || event.keyCode > 57) event.returnValue = false;
    
  if (texto == "." || texto == "/" ) event.returnValue = false;
 
  if (texto.length == 5 ) 
   {
   i.value = texto +"-";
   }
 }


// Coloca mascara na data
function mascaradata (i)
 {
 var texto = i.value
   //if (event.keyCode  == 47 || event.keyCode == 46) event.returnValue = false;
  

  if (i.value.length >= 10)
		 event.returnValue = false;

  if (event.keyCode  < 48 || event.keyCode > 57) event.returnValue = false;
    
  if (texto == "." || texto == "/" ) event.returnValue = false;
 
  if (texto.length == 2 || texto.length == 5 ) 
   {
   i.value = texto +"/";
   }
 }
 // Validação do campo DATA. 
 function validadata (i)
 {    var str = i.value;
 
     // if (str.length == 0)
     // { return true ; }
      
         // Verifica se foram digitados 10 caracteres.
         if (str.length != 10)
            {
            alert("\nO campo DATA requer 10 dígitos no formato:\n\nDD/MM/AAAA")
            i.focus() ;
            return false;
            }

       // Verifica se os caracteres são números e barra.
         for (var x = 0; x < str.length; x++) 
            {
            var ch = str.substring(x, x + 1);
            if ((ch < "0" || "9" < ch) && ch != "/") 
               {
               alert("\nO campo DATA aceita somente números e um barra no formato:\n\nDD/MM/AA");
            i.focus() ;
            return false;
               }
            }
         // Verifica o valor do dia.
         if ( (str.substring(0, 2) < 1)  ||  (str.substring(0, 2) > 31)  ) 
            {
            alert("\nDia incorreto.");
            i.focus() ;
            return false;
            }
         // Verifica o valor do dia no valor do mês.
            // Fevereiro
               if ( (str.substring(3, 5) == 2 )  &&  (str.substring(0, 2) > 29)  )
                  {
                  alert("\nFevereiro não tem mais que 29 dias.");
				  i.focus() ;
            return false;
                  }
               if ( (str.substring(3, 5) == 2 )  &&  (str.substring(0, 2) == 29)  )
                  { alert("\nVocê entrou com 29 de Fevereiro...\n\nVocê tem certeza de que é ano bissexto?"); }
            // Abril
               if ( (str.substring(3, 5) == 4 )  &&  (str.substring(0, 2) > 30)  )
                  {
                  alert("\nAbril não tem mais que 30 dias.");
				  i.focus() ;
				  return false;
                  }
            // Junho
               if ( (str.substring(3, 5) == 6 )  &&  (str.substring(0, 2) > 30)  )
                  {
                   alert("\nJunho não tem mais que 30 dias..");
				   i.focus() ;
				  return false;
                  }
            // Setembro
               if ( (str.substring(3, 5) == 9 )  &&  (str.substring(0, 2) > 30)  )
                  {
                    alert("\nSetembro não tem mais que 30 dias..");
				    i.focus() ;
				    return false;
                  }
            // Novembro
               if ( (str.substring(3, 5) == 11 )  &&  (str.substring(0, 2) > 30)  )
                  {
                   alert("\nNovembro não tem mais que 30 dias.");
                   i.focus() ;
				   return false;
                  }
         // Verifica o valor do mês.
         if ( (str.substring(3, 5) < 1)  ||  (str.substring(3, 5) > 12)  ) 
            {
            alert("\nMês incorreto.");
            i.focus() ;
            return false;
            }
         // Verifica o valor do ano.
         if ( (str.substring(6, 8) < 1)  ||  (str.substring(6, 8) > 99)  ) 
            {
            alert("\nAno incorreto.");
            i.focus() ;
            return false;
            }
         // Verifica posicionamento da barra.
         if ( str.substring(3, 4) == "/"  || str.substring(4, 5) == "/" ) 
            {
            alert("\nBarra misturada com o mês.");
            i.focus() ;
            return false;
            }
         if ( str.substring(0, 1) == "/"  || str.substring(1, 2) == "/" ) 
            {
            alert("\nBarra misturada com o dia.");
            i.focus() ;
            return false;
            }
         if ( str.substring(6, 7) == "/"  || str.substring(7, 8) == "/" ) 
            {
            alert("\nBarra misturada com o ano.");
            i.focus() ;
            return false;
            }
         if ( str.substring(2, 3) != "/"  ||  str.substring(5, 6) != "/" ) 
            {
            alert("\nBarra misturada com a data.");
            i.focus() ;
            return false;
            }
       
   return true;

 }
 
 
 
 function mascarahora24(i)
 {
 var texto = i.value
   //if (event.keyCode  == 47 || event.keyCode == 46) event.returnValue = false;
  

  if (i.value.length >= 5)
		 event.returnValue = false;

  if (event.keyCode  < 48 || event.keyCode > 57) event.returnValue = false;
    
  if (texto == "." || texto == "/" ) event.returnValue = false;
 
  if (texto.length == 2) 
   {
   i.value = texto +":";
   }
 } 
 
 
 
 // Validação do campo DATA. 
 function validahora24(i)
 {    var str = i.value;
 
     // if (str.length == 0)
     // { return true ; }
      
         // Verifica se foram digitados 10 caracteres.
         if (str.length != 5)
            {
            alert("\nO campo Hora requer 5 dígitos no formato:\n\nHH:MM")
            i.focus() ;
            return false;
            }

       // Verifica se os caracteres são números e barra.
         for (var x = 0; x < str.length; x++) 
            {
            var ch = str.substring(x, x + 1);
            if ((ch < "0" || "9" < ch) && ch != ":") 
               {
               alert("\nO campo DATA aceita somente números e dois pontos:\n\nHH:MM");
            i.focus() ;
            return false;
               }
            }
         // Verifica o valor da hora.
         if ( (str.substring(0, 2) < 00)  ||  (str.substring(0, 2) > 23)  ) 
            {
            alert("\nHora inválida.");
            i.focus() ;
            return false;
            }
            // Verifica os minutos.
        if ( (str.substring(3, 5) < 00 )  ||  (str.substring(0, 2) > 59)  )
            {
            alert("\nMinuto inválido.");
			i.focus() ;
			return false;
            }
       
   return true;

 }
 
    function comparadata (i,j,msg){
 		 data1 = i.value;
         data2 = j.value;
		 
		 if(data2=='') {
		  return true;
		 }
		 
         datainicial = data1.substring(6, 10) + data1.substring(3, 5) + data1.substring(0, 2)
         datafinal = data2.substring(6, 10) + data2.substring(3, 5) + data2.substring(0, 2)
		if(datainicial > datafinal){
		   	alert(msg);
			i.focus();
			return false;
		}
     }
  
  function vazio (i,mensagem)
{
str = document.forms[i].elements[i].value;
if ( str == "" )
  {
   alert( "Informe " + mensagem + " !!!" )
   document.forms[0].elements[i].focus() ;
   return false;
  } 
return true;
}
  
// Função que valida o e-mail .
 function validaemail(e)
{   var str = e.value;
  
       if (str == "")
            return true;
       
      
      if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
      else{
        return false;
        }
}
// Função que Formata Para Numero .
 
 function formatanumero(i)
{   
//alert(event.keyCode)

if ( event.keyCode == 45 || event.keyCode == 46 || event.keyCode == 47) event.returnValue = false;

if (event.keyCode  < 44 || event.keyCode > 57) event.returnValue = false;

}
 
 
 function validacpf (c) {
   var CPF = c.value;
    //alert (CPF)
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
	{
	    //alert("CPF inválido");
       // c.focus() ;
		return false;
	}
	
	
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9)))
			{
	   // alert("CPF inválido");
       // document.forms[0].elements[c].focus() ;
		return false;
	}
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10)))
			{
	   // alert("CPF inválido");
      //  document.forms[0].elements[c].focus() ;
		return false;
	}
	return true;
 }
 
 


function validaextensaoarquivo(arquivo)
{
	Indice = arquivo.value.indexOf(".");
	extensao= arquivo.value.substring(Indice,Indice + 4);

	extensaoValida = ".pdf, .doc, .rtf e .sxw";
	if ((extensao != ".pdf") &&(extensao != ".doc")&&(extensao != ".rtf")&&(extensao != ".sxw")&&(extensao != ".sdw") )
	{	
		alert('Extensão de Arquivo Invalida!!!\nAs extensões válidas são:'+extensaoValida)
		return (false);
    
	}
	else
		return (true);
}



function validanomearquivo(arquivo)
{

   var vObjeto = arquivo.value;
   var lenArquivo = vObjeto.length - 4;// 4 são da estensão

	
   var vCaracter = " ,.çàáèéìíòóùúâêîôûãõ~´`";
   var len = vCaracter.length+1;
   for (var i=1; i<= len-1 ; i++)
    {	  
      var caracter= vCaracter.substring(i,i-1);
      var vResult = vObjeto.indexOf(caracter);

	   if (vResult!='-1')
	   {
	      return(false);
	      break;
	   }
    }
  return(true);
}


function maxtamanho(frmCampo,tot, contagemregressiva) 
	{ 
		total = tot
		tam = frmCampo.value.length;   //  a variavel tam recebe o valor do objeto do form
		str=""; // a variavel str recebe valor ""
		str=str+tam; //  a variavel str recebe o seu valor mais o da variavel tam
		contagemregressiva.value = total - str; // o total tbm
		
				if (tam > total){  // se o tamanho for maior que o total
				aux = frmCampo.value; // a variavel aux recebe o valor do form
				frmCampo.value = aux.substring(0,total); // o script para a digitação dos caracteres
			//	Digitado.innerHTML = total
				contagemregressiva.value = 0 
								} 
								
	}  



	//Função que valida URL
	function validaurl(str) 
	{
	 var frmCampo = str.value;
	 	if (frmCampo == "")
			return true;
			
	  if (frmCampo.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	  {
        alert("Não é permitido preencher o campo de URL com o Email.");
        return false;
	  }
			
		if (frmCampo.search(/^(file|http):\/\/\S+\.(com|net|org|info|br|gov|pro|kit)$/) != -1)
			return true;
		else
		{
	 		alert(frmCampo+" é invalida.\n Digite o (http://) antes da sua URL.");
	 		return false;
		}
		
 	}
	function nomsobrenome(frmCampo) {
	nome = frmCampo.value;
	if (nome != '') {
		ponto 		= nome.lastIndexOf(' ');
		pontoFinal 	= nome.length;
		sobrenome 	= (nome.substr(ponto,pontoFinal));
		
		if (ponto == -1) {
				return false;
			};
		if (sobrenome == ' '){
				return false;
			};
		};
		return true;
	}
	
	
function testacaracterespecial(Caractervalido,campo)
{
  Alfabeto = Caractervalido;
  lenA = Alfabeto.length;
  len = campo.length;
  for (var i=0; i <= len-1 ; i++) {
	caracter= campo.substring(i,i+1);
	caracter= caracter.toLowerCase();
	   if (Alfabeto.indexOf(caracter,0) == -1) {
	      return true;
	      break;
	   }
  }
  return false;
}
	
	function confirma(texto,pagina,destino) {
	
	if(confirm(texto)==true) {
	
		window.open(pagina,destino);
	
	} else {
	
	return false;
	
	}
	
	}

//CONFIRMA AREA RESTRITA
function confirmar()
{
	if (document.form_sistema.usuario.value == "")
	{	alert ( "Informe o usuário ! ! ! ");
		document.form_sistema.usuario.focus();
		return false;
			}
	if (document.form_sistema.senha.value == "")
	{	alert( "Informe a senha ! ! ! ");
		document.form_sistema.senha.focus();
		return false;	
	}
return true;
}


//FUNÇÃO DE ENVIAR O EMAIL
function salvar(){
	  
   if(document.formulario.nome.value == '') {
   alert('Digite o nome!');
   document.formulario.nome.focus();
   return false;   
   }

   if(document.formulario.email.value == '') {
   alert('Digite o E-mail!');
   document.formulario.email.focus();
   return false;   
   }  else {
			 if(validaemail(document.formulario.email)==false) {
				 alert('E-mail inválido!');
				 document.formulario.email.focus();
				 return false;	
			 }			 
		 }
   
   if(document.formulario.mensagem.value == '') {
   alert('Digite a mensagem!');
   document.formulario.mensagem.focus();
   return false;   
   }
	   document.formulario.submit();
   }
/////

<!-- FUNÇÃO AJAX PARA ABRIR AS PÁGINAS
var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}


<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->



<!-- FUNÇÃO DE CLAUSULAS PARA NÃO FICAR EM BRANCO OS CAMPOS DO INFORMATIVO
function checa_formulario(form_informativo){
	
	if (form_informativo.nominformativo.value == "Nome:"){
		alert("É obrigatório colocar o seu Nome ! ! ! ");
		form_informativo.nominformativo.focus();
		return (false);	}
	
	if (form_informativo.desemailinformativo.value == "Seu E-mail:"){
		alert("É obrigatório colocar o seu E-mail ! ! ! ");
		form_informativo.desemailinformativo.focus();
		return (false);	}
	if (form_informativo.desemailinformativo.value.indexOf('@', 0) == -1){
		alert("O E-mail que você colocou é Inválido !!!");
		form_informativo.desemailinformativo.focus();
		return (false);	}

return (true);
}
//-->

<!-- ONFOCUS NOS CAMPOS INFORMATIVO
function clear_field(field){ if (field.value==field.defaultValue)
{ field.value='' } }
function check_field(field){
if (field.value=='' ||
field.value==' ') { field.value=field.defaultValue } }
//-->
