/* MENU CATEGORIAS */
function showmenu(o,a) {
	if (a==0) {
		document.getElementById(o).style.display = "none"
	} else {
		document.getElementById(o).style.display = ""
	}
}
/* MENU CATEGORIAS */


/* AJAX */
function carregaDoc(url,c) {
campo = c
// mozilla
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=stateChange
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=stateChange
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}

function stateChange() {
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  document.getElementById(campo).innerHTML = xmlhttp.responseText
  }
  else
  {
  alert("Erro:" + xmlhttp.statusText)
  }
  }
}
/* AJAX */

/* PREENCHE CAMPO */
function getValor(url,valor,acao,campo,id) {
	if (acao==1) {
		document.getElementById(campo).style.display = ""
		carregaDoc(url+'?busca='+valor,campo)
	} else if (acao==0) {
		document.getElementById(campo).value = valor
		document.getElementById(campo+'_id').value = id
		document.getElementById(campo+'id').value = id
		document.getElementById(url).style.display = "none"
	}
}
/* PREENCHE CAMPO */

/* ALTERAÇÕES DE QUESTÃO */
function salvaQuestao(id) {
	document.getElementById("questao_id").value = id
	document.getElementById("descricao").value = document.getElementById("descricao_"+id).value
	document.getElementById("resultado").value = document.getElementById("resultado_"+id).value
	document.frmAlteraQuestao.submit()
}
/* ALTERAÇÕES DE QUESTÃO */

/* ALTERA ORDEM DA QUESTÃO */
function salvaOrdem(id,modelo_id) {
	document.getElementById("modelo_questao_id").value = id
	document.getElementById("ordem").value = document.getElementById("ordem_"+id).value
	document.getElementById("modelo_id").value = modelo_id
	document.getElementById("frmAlteraOrdem").submit()
	}
/* ALTERA ORDEM DA QUESTÃO */

/* VALIDA PORCENTAGEM PERFIL */
function valida_perfil_old(n) {
	c = document.getElementById("resultado_" + n).value
	if (c <= 100) {
		document.getElementById('frmRC').submit()		
	}
	else {
		alert("Digite um valor entre 0 e 100.")
	}
}
function valida_perfil_new() {
	c = document.getElementById("resultado_ideal").value
	if (c <= 100) {
		return true		
	}
	else {
		alert("Digite um valor entre 0 e 100.")
		return false
	}
}	
/* VALIDA PORCENTAGEM PERFIL */

/* VALIDA CONTATO */
function validacontato() {
	var email=document.getElementById("email").value.indexOf("@")
	var nome=document.getElementById("nome").value
	var msgerro = "Confira o preenchimento dos seguintes campos: \n"
	submitOK="true"

	if (email==-1) {
		msgerro=msgerro+"- E-mail \n"
		submitOK="false"
	}
	if (!nome) {
		msgerro=msgerro+"- Nome \n"
		submitOK="false"
	}
	if (submitOK=="false") {
		alert(msgerro)
		return false
	}
}
/* VALIDA CONTATO */

/* EDITOR HTML */
var browser=navigator.appName
function editorHTML() {
if (browser=="Microsoft Internet Explorer") {
	o = conteudo.document
} else {
	o = document.getElementById("conteudo").contentDocument
}
o.designMode="on"
}

function formata(t) {
	o.execCommand(t, false, null)
}

function linka() {
	var szURL = prompt("Entre com a URL", "")
	o.execCommand('createlink',false,szURL)
}

function imagem() {
	var imgSrc = prompt('Entrar com o link da imagem', '');

	if(imgSrc != null)    
		o.execCommand('insertimage', false, imgSrc);
}

function esquerda() {
	o.execCommand('justifyleft', false, null);
}

function centro() {
	o.execCommand('justifycenter', false, null);
}

function direita() {
	o.execCommand('justifyright', false, null);
}

function tamanho(fSize) {
	if(fSize != '')
		o.execCommand('fontsize', false, fSize);
}

function carregaMateria() {
	document.getElementById("editar").style.display = "none"
	document.getElementById("showConteudo").style.display = "none"
	document.getElementById("botaoenviar").style.display = "block"
	document.getElementById("conteudo").style.display = "block"
	editorHTML()
	o.body.innerHTML = document.getElementById("texto").value
}
/* EDITOR HTML */
