/**********************************************************/	
/* Função Redimenciona Janela******************************/
/**********************************************************/	
window.onload=maxWindow;

function maxWindow() {
window.moveTo(0,0);

	if (document.all) {
	  top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth) {
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}


// JavaScript Document
/*
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
  				}
  			node.onmouseout=function() {
			  this.className=this.className.replace
			  (" over", "");
   			}
   		   }
  		}
 	}
}
window.onload=startList; */


/**********************************************************/	
/* Função Valida E-mail************************************/
/**********************************************************/	
function ValidaEmail(campo){
  var obj = eval(campo);
  var txt = obj.value;
  if ((txt.length != 0) && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7))) {
    return false ;
  }
  else return true;
}


/**********************************************************/	
/* Função valida CNPJ *************************************/
/**********************************************************/	
function ValidaCNPJ(campo) {
			 CNPJ = campo;
			 erro = new String;
			 if (CNPJ.length < 18) return false; 
			 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
			 if (erro.length == 0) return false;
			 }
			 //substituir os caracteres que não são números
		   if(document.layers && parseInt(navigator.appVersion) == 4){
				   x = CNPJ.substring(0,2);
				   x += CNPJ. substring (3,6);
				   x += CNPJ. substring (7,10);
				   x += CNPJ. substring (11,15);
				   x += CNPJ. substring (16,18);
				   CNPJ = x; 
		   } else {
				   CNPJ = CNPJ. replace (".","");
				   CNPJ = CNPJ. replace (".","");
				   CNPJ = CNPJ. replace ("-","");
				   CNPJ = CNPJ. replace ("/","");
		   }
		   var nonNumbers = /\D/;
		   if (nonNumbers.test(CNPJ)) return false; 
		   var a = [];
		   var b = new Number;
		   var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
		   for (i=0; i<12; i++){
				   a[i] = CNPJ.charAt(i);
				   b += a[i] * c[i+1];
}
		   if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
		   b = 0;
		   for (y=0; y<13; y++) {
				   b += (a[y] * c[y]); 
		   }
		   if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
		   if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
				   return false;
		   }
		   if (erro.length > 0){
				   return false;
		   } else {
				 return true;
		   }
		   return true;
   }	


/**********************************************************/	
/* Função Somente números**********************************/
/* Passar como parâmetro o número do CPF com a máscara****/
/**********************************************************/	
function OnlyNumbers(e) { 
	if (window.event)  { 
		tecla = e.keyCode; 
	} 
	else if (e.which) { 
		tecla = e.which; 
	} 
		if ( (tecla >= 48 && tecla <= 57)||(tecla == 8 ) ) {
				   return true;
		}
		else {
			   return false;
		}
}

/**********************************************************/	
/* Função Máscara campo************************************/
/**********************************************************/	

function MascaraCampo(tipo, campo, teclaPress) {
    if (window.event) {
        var tecla = teclaPress.keyCode;
    } else {
        tecla = teclaPress.which;
    }

    var s = new String(campo.value);
    // Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
    s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');

    tam = s.length + 1;

    if ( tecla != 9 && tecla != 8 ) {
        switch (tipo)
        {
        case 'CPF' :
            if (tam > 3 && tam < 7)
                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
            if (tam >= 7 && tam < 10)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
            if (tam >= 10 && tam < 12)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
        break;

        case 'CNPJ' :

            if (tam > 2 && tam < 6)
                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
            if (tam >= 6 && tam < 9)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
            if (tam >= 9 && tam < 13)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
            if (tam >= 13 && tam < 15)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
        break;

        case 'TEL' :
            if (tam > 2 && tam < 4)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
            if (tam >= 7 && tam < 11)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
        break;

        case 'DATA' :
            if (tam > 2 && tam < 4)
                campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
            if (tam > 4 && tam < 11)
                campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
        break;
        
        case 'CEP' :
            if (tam > 5 && tam < 7)
                campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
        break;
        }
    }
}



/**********************************************************/	
/* Função Validar CPF ************************************/
/* Passar como parâmetro o número do CPF com a máscara****/
/**********************************************************/	
function ValidaCPF (numero) {
	var numcpf, cpf;
	numcpf = numero.substr(0,3);
	numcpf += numero.substr(4,3);
	numcpf += numero.substr(8,3);
	numcpf += numero.substr(12,2);
	cpf = numcpf;

	if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
	return false;
	add = 0;
		for (i=0; i < 9; i ++)
		add += parseInt(cpf.charAt(i)) * (10 - i);
	rev = 11 - (add % 11);
	if (rev == 10 || rev == 11)
		rev = 0;
	if (rev != parseInt(cpf.charAt(9)))
		return false;
	add = 0;
	for (i = 0; i < 10; i ++)
		add += parseInt(cpf.charAt(i)) * (11 - i);
	rev = 11 - (add % 11);
	if (rev == 10 || rev == 11)
	rev = 0;
	if (rev != parseInt(cpf.charAt(10))) return false;
	return true;
}

/****************************************************************/	
/* Função que Valida o e-mail ***********************************/
/* Passar como parâmetro o email que retorna true ou false ******/
/***************************************************************/	
function ValidarEmail(email)
{
    er = /^[a-z0-9\._-]+@([a-z0-9-]{2,26}(\.[a-z0-9-]{2,26})+)|([0-9-]{1,3}\.[0-9-]{1,3}\.[0-9-]{1,3}\.[0-9-]{1,3})1$/;
    if (!er.test(email.toLowerCase())) { 
		return false;
	}
    else { 
		return true; 
	}
}
