window.open ("sessoes/popup/entrada.php", 'popAviso', "toolbars=0, status=0, menubar=0, scrollbars=no, resizable=1, left=250, top=250, width=300, height=300");

// Função que retorna o objeto de um id
function $(idx){
	return document.getElementById(idx);
}

// Função que retorna o valor objeto de um id
function $V(idx){
	return $(idx).value;
}

// Função que retorna o style de um objeto
function $S(idx){
	return $(idx).style;
}

// Ajax
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var anterior="";
var enq="n";

function carregaConteudo(containerid,url,id){
	if(id=="n") {
	alert('Escolha a opção na enquete.');
	return;
	}
	else if(id!=undefined) url+=id;
	if(containerid=="nascosto") abreJanela();
	else carregando(containerid,id);
enq="n";
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
	if (page_request.readyState == 4) loadpage(page_request, containerid, url)
}
if (bustcachevar) //if bust caching of external page
var bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid, url){
texto = "";
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
var texto = ""+page_request.responseText;
texto = texto.replace(/\+/g," ");
texto = unescape(texto);
$(containerid).innerHTML = texto;
anterior=url;
	if(texto.indexOf('texto" rows="5"')>0) editorTexto();
	else if(texto.indexOf('<script>')!=-1) executaScript(texto);
tamanhoSite('site','menu');
}

//Função que carrega o editor de texto
var altura=160;
function editorTexto(){
	var objScript = document.createElement("script");
	_editor_url = "admin/rt/";
	objScript.src=_editor_url+"editor.js?id="+new Date().getTime();
	document.body.appendChild(objScript);
}

//Função que executa os scripts das paginas carregadas por ajax
function executaScript(val){
var objScript = document.createElement("script");
ini = val.indexOf('<script>');
fim = val.indexOf('</script>', ini);
codigo = val.substring(ini+8,fim);
objScript.text = codigo;
document.body.appendChild(objScript);
}

function carregando(div,id){
	if($(div)) $(div).innerHTML = "<div style='text-align:center;'><p>&nbsp;</p><p>&nbsp;</p><img src='img/carregando.gif' vspace='5'><br>"+(div=="dentro"?"enviando dados":((div=="enqueteMostra"||div=="votacao")&&id!=undefined?"computando voto":"carregando"))+"...</div>";
}

//verifica form
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=$(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); 
  	if(val.value.indexOf('Digite ') != -1) val.value= "";
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm.replace("saq_","").replace("afi_","").replace("afiliados","Indicado por")+' precisa conter um endereco de email.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm.replace("saq_","").replace("afi_","").replace("afiliados","Indicado por")+' precisa conter somente numeros.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm.replace("saq_","").replace("afi_","").replace("afiliados","Indicado por")+' é requerido.\n'; }
  }  if( $('checkbox') && !$('checkbox').checked ) errors = "-Precisa marcar a caixa concordando com o contrato do sistema.";
	if (errors) alert('O(s) seguinte(s) erro(s) ocorreu(ram):\n'+errors);
  else setTimeout("carregando('dentro')",100);
  document.MM_returnValue = (errors == '');
}

//cor do fundo do objeto
var mud="";
var selec="";
function corFundo(val,ord){
var obj=val;
	if(val.length!=undefined) obj=$(val);
	if(ord==1) mud='#66CCFF';
	else if(ord=='n') mud="";
	else if(ord==0) mud=cor;
	else mud=ord;
selec=obj.name;
cor=obj.style.backgroundColor;
obj.style.backgroundColor=mud;
}

// NewsLetter
function adicionarNewsletter(){
	var d=document.f1;
	if($V('new_assunto')==""){
		alert('Preencha o assunto!');
		return;
	}
	$V('new_texto') = $V('new_texto').replace("##assunto##",$V('new_assunto'));
	d.submit();
	enviaInvisivel();
}

// AJusta o tamanho da Div em um site com ajax
var tamMenu=0;
var tamSite=0;
function tamanhoSite(val,val2){
	if(!$('altura')){
		document.body.innerHTML+='<div style="position:absolute;width:1px;height:100%;top:0px" id="altura"></div>';
	}
	else{
		$(val2).height=tamMenu;
		$(val).height=tamSite;
	}
	var tam = document.body.scrollHeight;
	var dis = $('altura').offsetHeight;
		if(tam<dis) tam = dis;
		if(tamMenu==0 && tamSite==0){
			tamMenu=(tam-301);
			tamSite=tam;
		}
	$(val).height=tam;
	$(val2).height=(tam-301);
}

//função que verifica a extensão do anexo a ser uploaded
function visualizaAnexo(campo,nome){
var t  =campo.value.toLowerCase().split(".");
var ext=t[t.length-1];
	if(ext=="mp3"||ext=="doc"||ext=="gif"||ext=="jpg"||ext=="pdf"||ext=="ppt"||ext=="rar"||ext=="swf"||ext=="xls"||ext=="zip"){
	document.getElementById(nome).value=ext;
	}
	else{
	document.getElementById(nome).value="";
	alert("Somente são permitidos os arquivos das extensões: MP3, DOC, GIF, JPG, PDF, PPT, RAR, SWF XLS e ZIP.");
	document.getElementById(campo.name).value="";
	}
}

function verificaId(){
	$('carregaForm').src='php/verificaId.php?id='+$V('afi_afiliados');
}
