/* ================================ Validação do campo de login e senha ====================================== */
function validarLogin()
{
	var login = document.getElementById("login").value;
	var senha = document.getElementById("senha").value;
	
	if(login == "")
	{
		alert("Login: Campo de preenchimento obrigatório!");
		document.getElementById("login").focus();
		return false;
	}
	else if(senha == "")
	{
		alert("Senha: Campo de preenchimento obrigatório!");
		document.getElementById("senha").focus();
		return false;
	}
	else
	{
		return true;
	}

}

/* ============================================= Marcar Todos e SelectMultiple ============================== */
//Marca todos os checkbox da tela de cadastro de usuarios:
function selecionarTodosTema(id_selecionar, id)
{
   	var objs, obj;
		
	//verifica se é para checar todos os inputs	    	
	if(document.getElementById(id_selecionar).checked)
	{
		objs = document.getElementsByTagName("input");
		    	
	   	for (var i = 0 ; i < objs.length ; i++)
	   	{
	   	    obj = objs[i];
		    	    
	   	    if(obj.type == "checkbox")
	   	    {
	   	        if(obj.id == id)
	   	        {
	   	        	obj.checked = true;
	   	        }
	   	    }
	   	}
	}
	else
	{
		objs = document.getElementsByTagName("input");
	    	
	   	for (var i = 0 ; i < objs.length ; i++)
	   	{
	   	    obj = objs[i];
		    	    
	   	    if(obj.type == "checkbox")
	   	    {
	   	        if(obj.id == id)
	   	        {
	   	        	obj.checked = false;
	   	        }
	   	    }
	   	}
	}	    	
   
}

//Marcar o combo de Select Multiple
function todosSelectMultiple(nome, valor) 
{
    var lista = document.getElementById(nome);
	
	for(var i = 0; i < lista.options.length; i++) 
	{
		lista.options[i].selected = valor;
	}
		
}

/* ================================================= CNPJ ===================================================== */

//Coloca maskara no cnpj
function maskCnpj(obj) 
{	
	if(obj.value.length == 2) 
	{ 
		obj.value += "."; 
	}
	
	if(obj.value.length == 6)
	{
		obj.value += "."; 
	}
	
	if(obj.value.length == 10) 
	{ 
		obj.value += "/"; 
	}
	
	if(obj.value.length == 15) 
	{ 
		obj.value += "-"; 
	}	
	
}

function isNUMB(c){

  if((cx=c.indexOf(","))!=-1){
	c = c.substring(0,cx)+"."+c.substring(cx+1);
  }
  if((parseFloat(c) / c != 1)){
      if(parseFloat(c) * c == 0){
	return(1);
      }
      else{
	return(0);
      }
  }
  else{
    return(1);
  }

}// fim usNUMB

function LIMP(c){
	 while((cx=c.indexOf("-"))!=-1){
		c = c.substring(0,cx)+c.substring(cx+1);
	 }
	 
	 while((cx=c.indexOf("/"))!=-1){
		c = c.substring(0,cx)+c.substring(cx+1);
	 }

	 while((cx=c.indexOf(","))!=-1){
		c = c.substring(0,cx)+c.substring(cx+1);
	 }

	 while((cx=c.indexOf("."))!=-1){
		c = c.substring(0,cx)+c.substring(cx+1);
	 }
	 
	 while((cx=c.indexOf("("))!=-1){
		c = c.substring(0,cx)+c.substring(cx+1);
	 }

	 while((cx=c.indexOf(")"))!=-1){
		c = c.substring(0,cx)+c.substring(cx+1);
	 }

	 while((cx=c.indexOf(" "))!=-1){
		c = c.substring(0,cx)+c.substring(cx+1);
	 }

	 return(c);
}// fim LIMP

function VerifyCNPJ(CNPJ){
	CNPJ = LIMP(CNPJ);
	if(isNUMB(CNPJ) != 1){
		return(0);
	}
	else{
		if(CNPJ == 0){
			return(0);
	}
	else{
		g=CNPJ.length-2;
		if(RealTestaCNPJ(CNPJ,g) == 1){
			g=CNPJ.length-1;

		if(RealTestaCNPJ(CNPJ,g) == 1){
		     return(1);
		}
	    else{
		     return(0);
		}
	}
	else{
	    return(0);
    }
   }
  }

 }// fim verifyCNPJ


function RealTestaCNPJ(CNPJ,g){
 var VerCNPJ=0;
 var ind=2;
 var tam;

 for(f=g;f>0;f--){
	VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind;
	if(ind>8){
		ind=2;
	}
	else{
	   ind++;
	}
 }// for

  VerCNPJ%=11;
  if(VerCNPJ==0 || VerCNPJ==1){
	VerCNPJ=0;
  }
  else{
	VerCNPJ=11-VerCNPJ;
  }
  if(VerCNPJ!=parseInt(CNPJ.charAt(g))){
	  return(0);
  }
  else{
	  return(1);
  }

}// fim RealTestaCNPJ

function BSY_openWin(url, nomeWin, widthWin, heightWin, configWin)
{
    var topWin  = (screen.height - heightWin) / 2;
    var leftWin = (screen.width - widthWin) / 2;

    configWin = configWin ? configWin + ", " : "";

    configWin += "width="+ widthWin +", height="+ heightWin +", top="+ topWin +", left="+ leftWin + ", scrollbars=auto";
    
    window.open(url, nomeWin, configWin);
    
}

function MascaraCPF(objeto)
{
	campo = eval (objeto);
    	
  	caracteres = '01234567890';
  	separacoes = 3;
  	separacao1 = '.';
 	 separacao2 = '-';
  	conjuntos = 4;
  	conjunto1 = 3;
  	conjunto2 = 7;
  	conjunto3 = 11;
  	conjunto4 = 14;
  	if((caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length <
  		(conjunto4))
  	{
  if(campo.value.length == conjunto1)
      campo.value = campo.value + separacao1;
  else if(campo.value.length == conjunto2)
      campo.value = campo.value + separacao1;
  else if(campo.value.length == conjunto3)
      campo.value = campo.value + separacao2;
  }
  else
  event.returnValue = false;

}

function Mascara (formato, objeto)
{//rodrigosor@audiopro.com.br
campo = eval (objeto);
if(formato=='CPF')
{
caracteres = '01234567890';
separacoes = 3;
separacao1 = '.';
separacao2 = '-';
conjuntos = 4;
conjunto1 = 3;
conjunto2 = 7;
conjunto3 = 11;
conjunto4 = 14;
if((caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length < 
(conjunto4))
{
if(campo.value.length == conjunto1) 
campo.value = campo.value + separacao1;
else if(campo.value.length == conjunto2) 
campo.value = campo.value + separacao1;
else if(campo.value.length == conjunto3) 
campo.value = campo.value + separacao2;
}
else 
event.returnValue = false;
} 
}

function formatar_mascara(src, mascara){
	var campo = src.value.length;
	var saida = mascara.substring(0,1);
	var texto = mascara.substring(campo);
	if(texto.substring(0,1) != saida){
		src.value += texto.substring(0,1);
	}
}
