//////////////////////////////////////////////////
// Função para abrir pop-up
//////////////////////////////////////////////////
function abrir(pagina,largura,altura, noscroll, alvo) {
	if(!noscroll){
		scrollbars = 'no';
	} else {
		scrollbars = 'yes';
	}
	config="toolbar=no,location=no,width="+largura+",height="+altura+",status=no,menubar=no,scrollbars=" + scrollbars + ",resizable=no,top=" + ((screen.height - altura) / 2) + ",left=" + ((screen.width - largura) /2);
	pop=window.open(pagina,alvo,config);
}

/*
//////////////////////////////////////////////////
// Função para checar ou unchecar todos checkbox
//////////////////////////////////////////////////
function checkaTodos(algumAlterado)
{
	f = validar;
	if (algumAlterado)
	{ 
		if (algumAlterado.checked == false) 
			f.br.checked = false;
	}
	else 
		for (i=0; i<f.length; i++) 
			if (f.elements[i].type == "checkbox")
				if (f.br.checked) 
					f.elements[i].checked = true
				else f.elements[i].checked = false
}
*/

/*
function menuOn(menu) {
	document.getElementById(menu).style.display = 'inline';
}

function menuOff(menu) {
	document.getElementById(menu).style.display = 'none';
}

//////////////////////////////////////////////////
// Função para validar as categorias com Checkbox
//////////////////////////////////////////////////
function Valida_Categorias(theForm)
{
   
   var quantidade = -1;
   for (var i=0; i < theForm.categorias.length; i++)
   {
      if (theForm.categorias[i].checked == true)
      {
		quantidade = quantidade + 1;
      }
   }
   
   if (quantidade == -1)
   {
	   alert("Selecione pelo menos uma categoria.");
	   return false;
   }
   
}

//////////////////////////////////////////////////
// Função para validar Formulário
//////////////////////////////////////////////////
function Valida_Cadastro(theForm)
{
	// Nome
	if (theForm.nome.value == "")
	{
		alert("Preencha o campo \"Nome\".");
		theForm.nome.focus();
		return false;
	}

	// E-mail
	if (theForm.email.value == ""){
		alert("Preencha o campo \"E-mail\".");
		theForm.email.focus();
		return false;
	}
	if (Valida_Email(theForm) == false)
		return false;
	
}
/*
//////////////////////////////////////////////////
// Função para validar Formulário
//////////////////////////////////////////////////
function Valida_Dados(theForm)
{
	// Nome
	if (theForm.nome.value == "")
	{
		alert("Preencha o campo \"Nome\".");
		theForm.nome.focus();
		return false;
	}

	// Sexo
	if (theForm.sexo.value == "")
	{
		alert("Preencha o campo \"Sexo\".");
		theForm.sexo.focus();
		return false;
	}
	if (theForm.dtnascimento.value == "")
	{
		alert("Preencha o campo \"Data Nacimento\".");
		theForm.dtnascimento.focus();
		return false;
	}
	if (theForm.telefone1.value == "")
	{
		alert("Preencha o campo \"Telefone1\".");
		theForm.telefone1.focus();
		return false;
	}
	if (Valida_Email(theForm) == false)
		return false;
	
	return true;
}


//////////////////////////////////////////////////
// Função que faz uma máscara para cep
//////////////////////////////////////////////////
function Formata_CEP(objeto){
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5){ objeto.value = ""; }
	if (objeto.value.length == 5){
		objeto.value += "-";
	}
}
//OnKeyPress="Formata_CEP(this)"


//////////////////////////////////////////////////
// Verifica CPF
//////////////////////////////////////////////////
function Valida_CPF(theForm)
{
var CPF = theForm.cpf.value; 

var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); 

for (I=0; I<=8; I++) {
 DIGITO[I] = CPF.substr( I, 1);
}

POSICAO = 10;
SOMA = 0;
 for (I=0; I<=8; I++) {
 SOMA = SOMA + DIGITO[I] * POSICAO;
 POSICAO = POSICAO - 1;
 }
DIGITO[9] = SOMA % 11;
 if (DIGITO[9] < 2) {
 DIGITO[9] = 0;
}
 else{
 DIGITO[9] = 11 - DIGITO[9];
}

POSICAO = 11;
SOMA = 0;
 for (I=0; I<=9; I++) {
 SOMA = SOMA + DIGITO[I] * POSICAO;
 POSICAO = POSICAO - 1;
 }
DIGITO[10] = SOMA % 11;
 if (DIGITO[10] < 2) {
 DIGITO[10] = 0;
 }
 else {
 DIGITO[10] = 11 - DIGITO[10];
 }

DV = DIGITO[9] * 10 + DIGITO[10];
 if (DV != DV_INFORMADO) {
 alert('CPF inválido');
 theForm.cpf.value = '';
 theForm.cpf.focus();
 return false;
 }

 for (I=0; I<=9; I++) {

	if (DIGITO[I] == DIGITO[9] && DIGITO[I] == DIGITO[8] && DIGITO[I] == DIGITO[7] && DIGITO[I] == DIGITO[6] && DIGITO[I] == DIGITO[5] && DIGITO[I] == DIGITO[4] && DIGITO[I] == DIGITO[3] && DIGITO[I] == DIGITO[2] && DIGITO[I] == DIGITO[1] && DIGITO[I] == DIGITO[0]) {
	  alert('CPF inválido');
  	  theForm.cpf.value = '';
      theForm.cpf.focus();
      return false;
    }
 }

}

//////////////////////////////////////////////////
// Função para validar e-mail
//////////////////////////////////////////////////
function Valida_Email(theForm)
{
	var email = theForm.email.value;
    var BadChars = "*|,\":<>[]{}`\'';()&$#% ";
    var GoodChars = "@.";
    var posarroba = email.indexOf ('@',0);
    if (email.length < 6){
        alert("E-mail inválido!");
        theForm.email.value = "";
        theForm.email.focus();
        return false;
    }
    for (var i = 0; i < email.length; i++){
        if (BadChars.indexOf(email.charAt(i)) != -1){
            alert("E-mail inválido!");
            theForm.email.value = "";
            theForm.email.focus();
            return false;
        }
    }
    for (var i = 0; i < GoodChars.length; i++){
        if (email.indexOf(GoodChars.charAt(i)) == -1){
            alert("E-mail inválido!");
            theForm.email.value = "";
            theForm.email.focus();
            return false;
        }
        if (email.indexOf(GoodChars.charAt(i),0) == 0){
            alert("E-mail inválido!");
            theForm.email.value = "";
            theForm.email.focus();
            return false;
        }
        if (email.lastIndexOf(GoodChars.charAt(i)) > email.length-3){
            alert("E-mail inválido!");
            theForm.email.value = "";
            theForm.email.focus();
            return false;
        }
    }
    if (email.lastIndexOf('@') > email.lastIndexOf('.')){
        alert("E-mail inválido!");
        theForm.email.value = "";
        theForm.email.focus();
        return false;
    }

    if (email.indexOf ('@.',0) != -1 || email.indexOf ('.@',0) != -1){
        alert("E-mail inválido!");
        theForm.email.value = "";
        theForm.email.focus();
        return false;
    }
    if (email.indexOf ('@',posarroba+1) != -1){
        alert("E-mail inválido!");
        theForm.email.value = "";
        theForm.email.focus();
        return false;
    }
}

//////////////////////////////////////////////////
// Habilita e Desabilita tipos do Conteúdo
//////////////////////////////////////////////////
function SelecionaTipo(tipo)
{
	if (document.form1.tipo[0].checked)
	{
		document.form1.corpo.disabled = true;
		document.form1.txtlink.disabled = false;
	}
	else if (document.form1.tipo[1].checked)
	{
		document.form1.corpo.disabled = true;
		document.form1.txtlink.disabled = true;
	}
	else
	{
		document.form1.corpo.disabled = false;
		document.form1.txtlink.disabled = true;
	}		
}

//////////////////////////////////////////////////
// FAQ
//////////////////////////////////////////////////
function changeVisibility(id) {
  if (document.getElementById(id).style.display != "inline")
    document.getElementById(id).style.display="inline";
  else
    document.getElementById(id).style.display="none";
}

var answers = new Array(0);

function setVisibility(id, visibility) {
  if (visibility)
    document.getElementById(id).style.display="inline";
  else
    document.getElementById(id).style.display="none";
}

function expand(visibility) {
  for (i = 0 ; i < answers.length ; i++) {
    setVisibility(answers[i], visibility);
  }
}

function openChecked() {
    var formulary = document.form;
    for (i = 0; i< formulary.elements.length; i++) {
        var element = formulary.elements[i];
        // alert("element = " + element.name);
        if (element.type == "checkbox" && element.checked) {
            // var parent = element.parentNode.parentNode.parentNode.nodeName;

            var parent = element.parentNode;

            while (parent != null && parent.nodeName != "DIV") {
                parent = parent.parentNode;
            }

            // alert("parent = " + parent.nodeName);

            // if (parent.nodeName == "DIV") {
                
            if (parent != null && parent.nodeName == "DIV") {
               // var par_element = element.parentNode.parentNode.parentNode;
               // alert("Check box! Parent node = " + par_element.nodeName);
               // alert("Name of the div = " + parent.id);
               
               if (parent.id != "") {
                  var avo = parent.parentNode;

                  // alert("Grand parent node = " + avo.id);
                  
                  document.getElementById(parent.id).style.display="inline";
                  // changeVisibility(par_element.id);

                   if (avo.id != "") {
                       document.getElementById(avo.id).style.display="inline";
                       // changeVisibility(avo.id);
                   }
               }
            }
        }
    }
}

*/