function ValidaFormulario(form){
	var valida = false;
	document.getElementById("alertas-texto").innerHTML = "";
	for (i=0;i<form.length;i++){
		if (!(isEmpty(form[i].title))) {
			if (isEmpty(String(form[i].value))) {
				if (!(String(form[i].value) == "0")) {
					var Valida = $('#'+form[i].id);
					//alert(form[i].id); Fazer Alerta
					$('#alertas-autenticacao').show();
					document.getElementById("alertas-texto").innerHTML = document.getElementById("alertas-texto").innerHTML + "<li>"+ form[i].title +"</li>";
					scroll(0,250);
					Valida.css('borderColor', "#FF0000");
					Valida.css('backgroundColor', "#FEE9E9");
					valida = true;
				}
			}
		}
	}
	if (valida == true) {
		return false;
	}
	return true
}

function visivel(){
    if (document.getElementById('clicado').className == 'off') {
        document.getElementById('clicado').className = 'on';
    } else if (document.getElementById('clicado').className == 'on') {
        document.getElementById('clicado').className = 'off';
    }
}

function textOn(txt){
	document.getElementById(txt).className="textboxOn";
}

function textNormal(txt){
	document.getElementById(txt).className="textbox";
}

function textArea(txt){
	document.getElementById(txt).className="txtArea";
}

function textAreaOn(txt){
	document.getElementById(txt).className="textAreaOn";
}

function Popup(url, width, height)    {
    window.open(url,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=no,width=" + width + ",height=" + height)
}
//-------------------------------
function mOvr(src,clrOver)			{ src.bgColor = clrOver; src.style.cursor = 'hand'; }
function mOut(src,clrIn)			{ if (!src.contains(event.toElement))	{ src.bgColor = clrIn; src.style.cursor = 'default'; } }
function mClk(src)					{ if (event.srcElement.tagName=='TD')	src.children.tags('A')[0].click(); }
//-------------------------------
function CheckAll()		{
      for (var i=0;i<document.form.elements.length;i++)
      {
         var e = document.form.elements[i];
         if (e.type == 'checkbox' && e.name != 'allbox')
            e.checked = document.form.allbox.checked;
      }
}
//-------------------------------
function OpConfirm(text)	{   
	for (var i=0;i<document.form.elements.length;i++)
	{
	 var e = document.form.elements[i];
	 if (e.type == 'checkbox' && e.name != 'allbox' && e.checked == 1 )
		return confirm(text);
	}
	alert("Seleção não encontrada!");
	return false;
}
//-------------------------------
function OpConfirmRadio(text)	{   
	for (var i=0;i<document.form.elements.length;i++)
	{
	 var e = document.form.elements[i];
	 if (e.type == 'radio' && e.name != 'allbox' && e.checked == 1 )
		return confirm(text);
	}
	alert("Uma opção deve ser escolhida!");
	return false;
}
//-------------------------------
function Inteiro()	{

	if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13) )
		{	return(true);	}
	else
		{	alert("Este é um campo numérico!");	return(false);	}
}
//-------------------------------
function Numerico()	{

	if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 46) || (event.keyCode == 44) || (event.keyCode == 13) )
		{	return(true);	}
	else
		{	alert("Este é um campo numérico!");	return(false);	}
}
//-------------------------------
function Telefone()	{

	if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 45) || (event.keyCode == 13) ) 
		{	return(true);	}
	else
		{	alert("Caracteres permitidos [0-9; - ]");	return(false);	}
}
//-------------------------------
function isEmpty(s)		{
	return ((s == null) || (s == 0) || (s.length == 0) || (s == "0,00") || (s == "0,0") || (s == "0,") || (s == "0.00") || (s == "0.0") || (s == "0."))
}
//-------------------------------
var foco      = "";
var msgstatus = "";

function aviso (campo, msg)	{
    alert(msg);
    campo.focus();
    return false;
}
//-------------------------------
function isSecurity(n)		{
     for(i=0; i < n.length; i++) {
		c = n.charAt(i); 
		if ( !((c >= "0") && (c <= "9")) && !((c >= "A") && (c <= "Z")) && !((c >= "a") && (c <= "z")) ) { 
			return false;
		}
     }
     return true;
}
//-------------------------------
function isSecurity2(n)		{
     for(i=0; i < n.length; i++) {
		c = n.charAt(i); 
		if ( !((c >= "-") && (c <= "9")) && !((c >= "@") && (c <= "Z")) && !((c >= "_") && (c <= "z")) ) { 
			return false;
		}
     }
     return true;
}
//-------------------------------
function Valida_email(mail) {
var iCount, achou, achou2;
	
	achou  = false;
	achou2 = false;
	
	if (mail.length == 0) return false;

	for (iCount = 1; iCount<mail.length; iCount++)	{
		if (! achou)
		{
			if (mail.charAt(iCount) == "@")	achou = true;
		}
		else
		{
			if (mail.charAt(iCount) == ".") {
				achou2 = true;
				break;
			}
		}
	}

	return achou2;
}
//-------------------------------

		function get(elemento){
			return document.getElementById(elemento);
		}

		function Expande(item){
			get('ID'+item).style.display = (get('ID'+item).style.display == 'none') ? 'block' : 'none';
		}
//-------------------------------











//-------------------------------

//-------------------------------
function abrejanela(nam,wid,hei) {

	var link = nam;
	var comp = "width=" + wid;
	var height = "height=" + hei;
	var tool = "toolbar=no,directories=no,status=no,scrollbars=yes,resize=yes,menubar=no,location=no,copyhistory=no";
	var num = comp + "," + height;

	window.open(link,"_blank",num,tool);

}
//-------------------------------
function CheckAll()		{
      for (var i=0;i<document.form.elements.length;i++)
      {
         var e = document.form.elements[i];
         if (e.type == 'checkbox' && e.name != 'allbox')
            e.checked = document.form.allbox.checked;
      }
}
//-------------------------------
function OpConfirm(text)	{   
	for (var i=0;i<document.form.elements.length;i++)
	{
	 var e = document.form.elements[i];
	 if (e.type == 'checkbox' && e.name != 'allbox' && e.checked == 1 )
		return confirm(text);
	}
	alert("Seleção não encontrada!");
	return false;
}
//-------------------------------
function OpConfirmRadio(text)	{   
	for (var i=0;i<document.form.elements.length;i++)
	{
	 var e = document.form.elements[i];
	 if (e.type == 'radio' && e.name != 'allbox' && e.checked == 1 )
		return confirm(text);
	}
	alert("Uma opção deve ser escolhida!");
	return false;
}
//-------------------------------
function Inteiro()	{

	if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13) )
		{	return(true);	}
	else
		{	alert("Este é um campo numérico!");	return(false);	}
}
//-------------------------------
function Numerico()	{

	if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 46) || (event.keyCode == 44) || (event.keyCode == 13) )
		{	return(true);	}
	else
		{	alert("Este é um campo numérico!");	return(false);	}
}
//-------------------------------
function Telefone()	{

	if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 45) || (event.keyCode == 13) ) 
		{	return(true);	}
	else
		{	alert("Caracteres permitidos [0-9; - ]");	return(false);	}
}
//-------------------------------
function CEP()	{

	if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 45) || (event.keyCode == 13) ) 
		{	return(true);	}
	else
		{	alert("Caracteres permitidos [0-9; - ]");	return(false);	}
}
//-------------------------------
function Data()	{

	if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 47) || (event.keyCode == 13) ) 
		{	return(true);	}
	else
		{	alert("Caracteres permitidos [0-9; / ]");	return(false);	}
}
//-------------------------------
function isEmpty(s)		{
	return ((s == null) || (s == 0) || (s.length == 0) || (s == "0,00") || (s == "0,0") || (s == "0,") || (s == "0.00") || (s == "0.0") || (s == "0."))
}
//-------------------------------
var foco      = "";
var msgstatus = "";

function aviso (campo, msg)	{
    alert(msg);
    campo.focus();
    return false;
}
//-------------------------------
function isSecurity(n)		{
     for(i=0; i < n.length; i++) {
		c = n.charAt(i); 
		if ( !((c >= "0") && (c <= "9")) && !((c >= "A") && (c <= "Z")) && !((c >= "a") && (c <= "z")) ) { 
			return false;
		}
     }
     return true;
}
//-------------------------------
function SortColuna(fCampo){
		document.form.Sort.value = fCampo;
		document.form.submit();
}
//-------------------------------



// formata campo -------------------------------

function SaltaCampo(campo, prox, tammax, teclapres) { var tecla = teclapres.keyCode; var vr = campo.value; var tam = vr.length; if ((tecla != 9) && (tecla != 16)) { if (campo.value.length >= tammax) { campo.value = campo.value.substring(0, tammax); prox.focus(); } } };
function SaltaCampoTras(campo, prox, tammax, e) { };

// JavaScript Document
//adiciona mascara de cnpj
function MascaraCNPJ(cnpj,teclapres){
		var e = teclapres.keyCode ? teclapres.keyCode : teclapres.which ? teclapres.which : teclapres.charCode;
        if (e < 48 || e > 57){
				if (window.teclapres) {//IE

				window.teclapres.returnValue = false;

				} else { //Firefox

				teclapres.preventDefault();

				}        
        }
		 return formataCampo(cnpj, '00.000.000/0000-00', teclapres);
        
}

//adiciona mascara de cep
function MascaraCep(cep){
        if(mascaraInteiro(cep)==false){
                event.returnValue = false;
        }       
        return formataCampo(cep, '00.000-000', event);
}

//adiciona mascara de data
function MascaraData(data){
        if(mascaraInteiro(data)==false){
                event.returnValue = false;
        }       
        return formataCampo(data, '00/00/0000', event);
}

//adiciona mascara ao telefone
function MascaraTelefone(tel){  
        if(mascaraInteiro(tel)==false){
                event.returnValue = false;
        }       
        return formataCampo(tel, '(00) 0000-0000', event);
}

//adiciona mascara ao CPF
function MascaraCPF(cpf,teclapres){
		var e = teclapres.keyCode ? teclapres.keyCode : teclapres.which ? teclapres.which : teclapres.charCode;

		if (e > 47 && e < 58) {
			        return formataCampo(cpf, '000.000.000-00', teclapres);
		} else
			{
				if (e != 8)
					if (window.teclapres) {//IE

					window.teclapres.returnValue = false;

					} else { //Firefox

					teclapres.preventDefault();

					}
				else
					return true;
			}


        return formataCampo(cpf, '000.000.000-00', teclapres);


}

//valida telefone
function ValidaTelefone(tel){
        exp = /\(\d{2}\)\ \d{4}\-\d{4}/
        if(!exp.test(tel.value))
                alert('Numero de Telefone Invalido!');
}

//valida CEP
function ValidaCep(cep){
        exp = /\d{2}\.\d{3}\-\d{3}/
        if(!exp.test(cep.value))
                alert('Numero de Cep Invalido!');               
}

//valida data
function ValidaData(data){
        exp = /\d{2}\/\d{2}\/\d{4}/
        if(!exp.test(data.value))
                alert('Data Invalida!');                        
}

//valida o CPF digitado
function ValidarCPF(Objcpf){
        var cpf = Objcpf.value;
        exp = /\.|\-/g
        cpf = cpf.toString().replace( exp, "" ); 
        var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
        var soma1=0, soma2=0;
        var vlr =11;
        
        for(i=0;i<9;i++){
                soma1+=eval(cpf.charAt(i)*(vlr-1));
                soma2+=eval(cpf.charAt(i)*vlr);
                vlr--;
        }       
        soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
        soma2=(((soma2+(2*soma1))*10)%11);
        
        var digitoGerado=(soma1*10)+soma2;
        if(digitoGerado!=digitoDigitado)        
                alert('CPF Invalido!');
//				Objcpf.focus();
}

//valida numero inteiro com mascara
function mascaraInteiro(teclapres){
        if (teclapres.keyCode < 48 || teclapres.keyCode > 57){
                teclapres.returnValue = false;
                return false;
        }
        return true;
}

//valida o CNPJ digitado
function ValidarCNPJ(ObjCnpj){
        var cnpj = ObjCnpj.value;
        var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
        var dig1= new Number;
        var dig2= new Number;
        
        exp = /\.|\-|\//g
        cnpj = cnpj.toString().replace( exp, "" ); 
        var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
                
        for(i = 0; i<valida.length; i++){
                dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);  
                dig2 += cnpj.charAt(i)*valida[i];       
        }
        dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
        dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
        
        if(((dig1*10)+dig2) != digito)  
                alert('CNPJ Invalido!');
                
}

//formata de forma generica os campos
function formataCampo(campo, Mascara, evento) { 
        var boleanoMascara; 
        
        var Digitato = evento.keyCode;
        exp = /\-|\.|\/|\(|\)| /g
        campoSoNumeros = campo.value.toString().replace( exp, "" ); 
   
        var posicaoCampo = 0;    
        var NovoValorCampo="";
        var TamanhoMascara = campoSoNumeros.length;; 
        
        if (Digitato != 8) { // backspace 
                for(i=0; i<= TamanhoMascara; i++) { 
                        boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                                                || (Mascara.charAt(i) == "/")) 
                        boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(") 
                                                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " ")) 
                        if (boleanoMascara) { 
                                NovoValorCampo += Mascara.charAt(i); 
                                  TamanhoMascara++;
                        }else { 
                                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo); 
                                posicaoCampo++; 
                          }              
                  }      
                campo.value = NovoValorCampo;
                  return true; 
        }else { 
                return true; 
        }
}
