// JavaScript Document
function showLayer(layerName){
       if( document.getElementById(layerName).style.display == "none" ) {
        document.getElementById(layerName).style.display = "block";
    } else {
        document.getElementById(layerName).style.display = "none";
    }
}
function ContaCaracteres(campo, contador) {
			caracteres = 250 - campo.value.length;
			if (caracteres >= 0) {
				contador.value = caracteres;
			} else {
				campo.value = campo.value.substring(0, 250);
			}
}
function verifica_pagamentoc(form) {
if (!form.pagamento[0].checked && !form.pagamento[1].checked) {
    alert("Escolha uma forma de pagamento");
    return false;
}
}
function verifica_pagamento(form) {
if (!form.pagamento[0].checked && !form.pagamento[1].checked && !form.pagamento[2].checked) {
    alert("Escolha uma forma de pagamento");
    return false;
}
}
function verifica_pergunta(form) {
d = form;
if (d.pergunta.value == "") {
   alert("Escreva sua pergunta");
   return false;
  }
}

function passa_foco(origem, destino, largura) {
	if (document.getElementById(origem).value.length == largura) {
		document.getElementById(destino).focus();
	}
}
function esvazia_campo(campo) {
document.getElementById(campo).value = "";
}
function foco() {
document.form_busca.busca.focus();
}
function abre_janela(pagina, titulo, tamanho) {
window.open (pagina, titulo, tamanho);
}

function limpa(form, campo) {
var altera = document.form.campo.value;
altera = "";
}

function atribui(origem, destino) {
var origem = document.getElementById(origem).value;
document.getElementById(destino).value = origem;
}

function mascara(iden, simbolo, q1, q2) {
var data = document.getElementById(iden).value;
if (data.length == q1) {
data = data + simbolo
}
if (data.length == q2) {
data = data + simbolo
}
document.getElementById(iden).value = data
if (iden == 'dataop') {
if (data.length == 10) {
document.getElementById('horaop').focus();
}
}
}
function paginaAtiva() {
var pagina = ["home","pergunte","produtos","cursos","contato"];
for (i=0; i<pagina.length; i++) {
if (document.getElementById("link_"+pagina[i]+"").href == window.location) {
document.getElementById("img_"+pagina[i]+"").src = "imagens/bot_"+pagina[i]+"_act.gif";
}
}
}

function vai_inscricao() {
	var cP = document.getElementById('formInscricao').opcao.length
	var cont = 0
	for (i=0;i<cP;i++) {
		if (!document.getElementById('formInscricao').opcao[i].checked) {
			cont++
		}
	}
	if (cont == cP) {
		alert("Escolha uma opção de horário para fazer o curso")
	} else {
		document.getElementById('formInscricao').submit();
	}
}

function Dec2Hex(num) {
	var Hex = [0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"];
	var Dec = new Array(100);
	var numDec = num;
	var i = 0;
	var numHex = "";
	while (Math.floor(numDec / 16) >= 16) {
		j = numDec % 16;
		Dec[i] = Hex[j];
		numDec = Math.floor(numDec / 16);
		i++;
	}
	j = numDec % 16;
	Dec[i] = Hex[j]
	i++;
	j = Math.floor(numDec / 16);
	Dec[i] = Hex[j];
	for (j=i;j>=0;j--) {
		numHex = numHex + String(Dec[j]);
	}
	return numHex;
}

function Hex2Dec(num) {
	var numHex = String(num);
	var Hex = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]
	var Dec = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
	var totNum = numHex.length;
	var soma = 0;
	var Indice = 0;
	var j = totNum - 1;
	for (i=0;i<totNum;i++) {
		k = String(numHex.charAt(i));
		for (l=0;l<16;l++) {
			if (String(k) == String(Hex[l])) {
				Indice = l
			}
		}
		soma = soma + (Dec[Indice] * Math.pow(16,j));
		j--;
	}
	return soma;
}

function codifica_html(texto) {
	var textoR = texto;
	var Letras = ["á","é","í","ó","ú","ã","õ","â","ê","ô","Á","É","Í","Ó","Ú","Ã","Õ","Â","Ê","Ô","à","À","ü","Ü","ç","Ç"];
	var CodHTML = ["$aacute;","$eacute;","$iacute;","$oacute;","$uacute;","$atilde;","$otilde;","$acirc;","$ecirc;","$ocirc;","$Aacute;","$Eacute;","$Iacute;","$Oacute;","$Uacute;","$Atilde;","$Otilde;","$Acirc;","$Ecirc;","$Ocirc;","$agrave;","$Agrave;","$uuml;","$Uuml;","$ccedil;","$Ccedil;"];
	textoR = textoR.replace(/á/g, "$aacute;");
	textoR = textoR.replace(/é/g, "$eacute;");
	textoR = textoR.replace(/í/g, "$iacute;");
	textoR = textoR.replace(/ó/g, "$oacute;");
	textoR = textoR.replace(/ú/g, "$uacute;");
	textoR = textoR.replace(/ã/g, "$atilde;");
	textoR = textoR.replace(/õ/g, "$otilde;");
	textoR = textoR.replace(/â/g, "$acirc;");
	textoR = textoR.replace(/ê/g, "$ecirc;");
	textoR = textoR.replace(/ô/g, "$ocirc;");
	textoR = textoR.replace(/Á/g, "$Aacute;");
	textoR = textoR.replace(/É/g, "$Eacute;");
	textoR = textoR.replace(/Í/g, "$Iacute;");
	textoR = textoR.replace(/Ó/g, "$Oacute;");
	textoR = textoR.replace(/Ú/g, "$Uacute;");
	textoR = textoR.replace(/Ã/g, "$Atilde;");
	textoR = textoR.replace(/Õ/g, "$Otilde;");
	textoR = textoR.replace(/Â/g, "$Acirc;");
	textoR = textoR.replace(/Ê/g, "$Ecirc;");
	textoR = textoR.replace(/Ô/g, "$Ocirc;");
	textoR = textoR.replace(/à/g, "$agrave;");
	textoR = textoR.replace(/À/g, "$Agrave;");
	textoR = textoR.replace(/ü/g, "$uuml;");
	textoR = textoR.replace(/Ü/g, "$Uuml;");
	textoR = textoR.replace(/ç/g, "$ccedil;");
	textoR = textoR.replace(/Ç/g, "$Ccedil;");
	textoR = textoR.replace(/ /gi, "$20e$");
	return textoR;
}

function decodifica_html(texto) {
	var textoR = texto
	var Letras = ["á","é","í","ó","ú","ã","õ","â","ê","ô","Á","É","Í","Ó","Ú","Ã","Õ","Â","Ê","Ô","à","À","ü","Ü","ç","Ç"];
	var CodHTML = ["$aacute;","$eacute;","$iacute;","$oacute;","$uacute;","$atilde;","$otilde;","$acirc;","$ecirc;","$ocirc;","$Aacute;","$Eacute;","$Iacute;","$Oacute;","$Uacute;","$Atilde;","$Otilde;","$Acirc;","$Ecirc;","$Ocirc;","$agrave;","$Agrave;","$uuml;","$Uuml;","$ccedil;","$Ccedil;"];
	textoR = textoR.replace(/\$aacute;/g, "á");
	textoR = textoR.replace(/\$eacute;/g, "é");
	textoR = textoR.replace(/\$iacute;/g, "í");
	textoR = textoR.replace(/\$oacute;/g, "ó");
	textoR = textoR.replace(/\$uacute;/g, "ú");
	textoR = textoR.replace(/\$atilde;/g, "ã");
	textoR = textoR.replace(/\$otilde;/g, "õ");
	textoR = textoR.replace(/\$acirc;/g, "â");
	textoR = textoR.replace(/\$ecirc;/g, "ê");
	textoR = textoR.replace(/\$ocirc;/g, "ô");
	textoR = textoR.replace(/\$Aacute;/g, "Á");
	textoR = textoR.replace(/\$Eacute;/g, "É");
	textoR = textoR.replace(/\$Iacute;/g, "Í");
	textoR = textoR.replace(/\$Oacute;/g, "Ó");
	textoR = textoR.replace(/\$Uacute;/g, "Ú");
	textoR = textoR.replace(/\$Atilde;/g, "Ã");
	textoR = textoR.replace(/\$Otilde;/g, "Õ");
	textoR = textoR.replace(/\$Acirc;/g, "Â");
	textoR = textoR.replace(/\$Ecirc;/g, "Ê");
	textoR = textoR.replace(/\$Ocirc;/g, "Ô");
	textoR = textoR.replace(/\$agrave;/g, "à");
	textoR = textoR.replace(/\$Agrave;/g, "À");
	textoR = textoR.replace(/\$uuml;/g, "ü");
	textoR = textoR.replace(/\$Uuml;/g, "Ü");
	textoR = textoR.replace(/\$ccedil;/g, "ç");
	textoR = textoR.replace(/\$Ccedil;/g, "Ç");
	return textoR;
}

function LarguraNum(num, larg) {
	var resultado = num;
	while (String(resultado).length < larg) {
		resultado = "0" + resultado;
	}
	return String(resultado);
}
function efeito_cor(elemento) {
	var q = 204;
	var e = elemento;
	var elemento = document.getElementById(elemento);
	for (i=0;i<=q;i++) {
		elemento.style.background = "#FFFF"+LarguraNum(Dec2Hex(i), 2);
	}
}

<!-- AJAX -->
function ObjMSXMLHttp() {
	var versoes = ["MSXML2.XMLHttp.6.0","MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
	for (var i = 0; i < versoes.length; i++) {
		try {
			var objetoXMLHttp = new ActiveXObject(versoes[i]);
			return objetoXMLHttp;
		} catch (ex) {
			//nda aki
		}
	}
	throw new Error("MSXML não esta instalado");
}
var ajax = false;
if (window.XMLHttpRequest) { //mozilla.
	ajax = new XMLHttpRequest();
} else if (window.ActiveXObject) { //IE
	ajax = ObjMSXMLHttp();
}
if (ajax) {
//nda
} else {
alert("Seu navegador nao tem suporte a ajax, esta pagina nao ira funcionar");
}
function exibir(pagina, elemento) {
var numero = document.getElementById('numero').value;
	var elemento = document.getElementById(elemento);
	ajax.open("POST", pagina, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
		//status carregando
		if(ajax.readyState == 1) {
			elemento.innerHTML = "<img src='../carregando.gif' alt='Carregando...' />";
		}
		//status pronto
		if(ajax.readyState == 4) {
			//pagina encontrada
			if(ajax.status == 200) {
				var resposta = ajax.responseText;
				elemento.innerHTML = resposta;
			} else {
				elemento.innerHTML = "Erro ao carregar os dados";
			}
		}
	}
	ajax.send("numero="+numero);
}

function LExt(pagina, elemento) {
	var usuario = document.getElementById('usuario').value;
	var senha = document.getElementById('senha').value;
	var elemento = document.getElementById(elemento);
	var IDcurso = document.getElementById('IDcurso').value;
	var IDOpcao = document.getElementById('IDOpcao').value;
	ajax.open("POST", pagina, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 1) {
			elemento.innerHTML = "<img src='imagens/carregando.gif' alt='Carregando...' />";
		}
		//status pronto
		if(ajax.readyState == 4) {
			//pagina encontrada
			if(ajax.status == 200) {
				var resposta = ajax.responseText;
				if (resposta == "Incorreto") {
					elemento.innerHTML = "<h4>Usuário e/ou senha incorretos</h4>"
				} else if (resposta == "Positivo") {
					window.location="pagamento_curso.asp?ID="+IDcurso+"&IDop="+IDOpcao;
				}
			} else {
				elemento.innerHTML = "Erro ao carregar os dados";
			}
		}
	}
	ajax.send("usuario="+usuario+"&senha="+senha);
}

<!-- AJAX para ver se existe o email -->

function VEmail(pagina, elemento) {
	var nome = document.getElementById('nome').value;
	var email = document.getElementById('email').value;
	var elemento = document.getElementById(elemento);
	ajax.open("POST", pagina, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 1) {
			elemento.innerHTML = "<img src='imagens/carregando.gif' alt='Carregando...' />";
		}
		//status pronto
		if(ajax.readyState == 4) {
			//pagina encontrada
			if(ajax.status == 200) {
				var resposta = ajax.responseText;
				if (resposta == "Incorreto") {
					elemento.innerHTML = "<h4>Email já está cadastrado</h4>"
				} else if (resposta == "Positivo") {
					elemento.innerHTML = "";
					document.getElementById('abriga_login_cad').style.display = "none";
					document.getElementById('abriga_form').style.display = "block";
					document.getElementById('emailC').value = email;
					document.getElementById('nomeC').value = nome;
				}
			} else {
				elemento.innerHTML = "Erro ao carregar os dados";
			}
		}
	}
	ajax.send("nome="+nome+"&email="+email);
}
<!-- FIM AJAX -->
		
		