var blank = new Image();
blank.src = 'img/blank.gif';
var h = 0;
function fixIE6(){
    var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
    if (badBrowser) {
        $('img[src$=.png]').each(function(){
            if (!this.complete) {
                this.onload = function(){
                    fixPng(this)
                };
            }
            else {
                fixPng(this);
            }
        });
    }
}

function fixPng(png){
    var src = png.src;
    if (!png.style.width) {
        png.style.width = $(png).width();
    }
    if (!png.style.height) {
        png.style.height = $(png).height();
    }
    png.onload = function(){
    };
    png.src = blank.src;
    png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}
function abre_newsletter(estado){
    $('#newsletter_slide').slideToggle();
    if (estado == 0) {
        newsletter_aberto == 1 ? newsletter_aberto = 0 : newsletter_aberto = 1;
        if (newsletter_aberto) {
            if (window.XMLHttpRequest) {
                xmlhttp = new XMLHttpRequest();
            }
            else {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function(){
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    $('#newsletter_slide').html(xmlhttp.responseText);
                }
            }
            xmlhttp.open("GET", "includes/newsletter_handler.php", true);
            setTimeout("xmlhttp.send()", 400);
        }
    }
    else 
        if (estado == 1) {
        }
}
function getContent(pagina){
	$('#restaurante_content').css('display','none');
	$('#linha_restaurante_content').css('display','none');
	$('#linha_topo_restaurante_content').css('display','none');
	$('#caixa_background').css('background','');
	var browserName=navigator.appName;
	if(browserName=='Microsoft Internet Explorer')
		h=($(document).height())-188;
	else
		h=($(document).height())-183;
	
	$('#caixa_background').height(h);
	$('#link_restaurante').html('<a onclick="getContent(\'restaurante\');"><img src="img/restaurante.jpg" alt="RESTAURANTE" onmouseover="this.src=\'img/restaurante_roll.jpg\'" onmouseout="this.src=\'img/restaurante.jpg\'" /></a>');
	$('#link_ementas').html('<a onclick="getContent(\'ementas\');"><img src="img/ementas.jpg" alt="EMENTAS" onmouseover="this.src=\'img/ementas_roll.jpg\'" onmouseout="this.src=\'img/ementas.jpg\'" /></a>');
	$('#link_especialidades').html('<a onclick="getContent(\'especialidades\');"><img src="img/especialidades.jpg" alt="ESPECIALIDADES" onmouseover="this.src=\'img/especialidades_roll.jpg\'" onmouseout="this.src=\'img/especialidades.jpg\'" /></a>');
	$('#link_eventos').html('<a onclick="getContent(\'eventos\');"><img src="img/social.jpg" alt="SOCIAL" onmouseover="this.src=\'img/social_roll.jpg\'" onmouseout="this.src=\'img/social.jpg\'" /></a>');
	$('#link_contactos').html('<a onclick="getContent(\'contactos\');"><img src="img/contactos.jpg" alt="CONTACTOS" onmouseover="this.src=\'img/contactos_roll.jpg\'" onmouseout="this.src=\'img/contactos.jpg\'" /></a>');
	$('#link_imprensa').html('<a onclick="getContent(\'imprensa\');"><img src="img/imprensa.jpg" alt="IMPRENSA" onmouseover="this.src=\'img/imprensa_roll.jpg\'" onmouseout="this.src=\'img/imprensa.jpg\'" /></a>');
	$('#link_reservas').html('<a onclick="getContent(\'reservas\');"><img src="img/reservas.jpg" alt="RESERVAS" onmouseover="this.src=\'img/reservas_roll.jpg\'" onmouseout="this.src=\'img/reservas.jpg\'" /></a>');
	$('#link_destaques').html('<a onclick="getContent(\'destaques\');"><img src="img/destaques.jpg" alt="DESTAQUES" onmouseover="this.src=\'img/destaques_roll.jpg\'" onmouseout="this.src=\'img/destaques.jpg\'" /></a>');
	
	switch(pagina){
		case'restaurante':$('#link_restaurante').html('<img src="img/restaurante_roll.jpg" alt="RESTAURANTE" />');
						h=$('#caixa_background').height();
						if(h<564)
							$('#caixa_background').css('background','url(img/fundo_restaurante.jpg) top right no-repeat');
						else
							$('#caixa_background').css('background','url(img/fundo_restaurante.jpg) bottom right no-repeat');
						$('#restaurante_content').css('display','block');
						$('#linha_restaurante_content').css('display','block');
						$('#linha_topo_restaurante_content').css('display','block');
						break;
		case'ementas':$('#link_ementas').html('<img src="img/ementas_roll.jpg" alt="EMENTAS" />');
					$('#restaurante_content').css('display','block');
					$('#linha_restaurante_content').css('display','block');
					$('#linha_topo_restaurante_content').css('display','block');
					break;
				
		case'especialidades':$('#link_especialidades').html('<img src="img/especialidades_roll.jpg" alt="ESPECIALIDADES" />');h=$('#caixa_background').height();if(h<564)
$('#caixa_background').css('background','url(img/fundo_especialidades.jpg) top right no-repeat');else
$('#caixa_background').css('background','url(img/fundo_especialidades.jpg) bottom right no-repeat');$('#restaurante_content').css('display','block');$('#linha_restaurante_content').css('display','block');$('#linha_topo_restaurante_content').css('display','block');break;case'eventos':$('#link_eventos').html('<img src="img/social_roll.jpg" alt="SOCIAL" />');h=$('#caixa_background').height();if(h<564)
$('#caixa_background').css('background','url(img/fundo_social.jpg) top right no-repeat');else
$('#caixa_background').css('background','url(img/fundo_social.jpg) bottom right no-repeat');$('#restaurante_content').css('display','block');$('#linha_restaurante_content').css('display','block');$('#linha_topo_restaurante_content').css('display','block');break;case'contactos':$('#link_contactos').html('<img src="img/contactos_roll.jpg" alt="CONTACTOS" />');h=$('#caixa_background').height();if(h<564)
$('#caixa_background').css('background','url(img/fundo_contactos.jpg) top right no-repeat');else
$('#caixa_background').css('background','url(img/fundo_contactos.jpg) bottom right no-repeat');$('#restaurante_content').css('display','block');$('#linha_restaurante_content').css('display','block');$('#linha_topo_restaurante_content').css('display','block');break;case'imprensa':$('#link_imprensa').html('<img src="img/imprensa_roll.jpg" alt="IMPRENSA" />');h=$('#caixa_background').height();if(h<564)
$('#caixa_background').css('background','url(img/fundo_imprensa.jpg) top right no-repeat');else
$('#caixa_background').css('background','url(img/fundo_imprensa.jpg) bottom right no-repeat');$('#restaurante_content').css('display','block');$('#linha_restaurante_content').css('display','block');$('#linha_topo_restaurante_content').css('display','block');break;case'reservas':$('#link_reservas').html('<img src="img/reservas_roll.jpg" alt="RESERVAS" />');h=$('#caixa_background').height();if(h<564)
$('#caixa_background').css('background','url(img/fundo_reservas.jpg) top right no-repeat');else
$('#caixa_background').css('background','url(img/fundo_reservas.jpg) bottom right no-repeat');$('#restaurante_content').css('display','block');$('#linha_restaurante_content').css('display','block');$('#linha_topo_restaurante_content').css('display','block');break;case'destaques':$('#link_destaques').html('<img src="img/destaques_roll.jpg" alt="DESTAQUES" />');h=$('#caixa_background').height();if(h<564)
$('#caixa_background').css('background','url(img/fundo_destaques.jpg) top right no-repeat');else
$('#caixa_background').css('background','url(img/fundo_destaques.jpg) bottom right no-repeat');$('#restaurante_content').css('display','block');$('#linha_restaurante_content').css('display','block');$('#linha_topo_restaurante_content').css('display','block');break;case'newsletter':$('#link_newsletter').html('<img src="img/newsletter_roll.jpg" alt="NEWSLETTER" />');break;case'home':$('#caixa_background').css('background','');break;}
$('#caixa_background').height(h);$('#conteudo').fadeOut();$('#conteudo').html('');if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200){$('#conteudo').html(xmlhttp.responseText);}}
xmlhttp.open("GET","includes/"+pagina+"_handler.php",true);setTimeout("xmlhttp.send();$('#conteudo').fadeIn();",400);setTimeout("fixIE6();",400);}
function abreContactos(sent){
    $('#restaurante_content').css('display', 'none');
    $('#linha_restaurante_content').css('display', 'none');
    $('#linha_topo_restaurante_content').css('display', 'none');
    $('#caixa_background').css('background', '');
    var h = ($(document).height()) - 163;
    $('#link_restaurante').html('<a onclick="getContent(\'restaurante\');"><img src="img/restaurante.jpg" alt="RESTAURANTE" onmouseover="this.src=\'img/restaurante_roll.jpg\'" onmouseout="this.src=\'img/restaurante.jpg\'" /></a>');
    $('#link_ementas').html('<a onclick="getContent(\'ementas\');"><img src="img/ementas.jpg" alt="EMENTAS" onmouseover="this.src=\'img/ementas_roll.jpg\'" onmouseout="this.src=\'img/ementas.jpg\'" /></a>');
    $('#link_especialidades').html('<a onclick="getContent(\'especialidades\');"><img src="img/especialidades.jpg" alt="ESPECIALIDADES" onmouseover="this.src=\'img/especialidades_roll.jpg\'" onmouseout="this.src=\'img/especialidades.jpg\'" /></a>');
    $('#link_eventos').html('<a onclick="getContent(\'eventos\');"><img src="img/eventos.jpg" alt="EVENTOS" onmouseover="this.src=\'img/eventos_roll.jpg\'" onmouseout="this.src=\'img/eventos.jpg\'" /></a>');
    $('#link_imprensa').html('<a onclick="getContent(\'imprensa\');"><img src="img/imprensa.jpg" alt="IMPRENSA" onmouseover="this.src=\'img/imprensa_roll.jpg\'" onmouseout="this.src=\'img/imprensa.jpg\'" /></a>');
    $('#link_reservas').html('<a onclick="getContent(\'reservas\');"><img src="img/reservas.jpg" alt="RESERVAS" onmouseover="this.src=\'img/reservas_roll.jpg\'" onmouseout="this.src=\'img/reservas.jpg\'" /></a>');
    $('#link_destaques').html('<a onclick="getContent(\'destaques\');"><img src="img/destaques.jpg" alt="DESTAQUES" onmouseover="this.src=\'img/destaques_roll.jpg\'" onmouseout="this.src=\'img/destaques.jpg\'" /></a>');
    $('#link_contactos').html('<img src="img/contactos_roll.jpg" alt="CONTACTOS" />');
    var h = $('#caixa_background').height();
    if (h < 564) 
        $('#caixa_background').css('background', 'url(img/fundo_contactos.jpg) top right no-repeat');
    else 
        $('#caixa_background').css('background', 'url(img/fundo_contactos.jpg) bottom right no-repeat');
    $('#restaurante_content').css('display', 'block');
    $('#linha_restaurante_content').css('margin-top', '-20px');
    $('#linha_restaurante_content').css('display', 'block');
    $('#linha_topo_restaurante_content').css('display', 'block');
    h = ($(document).height()) - 173;
    $('#caixa_background').height(h);
    $('#conteudo').fadeOut();
    $('#conteudo').html('');
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#conteudo').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/contactos_handler.php?sent=" + sent, true);
    setTimeout("xmlhttp.send();$('#conteudo').fadeIn();", 400);
    setTimeout("fixIE6();", 400);
}

function abreReservas(sent){
    $('#restaurante_content').css('display', 'none');
    $('#linha_restaurante_content').css('display', 'none');
    $('#linha_topo_restaurante_content').css('display', 'none');
    $('#caixa_background').css('background', '');
    var h = ($(document).height()) - 163;
    $('#link_restaurante').html('<a onclick="getContent(\'restaurante\');"><img src="img/restaurante.jpg" alt="RESTAURANTE" onmouseover="this.src=\'img/restaurante_roll.jpg\'" onmouseout="this.src=\'img/restaurante.jpg\'" /></a>');
    $('#link_ementas').html('<a onclick="getContent(\'ementas\');"><img src="img/ementas.jpg" alt="EMENTAS" onmouseover="this.src=\'img/ementas_roll.jpg\'" onmouseout="this.src=\'img/ementas.jpg\'" /></a>');
    $('#link_especialidades').html('<a onclick="getContent(\'especialidades\');"><img src="img/especialidades.jpg" alt="ESPECIALIDADES" onmouseover="this.src=\'img/especialidades_roll.jpg\'" onmouseout="this.src=\'img/especialidades.jpg\'" /></a>');
    $('#link_eventos').html('<a onclick="getContent(\'eventos\');"><img src="img/eventos.jpg" alt="SOCIAL" onmouseover="this.src=\'img/eventos_roll.jpg\'" onmouseout="this.src=\'img/eventos.jpg\'" /></a>');
    $('#link_contactos').html('<a onclick="getContent(\'contactos\');"><img src="img/contactos.jpg" alt="CONTACTOS" onmouseover="this.src=\'img/contactos_roll.jpg\'" onmouseout="this.src=\'img/contactos.jpg\'" /></a>');
    $('#link_imprensa').html('<a onclick="getContent(\'imprensa\');"><img src="img/imprensa.jpg" alt="IMPRENSA" onmouseover="this.src=\'img/imprensa_roll.jpg\'" onmouseout="this.src=\'img/imprensa.jpg\'" /></a>');
    $('#link_destaques').html('<a onclick="getContent(\'destaques\');"><img src="img/destaques.jpg" alt="DESTAQUES" onmouseover="this.src=\'img/destaques_roll.jpg\'" onmouseout="this.src=\'img/destaques.jpg\'" /></a>');
    $('#link_reservas').html('<img src="img/reservas_roll.jpg" alt="RESERVAS" />');
    var h = $('#caixa_background').height();
    if (h < 564) 
        $('#caixa_background').css('background', 'url(img/fundo_reservas.jpg) top right no-repeat');
    else 
        $('#caixa_background').css('background', 'url(img/fundo_reservas.jpg) bottom right no-repeat');
    $('#restaurante_content').css('display', 'block');
    $('#linha_restaurante_content').css('margin-top', '0px');
    $('#linha_restaurante_content').css('display', 'block');
    $('#linha_topo_restaurante_content').css('display', 'block');
	
    var browserName = navigator.appName;
    if (browserName == 'Microsoft Internet Explorer') 
        h = ($(document).height()) - 193;
    else 
        h = ($(document).height()) - 188;
    $('#caixa_background').height(h);
    $('#conteudo').fadeOut();
    $('#conteudo').html('');
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#conteudo').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/reservas_handler.php?sent=" + sent, true);
    setTimeout("xmlhttp.send();$('#conteudo').fadeIn();", 400);
    setTimeout("fixIE6();", 400);
}

function abreEmentas(){
    $('#restaurante_content').css('display', 'none');
    $('#linha_restaurante_content').css('display', 'none');
    $('#linha_topo_restaurante_content').css('display', 'none');
    $('#caixa_background').css('background', '');
	
    $('#link_restaurante').html('<a onclick="getContent(\'restaurante\');"><img src="img/restaurante.jpg" alt="RESTAURANTE" onmouseover="this.src=\'img/restaurante_roll.jpg\'" onmouseout="this.src=\'img/restaurante.jpg\'" /></a>');
  	$('#link_ementas').html('<img src="img/ementas_roll.jpg" alt="EMENTAS" />');
   	$('#link_especialidades').html('<a onclick="getContent(\'especialidades\');"><img src="img/especialidades.jpg" alt="ESPECIALIDADES" onmouseover="this.src=\'img/especialidades_roll.jpg\'" onmouseout="this.src=\'img/especialidades.jpg\'" /></a>');
    $('#link_eventos').html('<a onclick="getContent(\'eventos\');"><img src="img/eventos.jpg" alt="EVENTOS" onmouseover="this.src=\'img/eventos_roll.jpg\'" onmouseout="this.src=\'img/eventos.jpg\'" /></a>');
    $('#link_contactos').html('<a onclick="getContent(\'contactos\');"><img src="img/contactos.jpg" alt="CONTACTOS" onmouseover="this.src=\'img/contactos_roll.jpg\'" onmouseout="this.src=\'img/contactos.jpg\'" /></a>');
    $('#link_imprensa').html('<a onclick="getContent(\'imprensa\');"><img src="img/imprensa.jpg" alt="IMPRENSA" onmouseover="this.src=\'img/imprensa_roll.jpg\'" onmouseout="this.src=\'img/imprensa.jpg\'" /></a>');
    $('#link_destaques').html('<a onclick="getContent(\'destaques\');"><img src="img/destaques.jpg" alt="DESTAQUES" onmouseover="this.src=\'img/destaques_roll.jpg\'" onmouseout="this.src=\'img/destaques.jpg\'" /></a>');
    $('#link_reservas').html('<a onclick="getContent(\'reservas\');"><img src="img/reservas.jpg" alt="RESERVAS" onmouseover="this.src=\'img/reservas_roll.jpg\'" onmouseout="this.src=\'img/reservas.jpg\'" /></a>');
   
    var browserName = navigator.appName;
    if (browserName == 'Microsoft Internet Explorer') 
        h = ($(document).height()) - 193;
    else 
        h = ($(document).height()) - 188;
  	$('#caixa_background').height(h);
 	$('#caixa_background').css('background', 'url(img/fundo_entradas.jpg) bottom right no-repeat');
		
    $('#restaurante_content').css('display', 'block');
    $('#linha_restaurante_content').css('margin-top', '0px');
    $('#linha_restaurante_content').css('display', 'block');
    $('#linha_topo_restaurante_content').css('display', 'block');

    $('#conteudo').fadeOut();
    $('#conteudo').html('');
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#conteudo').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/ementas_handler.php", true);
    setTimeout("xmlhttp.send();$('#conteudo').fadeIn();", 400);
    setTimeout("fixIE6();", 400);
}

function changeFoto(index){
    //$('#caixa_foto').html('<img src="gestor/ficheiros/' + src + '" alt="" style="border:2px solid #FFFFFF;" />');
	
	$('#link_galeria_0').css('display', 'none');	
	$('#link_galeria_1').css('display', 'none');
	$('#link_galeria_2').css('display', 'none');
	$('#link_galeria_3').css('display', 'none');
	$('#link_galeria_4').css('display', 'none');
	$('#link_galeria_5').css('display', 'none');
	$('#link_galeria_6').css('display', 'none');
	$('#link_galeria_7').css('display', 'none');
	
	$('#link_galeria_'+index).css('display', 'block');
}

function changeEmenta(id, elemento, imagem){
	$('#link_batizados').html('<img src="img/baptizados.jpg" alt="BAPTIZADOS" onmouseover="this.src=\'img/baptizados_roll.jpg\';" onmouseout="this.src=\'img/baptizados.jpg\';" />');
	$('#link_grupos').html('<img src="img/grupos.jpg" alt="GRUPOS" onmouseover="this.src=\'img/grupos_roll.jpg\';" onmouseout="this.src=\'img/grupos.jpg\';" />');
    $('.ementa_link_selected').attr('class', 'ementa_link');
    elemento.className = 'ementa_link_selected';
    $('#content_ementas').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#content_ementas').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/ementa_handler.php?id=" + id, true);
    setTimeout("xmlhttp.send();$('#content_ementas').fadeIn();", 800);
    setTimeout("$('.scroll_ementa').jScrollPane({dragMaxHeight:100});", 1000);
    var browserName = navigator.appName;
    if (browserName == 'Microsoft Internet Explorer') 
        h = ($(document).height()) - 193;
    else 
        h = ($(document).height()) - 188;
    $('#caixa_background').height(h);
    $('#caixa_background').css('background', 'url(gestor/ficheiros/' + imagem + ') bottom right no-repeat');
}

function abreBatizados(){
	$('#link_batizados').html('<img src="img/baptizados_roll.jpg" alt="BAPTIZADOS" />');
	$('#link_grupos').html('<img src="img/grupos.jpg" alt="GRUPOS" onmouseover="this.src=\'img/grupos_roll.jpg\';" onmouseout="this.src=\'img/grupos.jpg\';" />');
    $('.ementa_link_selected').attr('class', 'ementa_link');
    $('#content_ementas').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#content_ementas').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/batizados_handler.php", true);
    setTimeout("xmlhttp.send();$('#content_ementas').fadeIn();", 800);  
}

function abreGrupos(){
	$('#link_grupos').html('<img src="img/grupos_roll.jpg" alt="GRUPOS" />');
	$('#link_batizados').html('<img src="img/baptizados.jpg" alt="BAPTIZADOS" onmouseover="this.src=\'img/baptizados_roll.jpg\';" onmouseout="this.src=\'img/baptizados.jpg\';" />');
    $('.ementa_link_selected').attr('class', 'ementa_link');
    $('#content_ementas').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#content_ementas').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/grupos_handler.php", true);
    setTimeout("xmlhttp.send();$('#content_ementas').fadeIn();", 800); 
}

function changeEvento(id, index){
    $('.link_evento_selected').attr('class', 'link_evento');
    $('#link_evento_' + index).attr('class', 'link_evento_selected');
    $('#content_evento').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#content_evento').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/evento_handler.php?id=" + id, true);
    setTimeout("xmlhttp.send();$('#content_evento').fadeIn();", 400);
}

function changeEventos(tipo){
    var pagina = 'social';
    h = $('#caixa_background').height();
    if (tipo == 1) {
        pagina = 'participacoes';
        $('#link_participacoes').attr('class', 'eventos_link_selected');
        $('#link_social').attr('class', 'eventos_link');
        if (h < 564) 
            $('#caixa_background').css('background', 'url(img/fundo_gastronomia.jpg) top right no-repeat');
        else 
            $('#caixa_background').css('background', 'url(img/fundo_gastronomia.jpg) bottom right no-repeat');
    }
    else {
        $('#link_participacoes').attr('class', 'eventos_link');
        $('#link_social').attr('class', 'eventos_link_selected');
        if (h < 564) 
            $('#caixa_background').css('background', 'url(img/fundo_social.jpg) top right no-repeat');
        else 
            $('#caixa_background').css('background', 'url(img/fundo_social.jpg) bottom right no-repeat');
    }
    $('#conteudo_eventos').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#conteudo_eventos').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/" + pagina + ".php", true);
    setTimeout("xmlhttp.send();$('#conteudo_eventos').fadeIn();", 600);
}

function changePaginaSocial(pagina, total){
    $('#caixa_social').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#caixa_social').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/caixa_social.php?pagina=" + pagina, true);
    setTimeout("xmlhttp.send();$('#caixa_social').fadeIn();", 600);
    $('#content_evento').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp1 = new XMLHttpRequest();
    }
    else {
        xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp1.onreadystatechange = function(){
        if (xmlhttp1.readyState == 4 && xmlhttp1.status == 200) {
            $('#content_evento').html(xmlhttp1.responseText);
        }
    }
    xmlhttp1.open("GET", "includes/primeiro_caixa_social.php?pagina=" + pagina, true);
    setTimeout("xmlhttp1.send();$('#content_evento').fadeIn();", 600);
    var str = '';
    for (var i = 1; i <= total; i++) {
        if (i == pagina) 
            str += i;
        else 
            str += '<a onclick="changePaginaSocial(' + i + ', ' + total + ');">' + i + '</a>';
        str += ' | ';
    }
    str = rtrim(str, ' | ');
    setTimeout("$('.paginacao_eventos').html('" + str + "');", 700);
}

function changePaginaParticipacoes(pagina, total){
    $('#caixa_participacoes').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#caixa_participacoes').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/caixa_participacoes.php?pagina=" + pagina, true);
    setTimeout("xmlhttp.send();$('#caixa_participacoes').fadeIn();", 600);
    $('#content_evento').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp1 = new XMLHttpRequest();
    }
    else {
        xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp1.onreadystatechange = function(){
        if (xmlhttp1.readyState == 4 && xmlhttp1.status == 200) {
            $('#content_evento').html(xmlhttp1.responseText);
        }
    }
    xmlhttp1.open("GET", "includes/primeiro_caixa_participacoes.php?pagina=" + pagina, true);
    setTimeout("xmlhttp1.send();$('#content_evento').fadeIn();", 600);
    var str = '';
    for (var i = 1; i <= total; i++) {
        if (i == pagina) 
            str += i;
        else 
            str += '<a onclick="changePaginaParticipacoes(' + i + ', ' + total + ');">' + i + '</a>';
        str += ' | ';
    }
    str = rtrim(str, ' | ');
    setTimeout("$('.paginacao_eventos').html('" + str + "');", 700);
}

function overIconImprensa(index){
    $('#imp_' + index).attr('src', 'img/icon_imprensa_roll.jpg');
}

function outIconImprensa(index){
    $('#imp_' + index).attr('src', 'img/icon_imprensa.jpg');
}

function rtrim(str, chars){
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function changeImprensa(id, index){
    $('.link_imprensa_selected').attr('class', 'link_imprensa');
    $(".link_imprensa").hover(function(){
        var id = $(this).attr('id');
        var i = id.substring(14, id.length);
        overIconImprensa(i);
    }, function(){
        var id = $(this).attr('id');
        var i = id.substring(14, id.length);
        outIconImprensa(i);
    });
    $('#link_imprensa_' + index).attr('class', 'link_imprensa_selected');
    $('#link_imprensa_' + index).hover(function(){
        $('#imp_' + index).attr('src', 'img/icon_imprensa_roll.jpg');
    }, function(){
        $('#imp_' + index).attr('src', 'img/icon_imprensa_roll.jpg');
    });
    $('.icon_imp').attr('src', 'img/icon_imprensa.jpg');
    $('#imp_' + index).attr('src', 'img/icon_imprensa_roll.jpg');
    $('#content_imprensa').fadeOut();
    
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#content_imprensa').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/imp_handler.php?id=" + id, true);
    setTimeout("xmlhttp.send();", 500);
    setTimeout("$('#content_imprensa').stop().fadeIn();", 1000);
}

function changePaginaImprensa(pagina, total){
    $('#caixa_imprensa').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            $('#caixa_imprensa').html(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "includes/caixa_imprensa.php?pagina=" + pagina, true);
    setTimeout("xmlhttp.send();$('#caixa_imprensa').fadeIn();", 600);
    $('#content_imprensa').fadeOut();
    if (window.XMLHttpRequest) {
        xmlhttp1 = new XMLHttpRequest();
    }
    else {
        xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp1.onreadystatechange = function(){
        if (xmlhttp1.readyState == 4 && xmlhttp1.status == 200) {
            $('#content_imprensa').html(xmlhttp1.responseText);
        }
    }
    xmlhttp1.open("GET", "includes/primeiro_caixa_imprensa.php?pagina=" + pagina, true);
    setTimeout("xmlhttp1.send();$('#content_imprensa').fadeIn();", 600);
    var str = '';
    for (var i = 1; i <= total; i++) {
        if (i == pagina) 
            str += i;
        else 
            str += '<a onclick="changePaginaImprensa(' + i + ', ' + total + ');">' + i + '</a>';
        str += ' | ';
    }
    str = rtrim(str, ' | ');
    setTimeout("$('.paginacao_imprensa').html('" + str + "');", 700);
}

function valida_cont(){
    var erros = 0;
    $('#nome').css('border', '1px solid #c9c196');
    $('#email').css('border', '1px solid #c9c196');
    $('#assunto').css('border', '1px solid #c9c196');
    $('#telefone').css('border', '1px solid #c9c196');
    $('#msg').css('border', '1px solid #c9c196');
    if ($('#nome').val() == '') {
        $('#nome').css('border', '1px solid #30001a');
        erros++;
    }
    if ($('#email').val() == '' || !echeck($('#email').val())) {
        $('#email').css('border', '1px solid #30001a');
        erros++;
    }
    if ($('#assunto').val() == '') {
        $('#assunto').css('border', '1px solid #30001a');
        erros++;
    }
    if ($('#msg').val() == '') {
        $('#msg').css('border', '1px solid #30001a');
        erros++;
    }
    if (erros > 0) {
        $('#aviso').html('* Por favor preencha os campos assinalados correctamente.');
    }
    else {
        $('#form_cont').submit();
    }
}

function valida_reservas(){
    var erros = 0;
    $('#nome_r').css('background', 'white');
    $('#telefone_r').css('background', 'white');
    $('#email_r').css('background', 'white');
    $('#num_r').css('background', 'white');
    $('#datePicker1').css('background', 'white');
    if ($('#nome_r').val() == '') {
        $('#nome_r').css('background', '#aca480');
        erros++;
    }
    if ($('#telefone_r').val() == '') {
        $('#telefone_r').css('background', '#aca480');
        erros++;
    }
    if ($('#email_r').val() == '' || !echeck($('#email_r').val())) {
        $('#email_r').css('background', '#aca480');
        erros++;
    }
    now = new Date();
    fivedaysfromnow = new Date(now.getTime() + (5 * 24 * 60 * 60 * 1000));
    var month = fivedaysfromnow.getMonth() + 1;
    month += "";
    if (month.length < 2) 
        month = "0" + month;
    var day = fivedaysfromnow.getDate();
    day += "";
    if (day.length < 2) 
        day = "0" + day;
    var year = fivedaysfromnow.getFullYear();
    var data = year + '-' + month + '-' + day;
    if ($('#datePicker1').val() < data) {
        $('#datePicker1').css('background', '#aca480');
        erros++;
    }
    if ($('#num_r').val() == '') {
        $('#num_r').css('background', '#aca480');
        erros++;
    }
    if (erros > 0) {
        $('#aviso_reservas').html('Por favor preencha os campos assinalados correctamente.');
    }
    else {
        $('#form_reservas').submit();
    }
}

function valida_news(){
    var erros = 0;
    $('#nome_news').css('border', '1px solid #aca480');
    $('#email_news').css('border', '1px solid #aca480');
    if ($('#nome_news').val() == '') {
        $('#nome_news').css('border', '1px solid #ffffff');
        erros++;
    }
    if ($('#email_news').val() == '' || !echeck($('#email_news').val())) {
        $('#email_news').css('border', '1px solid #ffffff');
        erros++;
    }
    if (erros == 0) {
        $('#form_news').submit();
    }
    else {
        $('#aviso_news').html('Por favor preencha todos os campos correctamente.');
    }
}

function validar_remover(){
	var erros = 0;
	
	$('#email').css('border', '1px solid #30001a');
	
	if($('#email').val()=='' || !echeck($('#email').val())){
		$('#email').css('border', '1px solid #aca480');
		erros++;
	}	
	
	if(erros > 0){
		$('#aviso_remover').html('* Por favor preencha o campo com um e-mail válido.');	
	}
	else
		$('#send_remover').submit();
}

function echeck(str){
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        return false
    }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false
    }
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false
    }
    if (str.indexOf(at, (lat + 1)) != -1) {
        return false
    }
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false
    }
    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false
    }
    if (str.indexOf(" ") != -1) {
        return false
    }
    return true
}
