// JavaScript Document

// brackground edit
function enable(componente, tipo)
{
   	 componente.className = 'campo2';
}

function disable(componente)
{
   componente.className = 'campo';
}

function validaemail(id){
    
	campo=document.getElementById(id);
	
	if(campo.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){
        alert("Insira um e-mail válido.!");
		campo.value="";
		campo.focus();
       return (false);
    }
    return true;
}
/*
<html>
<head>
<title>Teste Funcao Ismail</title>
</head>
<body>
<form method="POST" name="tstmail" action="seila.htm" onsubmit="return isEmail2(document.tstmail.mail);">
<input type="text" name="mail" size="50">
  <input type="submit" value="Envia" name="tst1">
  <input type="reset" value="limpa" name="tst2">
</form>
</body>
</html>*/
/*
<script language="JavaScript">
    
	function LimitarCaracter()
	{ 
         
		 Campo = document.getElementById("mensagem"); 

         Display = document.getElementById("contador");

   		Caracteres = 50 - Campo.value.length; 

    	Display.innerHTML = Caracteres; 

    	if(Campo.value.length >= 50){ 

        	Campo.value = Campo.value.substring(0, 50); 
    	} 
   } 

</script>
<onUnload="xpop()" */
    function confirmar(){	
		if(confirm("Deseja confirmar as Alterações?")){return true}else{return false}
    }	
	
	function LimitarCaracter(limite,id_campo)
	{ 
        Campo=document.getElementById(id_campo); 
    	Display = document.getElementById("contador"); 
		
   		Caracteres=limite-Campo.value.length; 

    	if(Caracteres<=0){ 
	    	Display.innerHTML=0
	 	} else{
	       	   	Display.innerHTML = Caracteres;
		      } 

    	if(Campo.value.length>=limite){
        	Campo.value = Campo.value.substring(0,limite);
			
        } 
    } 
	
	function menu(valor){
       if(document.getElementById(valor).style.display == "none"){
          document.getElementById(valor).style.display = "inline";
       }else{
            	document.getElementById(valor).style.display = "none";
            }
    }
	
	/*function TextBoxCPF_OnKeyUp(fsValor, foForm, foNome) { 
   var piLoop; 
   var psPalavra=''; 
   var psResposta='';  
   if (window.event.keyCode == 8){
      if (isNaN(fsValor.charAt(fsValor.length-1)) == true){
         document.forms[foForm].elements[foNome].value = fsValor.substring(0, (fsValor.length-1));
      }
   }
   else if (
	window.event.keyCode != 9  && 
	window.event.keyCode != 16 && 
	window.event.keyCode != 36 && 
	window.event.keyCode != 37 && 
	window.event.keyCode != 39){ 
		for(piLoop=0; piLoop <= (fsValor.length-1); piLoop++) { 
			if (fsValor.charAt(piLoop) >= '0' && fsValor.charAt(piLoop) <= '9') {
				psPalavra = psPalavra + fsValor.charAt(piLoop); 
			} 
		}
		for(piLoop=0; piLoop <= (psPalavra.length-1); piLoop++) { 
			if (piLoop == 2 || piLoop == 5){
				psResposta = psResposta + psPalavra.charAt(piLoop) + '.'; 
			}
			else if (piLoop == 8){
				psResposta = psResposta + psPalavra.charAt(piLoop) + '-'; 
			}
			else {
				psResposta = psResposta + psPalavra.charAt(piLoop);  
			}
		}  
   	document.forms[foForm].elements[foNome].value = psResposta.substring(0, 14);  
   }
   } */
   
   //-----------------------------------------------------
//Funcao: MascaraMoeda
//Sinopse: Mascara de preenchimento de moeda
//Parametro:
//   objTextBox : Objeto (TextBox)
//   SeparadorMilesimo : Caracter separador de milésimos
//   SeparadorDecimal : Caracter separador de decimais
//   e : Evento
//Retorno: Booleano
//Autor: Gabriel Fróes
//Data Criação: 15/02/2005
//-----------------------------------------------------


function validacpf(id)
{
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	numcpf=document.getElementById(id).value;
	len = numcpf.length; x = len -1;
	// var numcpf = "12345678909";
	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	//alert ("Digito Verificador : " + dig1 + "" + dig2);
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return '';
	}
	//alert ("Numero do CPF invalido !!!");
	return 'ERRO';
}


//-->

/*function so_numero(field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
}
*/	
//	onkeypress="return handleEnter(this, event)"


function BoxFormat(objForm, strField, strfull, sMask) {
      var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

      sValue = strfull;

      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( " ", "" );
      sValue = sValue.toString().replace( " ", "" );
      fldLen = sValue.length;
      mskLen = sMask.length;

      i = 0;
      nCount = 0;
      sCod = "";
      mskLen = fldLen;

      while (i <= mskLen) {
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

        if (bolMask) {
          sCod += sMask.charAt(i);
          mskLen++; }
        else {
          sCod += sValue.charAt(nCount);
          nCount++;
        }

        i++;
      }

      objForm[strField].value = sCod;

      if (nTecla != 8) { // backspace
        if (sMask.charAt(i-1) == "9") { // apenas números...
          return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
        else { // qualquer caracter...
          return true;
        } }
      else {
        return true;
      }
}


function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
      var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

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

      sValue = objForm[strField].value;

      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( " ", "" );
      sValue = sValue.toString().replace( " ", "" );
      fldLen = sValue.length;
      mskLen = sMask.length;

      i = 0;
      nCount = 0;
      sCod = "";
      mskLen = fldLen;

      while (i <= mskLen) {
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

        if (bolMask) {
          sCod += sMask.charAt(i);
          mskLen++; }
        else {
          sCod += sValue.charAt(nCount);
          nCount++;
        }

        i++;
      }

      objForm[strField].value = sCod;

      if (nTecla != 8) { // backspace
        if (sMask.charAt(i-1) == "9") { // apenas números...
          return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
        else { // qualquer caracter...
          return true;
        } }
      else {
        return true;
      }
}


//onkeypress="return txtBoxFormat(document.myForm, 'str_cep', '99999-999', event);"

function currencyFormat(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}
//onKeyPress="return(currencyFormat(this,',','.',event))"
	
function somente_numero(id){
	var digits="0123456789"
	var campo_temp 
	var campo = document.getElementById(id);
	for (var i=0;i<campo.value.length;i++){
	  campo_temp=campo.value.substring(i,i+1)	
	  if (digits.indexOf(campo_temp)==-1){
		    //campo.value = campo.value.substring(0,i);
		    return 'Telefone Inválido';
	   }
	}
	return '';
}
	
//////////////////////////////////////////////

function vertical() { 

   var navItems = document.getElementById("nav").getElementsByTagName("li"); 
    
   for (var i=0; i< navItems.length; i++) { 
      if(navItems[i].className == "submenu") { 
         navItems[i].onmouseover=function() {this.getElementsByTagName('ul')[0].style.display="block";this.style.backgroundColor = "#cccccc";} 
         navItems[i].onmouseout=function() {this.getElementsByTagName('ul')[0].style.display="none";this.style.backgroundColor = "#cccccc";} 
      } 
   } 

} 

function horizontal() { 

   var navItems = document.getElementById("barra").getElementsByTagName("li"); 
    
   for (var i=0; i< navItems.length; i++) { 
      if((navItems[i].className == "menuvertical") || (navItems[i].className == "submenu")) 
      { 
         if(navItems[i].getElementsByTagName('ul')[0] != null) 
         { 
            navItems[i].onmouseover=function() {this.getElementsByTagName('ul')[0].style.display="block";this.style.backgroundColor = "#cccccc";} 
            navItems[i].onmouseout=function() {this.getElementsByTagName('ul')[0].style.display="none";this.style.backgroundColor = "#cccccc";} 
         } 
      } 
   } 

} 


// nao seleciona 
function click() {
if (event.button==2||event.button==3) {
 oncontextmenu='return false';
  }
}
document.onmousedown=click
document.oncontextmenu = new Function("return false;")
	

function MM_formtCep(e,src,mask) {
    if(window.event) { _TXT = e.keyCode; } 
    else if(e.which) { _TXT = e.which; }
    if(_TXT > 47 && _TXT < 58) { 
 var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
 if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); } 
    return true; } else { if (_TXT != 8) { return false; } 
 else { return true; }
    }
}

function windowopen()
{
    window.open ("intranet/index.php", "novaJanela", "scrollbars=yes, status=yes, toolbar=no, location=no, directories=yes, menubar=yes, resizable=yes, fullscreen=yes");
}

  /*function mostra(valor,tipo)
  {
  		
		var get=<? if($_GET['id_tipo']!=''){ echo $_GET['id_tipo'];}else{ echo "''"; }?>;
		var get2=<? if($_GET['id_empresa']!=''){ echo $_GET['id_empresa'];}else{ echo "''"; }?>;
		
		if((get!='') && (tipo=='2'))
		{
			valor='1';
			document.getElementById(valor).style.display = "inline";
		}else{
		        if((get2!='') && (tipo=='2'))
				{
					valor='1';
					document.getElementById(valor).style.display = "inline";
				}else{
		
					 	if(tipo=='1')
						{
						
							if(document.getElementById(valor).style.display == "none")
							{
								document.getElementById(valor).style.display = "inline";
  							}else
								{
 									document.getElementById(valor).style.display = "none";
  								}
					  					  	
					  	}	
					}
		
			 }
				
		
		
		
 }*/
	
// Início do código de Aumentar/ Diminuir a letra
 
// Para usar coloque o comando: "javascript:mudaTamanho('tag_ou_id_alvo', -1);" para diminuir
// e o comando "javascript:mudaTamanho('tag_ou_id_alvo', +1);" para aumentar
 
var tagAlvo = new Array('p'); //pega todas as tags p//
 
// Especificando os possíveis tamanhos de fontes, poderia ser: x-small, small...
var tamanhos = new Array( '9px','10px','11px','12px','13px','14px','15px' );
var tamanhoInicial = 2;
 
function mudaTamanho( idAlvo,acao ){
  if (!document.getElementById) return
  var selecionados = null,tamanho = tamanhoInicial,i,j,tagsAlvo;
  tamanho += acao;
  if ( tamanho < 0 ) tamanho = 0;
  if ( tamanho > 6 ) tamanho = 6;
  tamanhoInicial = tamanho;
  if ( !( selecionados = document.getElementById( idAlvo ) ) ) selecionados = document.getElementsByTagName( idAlvo )[ 0 ];
  
  selecionados.style.fontSize = tamanhos[ tamanho ];
  
  for ( i = 0; i < tagAlvo.length; i++ ){
    tagsAlvo = selecionados.getElementsByTagName( tagAlvo[ i ] );
    for ( j = 0; j < tagsAlvo.length; j++ ) tagsAlvo[ j ].style.fontSize = tamanhos[ tamanho ];
  }
}
// Fim do código de Aumentar/ Diminuir a letra


//======================================================= segurança de senha
/*
www.brunogross.com
*/
function Security(val, tamanho) {
 	
 	document.getElementById('d_baixa').style.background = 'white';
 	document.getElementById('d_media').style.background = 'white';
 	document.getElementById('d_alta').style.background = 'white';
 if(val == "")
 {
	document.getElementById('d_baixa').style.background = 'white';
 	document.getElementById('d_media').style.background = 'white';
 	document.getElementById('d_alta').style.background = 'white';
  
   return;   
 }
 if(val.length < tamanho )
 {
	document.getElementById('d_baixa').style.background = 'white';
 	document.getElementById('d_media').style.background = 'white';
 	document.getElementById('d_alta').style.background = 'white';
   
   return;   
 }
 
 
	if( val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) != -1 
		||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) 
		||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1 && val.search(/[0-9]/) 
		||val.length >= tamanho  && val.search(/[@!#$%&*+=?|-]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) )
		{
  			document.getElementById('d_baixa').style.background = 'green';
 				document.getElementById('d_media').style.background = 'green';
 				document.getElementById('d_alta').style.background = 'green';
  		
  	} else{
  		if( val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 
  			||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[0-9]/) != -1 
  			||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1
				||val.length >= tamanho && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) != -1
				||val.length >= tamanho && val.search(/[A-Z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1
				||val.length >= tamanho && val.search(/[0-9]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1){
  			
  				document.getElementById('d_baixa').style.background = 'yellow';
 				document.getElementById('d_media').style.background = 'yellow';
 				document.getElementById('d_alta').style.background = 'white';
  				
  			} 
  			else {
  				if(val.length >= tamanho)
  				{
  					document.getElementById('d_baixa').style.background = 'red';
 						document.getElementById('d_media').style.background = 'white';
 						document.getElementById('d_alta').style.background = 'white';
  					
  				}
  		}
  	}
  }
	
//=================================================ADICIONAR INPUT

function addRowToTable() 
{ 
	var tbl = document.getElementById('tblSample'); 
	var lastRow = tbl.rows.length; 
	// if there's no header row in the table, then iteration = lastRow + 1 
	var iteration = lastRow; 
	var row = tbl.insertRow(lastRow); 
	
	// left cell 
	var cellLeft = row.insertCell(0); 
	var textNode = document.createTextNode(iteration); 
	cellLeft.appendChild(textNode); 
	
	// right cell 
	var cellRight = row.insertCell(1); 
	var el = document.createElement('input'); 
		el.setAttribute('type', 'text'); 
		el.setAttribute('name', 'txtRow' + iteration); 
		el.setAttribute('id', 'txtRow' + iteration); 
		el.setAttribute('size', '40');
		el.setAttribute('class', 'campo3');
		el.onkeypress = keyPressTest;
		cellRight.appendChild(el); 
		document.getElementById('txtRow' + iteration).focus();
	
	// select cell 
	/*var cellRightSel = row.insertCell(2); 
	var sel = document.createElement('select'); 
	sel.setAttribute('name', 'selRow' + iteration); 
	sel.options[0] = new Option('text zero', 'value0'); 
	sel.options[1] = new Option('text one', 'value1'); 
	cellRightSel.appendChild(sel); */
} 
function keyPressTest(e, obj) 
{ 
	var validateChkb = document.getElementById('chkValidateOnKeyPress'); 
	if (validateChkb.checked) { 
	var displayObj = document.getElementById('spanOutput'); 
	var key; 
	if(window.event) { 
	key = window.event.keyCode; 
	} 
	else if(e.which) { 
	key = e.which; 
	} 
	var objId; 
	if (obj != null) { 
	objId = obj.id; 
	} else { 
	objId = this.id; 
	} 
	displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key); 
	} 
} 
function removeRowFromTable() 
{ 
	var tbl = document.getElementById('tblSample'); 
	var lastRow = tbl.rows.length; 
	if (lastRow > 0) tbl.deleteRow(lastRow - 1);
} 

function validateRow(frm) 
{ 
	var chkb = document.getElementById('chkValidate'); 
	if (chkb.checked) { 
	var tbl = document.getElementById('tblSample'); 
	var lastRow = tbl.rows.length - 1; 
	var i; 
	for (i=1; i<=lastRow; i++) { 
	var aRow = document.getElementById('txtRow' + i); 
	if (aRow.value.length <= 0) { 
	alert('A linha ' + i + ' esta vazia'); 
	return; 
} 
} 
} 
openInNewWindow(frm); 
}

