var pagat = 1;
var palavra = "";
function AbrePagina(perfil, tamx, tamy, yn) {
	lf = Math.floor(screen.width/2) - Math.floor(tamx/2);
	tp = Math.floor(screen.height/2) - Math.floor(tamy/2);
	var janela = window.open(perfil,"","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=" + yn + ",width=" + tamx + ",height=" + tamy + ", left = " + lf + ", top = " + tp)
}


startSz = 11;
var tgs = new Array( 'div','td','tr','a','p','font','span', 'li');
function fonte(trgt,acao) {
	size = startSz;
	switch(acao) {
		case "+" :
		if(size >= 16) {
			size = 16;
		} else {
			size++;
		}
		break;
		case "-" :
		if(size <= 11) {
			size = 11;
		} else {
			size--;
		}
		break;
	}

	startSz = size;
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	if(!(cEl = d.getElementById(trgt))) cEl = d.getElementsByTagName( trgt )[ 0 ];
	cEl.style.fontSize = size+'px';
	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = startSz+'px';
	}

}

function incrementa_foto(id) {
	var lv = new LoadVars();
	lv.iid = id;

	lv.onLoad = function () {
		if(document.getElementById("aguarde")) {
			document.getElementById("aguarde").style.display = "none";
		}
	}

	lv.send("ajax.php?modelo=front_imagem","POST");
	if(document.getElementById("aguarde")) {
		document.getElementById("aguarde").innerHTML = "Aguarde!<br />Carregando Mensagens";
		document.getElementById("aguarde").style.display = "block";
	}
}

function get_sky(id) {
	var lv = new LoadVars();
	lv.secao = id;

	lv.onLoad = function () {
		document.getElementById('theSky').innerHTML = lv.content;
	}

	if(screen.width>800) {
		lv.send("ajax.php?modelo=front_sky","POST");
	}
}

function get_flash(arquivo, largura, altura, bgcolor, id, qualidade, alinhamento,transparente) {
	var obj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="'+id+'" align="'+alinhamento+'">';
	obj+= '<param name="allowScriptAccess" value="sameDomain" />';
	obj+= '<param name="movie" value="'+arquivo+'" />';
	obj+= '<param name="quality" value="'+qualidade+'" />';
	if(transparente == true) {
		obj+= '<param name="wmode" value="transparent" />';
	}
	obj+= '<param name="bgcolor" value="'+bgcolor+'" />';
	obj+= '<embed src="'+arquivo+'" '+((transparente==true)?'wmode="transparent"':'')+'" quality="'+qualidade+'" bgcolor="'+bgcolor+'" width="'+largura+'" height="'+altura+'" name="'+id+'" align="'+alinhamento+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	obj+= '</object>';
	document.write(obj);
}

function get_flash_var(arquivo, largura, altura, bgcolor, id, qualidade, alinhamento,transparente,variavel) {
	obj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="'+id+'" align="'+alinhamento+'">';
	obj+= '<param name="allowScriptAccess" value="sameDomain" />';
	obj+= '<param name="movie" value="'+arquivo+'" />';
	obj+= '<param name="flashvars" value="'+variavel+'" />';
	obj+= '<param name="quality" value="'+qualidade+'" />';
	if(transparente == true) {
		obj+= '<param name="wmode" value="transparent" />';
	}
	obj+= '<param name="bgcolor" value="'+bgcolor+'" />';
	obj+= '<embed src="'+arquivo+'" '+((transparente==true)?'wmode="transparent"':'')+'" quality="'+qualidade+'" flashvars="'+variavel+'" bgcolor="'+bgcolor+'" width="'+largura+'" height="'+altura+'" name="'+id+'" align="'+alinhamento+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	obj+= '</object>';
	document.write(obj);
}

function get_video(arquivo, largura, altura) {
	var obj = '<OBJECT id="VIDEO" width="'+largura+'" height="'+altura+'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject">';
	obj+= '<PARAM NAME="URL" VALUE="'+arquivo+'">';
	obj+= '<PARAM NAME="SendPlayStateChangeEvents" VALUE="True">';
	obj+= '<PARAM NAME="AutoStart" VALUE="True">';
	obj+= '<PARAM name="enabled" value="True">';
	obj+= '<PARAM name="uiMode" value="mini">';
	obj+= '<PARAM name="PlayCount" value="9999">';
	obj+= '<embed type="application/x-mplayer2" src="'+arquivo+'" width='+largura+' height='+altura+' align="right"> </embed>';
	obj+= '</OBJECT>';
	document.write(obj);
}


function FV_close() {
	if(document.getElementById("formato5")) {
		document.getElementById("formato5").style.display = "none";
	}
}

function FV_closel() {
	if(document.getElementById("formato5")) {
		document.getElementById("formato5").style.display = "none";
	}
}

function FV_expande(xid,x,y) {
	if(document.getElementById('formato'+xid)) {
		document.getElementById('formato'+xid).style.width = x;
		document.getElementById('formato'+xid).style.height = y;
	}
}

function FV_contrai(xid,x,y) {
	if(document.getElementById('formato'+xid)) {
		document.getElementById('formato'+xid).style.width = x;
		document.getElementById('formato'+xid).style.height = y;
	}
}

function carrega_formato(formato) {
	var lv = new LoadVars();
	lv.formato = formato;

	lv.onLoad = function () {
		document.getElementById("container").innerHTML = lv.content;

		if(document.getElementById("aguarde")) {
			document.getElementById("aguarde").style.display = "none";
		}
	}

	lv.send("ajax.php?modelo=front_anuncie","POST");
	if(document.getElementById("aguarde")) {
		document.getElementById("aguarde").innerHTML = "Aguarde!<br />Carregando Mensagens";
		document.getElementById("aguarde").style.display = "block";
	}

}

function php_unescape() {
	document.body.innerHTML = document.body.innerHTML.replace( /(%u([0-9A-F]{4}))/gi, "&#x$2;");
}

function lista_noticia(pagina) {
	var lv = new LoadVars();
	lv.acao = "lista";
	lv.pagina = pagina;
	lv.cid = categoria;

	lv.onLoad = function () {
		document.getElementById("listanoticia").innerHTML = lv.content;

		if(document.getElementById("aguarde")) {
			document.getElementById("aguarde").style.display = "none";
		}
	}

	lv.send("ajax.php?modelo=front_noticia","POST");
	if(document.getElementById("aguarde")) {
		document.getElementById("aguarde").innerHTML = "Aguarde!<br />Carregando Mensagens";
		document.getElementById("aguarde").style.display = "block";
	}

}

/**
*
* AS FUNCOES ABAIXO DEPENDEM DA BIBLIOTECA LOADVARS
*
*/

function exibe_foto(fsrc, id, legenda) {
	//carrega_form_amigo(id);
	document.getElementById("foto-ampliada").innerHTML = '<img src="'+fsrc+'" name="fotoprin" >';
	document.getElementById("foto-legenda").innerHTML = legenda;

}

function lista_foto(pagina) {
	var lv = new LoadVars();
	lv.pagina = pagina;
	lv.acao = "listafoto";
	lv.eid = num_album;
	lv.onLoad = function () {
		document.getElementById("thumb-popup").innerHTML = lv.content;
		//pagina_foto(lv.pagina);
	}

	lv.send("ajax.php?modelo=front_evento","POST");
}

function pagina_foto(pagina) {
	var lv = new LoadVars();
	lv.pagina = pagina;
	lv.acao = "pagina_foto";

	lv.onLoad = function () {
		document.getElementById("paginacao").innerHTML = lv.content;
	}

	lv.send("ajax.php?modelo=front_evento","POST");
}

function lista_projeto(pagina) {
	var lv = new LoadVars();
	lv.pagina = pagina;
	lv.acao = "lista_geral";
	lv.onLoad = function () {
		document.getElementById("listaprojeto").innerHTML = lv.content;
	}

	lv.send("ajax.php?modelo=front_projeto","POST");
}

function lista_extensao(pagina) {
	var lv = new LoadVars();
	lv.pagina = pagina;
	lv.acao = "lista_extensao";
	lv.onLoad = function () {
		document.getElementById("listaextensao").innerHTML = lv.content;
	}

	lv.send("ajax.php?modelo=front_projeto","POST");
}

function lista_noticia(pagina) {
	var lv = new LoadVars();
	lv.pagina = pagina;
	lv.acao = "lista_geral";
	lv.onLoad = function () {
		document.getElementById("listanoticia").innerHTML = lv.content;
	}

	lv.send("ajax.php?modelo=front_noticia","POST");
}

function expandeMenu(h)
{
	var dmenu = document.getElementById("dmenu");
	dmenu.style.height=h+"px";
	//dmenu.style.height="950px";
}

function contraiMenu()
{
	var dmenu = document.getElementById("dmenu");
	dmenu.style.height="500px";
	//alert("contrai");
}

function lista_busca_curso(pagina) {
	var lv = new LoadVars();
	lv.pagina = pagina;
	lv.palavra = palavra;
	lv.local = "curso";
	pagat = pagina;

	lv.onLoad = function () {
		document.getElementById("listacurso").innerHTML = lv.content;
	}

	lv.send("ajax.php?modelo=front_busca","POST");
}

function lista_busca_noticia(pagina) {
	var lv = new LoadVars();
	lv.pagina = pagina;
	lv.palavra = palavra;
	lv.local = "noticia";
	pagat = pagina;

	lv.onLoad = function () {
		document.getElementById("listanoticia").innerHTML = lv.content;
	}

	lv.send("ajax.php?modelo=front_busca","POST");
}

function lista_busca_evento(pagina) {
	var lv = new LoadVars();
	lv.pagina = pagina;
	lv.palavra = palavra;
	lv.local = "evento";
	pagat = pagina;

	lv.onLoad = function () {
		document.getElementById("listaevento").innerHTML = lv.content;
	}

	lv.send("ajax.php?modelo=front_busca","POST");
}

function carrega_resultado() {
	var lv = new LoadVars();
	lv.local = "resultado";
	lv.palavra = palavra;

	lv.onLoad = function () {
		document.getElementById("resultado").innerHTML = lv.content;
	}

	lv.send("ajax.php?modelo=front_busca","POST");
}

function resultado() {
	lista_busca_curso(1);
	lista_busca_noticia(1);
	lista_busca_evento(1);
	carrega_resultado();
}

function abreInstitucional()
{
	var e = document.getElementById("div_menu_institucional");
	e.style.height = "165px";
}

function fechaInstitucional()
{
	var e = document.getElementById("div_menu_institucional");
	e.style.height = "30px";
}


function carrega_calendario(mes,ano) {
	var lv = new LoadVars();
	lv.mes= mes;
	lv.ano= ano;

	lv.onLoad = function () {
		document.getElementById("calendario").innerHTML = lv.content;
		carrega_evento(lv.mes,lv.ano);
		if(document.getElementById("aguarde")) {
			document.getElementById("aguarde").style.display = "none";
		}
	}

	lv.send("ajax.php?modelo=calendario","POST");
	if(document.getElementById("aguarde")) {
		document.getElementById("aguarde").innerHTML = "Aguarde!<br />Carregando Mensagens";
		document.getElementById("aguarde").style.display = "block";
	}

}

function carrega_evento(mes,ano) {
	var lv = new LoadVars();
	lv.mes= mes;
	lv.ano= ano;

	lv.onLoad = function () {
		document.getElementById("eventos").innerHTML = lv.content.UNhtmlEntities();
		if(document.getElementById("aguarde")) {
			document.getElementById("aguarde").style.display = "none";
		}
	}

	lv.send("ajax.php?modelo=front_agenda","POST");
	if(document.getElementById("aguarde")) {
		document.getElementById("aguarde").innerHTML = "Aguarde!<br />Carregando Mensagens";
		document.getElementById("aguarde").style.display = "block";
	}

}

function limpar() {
	setTimeout('document.logonuser.reset();',1000);
}




function AbreFoto(foto, tamx, tamy) {
	lf = Math.floor(screen.width/2) - Math.floor(tamx/2);
	tp = Math.floor(screen.height/2) - Math.floor(tamy/2);
	w = open(foto,"Foto","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=no,width=" + tamx + ",height=" + tamy + ", left = " + lf + ", top = " + tp)
	w.document.open();
	w.document.write("<html><title>FAESA</title>");
	w.document.write("<body bgcolor=\"#FFFFFF\" topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\">");
	w.document.write("<img src=\""+foto+"\">");
	w.document.write("</body></html>");
	w.document.close();
}


function isMail(str)
{
	return (str.indexOf("@")>0 && str.indexOf(".")>0);
}

function limpaNews()
{
	if(document.formulario.nome != undefined)
	document.formulario.nome.value = document.formulario.email.value = "";
	else
	document.getElementById("nome").value = document.getElementById("email").value = "";
	
}

function enviaNews()
{

	if(document.formulario.nome != undefined)
	var nome = document.formulario.nome.value;
	else
	var nome = document.getElementById("nome").value;
	
	
	if(document.formulario.email != undefined)
	var email = document.formulario.email.value;
	else
	var email = document.getElementById("email").value;
	
	var erro = "";
	
	if(email == "| E-mail" || email == "" || ! isMail(email))
	{
		erro += "- Preencha o E-mail corretamente\n";
	
	}
	
	if(nome == "| Nome" || nome == "")
	{
		erro += "- Preencha o Nome corretamente\n";
	
	}
	
	if(erro == "")
	{
	
		var lv = new LoadVars();
		lv.nome = nome;
		lv.email = email;
		lv.acao="ins";
		lv.idioma = "pt";
		
		lv.onLoad = function()
		{
			switch(this.content)
			{
				case "true":
					alert("Cadastro efetuado com sucesso.");
					limpaNews();
				break;
				
				case "false":
					alert("Falha no cadastro.");
				break;
				
			}
		}
		
		lv.sendAndLoad("?target=newsletter_envie","POST");
		
	}
	else
	{
		alert("Foram encontrados os seguintes erros:\n\n"+erro);
	}
	
}


function valida_form(form) {
	m = "Os campos abaixo devem ser preenchidos corretamente: \n\n";
	c = "";
	with(form) {
		for(i=0;i<elements.length;i++) {
			if(elements[i].title != "" && elements[i].value == "") {
				cp = elements[i].title;
				c+= " - "+cp+"\n";
			}			
		}
	}
	if(c.length > 0) {
		alert(m+c);
		return false;
	}
	
	return true;
}