// JavaScript Document
function Void(){
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function data(){
if (self.parent.frames.length != 0){ self.parent.location=document.location; }
}
function validaMail(obj, resp){
var email = obj;
var BadChars = "*|,\":<>[]{}`\'';()&$#% ";
var GoodChars = "@."; 
var posarroba = email.indexOf ('@',0);
if (email.length < 6) // o email é menor que 6 caracteres
{
	if(resp==1){
		showMsgAlert("E-mail inválido!", 1, null);
	}else{
	   alert("E-mail inválido!"); 
	}
   return false;
}
for (var i = 0; i < email.length; i++) 
{
   if (BadChars.indexOf(email.charAt(i)) != -1) // Contém caracteres inválidos, badchars
	{
	if(resp==1){
		showMsgAlert("Seu \"E-mail\" contém caracteres inválidos!", 1, null);
	}else{
		alert("Seu \"E-mail\" contém caracteres inválidos!");
	}
	obj.email.value = '';
	return false;
	}
}
for (var i = 0; i < GoodChars.length; i++) 
{
	if (email.indexOf(GoodChars.charAt(i)) == -1) // não tem goodchars
	{
	if(resp==1){
		showMsgAlert("E-mail inválido!", 1, null);
	}else{
	   alert("E-mail inválido!"); 
	}
	return false;
	}
	if (email.indexOf(GoodChars.charAt(i),0) == 0) // começou com goodchars (. ou @)
	{
		if(resp==1){
			showMsgAlert("E-mail inválido!", 1, null);
		}else{
		   alert("E-mail inválido!"); 
		}
		return false;
	}
	if (email.lastIndexOf(GoodChars.charAt(i)) > email.length-3) //existe menos de 2 caracteres depois do ultimo goodchar
		{
		if(resp==1){
			showMsgAlert("E-mail inválido! Seu e-mail não deve terminar com @.", 1, null);
		}else{
			alert("E-mail inválido! Seu e-mail não deve terminar com @.");
		}
		return false;
		}
}
if (email.lastIndexOf('@') > email.lastIndexOf('.')) //Não tem ponto depois do arroba
	{
	if(resp==1){
		showMsgAlert("E-mail inválido!", 1, null);
	}else{
	   alert("E-mail inválido!"); 
	}
	return false;
	}
if (email.indexOf ('@.',0) != -1 || email.indexOf ('.@',0) != -1) // . e @ colados
	{
	if(resp==1){
		showMsgAlert("E-mail inválido!", 1, null);
	}else{
	   alert("E-mail inválido!"); 
	}
	return false;
	}
if (email.indexOf ('@',posarroba+1) != -1) // Contém mais de um " @ " 
	{
	if(resp==1){
		showMsgAlert("E-mail inválido! Contém mais de um @", 1, null);
	}else{
		alert("E-mail inválido! Contém mais de um @");
	}
	return false;
	}
return true;
}
//----------------
function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}
function contaTexto(obj,maximo,form){
	if(obj.value.length>maximo){
		obj.value = obj.value.substr(0,maximo-1);
	}
	document.getElementById(form).innerHTML = "<strong>"+(maximo-obj.value.length)+"</strong>";
}
function contaTextoLivre(obj,form){
	document.getElementById(form).innerHTML = "<strong>"+obj.value.length+"</strong>";
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_showHideDisplay() { //v6.0
  var i,p,v,obj,args=MM_showHideDisplay.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}
var enviouForm = 0;
function valid(path){
	validCont();
}
function validCont(path){
	obj = document.Conta;
	if(enviouForm==0){
		obj.Submit2.value = 'Espere';
		enviouForm = 1;
		obj.action = path+"ead/cadastro/index.php";
		obj.submit();
	}	
}
function sair(path){
	ourDate = new Date();
	location.href = path+"clientes/?logout="+ourDate.getTimezoneOffset();
}
function emBranco(str) {
tamanho = str.length;
contador = 0;
for (x=0; x<tamanho; x++) {
	if (str.substring(x,x+1) == " ") { ++contador;}
	}
return ((contador == tamanho) || (str == ""));
}
// fecha busca search
var timeClick1 = 0;
var timeClick2 = 0;
function click() {
	if (event.button==1){ 
		if(document.getElementById("boxForm1")!=null){
			timeClick1 = setTimeout("formBusca(0, 1)",250);
		}
		if(document.getElementById("boxForm2")!=null){
			timeClick2 = setTimeout("formBusca(0, 2)",250);
		}
		return true;
	}
}
function limpaClick(){
	clearTimeout(timeClick1);
	clearTimeout(timeClick2);
}
document.onmousedown=click;
document.oncontextmenu=new Function("return false")
window.defaultStatus='www.desenhotudo.com';
var navegador = navigator.appName;
//
function showHideWaiting(op){
	var objwaitingFundo = xGetElementById('WaitingBack');
	var objwaiting = xGetElementById('Waiting');
	var left = (screen.width /2)-150;
	var height = screen.height;
	var top = height/2;
	window.status = left;
	//
	if (window.innerHeight) {
		top = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		top = document.documentElement.scrollTop;
	} else if (document.body) {
	    top = document.body.scrollTop;
	}
	top = 160 + top;
	objwaitingFundo.style.height = (top + 900)+"px";
	objwaiting.style.top = top + "px";
	objwaiting.style.left = left + "px";
	if(op==1){
		MM_showHideLayers("WaitingBack","","show");
		MM_showHideLayers("Waiting","","show");
	}else{	
		MM_showHideLayers("Waiting","","hide");
		MM_showHideLayers("WaitingBack","","hide");
	}	
}	
function esqueceu(path){
	if(path==null){
		parent.location.href = "../cadastro/?lembrar=1";
	}else{
		parent.location.href = path+"cadastro/?lembrar=1";
	}
}
function ajuda(op,path){
	op = op==null ? "" : op;
	if(path==null){
		parent.location.href = "../../atendimento/contato.php?op="+op;
	}else{
		parent.location.href = path+"atendimento/contato.php?op="+op;
	}
}
function hideMDWainting(){
	obj = window.parent.document.getElementById("WaitingBack");
	obj.style.visibility = "hidden";
	obj = window.parent.document.getElementById("Waiting");
	obj.style.visibility = "hidden";
}		
function sendMail(){
	valMail();
}
function valMail(){
	obj = document.Contato;
	if(emBranco(obj.nome.value)){
		alert("Por favor informe o seu nome.");
		obj.nome.focus();
		return false;
	}
	if(!validaMail(obj.__contato.value)){
		obj.__contato.focus();
		return false;
	}
	if(emBranco(obj.mensagem.value)){
		alert("Por favor coloque a sua mensagem.");
		obj.mensagem.focus();
		return false;
	}
	obj.submit();
}
function assinar(){
	validAssina();
}
function callHD(id){
	larg = 441;
	alt = 581;
	l = (screen.width/2)-(larg/2);
	t = 30;
	MM_openBrWindow(pathHD+"ead/helpdesk/index.php?ID="+id,"janela_tira","left="+l+",top="+t+",width="+larg+",height="+alt+",status=no,toolbar=no,menubar=no,location=no");
}
//
var Fav = new Object();
var gif_fav = 1;
var pos;
Fav.Request = function(cont, cod_cont, fav, ps){
	gif_fav = fav;
	pos = ps;
	MM_showHideLayers('w_fav'+gif_fav,'','show');
	Fav.request = Fav.createRequestObject();
	Fav.request.onreadystatechange = Fav.Response;
	Fav.request.open("POST", pathAJ+"__js/marcaFAV.php?cont="+cont+"&cod_cont="+cod_cont, true);
	Fav.request.send(pathAJ+"__js/marcaFAV.php");
}
Fav.Response = function (){
	if(Fav.CheckReadyState(Fav.request)==200){		
		var response = Fav.request.responseXML.documentElement;
		var _data = response.getElementsByTagName('fav');
		if(_data.length == 0){
			// achou nada;	
		}else{
			var localRes = response.getElementsByTagName('id')[0].firstChild.data;
			//
			if(localRes==1){
				if(document.getElementById('resp_fav'+gif_fav)!=null){
					if(pos=='h'){
						document.getElementById('resp_fav'+gif_fav).innerHTML = '<img src="'+pathAJ+'__img/bt_favorito_h_sel.gif" alt="Adicionado no seu Favoritos" width="56" height="15" border="0" align="absmiddle">';
					}else{
						if(pos=='p'){
							document.getElementById('resp_fav'+gif_fav).innerHTML = '<img src="'+pathAJ+'__img/bt_aula_favorito.gif" alt="Adicionado no seu Favoritos" width="15" height="15" border="0" align="absmiddle">';
						}else{
							document.getElementById('resp_fav'+gif_fav).innerHTML = '<img src="'+pathAJ+'__img/bt_favorito_sel.gif" alt="Adicionado no seu Favoritos" width="48" height="30" border="0" align="absmiddle">';
						}
					}
				}
			}
			setTimeout("MM_showHideLayers('w_fav"+gif_fav+"','','hide')",400);
		}	
	}
}
Fav.createRequestObject = function(){
	var obj;
	if(window.XMLHttpRequest)	{
		obj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		obj = new ActiveXObject("MSXML2.XMLHTTP");
	}
	return obj;
}
Fav.CheckReadyState = function(obj){
	if(obj.readyState < 4) {		
		window.status = "Loading...";
	}
	if(obj.readyState == 4){
		if(obj.status == 200){
			window.status = "Loaded!";
			return obj.status;
		}else{
			window.status = "HTTP " + obj.status;
		}
	}
}
var lineBox = 0;
function formBusca(op, org){
	if(org==1){
		if(document.getElementById("boxForm1")!=null){
			if(op==0){
				objbox = xGetElementById("boxForm1");
				objbox.style.display = "none";
				obj = xGetElementById("form_busca1");
				obj.a.value = 0;
				objbox = xGetElementById("boxForm0");
				objbox.style.display = "";
			}else{
				objbox = xGetElementById("boxForm0");
				if(objbox.style.display==""){
					objbox.style.display = "none";
					objbox = xGetElementById("boxForm1");
					objbox.style.display = "";
					obj = xGetElementById("form_busca1");
					//
					if(document.form_busca2!=null){
						objbox = xGetElementById("boxForm2");
						objbox.style.display = "none";
					}
					/*
					Animação
					*/
					lineBox = 0;
					limpaClick();
					dropBoxBusca("boxForm1opc",250);
				}
			}	
		}
	}else{
		if(document.getElementById("boxForm2")!=null){
			objbox = xGetElementById("boxForm2");
			if(op==0){
				objbox.style.display = "none";
				obj = xGetElementById("form_busca2");
				obj.a.value = 0;
				//
				objbox = xGetElementById("boxForm1");
				objbox.style.display = "none";
				objbox = xGetElementById("boxForm0");
				objbox.style.display = "";
				document.form_busca2.q.focus();
			}else{	
				objbox.style.display = "";
				objbox = xGetElementById("boxForm1");
				objbox.style.display = "none";
				objbox = xGetElementById("boxForm0");
				objbox.style.display = "";
				document.form_busca2.a[0].checked = true;
				/*
				Animação
				*/
				lineBox = 0;
				limpaClick();
				dropBoxBusca("boxForm2",250);
			}	
		}
	}
}
function sendBusca(obj, box){
	valSendBusca(obj, box);
}
function valSendBusca(obj, box){
	obj = xGetElementById(obj);
	objbox = xGetElementById(box);
	send = "";
	if(obj.a1.checked){
		send+= "1";
	}
	if(obj.a2.checked){
		send+= "2";
	}
	if(obj.a3.checked){
		send+= "3";
	}
	if(obj.a4.checked){
		send+= "4";
	}
	if(obj.a5.checked){
		send+= "5";
	}
	if(obj.a6.checked){
		send+= "6";
	}
	if(obj.a7.checked){
		send+= "7";
	}
	if(obj.a8.checked){
		send+= "8";
	}
	obj.o.value = send;
	obj.submit();
}
function checkarea(elem, objtxt){
	obj = xGetElementById(objtxt);
	if(elem.checked){
		if(elem.name!="a0"){
			obj.a0.checked = false;
			if(objtxt=="form_busca1"){
				obj.a.value = 1;
			}else{
				obj.a[1].checked = true;
			}
		}else{
			if(objtxt=="form_busca1"){
				obj.a.value = 0;
			}else{
				obj.a[0].checked = true;
			}
			obj.a1.checked = false;
			obj.a2.checked = false;
			obj.a3.checked = false;
			obj.a4.checked = false;
			obj.a5.checked = false;
			obj.a6.checked = false;
			obj.a7.checked = false;
			obj.a8.checked = false;
		}
	}
}
function dropBoxBusca(obj,alt){
	/*
	Animação
	rect('top', 'right', 'bottom', 'left')
	*/
	objbox = xGetElementById(obj);
	if(lineBox<alt){
		lineBox = lineBox+100;
		objbox.style.clip = "rect(0px "+lineBox+"px "+(lineBox+1)+"px 0px)"; 
		setTimeout("dropBoxBusca('"+obj+"',"+alt+")",0.5);
	}else{
		if(obj=="boxForm2"){
			document.form_busca2.q.focus();
		}else{
			document.form_busca1.q.focus();
		}
	}
}
function marca(p){
	obj = document.Cadastro;
	obj.tipo[p].checked = true;
	// Escreve o código para divulgação
	document.getElementById("Cod0").style.display = "none";
	document.getElementById("Cod1").style.display = "none";
	document.getElementById("Cod2").style.display = "none";
	document.getElementById("Cod3").style.display = "none";
	document.getElementById("Cod4").style.display = "none";
	document.getElementById("Cod"+p).style.display = "block";
}
var ult_faq = 0;
function buscaFAQ(evt){
	var key_code = evt.keyCode  ? evt.keyCode  :
                   evt.charCode ? evt.charCode :
                   evt.which    ? evt.which    : void 0;
	if(key_code==32 || key_code==10 || key_code==13){
		ult_faq = 0;
		Faq.Request();
	}	
}
function fecharFaq(){
	if(document.getElementById("faqBox").style.display == "block"){
		document.getElementById("faqBox").style.display = "none";
	}
	ult_faq = 1;
}

var Faq = new Object();
Faq.Request = function(){
	texto = document.Contato.mensagem.value;
	MM_showHideLayers('w_faq','','show');
	Faq.request = Faq.createRequestObject();
	Faq.request.onreadystatechange = Faq.Response;
	Faq.request.open("POST", pathAJ+"__js/buscaFAQ.php?tex="+texto, true);
	Faq.request.send(pathAJ+"__js/buscaFAQ.php");
}
Faq.Response = function (){
	if(Faq.CheckReadyState(Faq.request)==200){		
		var response = Faq.request.responseXML.documentElement;
		var _data = response.getElementsByTagName('id');
		if(_data.length == 0){
			// achou nada;	
			setTimeout("MM_showHideLayers('w_faq','','hide')",400);
			if(document.getElementById("faqBox").style.display == "block"){
				document.getElementById("faqBox").style.display = "none";
			}
			document.getElementById("faqDisplay").innerHTML = "";
		}else{
			var localRes = response.getElementsByTagName('id')[0].firstChild.data;
			//
			if(localRes.length>0){
				txtResp = '';
				resp = localRes.split("|");
				for(n=0;n<resp.length;n++){
					tmp = resp[n].split(";");
					txtResp+= '<strong>'+(n+1)+'</strong> - <a href="faq.php?ID=44564dd45654ddd545d&cod_faq='+tmp[0]+'">'+tmp[1]+'</a><br><br>';
				}
				if(ult_faq ==0 && document.getElementById("faqBox").style.display == "none"){
					document.getElementById("faqBox").style.display = "block";
				}
				document.getElementById("faqDisplay").innerHTML = txtResp;
			}
			setTimeout("MM_showHideLayers('w_faq','','hide')",400);
		}	
	}
}
Faq.createRequestObject = function(){
	var obj;
	if(window.XMLHttpRequest)	{
		obj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		obj = new ActiveXObject("MSXML2.XMLHTTP");
	}
	return obj;
}
Faq.CheckReadyState = function(obj){
	if(obj.readyState < 4) {		
		window.status = "Loading...";
	}
	if(obj.readyState == 4){
		if(obj.status == 200){
			window.status = "Loaded!";
			return obj.status;
		}else{
			window.status = "HTTP " + obj.status;
		}
	}
}
function buscaNews(op){
	Noticia.Request(op);
}
function cadMailNews(form){
	alert(document.formNews);
	NoticiaMail.Request(form);
}
function marcaItem(obj){
	try{
		obj.checked = true;
	}catch(er){ alert(er); }
}
