function help(id, color)
{
    var aux = document.getElementById(id);
    aux.color=color;
}

	function isNum( caractere )
	{
		var strValidos = "0123456789"
		if ( strValidos.indexOf( caractere ) == -1 )
			return false;
		return true;
	}

	function validaTecla(campo, event)
	{
		var BACKSPACE= 8;
		var key;
		var tecla;
		CheckTAB=true;

		if(navigator.appName.indexOf("Netscape")!= -1)
			tecla= event.which;
		else
			tecla= event.keyCode;

		key = String.fromCharCode( tecla);

		if ( tecla == 13 )
			return false;

		if ( tecla == BACKSPACE )
		return true;

	return ( isNum(key));
	}


	function FormataCNPJ( el )
	{
		vr = el.value;
		tam = vr.length;

		if ( vr.indexOf(".") == -1 )
		{
			if ( tam <= 2 )
			el.value = vr;

			if ( (tam > 2) && (tam <= 6) )
			el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam );

			if ( (tam >= 7) && (tam <= 10) )
			el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/';

			if ( (tam >= 11) && (tam <= 18) )
			el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ;

		}
	return true;
	}
         function validaCNPJ(a) {
                 CNPJ = a.value;
                 erro = new String;
                 if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! ";
                 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
                 if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! ";
                 }
                 //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)) erro += "A verificação de CNPJ suporta apenas números! ";
               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])){
                       erro +="Dígito verificador com problema!";
               }
               if (erro.length > 0){
                       alert(erro);
                       return false;
               } else {
                       alert("CNPJ valido!");
               }
               return true;
       }

function DeleteEmpr() {
	var a = document.editar;
	var question = confirm("Deseja realmente remover a Empresa selecionada?");
	if(question) {
		a.action = "./index.php?id=modulo&mod=1&id_page=6";
		a.submit();
	}
}

function DeletePlanta() {
	var a = document.editar;
	var question = confirm("Deseja realmente remover a planta selecionada?");
	if(question) {
		a.action = "./index.php?id=modulo&mod=1&id_page=10&op=7";
		a.submit();
	}
}

