// JavaScript Document
function atualizar_online()
{
	var url = '/includes/comum/atualizar.php';
		url = antiCacheRand(url);
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post',
			encoding: 'ISO-8859-1',
			contentType: 'text/html; charset=ISO-8859-1',
			requestHeaders: 'Content-type', 
			onFailure: mostraErro,
			onComplete: atualizou
		});	
}

function atualizou()
{
	//$("atualizacao_usuario").innerHTML += 's';
	setTimeout("atualizar_online()",60000);
}

window.onload = atualizou;
window.onfocus = atualizou;

function ver_filme(filme)
{
	if(filme > 0)
	{
		window.location = 'http://boanoitebh.oi.com.br/cinema/detalhes.php?Id=' + filme;
	}
}

function ver_cinema(cinema)
{
	if(cinema > 0)
	{
		window.location = 'http://boanoitebh.oi.com.br/cinema/cinema.php?cinema=' + cinema;
	}
}

function IsAlphaNum(str)
{
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")
	return false;
	var isValid = true;
	
	// convert to a string for performing string comparisons.
	str += "";
	// Loop through length of string and test for any alpha numeric
	// characters
	for (i = 0; i < str.length; i++)
	{
	// Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
	if (!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) ||
	((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
	((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))))
	{
	isValid = false;
	break;
	}
	} // END for
	
	return isValid;
} // end IsAlphaNum

function abrir_mapa(local_id)
{
	var w = 500;
	var h = 300;
	var lado = (screen.width - w) / 2;
	var topo = (screen.height - h) / 2;
			
	window.open("/local/?id_local="+local_id,local_id,"toolbar=no,status=no,width="+ w +",height="+ h +",resizable=no,scrollbars=no,top="+topo+",left="+lado);
}

function fale_conosco()
{
	var w = 400;
	var h = 350;
	var lado = (screen.width - w) / 2;
	var topo = (screen.height - h) / 2;
			
	window.open("/contato/","Fale","toolbar=no,status=no,width="+ w +",height="+ h +",resizable=no,scrollbars=yes,top="+topo+",left="+lado);
}

function trabalhe_conosco()
{
	var w = 400;
	var h = 600;
	var lado = (screen.width - w) / 2;
	var topo = (screen.height - h) / 2;
			
	window.open("/contato/trabalheconosco.php","Trabalhe","toolbar=no,status=no,width="+ w +",height="+ h +",resizable=no,scrollbars=yes,top="+topo+",left="+lado);
}

function participar(promocao)
{
	var w = 400;
	var h = 400;
	var lado = (screen.width - w) / 2;
	var topo = (screen.height - h) / 2;
			
	window.open("/promocoes/participar.php?rules=1&promocao="+promocao,promocao,"toolbar=no,status=no,width="+ w +",height="+ h +",resizable=no,scrollbars=no,top="+topo+",left="+lado);
}

function votar_enquete(enquete,valor)
{
	onde = 'perguntas_enquete';
	
	var onde_r = document.getElementById('perguntas_enquete');
	
	onde_r.innerHTML = "<center><img src='/imagens/loading.gif' width='20' /></center>";
	
	var url = '/enquetes/votar_enquete.php';
		url = antiCacheRand(url);
	var pars = 'Voto=' + valor + '&Enquete=' + enquete;
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get',
			encoding: 'ISO-8859-1',
			contentType: 'text/html; charset=ISO-8859-1',
			requestHeaders: 'Content-type',
			parameters: pars, 
			onFailure: mostraErro,
			onComplete: processaEnquete(enquete)
		});
}

function processaEnquete(enquete)
{
	var url = '/enquetes/resultado.php';
		url = antiCacheRand(url);
	var pars = 'e=' + enquete;
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get',
			encoding: 'ISO-8859-1',
			contentType: 'text/html; charset=ISO-8859-1',
			requestHeaders: 'Content-type',
			parameters: pars, 
			onFailure: mostraErro,
			onComplete: processaForm
		});
}

function carrega_perfil(pagina,parametros,local)
{	
	onde = local;
	var onde_r = document.getElementById(onde);
	onde_r.innerHTML = "<center><img src='/imagens/loading.gif' width='20' /></center>";

	var url = '/usuarios/perfil_carrega.php';
		url = antiCacheRand(url);
	var pars = 'f=' + pagina + '&' + parametros;
	//alert(pars);
	
	var myAjax = new Ajax.Request(
					url, 
					{
						method: 'get',
						encoding: 'ISO-8859-1',
						contentType: 'text/html; charset=ISO-8859-1',
						requestHeaders: 'Content-type',
						parameters: pars, 
						onFailure: mostraErro,
						onComplete: processaForm
					});
}

function processaForm(RequestX)
{
	obj = RequestX.responseText;
	//alert(obj);
	var formi = document.getElementById(onde);
	formi.innerHTML = obj;
}

function ativar_suite(objeto)
{
	var obj = objeto;
	obj.style.backgroundColor = '#EAEAEA';
	obj.style.borderTop= '1px solid #FFFFFF';
	obj.style.borderLeft= '1px solid #FFFFFF';
	obj.style.borderRight= '1px solid #FFFFFF';
}

function desativar_suite(objeto)
{
	var obj = objeto;
	obj.style.backgroundColor = '#FFFFFF';
	obj.style.borderTop= '1px solid #FFFFFF';
	obj.style.borderLeft= '1px solid #FFFFFF';
	obj.style.borderRight= '1px solid #FFFFFF';
}

function muda_style_color(objeto,cor)
{
	var obj = objeto;
	obj.style.backgroundColor = cor;
}

function muda_cor(objeto,cor)
{
	var obj = objeto;
	obj.bgColor = cor;
}

function exibir(objeto)
{
	var obj = document.getElementById(objeto)
	obj.style.visibility = "visible";
	obj.style.display = "block";
}

function esconder(objeto)
{
	var obj = document.getElementById(objeto)
	obj.style.visibility = "hidden";
	obj.style.display = "none";	
}

function mudar_inner(objeto,inner)
{
	var obj = document.getElementById(objeto)
	obj.innerHTML = inner;
}

function exibir_esconder(objeto)
{
	var obj = document.getElementById(objeto)
	
	if(obj.style.visibility == "hidden")
	{
		obj.style.visibility = "visible"
	}
	else
	{
		obj.style.visibility = "hidden"	
	}
	
	if(obj.style.display == "none")
	{
		obj.style.display = "block";
	}
	else
	{
		obj.style.display = "none";
	}
}

function MM_preloadImages() 
{
  	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 ver_fotos_album(album_foto_id)
{
	if(album_foto_id == 0)
	{
		album_foto_id = '';
		return false;
	}
	else
	{
		window.open("/usuarios/album/album_ver_foto.php?album_foto="+album_foto_id,album_foto_id,"toolbar=0,status=0,width=640,height=600,resizable=0,scrollbars=1");
	}
}

function ver_foto(foto)
{
	var w = 780;
	var h = 640;
	var lado = (screen.width - w) / 2;
	var topo = (screen.height - h) / 2;
	
	if(foto == 0)
	{
		foto = '';
	}
	window.open("/fotos/foto.php?foto="+foto,foto,"toolbar=0,status=0,width=780,height=640,resizable=0,scrollbars=1,top="+topo+",left="+lado);
}

function verfotos(foto,festa)
{
	var w = 780;
	var h = 640;
	var lado = (screen.width - w) / 2;
	var topo = (screen.height - h) / 2;
	
	if(foto == 0)
	{
		foto = '';
	}
	window.open("/fotos/foto.php?foto="+foto,foto,"toolbar=0,status=0,width=780,height=640,resizable=0,scrollbars=1,top="+topo+",left="+lado);
	//window.open("/fotos/ver.php?foto="+foto+"&festa="+ festa,foto,"toolbar=0,status=0,width=640,height=600,resizable=0,scrollbars=1");
}

function verfotos_15anos(foto,festa)
{
	var w = 780;
	var h = 640;
	var lado = (screen.width - w) / 2;
	var topo = (screen.height - h) / 2;
	
	if(foto == 0)
	{
		foto = '';
	}
	window.open("/15anos/foto.php?foto="+foto,foto,"toolbar=0,status=0,width=780,height=640,resizable=0,scrollbars=1,top="+topo+",left="+lado);
	//window.open("/fotos/ver.php?foto="+foto+"&festa="+ festa,foto,"toolbar=0,status=0,width=640,height=600,resizable=0,scrollbars=1");
}

function ver_fotos_festa(festa)
{
	if(festa > 0)
	{
		window.open("/fotos/ver_fotos.php?Id="+ festa,festa,"toolbar=0,status=0,width=780,height=640,resizable=0,scrollbars=1");
	}
}

function ver_fotos_festa_15(festa)
{
	if(festa > 0)
	{
		window.open("/15anos/ver_fotos.php?Id="+ festa,festa,"toolbar=0,status=0,width=780,height=640,resizable=0,scrollbars=1");
	}
}

function ver15anos(foto,festa)
{
	if(foto == 0)
	{
		foto = '';
	}
	window.open("/15anos/ver.php?foto="+foto+"&festa="+ festa,foto,"toolbar=0,status=0,width=640,height=600,resizable=0,scrollbars=1");
}

function findPosX(objPos1)
{
	var curleft=0;
	if(objPos1.offsetParent)
	{
		while(objPos1.offsetParent)
		{
			curleft+=objPos1.offsetLeft
			objPos1=objPos1.offsetParent;
		}
	} 
	else if(objPos1.x)
		curleft+=objPos1.x;
	return curleft;
}

function findPosY(objPos1)
{
	var curtop=0;
	if(objPos1.offsetParent)
	{
		while(objPos1.offsetParent)
		{
			curtop+=objPos1.offsetTop
			objPos1=objPos1.offsetParent;
		}
	} 
	else if(objPos1.y)
		curtop+=objPos1.y;
	return curtop;
}

function adicionar_campo(botao)
{
	var tabela = botao.parentNode.parentNode.parentNode.parentNode;
	var linhas = tabela.rows;
	var totalLinhas = linhas.length;
	if(totalLinhas >= 5)
	{
		return false;	
	}
	var linha = tabela.insertRow(totalLinhas)
	var celula1 = linha.insertCell(0)
		celula1.width = "175px";
		
	var celula2 = linha.insertCell(1)
		celula2.innerHTML = "<img src='/imagens/excluir.gif' onClick='remover_campo(this)' alt='Excluir'>";
		
	var novo = document.createElement("input");
	
		novo.setAttribute("type","text");
		novo.type = "text";
		
		novo.setAttribute("name", "evento_producao[]");
		novo.name = "evento_producao[]";
		
		novo.setAttribute("class", "inputCadastro");
		novo.className = "inputCadastro";
		
		novo.setAttribute("size", "30");
		novo.size = "30";
		
	var novo2 = document.createElement("input");
	
		novo2.setAttribute("type","hidden");
		novo2.type = "hidden";
		
		novo2.setAttribute("name", "evento_producao_id[]");
		novo2.name = "evento_producao_id[]";
		
		novo2.setAttribute("value","0");
		novo2.value = "0";
		
		
		celula1.appendChild(novo);
		celula1.appendChild(novo2);
}

function remover_campo(botao)
{
	var tabela = botao.parentNode.parentNode.parentNode.parentNode;
	var linha = botao.parentNode.parentNode;
	
	tabela.deleteRow(linha.rowIndex)
}

function antiCacheRand(aurl)
{
	var dt = new Date();
	if(aurl.indexOf("?")>=0){// já tem parametros
		return aurl + "&" + encodeURI(Math.random() + "_" + dt.getTime());
	}else{ return aurl + "?" + encodeURI(Math.random() + "_" + dt.getTime());}
}

function mostraErro()
{
	//alert("Ocorreu um erro no processamento, tente novamente!");
}


function adicionar_eu_vou(usuario_id, agenda_id, euvou_status)
{
	var url = '/usuarios/inserir_euvou.php';
		url = antiCacheRand(url);
	var pars = "usuario_id="+ usuario_id +"&agenda_id="+ agenda_id +"&euvou_status="+ euvou_status;
	//alert(pars);
	
	var myAjax = new Ajax.Request(
					url, 
					{
						method: 'get',
						parameters: pars, 
						onFailure: mostraErro,
						onComplete: resultado_adicionar_eu_vou
					});
}

function resultado_adicionar_eu_vou(RequestX)
{
	var str = RequestX.responseText;
	eval(str);
}

function remover_foto_album_novo(foto_id)
{
	//alert('agenda Id: ' + agenda_id + " - Foto Id: " + foto_id);
	
	var url = '/usuarios/album/album_del_foto.php';
		url = antiCacheRand(url);
	var pars = "foto_id="+ foto_id;
	
	var myAjax = new Ajax.Request(
					url, 
					{
						method: 'get',
						parameters: pars, 
						onFailure: mostraErro,
						onComplete: resultado_adicionar_foto_album
					});
}

function adicionar_foto_album_novo(foto_id)
{
	//alert('agenda Id: ' + agenda_id + " - Foto Id: " + foto_id);
	
	var url = '/usuarios/album/album_add_foto.php';
		url = antiCacheRand(url);
	var pars = "foto_id="+ foto_id;
	
	var myAjax = new Ajax.Request(
					url, 
					{
						method: 'get',
						parameters: pars, 
						onFailure: mostraErro,
						onComplete: resultado_adicionar_foto_album
					});
}

function adicionar_foto_album(agenda_id, foto_id, pb, sephia)
{
	//alert('agenda Id: ' + agenda_id + " - Foto Id: " + foto_id);
	
	var url = '/usuarios/album_adicionar_foto.php';
		url = antiCacheRand(url);
	var pars = "agenda_id="+ agenda_id +"&foto_id="+ foto_id + "&pb="+ pb + "&sephia=" + sephia;
	//alert(pars);
	
	var myAjax = new Ajax.Request(
					url, 
					{
						method: 'get',
						parameters: pars, 
						onFailure: mostraErro,
						onComplete: resultado_adicionar_foto_album
					});
}

function resultado_adicionar_foto_album(RequestX)
{
	var str = RequestX.responseText;
	//alert(str);
	eval(str);
}


function CorCampo(Id,Check,CorMarcado,CorDesmarcado){
	if(Check.checked == false)
		{
			document.getElementById(Id).style.borderColor = CorDesmarcado;
			Check.checked = false;
		} 
	else
		{
			document.getElementById(Id).style.borderColor = CorMarcado;
			Check.checked = true;
		}
	
	}
