//***************************************************
//Funções para montagem do menu
function Subcategorias(Tabela){
	Tabela = document.getElementById(Tabela);
	if(Tabela.style.display=="none"){
		Tabela.style.display = "block";
	}else{
		Tabela.style.display = "none";
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//***************************************************
//Funções para limitar quantidade de caracteres
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}

//***************************************************
//Funções para alterar a imagem na galeria de fotos
function nph_change_img_src(name, nsdoc, rpath)
{
     var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
     if (name == '')    return;
     if (img) {  img.altsrc = img.src;  img.src = rpath; }
}

//***************************************************
//Funções para importar e exportar as tags do editos de texto
function ImpTAGs(){
document.form.texto2.value = document.all.Editor.html;
}
function ExpTAGs(){
	document.all.Editor.html = document.form.texto2.value;
}

//**********************************************************
//Função window open centralizada na página
function janport(local){
var left=screen.width/2-688/2;
var top=screen.height/2-531/2;
window.open(local,"questp","status=no,toolbar=no,location=no,menu=no,scrollbars=yes,left="+left+",top="+top+"");
}

function resize() {
var vary = document.photo.height + 91;
var varx = document.photo.width + 12;
window.resizeTo(varx,vary);
window.focus()
}

//***********************************************************
//Validar campos no formulário (se vazio)
function checkdata(){
	with(document.cadastro){
         if (nome.value == ""){alert("Nome é um campo obrigatório!");nome.focus();return false;}
         if (segmento.value == ""){alert("Segmento é um campo obrigatório!");segmento.focus();return false;}
         if (email.value == ""){alert("E-mail é um campo obrigatório!");email.focus();return false;}
         if (endereco.value == ""){alert("Endereço é um campo obrigatório!");endereco.focus();return false;}
         if (bairro.value == ""){alert("Bairro é um campo obrigatório!");bairro.focus();return false;}
         if (cidade.value == ""){alert("Cidade é um campo obrigatório!");cidade.focus();return false;}
         if (estado.value == ""){alert("Estado é um campo obrigatório!");estado.focus();return false;}
         if (cep.value == ""){alert("Cep é um campo obrigatório!");cep.focus();return false;}
         if (fone.value == ""){alert("Informe pelo menos um nímero de Telefone!");fone.focus();return false;}
         if (cnpj.value == ""){alert("CNPJ ou CPF é um campo obrigatório!");cnpj.focus();return false;}
         submit();
	}
}
//*****************************************************************
// Validar Campos no formulário (se números)
function Tecla(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
				if (tecla != 8) // backspace
					event.keyCode = 0;
					//return false;
				else
					return true;
			}
}

//**********************************************************************
//Valida CNPJ
function valida_cpf(cpf)
      {
      var numeros, digitos, soma, i, resultado, digitos_iguais;
      digitos_iguais = 1;
      if (cpf.length < 11)
            return false;
      for (i = 0; i < cpf.length - 1; i++)
            if (cpf.charAt(i) != cpf.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            numeros = cpf.substring(0,9);
            digitos = cpf.substring(9);
            soma = 0;
            for (i = 10; i > 1; i--)
                  soma += numeros.charAt(10 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            numeros = cpf.substring(0,10);
            soma = 0;
            for (i = 11; i > 1; i--)
                  soma += numeros.charAt(11 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
      }

//**********************************************************************
//Oculta texto
var div1 = "m1";
function AparecerDiv1(){ // função aparecer
    document.getElementById(div1).style.display = "block";
}

function OcultarDiv1(){  // função ocultar
    document.getElementById(div1).style.display = "none";
}

var div2 = "m2";
function AparecerDiv2(){ // função aparecer
    document.getElementById(div2).style.display = "block";
}

function OcultarDiv2(){  // função ocultar
    document.getElementById(div2).style.display = "none";
}


var div3 = "m3";
function AparecerDiv3(){ // função aparecer
    document.getElementById(div3).style.display = "block";
}

function OcultarDiv3(){  // função ocultar
    document.getElementById(div3).style.display = "none";
}

