// JavaScript Document
 
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY){
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;
	if(xScroll < windowWidth) pageWidth = windowWidth;
	else pageWidth = xScroll;
	arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
	return arrayPageSize;
}

function posicao(){
	var divBanner = document.getElementById("banner_happy_hour");
	var divCarregar = document.getElementById("carregar");	
	var divNav = document.getElementById("nav");
	var xScroll = document.body.scrollWidth;

	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	var pageSize = getPageSize();
	var posBanner = ((xScroll / 2) + 250);
	divBanner.style.left = posBanner + "px";
	divBanner.style.top = 65 + "px";
//	$("banner_happy_hour").innerHTML = $("carregar").innerHTML;
	divBanner.innerHTML = divCarregar.innerHTML;
	var posNav = ((pageSize.windowWidth /2) - 390);
//	divNav.style.left = posNav + "px";
}

function posicao_musical(){
	var divBanner = document.getElementById("banner_musical");
	var divCarregar = document.getElementById("carregar");
	var divNav = document.getElementById("nav");
	var xScroll = document.body.scrollWidth;

	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	var pageSize = getPageSize();
	var posBanner = ((xScroll / 2) + 150);
	divBanner.style.left = posBanner + "px";
	divBanner.style.top = 65 + "px";
	divBanner.innerHTML = divCarregar.innerHTML;
	var posNav = ((pageSize.windowWidth /2) - 390);
//	divNav.style.left = posNav + "px";
}

function posicaoPatricks(){
	var divBanner = document.getElementById("banner_patricks");
	var divNav = document.getElementById("nav");
	var xScroll = document.body.scrollWidth;

	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	var pageSize = getPageSize();
	var posBanner = ((xScroll / 2) - 235);
	divBanner.style.left = posBanner + "px";
	divBanner.style.top = 65 + "px";
	$("banner_patricks").innerHTML = $("carregaPatricks").innerHTML;
	var posNav = ((pageSize.windowWidth /2) - 390);
//	divNav.style.left = posNav + "px";
}

function fechar(){
	document.getElementById("banner_happy_hour").style.display = "none";
	if(document.getElementById("formLogin") != null){
		document.getElementById("formLogin").style.marginLeft = 390 + "px";
	}
	document.getElementById("logout").style.paddingRight = 0 + "px";
}

function fechar_musical(){
	document.getElementById("banner_musical").style.display = "none";
	if(document.getElementById("formLogin") != null){
		document.getElementById("formLogin").style.marginLeft = 390 + "px";
	}
	document.getElementById("logout").style.paddingRight = 0 + "px";
}

function fechar_patricks(){
	document.getElementById("banner_patricks").style.display = "none";
	if(document.getElementById("formLogin") != null){
		document.getElementById("formLogin").style.marginLeft = 390 + "px";
	}
	document.getElementById("logout").style.paddingRight = 0 + "px";
}

function aumenta(){
	document.getElementById("nav").style.width = 550 + "px";
}
function diminui(){
	document.getElementById("nav").style.width = 210 + "px";
}

function objXMLHttp(){
	
	if(window.XMLHttpRequest){//objeto válido em Mozilla, Safari, etc...
		var objetoXMLHttp = new XMLHttpRequest();
		return objetoXMLHttp;
	}else if(window.ActiveXObject){//objeto válido para IE...
	
		//versoes disponíveis de objetos XMLHttp do IE
		var versoes = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0",
					   "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
		
		//verifica a versao usada pelo IE e a retorna
		for(var i = 0; i < versoes.length; i++){
			try {
				var objetoXMLHttp = new ActiveXObject(versoes[i]);
				return objetoXMLHttp;
			} catch (ex){
				//nada
			}
		}
	}
	return false;
}

function excluirAjax(id, sessao, pasta){
	//captura valor do campo departamento
	var dados = "id="+id+"&sessao="+sessao+"&pasta="+pasta;
	
	//pega o objeto XMLHttp ou XMLHttpRequest
	var oXMLHttp = objXMLHttp();
	
	//indica a forma como será enviado o formulário
	oXMLHttp.open("POST", "../ajax/excluirImagem.php", true);
	
	oXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	//verifica se já foi carregada a resposta dada pelo servidor
	oXMLHttp.onreadystatechange = function(){
		if(oXMLHttp.readyState == 4){
				//mensagem("Carregando...");
			if(oXMLHttp.status == 200){
				mensagem(oXMLHttp.responseText);
			}else{
				mensagem("Ocorreu um erro: "+oXMLHttp.statusText);	
			}
		}
	};
	
	//envia os dados através do método send()
	oXMLHttp.send(dados);
}

function verificaLogin(email){
	//captura valor do campo departamento
	var dados = "email="+email;
	
	//pega o objeto XMLHttp ou XMLHttpRequest
	var oXMLHttp = objXMLHttp();
	
	//indica a forma como será enviado o formulário
	oXMLHttp.open("POST", "ajax/verificaLogin.php", true);
	
	oXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	//verifica se já foi carregada a resposta dada pelo servidor
	oXMLHttp.onreadystatechange = function(){
		if(oXMLHttp.readyState == 4){
				//mensagem("Carregando...");
			if(oXMLHttp.status == 200){
				if(oXMLHttp.responseText !== ""){
					//alert("");
					document.cadastro.email.value = "";
					document.cadastro.email.focus();
				}
				document.getElementById("msg").innerHTML = oXMLHttp.responseText;
			}else{
				document.getElementById("msg").innerHTML = "Ocorreu um erro: "+oXMLHttp.statusText;	
			}
		}
	};
	
	//envia os dados através do método send()
	oXMLHttp.send(dados);
}

//método responsável por exibir a mensagem ao usuario
function mensagem(msg){
	document.getElementById('imagem').innerHTML = msg;
}

function checaCadastro(){
	var obj = document.cadastro;
	if(obj.nome.value == "") {
		alert('Preencha o campo Nome');
		obj.nome.focus();
	}
	else if(obj.dia.value == ""){
		alert('Informe o Dia!');
		obj.dia.focus();
	}
	else if(obj.dia.value < 1 || obj.dia.value >31){
		alert('Campo Dia invalido!');
		obj.dia.focus();
	}
	else if(obj.mes.value == ""){
		alert('Informe o Mes!');
		obj.mes.focus();
	}
	else if(obj.mes.value < 1 || obj.mes.value >12){
		alert('Campo Mes invalido!');
		obj.mes.focus();
	}
	else if(obj.ano.value == ""){
		alert('Informe o Ano!');
		obj.ano.focus();
	}
	else if(obj.ano.value < 1900 || obj.ano.value >9999){
		alert('Campo Ano invalido!');
		obj.ano.focus();
	}
	else if(obj.email.value == "") {
		alert('Preencha o campo Email');
		obj.email.focus();
	}
	else if(obj.email.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.email.focus();
	}
	else if(obj.email.value == "" && obj.alt.value == '0'){
		alert('Escolha um login Usuario!');
		obj.email.focus();
	}
	else if(obj.senha.value == ""){
		alert('Informe a Senha!');
		obj.senha.focus();
	}
	else if(obj.repitasenha.value == ""){
		alert('Confirme a senha!');
		obj.repitasenha.focus();
	}	
	else if(obj.repitasenha.value != obj.senha.value){
		alert('Voce informou 2 senhas diferentes!');
		obj.repitasenha.focus();
	}else{
		obj.submit();
		}
}

function checaContato(){
	var obj = document.faleconosco;
	if(obj.nm_faleconosco.value == "") {
		alert('Preencha o campo Nome');
		obj.nm_faleconosco.focus();
	}
	else if(obj.email_faleconosco.value == ""){
		alert('Preencha o campo E-mail!');
		obj.email_faleconosco.focus();
	}
	else if(obj.email_faleconosco.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.email_faleconosco.focus();
	}
	else if(obj.msg_faleconosco.value == ""){
		alert('Preencha o campo Mensagem!');
		obj.msg_faleconosco.focus();
	}else{
		obj.submit();
		}
}
function zerar(campo, texto){
	if (campo.value==texto){
		campo.value="";
	}
}
function campoVazio(campo, texto){
	if (campo.value==""){
		campo.value=texto;
	}
}

function eNumerico(campo){
	var valor = campo.value;
	if(isNaN(valor)){
		campo.value = "";
		alert("Digite apenas numeros!");
		campo.focus();
	}
}

function ampliaFlash(src)
{
    //criando um link falso, para o LightBox captar as informaçoes
    var a_false = document.createElement("A");
    a_false.rel = "lightbox";
    a_false.href = src;
    //chamando a funçao do lightbox responsável pelo início das açoes
    myLightbox.start(a_false);
    //anulando o link
    a_false = null;
}
function tamanhotext(campo, limite)
{
	if (campo.value.length > limite){
		campo.value = campo.value.substr(0,limite);
		alert('O limite deste campo é de 100 caracteres!');
	}
}
function tamanhoPop(campo, limite)
{
	if (campo.value.length > limite){
		campo.value = campo.value.substr(0,limite);
		alert('O limite deste campo é de 53 caracteres!');
	}
}
function tamanhoAgenda(campo, limite)
{
	if (campo.value.length > limite){
		campo.value = campo.value.substr(0,limite);
		alert('O limite deste campo é de 23 caracteres!');
	}
}

function tbh(id){
	var ids = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27"); 
	for(i=0;i<ids.length;i++){
		var some = "tbh"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("tbh"+id).style.display = "block";
		}
	}
}
function agenda(id){
	var ids = new Array("1"); 
	for(i=0;i<ids.length;i++){
		var some = "agenda"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("agenda"+id).style.display = "block";
		}
	}
}

function sobre(id){
	var ids = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27"); 
	for(i=0;i<ids.length;i++){
		var some = "sobre"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("sobre"+id).style.display = "block";
		}
	}
}

function Hcerveja(id){
	var ids = new Array("1","2","3","4","5","6"); 
	for(i=0;i<ids.length;i++){
		var some = "Hcerveja"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("Hcerveja"+id).style.display = "block";
		}
	}
}

function Tcerveja(id){
	var ids = new Array("1","2"); 
	for(i=0;i<ids.length;i++){
		var some = "Tcerveja"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("Tcerveja"+id).style.display = "block";
		}
	}
}

function Hwhisky(id){
	var ids = new Array("1","2","3"); 
	for(i=0;i<ids.length;i++){
		var some = "Hwhisky"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("Hwhisky"+id).style.display = "block";
		}
	}
}
function Twhisky(id){
	var ids = new Array("1","2"); 
	for(i=0;i<ids.length;i++){
		var some = "Twhisky"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("Twhisky"+id).style.display = "block";
		}
	}
}

function historia_pubs(id){
	var ids = new Array("1","2","3","4","5"); 
	for(i=0;i<ids.length;i++){
		var some = "historia_pubs"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("historia_pubs"+id).style.display = "block";
		}
	}
}

function theblack(id){
	var ids = new Array("1","2","3","4"); 
	for(i=0;i<ids.length;i++){
		var some = "theblack"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("theblack"+id).style.display = "block";
		}
	}
}

function MudaPrato(id){
	$('atualizaAjax').innerHTML = $('atualizaAjax').innerHTML;
	var retorno = new Ajax.Request('ajax/mudaCardapioDia.php',{ method: 'post',parameters: "id="+id , onComplete: mostrarCardapio});

}

function mostrarCardapio(resp){
	$('atualizaAjax').innerHTML = resp.responseText;
}

function VerificarData(){

var retorno = new Ajax.Request('ajax/verificaData.php',{ method: 'post',parameters: "data="+$('dt_evento').value , onComplete: mostraResp});

}

function mostraResp(resp){
	$('Data').value = resp.responseText;
}

function ValidaPost(){
	
	if($('foto').value == ''){
		alert('Campo de Upload é de preenchimento obrigatório!');
		return false;
	}else if($('legenda').value == ''){
		alert('Campo de Legenda é de preenchimento obrigatório!');
		return false;
	}else if($('dia1').value == ''){
		alert('Informe o Dia!');
		return false;
	}else if($('dia1').value < 1 || $('dia1').value > 31){
		alert('Campo Dia invalido!');
		return false;
	}else if($('mes1').value == ''){
		alert('Informe o Mes!');
		return false;	
	}else if($('mes1').value < 1 || $('mes1').value > 12){
		alert('Campo Mes invalido!');
		return false;
	}else if($('ano1').value == ''){
		alert('Informe o Ano!');
		return false;
	}else if($('ano1').value < 1900 || $('ano1').value > 9999){
		alert('Campo Ano invalido!');
		return false;
	}else{
		return true;	
	}
} 

function Comentario(id){

var retorno = new Ajax.Request('ajax/comentario.php',{ method: 'post',parameters: "muralId="+id , onComplete: mostraComentario});

}

function cadastrarMutal(){

var paras = "id="+$('idImagem').value+"&nome="+$('nome').value+"&email="+$('email').value+"&comentario="+$('comentario').value;
var retorno = new Ajax.Request('ajax/CadastrarMural.php',{ method: 'post',parameters: paras , onComplete: Cadastrar});

}

function Cadastrar(resp){
	$('msgRetorno').innerHTML = resp.responseText;
}

function mostraComentario(resp){
	$('comentarios').innerHTML = resp.responseText;
}

function VerificaMural(){
	if($('nome').value == ''){
		alert('Preencha o campo Nome');
		return false;
	}
	else if($('email').value == '') {
		alert('Preencha o campo Email');
		return false;
	}
	else if($('email').value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		return false;
	}
	else if($('comentario').value == ''){
		alert('Preencha o campo Comentário!');
		return false;
	}else{
		return true;
	}
} 

function campos(variavel){
	if(variavel == 1){		
		document.getElementById("subtt_popup").style.display = "block";
		document.getElementById("data_festa").style.display = "block";
		document.getElementById("id_link").style.display = "block";
		document.getElementById("flagMostraDataFesta").style.display = "block";		
		document.getElementById("desc_popup").setAttribute('maxlength', 100);
		document.getElementById("subtt_popup").setAttribute('maxlength', 18);
		document.getElementById("tt_popup").setAttribute('maxlength', 16);
		//document.getElementById("info_tt").innerHMTL = "16";
		
	}else{
		document.getElementById("subtt_popup").style.display = "none";
		document.getElementById("data_festa").style.display = "none";
		document.getElementById("id_link").style.display = "none";
		document.getElementById("flagMostraDataFesta").style.display = "none";		
		document.getElementById("desc_popup").setAttribute('maxlength', 53);
		//document.getElementById("info_tt").innerHMTL = "12";
		if(document.getElementById("tt_popup").value.length > 12){
			document.getElementById("tt_popup").value = document.getElementById("tt_popup").value.substr(0, 12);
		}
	}
}


function mostraDataFesta(variavel){
	if(variavel == 'S'){		
		document.getElementById("data_festa").style.display = "block";
		document.getElementById("outraDesc").style.display = "none";
	}else{
		document.getElementById("data_festa").style.display = "none";
		document.getElementById("outraDesc").style.display = "block";
	}
}


function tbhTexto(id){
	
	texto = $("#tbh_"+id);
	varlink = $("a#abre"+id);
	
	for(i = 1; i <= 8; i++){
		if(Number(i) != Number(id)){
			$("#sub_"+i).slideUp();			
			$("a#abre"+i).attr("class", "abre");			
		}
	}
	
	if(varlink.attr("class") == "abre"){
		texto.slideDown();
		varlink.attr("class", "fecha");
	}else{
		texto.slideUp();
		varlink.attr("class", "abre");
	}
	
}
