var scroll_mc=0;
var limite_dias_calendario=30;
var dias_abertos_calendario=new Array();
var dias_vagos=new Array();
var i;
for (i=1;i<=limite_dias_calendario;i++){
    dias_vagos[i]=0;
}
var total_dias_abertos_calendario=0;
var req;
if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4;
}
//document.oncontextmenu=new Function("return false");
var overlayOpacity = 0.8;
var msgoverlayOpacity = 0.5;
var overlayDuration = 0.2;
var coords_value='';
var mc_Ajax = create_mc_Ajax();
var mc_Ajax2 = create_mc_Ajax();
var mc_Ajax3 = create_mc_Ajax();
var mc_Ajax4 = create_mc_Ajax();
var mc_Ajax5 = create_mc_Ajax();
var mc_Ajax6 = create_mc_Ajax();
var novas_user=0;
var novas_com=0;
var novas_adm=0;
var msg_sel='n';
var old_over='';
var old_out='';
var mensagens_sel=new Array();
var mensagens_para_sel=new Array();
var flag_sel=1;
var Gfotohonra=Gfotomes=Gfotodia=Gfotoconcurso=Gfotorecente=0;
var pm='';
var fecha_edit='';
var fecha_add='';
var close='';
var old_edit='';
var saveclick;
var old_edit_id='';
var flag_click=0;
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}

function checkOrder(ul){
    var ordem='';
    $(ul+'>li').each(
        function(idx){
            ordem+="|"+$(this).attr('id');
        }
        );
    $.post("/jx.php?rnd="+Math.ceil(Math.random()*10000),"preapporder="+ordem,function(){
        window.location.reload();
    });
}

function alignThumbs(moldura,holder,discp){
    
    var disc=0;
    var thumbw=$('.'+moldura).width();
    var avai=$('#divflist'+holder).innerWidth();
    if (discp && parseInt(discp)>0) disc+=discp;
    avai=avai-parseInt(disc);
    var nfotos=parseInt(avai / thumbw);
    // alert(avai);
    var per;
    var n_fotos_present=parseInt($('#divflist'+holder+' li').length);
    if (n_fotos_present>=nfotos)  per= 100 / nfotos;
    else  per= 100 / n_fotos_present;
    //if(per==100)per=50;
    $('#divflist'+holder+' .fotosul>li').css('width',per+'%');
    return true;
}

function delegrtm(a,b){
    if (confirm('Tem a certeza/Sure?')){
        $("#delgrtm_apagargrupo").val(a);
        $("#delgrtm_k").val(b);
        $("#delgrtm_form").submit();
    }
}
function delefotoprom(a){
    if (confirm('Tem a certeza/Sure?')){
        $("#delfotoval").val(a);
        $("#delfotoform").submit();
    }
}
function confDelCom(a){
    if (confirm('Tem a certeza/Sure?')){
        $("#"+a).submit();
    }
}/*
function calendario(m,y) {
    var url = "calendario.php?m="+m+"&y="+y;
    if(window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.open("GET", url, true);
    req.onreadystatechange = cal_refresh;
    req.send(null);
}
function cal_refresh() {

    obj = document.getElementById("calendario");
    setFade(0);

    if(req.readyState == 4) {
        if(req.status == 200) {
            response = req.responseText;
            obj.innerHTML = response;
            actualiza_yes();
            fade_cal(0);
        } else {
            alert("Erro de Sistema:\n" + req.statusText);
        }
    }
}
function fade_cal(amt) {
    if(amt <= 100) {
        setFade(amt);
        amt += 10;
        setTimeout("fade_cal("+amt+")", 5);
    }
}

function setFade(amt) {
    obj = document.getElementById("calendario");

    amt = (amt == 100)?99.999:amt;

    // IE
    obj.style.filter = "alpha(opacity:"+amt+")";

    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = amt/100;

    // Mozilla and Firefox
    obj.style.MozOpacity = amt/100;

    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = amt/100;
}
function actualiza_yes(){
    for(key in dias_abertos_calendario){
        if ( document.getElementById('dia'+key)) document.getElementById('dia'+key).style.backgroundImage = "url('/imagens/yes.png')";
    }
}
function abreDia(dia){


    if (dias_abertos_calendario[dia]){
        htm='<table width="100%" border="0" cellspacing="0" cellpadding="3" class="menutops"><tr ><td  ><div align="center" id="p1" class="title_green">Programa do dia '+dia.substr(0,4)+'-'+dia.substr(4,2)+'-'+dia.substr(6,2)+', escolha a hora e acerte os minutos </div></td></tr><tbody id="pdia" class="off" ><tr ><td ><div style="float:left;"><input type="button" value="Apagar Dia" onClick="javascript: if (confirm(\'Confirma?\')){ fecha_pop_layer(\''+(dias_abertos_calendario[dia])+'\',1)}"></div><div align="center" id="p1" class="title_green"><span class="style12">Preço deste dia - Utilizadores com plano pago:<input name="a_preco_adulto" type="text" id="a_preco_adulto" value="" size="6" maxlength="6" />&nbsp;Outros participantes:<input name="a_preco_acomp" type="text" id="a_preco_acomp" value="" size="6" maxlength="6" />&nbsp;Crian&ccedil;as:<input name="a_preco_crianca" type="text" id="a_preco_crianca" value="" size="6" maxlength="6" /></span></div></td></tr></tbody><tr><td><div align="center"><table width="100%" border="0" cellspacing="0" cellpadding="3"  ><tr><td  width="60" align="left">08:<input name="a_h_8" type="text" id="a_h_8" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_8" id="a_p_8" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">09:<input name="a_h_9" type="text" id="a_h_9" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_9" id="a_p_9" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">10:<input name="a_h_10" type="text" id="a_h_10" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_10" id="a_p_10" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">11:<input name="a_h_11" type="text" id="a_h_11" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_11" id="a_p_11" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">12:<input name="a_h_12" type="text" id="a_h_12" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_12" id="a_p_12" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">13:<input name="a_h_13" type="text" id="a_h_13" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_13" id="a_p_13" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">14:<input name="a_h_14" type="text" id="a_h_14" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_14" id="a_p_14" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">15:<input name="a_h_15" type="text" id="a_h_15" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_15" id="a_p_15" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">16:<input name="a_h_16" type="text" id="a_h_16" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_16" id="a_p_16" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">17:<input name="a_h_17" type="text" id="a_h_17" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_17" id="a_p_17" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">18:<input name="a_h_18" type="text" id="a_h_18" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_18" id="a_p_18" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">19:<input name="a_h_19" type="text" id="a_h_19" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_19" id="a_p_19" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">20:<input name="a_h_20" type="text" id="a_h_20" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_20" id="a_p_20" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">21:<input name="a_h_21" type="text" id="a_h_21" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_21" id="a_p_21" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">22:<input name="a_h_22" type="text" id="a_h_22" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_22" id="a_p_22" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">23:<input name="a_h_23" type="text" id="a_h_23" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_23" id="a_p_23" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">24:<input name="a_h_24" type="text" id="a_h_24" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_24" id="a_p_24" style="width:100%;" rows="2"></textarea></td></tr></table></div></td></tr></table>';
        pop_layer(htm,  dias_abertos_calendario[dia]);



    }else{

        if (total_dias_abertos_calendario>limite_dias_calendario){

            alert("Só são permitidos o uso de "+limite_dias_calendario+" dias no total.");
        }else{
            total_dias_abertos_calendario++;
            for (i=1;i<=limite_dias_calendario;i++){
                if (dias_vagos[i]==0){
                    ndia=i;
                    break;
                }
            }



            dias_abertos_calendario[dia]=ndia;
            document.getElementById('dia'+dia).style.backgroundImage = "url('/imagens/yes.png')";
            dias_vagos[ndia]=1;
            document.getElementById('d'+ndia).value=dia;
            htm='<table width="100%" border="0" cellspacing="0" cellpadding="3" class="menutops"><tr ><td  ><div align="center" id="p1" class="title_green">Programa do dia '+dia.substr(0,4)+'-'+dia.substr(4,2)+'-'+dia.substr(6,2)+', escolha a hora e acerte os minutos </div></td></tr><tbody id="pdia" class="off" ><tr ><td ><div align="center" id="p1" class="title_green"><span class="style12">Preço deste dia - Utilizadores com plano pago:<input name="a_preco_adulto" type="text" id="a_preco_adulto" value="" size="6" maxlength="6" />&nbsp; Outros participantes:<input name="a_preco_acomp" type="text" id="a_preco_acomp" value="" size="6" maxlength="6" />&nbsp;Crian&ccedil;as:<input name="a_preco_crianca" type="text" id="a_preco_crianca" value="" size="6" maxlength="6" /></span></div></td></tr></tbody><tr><td><div align="center"><table width="100%" border="0" cellspacing="0" cellpadding="3"  ><tr><td  width="60" align="left">08:<input name="a_h_8" type="text" id="a_h_8" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_8" id="a_p_8" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">09:<input name="a_h_9" type="text" id="a_h_9" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_9" id="a_p_9" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">10:<input name="a_h_10" type="text" id="a_h_10" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_10" id="a_p_10" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">11:<input name="a_h_11" type="text" id="a_h_11" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_11" id="a_p_11" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">12:<input name="a_h_12" type="text" id="a_h_12" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_12" id="a_p_12" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">13:<input name="a_h_13" type="text" id="a_h_13" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_13" id="a_p_13" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">14:<input name="a_h_14" type="text" id="a_h_14" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_14" id="a_p_14" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">15:<input name="a_h_15" type="text" id="a_h_15" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_15" id="a_p_15" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">16:<input name="a_h_16" type="text" id="a_h_16" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_16" id="a_p_16" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">17:<input name="a_h_17" type="text" id="a_h_17" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_17" id="a_p_17" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">18:<input name="a_h_18" type="text" id="a_h_18" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_18" id="a_p_18" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">19:<input name="a_h_19" type="text" id="a_h_19" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_19" id="a_p_19" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">20:<input name="a_h_20" type="text" id="a_h_20" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_20" id="a_p_20" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">21:<input name="a_h_21" type="text" id="a_h_21" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_21" id="a_p_21" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">22:<input name="a_h_22" type="text" id="a_h_22" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_22" id="a_p_22" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">23:<input name="a_h_23" type="text" id="a_h_23" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_23" id="a_p_23" style="width:100%;" rows="2"></textarea></td></tr><tr><td  width="60" align="left">24:<input name="a_h_24" type="text" id="a_h_24" value="00" size="3" maxlength="2" /> -</td><td align="left"><textarea name="a_p_24" id="a_p_24" style="width:100%;" rows="2"></textarea></td></tr></table></div></td></tr></table>';
            pop_layer(htm,ndia);
        }
    }
}
*/
function pop_layer(htm,ndia){

    //hideFlash();
    var arrayPageSize = getPageSize();

    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','layer_mapa');
    objOverlay.style.display = 'none';
    objBody.appendChild(objOverlay);
    $("#layer_mapa").addClass('layer_overlay');
    $('#layer_mapa').height(arrayPageSize[1]);
    $('#layer_mapa').fadeIn();




    var objMapa = document.createElement("div");
    objMapa.setAttribute('id','pre_mapa');
    objMapa.style.display = 'none';
    objBody.appendChild(objMapa);
    $("#pre_mapa").addClass('pre_mapa');
    var  XX= (arrayPageSize[0] /2) -400;
    $("#pre_mapa").css('left',XX+'px');
    $("#pre_mapa").css('top','600px');

    $("#pre_mapa").html(htm+'<br><br><center><input class="submit" type="button" value="Fechar" onClick="fecha_pop_layer(\''+ndia+'\',0);"></center>');


    if (document.getElementById('tipo_preco_1').checked) document.getElementById('pdia').className='on';
    document.getElementById('a_preco_adulto').value=document.getElementById('preco_adulto'+ndia).value;
    document.getElementById('a_preco_crianca').value=document.getElementById('preco_crianca'+ndia).value;
    document.getElementById('a_preco_acomp').value=document.getElementById('preco_acomp'+ndia).value;
    for (i=8;i<=24;i++){
        document.getElementById('a_h_'+i).value=document.getElementById('h'+ndia+'_'+i).value;
        document.getElementById('a_p_'+i).value=document.getElementById('p'+ndia+'_'+i).value;
    }
    $('#pre_mapa').fadeIn();

}
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){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}
function fecha_pop_layer(ndia,limpa){

    document.getElementById('preco_adulto'+ndia).value=(limpa==1)?'':document.getElementById('a_preco_adulto').value;
    document.getElementById('preco_crianca'+ndia).value=(limpa==1)?'':document.getElementById('a_preco_crianca').value;
    document.getElementById('preco_acomp'+ndia).value=(limpa==1)?'':document.getElementById('a_preco_acomp').value;
    lixo='';
    for (i=8;i<=24;i++){
        lixo+=(limpa==1)?'':document.getElementById('a_p_'+i).value;
        document.getElementById('h'+ndia+'_'+i).value=(limpa==1)?'':document.getElementById('a_h_'+i).value;
        document.getElementById('p'+ndia+'_'+i).value=(limpa==1)?'':document.getElementById('a_p_'+i).value;
    }
    $('#pre_mapa').remove();


    $('#layer_mapa').fadeOut('fast', function() {
        $('#layer_mapa').remove();
    });

    //showFlash();
    if (lixo==''){
        total_dias_abertos_calendario--;
        // dias_abertos_calendario.splice(document.getElementById('d'+ndia).value,1);

        tmp=dias_abertos_calendario;
        dias_abertos_calendario = new Array();
        for(key in tmp){
            if ( key != document.getElementById('d'+ndia).value) dias_abertos_calendario[key]=tmp[key];
        }

        document.getElementById('dia'+ document.getElementById('d'+ndia).value).style.backgroundImage = "";
        dias_vagos[ndia]=0;
    }
}

function showmapa(v){
    var uget='';
    //hideFlash();
    var arrayPageSize = getPageSize();

    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','layer_mapa');
    objOverlay.style.display = 'none';
    objBody.appendChild(objOverlay);
    $("#layer_mapa").addClass('layer_overlay');
    $('#layer_mapa').height(arrayPageSize[1]);
    $('#layer_mapa').fadeIn();



    var objMapa = document.createElement("div");
    objMapa.setAttribute('id','pre_mapa');
    objMapa.style.display = 'none';
    objBody.appendChild(objMapa);
    $("#pre_mapa").addClass('pre_mapa');
    var  XX= (arrayPageSize[0] /2) -400;
    $("#pre_mapa").css('left',XX+'px');
    $('#pre_mapa').fadeIn();


    var cidade='';
    var pais='';
    var Temeventos;
    if (v==0){
        coords_value=document.getElementById('coords').value;
        cidade=document.getElementById('mapa_cidade').value;
        pais=document.getElementById('mapa_pais').value;
    }else if (v==0.1){
        coords_value=document.getElementById('coords').value;
        uget='&e='+coords_value;
    }else if (v==0.2){
        coords_value=document.getElementById('coords').value;
        uget='s='+coords_value;
    }else if (v>0){
        uget='u='+v;
    }
    if (document.getElementById('eventos')){
        Temeventos="&evento";
    }else{
        Temeventos='';
    }

    if (v<0.2){
        document.getElementById('pre_mapa').innerHTML='<iframe width="800" height="500" marginheight="0" marginwidth="0" scrolling="no" id="imapa"  frameborder="0" src="mapa.php?cidade='+cidade+Temeventos+'&pais='+pais+uget+'" allowtransparency="false"></iframe><br><br><center><input class="submit" type="button" value="Cancelar" onClick="cancela_mapa();">&nbsp;&nbsp;&nbsp;&nbsp;<input class="submit" type="button" value="Gravar Posição" onClick="fecha_mapa();"></center>';
    }else{
        document.getElementById('pre_mapa').innerHTML='<iframe width="800" height="500" marginheight="0" marginwidth="0" scrolling="no" id="imapa"  frameborder="0" src="mapa.php?'+uget+'" allowtransparency="false"></iframe><br><br><center><input class="submit" type="button" value="Fechar" onClick="fecha_mapa();"></center>';
    }
}
function cancela_mapa(){

    $('#coords').val(coords_value);

    fecha_mapa();
}

function fecha_mapa(closerr){
    $('#imapa').remove();
    $('#pre_mapa').remove();
    $('#layer_mapa').fadeOut('fast', function() {
        $('#layer_mapa').remove();
    });
    //showFlash();
    if (closerr && document.getElementById(closerr))document.getElementById(closerr).focus();
}
function create_mc_Ajax(){
    var mc_Ajax;
    if (typeof XMLHttpRequest != "undefined") {
        mc_Ajax=new XMLHttpRequest();
    } else if (typeof ActiveXObject != "undefined") {
        mc_Ajax=new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        throw new Error("Erro 2341");
    }

    return mc_Ajax;
}

function toggleTbody(id) {
    if (document.getElementById) {
        var tbod = document.getElementById(id);
        if (tbod && typeof tbod.className == 'string') {
            if (tbod.className == 'off') {
                tbod.className = 'on';
            } else {
                tbod.className = 'off';
            }
        }
    }
    return false;
}
function validacao_voto(f) {
    var c=document.getElemenetById("1");
    if (c.checked) {
        if (f.votacao_comentario.value!="") {
            alert("Comentário Obrigatório se Votou na Galeria");
            return false;
        }
    }
    return true;
}
function get_indice(arr,val){
    var i
    for (i in arr){
        if (arr[i]==val) return i;
    }
    return false;
}
function muda_caixa(cx){
    var pvals= new Array("com","user","adm","env","lixo","sup_10","sup_20","sup_30");
    for (var i=0;i<pvals.length;i++){
        if (document.getElementById('cx_'+pvals[i])) document.getElementById('cx_'+pvals[i]).className='box_off';
    }
    document.getElementById('cx_'+cx).className='box_on';
    if (cx=="env") document.getElementById('title_de').innerHTML='Para';
    else document.getElementById('title_de').innerHTML='De';
    if (cx=="lixo"){
        document.getElementById('ic_holder_dd').innerHTML='';
        document.getElementById('ic_holder_sel').innerHTML='';
    }else{
        document.getElementById('ic_holder_dd').innerHTML='<img src="/imagens/lixo.png" width="15" height="15" border="0" title="Apagar mensagens seleccionadas" onmouseover="this.style.cursor=\'pointer\'" onclick="apaga_sel();">';
        document.getElementById('ic_holder_sel').innerHTML='<img src="/imagens/chek.png" width="10" height="10" border="0" title="Seleccionar todas as mensagens" onclick="return mail_sel_all();" onmouseover="this.style.cursor=\'pointer\'">';
    }
    get_mail(cx);
    return false;
}
function get_mail(cx){
    if (mc_Ajax){
        document.getElementById('msg_bottom_sep').className='msg_bot_sep_empty';
        document.getElementById('mail_action').className='off';
        document.getElementById('mail_body').innerHTML='';
        document.getElementById('msg_top').innerHTML='';
        msg_sel='n';
        try{
            showSpinner();
            mc_Ajax.open("GET","mailServ.php?cx="+cx+'&rnd='+(Math.ceil(1000*Math.random())),true);
            mc_Ajax.onreadystatechange=updateMail;
            mc_Ajax.send(null);
        }catch (e){
        //alert('Erro, servidor indisponivel');
        }
    }else{
//alert('Erro 2239');
}
}
function updateMail(){
    if (mc_Ajax.readyState==4){
        hideSpinner();
        if (mc_Ajax.status==200){
            try{
                var out='<table id="msg_container">';
                eval('var jsonData='+ mc_Ajax.responseText+';');

                document.getElementById("msg_top").innerHTML='';
                mensagens_para_sel=new Array();
                mensagens_sel=new Array();
                flag_sel=1;
                if (jsonData.length>0){
                    eval('novas_'+jsonData[0].folder+'=0;');

                    for (var i=0;i<jsonData.length;i++){
                        if (jsonData[i].nova=="0"){
                            eval('novas_'+jsonData[i].folder+'=novas_'+jsonData[i].folder+'+1;');
                            out+='<tr id="'+jsonData[i].folder+jsonData[i].id+'" onclick="get_msg('+jsonData[i].id+',\''+jsonData[i].folder+'\')" bgcolor="#111" onmouseover="this.style.backgroundColor=\'#222\';this.style.cursor=\'pointer\'" onmouseout="this.style.backgroundColor=\'#161610\'"><td width="18" class="txt_mail" align="center" id="a'+jsonData[i].folder+jsonData[i].id+'"><img src="/imagens/new_mail.png" width="9" height="9" border="0"></td><td width="20">&nbsp;</td><td id="b'+jsonData[i].folder+jsonData[i].id+'" width="231" class="txt_mail_bold">'+jsonData[i].de+'</td><td id="c'+jsonData[i].folder+jsonData[i].id+'" width="350" class="txt_mail_bold">'+jsonData[i].assunto+'</td><td  class="txt_mail_bold" id="d'+jsonData[i].folder+jsonData[i].id+'">'+jsonData[i].recebida+'</td></tr>';
                        }else{
                            var tlx='&nbsp;';
                            if (jsonData[i].folder!='lixo') tlx='<input type="checkbox" class="msg_chk" id="chk_'+jsonData[i].folder+'_'+jsonData[i].id+'" onclick="return msg_sel2del(this);">';
                            if (jsonData[i].viewed) tlx='<img title="Replied by '+jsonData[i].viewed+'" src="/imagens/mail_reply.png">';
                            
                            out+='<tr id="'+jsonData[i].folder+jsonData[i].id+'" onclick="get_msg('+jsonData[i].id+',\''+jsonData[i].folder+'\')" bgcolor="#111" onmouseover="this.style.backgroundColor=\'#222\';this.style.cursor=\'pointer\'" onmouseout="this.style.backgroundColor=\'#161616\'"><td width="18" class="txt_mail" align="center" id="a'+jsonData[i].folder+jsonData[i].id+'">'+tlx+'</td><td width="20">&nbsp;</td><td width="231" class="txt_mail" id="b'+jsonData[i].folder+jsonData[i].id+'">'+jsonData[i].de+'</td><td id="c'+jsonData[i].folder+jsonData[i].id+'" width="350" class="txt_mail">'+jsonData[i].assunto+'</td><td id="d'+jsonData[i].folder+jsonData[i].id+'" class="txt_mail">'+jsonData[i].recebida+'</td></tr>';
                            mensagens_para_sel.push('chk_'+jsonData[i].folder+'_'+jsonData[i].id);
                        }

                    }
                    if (novas_user>0){
                        document.getElementById('nov_user_count').innerHTML='('+novas_user+')';
                    }
                    if (novas_com>0){
                        document.getElementById('nov_com_count').innerHTML='('+novas_com+')';
                    }
                    if (novas_adm>0){
                        document.getElementById('nov_adm_count').innerHTML='('+novas_adm+')';
                    }
                }else{
                    out+='<tr><td  align="center">&nbsp;</td></tr><tr><td class="txt_mail"><i>No message</i></td></tr>';
                }
                out+='</table>';
                document.getElementById('msg_top').innerHTML=out;
            }catch (e){
            //alert('Resposta invalida: '+e.toString());
            }
        }else{
    //alert("Sem reposta: \n"+mc_Ajax.statusText);
    }
    }

}
function msg_sel2del(obj){
    var x=get_indice(mensagens_sel,obj.id);
    if (x){
        mensagens_sel.splice(x,1);
    }else{
        mensagens_sel.push(obj.id);
    }
}
function apaga_sel(){
    var conf=confirm('Confirma que pretente mover as mensagens seleccionads para o lixo?');
    if (conf){
        var poststr = "arr=" + encodeURI(mensagens_sel.toString()) ;
        if (mc_Ajax){
            try{
                
                mc_Ajax.open("POST","mailServ.php?movelixo&rnd="+(Math.ceil(1000*Math.random())),true);
                mc_Ajax.onreadystatechange=apagouMsg;
                mc_Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                mc_Ajax.setRequestHeader("Content-length", poststr.length);
                mc_Ajax.setRequestHeader("Connection", "close");
                mc_Ajax.send(poststr);
            }catch (e){
            }
        }else{
    }

    }
}


function mail_sel_all(){
    var i
    for (i in mensagens_para_sel){

        if (document.getElementById(mensagens_para_sel[i])){
            if (flag_sel==1){
                document.getElementById(mensagens_para_sel[i]).checked=true;
                mensagens_sel[i]=mensagens_para_sel[i];
            }else{
                document.getElementById(mensagens_para_sel[i]).checked=false;

                mensagens_sel.splice(get_indice(mensagens_sel,mensagens_para_sel[i]),1);
            }
        }
    }
    if (flag_sel==1) flag_sel=0;
    else flag_sel=1;

    return false;
}
function esvazia(){
    var conf=confirm('Confirma que pretente apagar todas as mensagens no lixo?');
    if (conf){
        if (mc_Ajax){
            try{
                mc_Ajax.open("GET","mailServ.php?esvazia&rnd="+(Math.ceil(1000*Math.random())),true);
                mc_Ajax.onreadystatechange=apagouMsg;
                mc_Ajax.send(null);
            }catch (e){
            }
        }else{
    }
    }
    return false;
}

function get_msg(mid,cxx){
    if (mc_Ajax){
        if (msg_sel!='n'){
            document.getElementById(msg_sel).style.backgroundColor='#111';
            document.getElementById(msg_sel).onmouseout=old_out;
            document.getElementById(msg_sel).onmouseover=old_over;
        }
        msg_sel=cxx+mid;
        old_over=document.getElementById(msg_sel).onmouseover;
        old_out=document.getElementById(msg_sel).onmouseout;
        document.getElementById(msg_sel).style.backgroundColor='#003';
        document.getElementById(msg_sel).onmouseout=null;
        document.getElementById(msg_sel).onmouseover=null;
        try{
             showSpinner();
            mc_Ajax.open("GET","mailServ.php?mid="+mid+'&c='+cxx+'&rnd='+(Math.ceil(1000*Math.random())),true);
            mc_Ajax.onreadystatechange=updateMsg;
            mc_Ajax.send(null);
        }catch (e){        
        }
    }else{
}
}
function del_msg(id,fold){
    if (mc_Ajax){
        try{
            mc_Ajax.open("GET","mailServ.php?did="+id+'&c='+fold+'&rnd='+(Math.ceil(1000*Math.random())),true);
            mc_Ajax.onreadystatechange=apagouMsg;
            mc_Ajax.send(null);
        }catch (e){
        }
    }else{
    }
    return false;
}
function rep_msg(id,fold){
    if (mc_Ajax){
        try{
            mc_Ajax.open("GET","mailServ.php?rid="+id+'&c='+fold+'&rnd='+(Math.ceil(1000*Math.random())),true);
            mc_Ajax.onreadystatechange=apagouMsg;
            mc_Ajax.send(null);
        }catch (e){
        }
    }else{
    }
    return false;
}
function apagouMsg(){
    if (mc_Ajax.readyState==4){
        if (mc_Ajax.status==200){
            try{
                eval('var jsonData='+ mc_Ajax.responseText+';');
                if (jsonData.length==1){
                    setTimeout('muda_caixa(\''+jsonData[0].folder+'\')',100);
                }
            }catch (e){
            }
        }else{
    }
    }
}

function setreplySupLang(lang){
    var tit=$('#sup_rep_'+lang+'_tit').text() + ' '+$('#hlmsgfrm').text()+",\n";
    var foot=$('#sup_rep_'+lang+'_foot').text()+"\n";
 
    $('#replysupmsg').val(tit+"\n\n\n\n"+foot);
}
function replySup(inp){
    var y=$('#hlmsgfrm').text();
    if ($('#replysupport').length)$('#replysupmsg').val('');
    else $('body').append('<div id="replysupport" title="Reply to '+y+'"><div class="replysupport">Lang: <select onchange="setreplySupLang(this.value);"><option>en</option><option>pt</option></select><textarea id="replysupmsg" name="replysupmsg"></textarea></div></div>');
    
    setreplySupLang('en');
    $('#replysupport').dialog({
        autoOpen: true, 
        modal: true, 
        width: 700, 
        height: 'auto',
        zIndex: 1001, 
        resizable: false, 
        hide:'drop',
        show:'drop',
        buttons: {
            "Close": function() {
                $(this).dialog("close");
            },
            "Reply": function() { 
                var xpto=this;
                var x=$.trim($('#replysupmsg').val());
                    if (x.length>0){
                     showSpinner();
                    $.get("mailServ.php", {reply: inp,msg: x},
                                function(data){
                                hideSpinner();
                                shout( data.res,'&nbsp;');
                                $(xpto).dialog("close");

                    }, "json");
                }else{
                     shout('Cannot reply with an empty message!','&nbsp;');
                }
            }
        }
    });


    
}
function updateMsg(){
    if (mc_Ajax.readyState==4){
        hideSpinner();
        if (mc_Ajax.status==200){
            try{
                var out='';
                eval('var jsonData='+ mc_Ajax.responseText+';');
                if (jsonData.length==1){
                    if (jsonData[0].trash==0){
                        document.getElementById('msg_tx_apagar').innerHTML='Delete';
                        document.getElementById('msg_im_apagar').innerHTML='<img  src="/imagens/apagar.png" width="16" height="16" border="0" id="ic_del" onmouseover="document.getElementById(\'msg_del\').className=\'caixas_mail_hover\'" onmouseout="document.getElementById(\'msg_del\').className=\'caixas_mail\'">'
                        document.getElementById('msg_del').onclick=function () {
                            del_msg(jsonData[0].id,jsonData[0].folder);
                            return false;
                        };
                        document.getElementById('ic_del').onclick=function () {
                            del_msg(jsonData[0].id,jsonData[0].folder);
                            return false;
                        };
                    }else{
                        document.getElementById('msg_tx_apagar').innerHTML='Repor';
                        document.getElementById('msg_im_apagar').innerHTML='<img  src="/imagens/undo.png" width="16" height="16" border="0" id="ic_del" onmouseover="document.getElementById(\'msg_del\').className=\'caixas_mail_hover\'" onmouseout="document.getElementById(\'msg_del\').className=\'caixas_mail\'">'
                        document.getElementById('msg_del').onclick=function () {
                            rep_msg(jsonData[0].id,'lixo');
                            return false;
                        };
                        document.getElementById('ic_del').onclick=function () {
                            rep_msg(jsonData[0].id,'lixo');
                            return false;
                        };
                    }
                    if (jsonData[0].folder=="user" && jsonData[0].trash==0){
                        document.getElementById('msg_txt_resp').innerHTML='<a id="resp_lnk" href="/author/'+jsonData[0].senderid+'/contact" class="caixas_mail">Reply</a>';
                        document.getElementById('msg_ic_resp').innerHTML='<a href="/author/'+jsonData[0].senderid+'/contact"><img src="/imagens/reenviar.png" width="16" height="16" border="0" onmouseover="document.getElementById(\'resp_lnk\').className=\'caixas_mail_hover\'" onmouseout="document.getElementById(\'resp_lnk\').className=\'caixas_mail\'"></a>';
                    }else if (jsonData[0].folder=="sup_10" ){
                        document.getElementById('msg_txt_resp').innerHTML='<a id="resp_lnk" href="#" class="caixas_mail" onclick="replySup(\''+jsonData[0].senderid+'\');return false;">Reply</a>';
                        document.getElementById('msg_ic_resp').innerHTML='<a href="#"  onclick="replySup(\''+jsonData[0].senderid+'\');return false;"><img src="/imagens/reenviar.png" width="16" height="16" border="0" onmouseover="document.getElementById(\'resp_lnk\').className=\'caixas_mail_hover\'" onmouseout="document.getElementById(\'resp_lnk\').className=\'caixas_mail\'"></a>';   
                        
                    }else{
                        document.getElementById('msg_txt_resp').innerHTML='';
                        document.getElementById('msg_ic_resp').innerHTML='';
                    }
                    document.getElementById('mail_data').innerHTML=jsonData[0].recebida;
                    document.getElementById('mail_assunto').innerHTML=jsonData[0].assunto;
                    document.getElementById('msg_bottom_sep').className='msg_bot_sep_full';
                    document.getElementById('mail_action').className='on';
                    document.getElementById('mail_body').innerHTML='<br><strong><font color="#A0A0A0">&nbsp;&nbsp;De: </font></strong><span id="hlmsgfrm">'+jsonData[0].de+'</span> <br><hr size="1"><br><div align="justify">'+jsonData[0].conteudo+'</div>';
                    if (jsonData[0].nova=="0"){
                        if (jsonData[0].folder=='user' && novas_user>0){
                            novas_user=novas_user-1;
                            if (novas_user>0){
                                document.getElementById('nov_user_count').innerHTML='('+novas_user+')';
                            }else{
                                document.getElementById('nov_user_count').innerHTML='&nbsp;';
                            }
                            document.getElementById('auser'+jsonData[0].id).innerHTML='<input type="checkbox" class="msg_chk" id="chk_user_'+jsonData[0].id+'" onclick="return msg_sel2del(this);">';
                            mensagens_para_sel.push('chk_user_'+jsonData[0].id);
                            document.getElementById('buser'+jsonData[0].id).className='txt_mail';
                            document.getElementById('cuser'+jsonData[0].id).className='txt_mail';
                            document.getElementById('duser'+jsonData[0].id).className='txt_mail';
                        }else if(jsonData[0].folder=='com' && novas_com>0){
                            novas_com=novas_com-1;
                            if (novas_com>0){
                                document.getElementById('nov_com_count').innerHTML='('+novas_com+')';
                            }else{
                                document.getElementById('nov_com_count').innerHTML='&nbsp;';
                            }
                            document.getElementById('acom'+jsonData[0].id).innerHTML='<input type="checkbox" class="msg_chk" id="chk_com_'+jsonData[0].id+'" onclick="return msg_sel2del(this);">';
                            mensagens_para_sel.push('chk_com_'+jsonData[0].id);
                            document.getElementById('bcom'+jsonData[0].id).className='txt_mail';
                            document.getElementById('ccom'+jsonData[0].id).className='txt_mail';
                            document.getElementById('dcom'+jsonData[0].id).className='txt_mail';
                        }else if(jsonData[0].folder=='adm' && novas_adm>0){
                            novas_adm=novas_adm-1;
                            if (novas_adm>0){
                                document.getElementById('nov_adm_count').innerHTML='('+novas_adm+')';
                            }else{
                                document.getElementById('nov_adm_count').innerHTML='&nbsp;';
                            }
                            document.getElementById('aadm'+jsonData[0].id).innerHTML='<input type="checkbox" class="msg_chk" id="chk_adm_'+jsonData[0].id+'" onclick="return msg_sel2del(this);">';
                            mensagens_para_sel.push('chk_adm_'+jsonData[0].id);
                            document.getElementById('badm'+jsonData[0].id).className='txt_mail';
                            document.getElementById('cadm'+jsonData[0].id).className='txt_mail';
                            document.getElementById('dadm'+jsonData[0].id).className='txt_mail';
                        }
                    }


                }

            }catch (e){
            //alert('Resposta invalida: '+e.toString());
            }
        }else{
    //alert("Sem reposta: \n"+mc_Ajax.statusText);
    }
    }
}
/*
function slidajx(v){
    try{
        janela_ajx.focus();
    }catch (e){}
    uu="slide.html";
    if (v) uu="slideautor.php?n="+v;
    //janela_ajx = open("slide.php","ajxWindow","width="+screen.width+",height="+screen.height+",fullscreen=yes,left=0,top=0,scrollbars=no,resizable=no");
    janela_ajx = open(uu,"ajxWindow","width="+screen.width+",height="+screen.height+",fullscreen=yes,left=0,top=0,scrollbars=yes,resizable=yes");
}
*/

function val_foto(){
    if(document.adfoto.gpublica.value=='0'){
        alert('Escolha uma galeria');
        return false;
    }
    str=document.adfoto.titulo.value.replace(/(^\s+|\s+$)/g,'');
    if (str.length==0){
        alert('Tem de Introduzir um Título');
        return false;
    }
    return true;
}
function valid(){
    msg="Atenção:\n";
    erros=false;
    str=document.form1.nome.value.replace(/(^\s+|\s+$)/g,'');
    if (str.length==0){
        erros=true;
        msg +=" - O campo NOME é obrigatório.\n";
    }
    str=document.form1.username.value.replace(/(^\s+|\s+$)/g,'');
    if (str.length<2 || str.indexOf(' ')>=0){
        erros=true;
        msg +=" - O campo USERNAME é obrigatório e deverá ter mais de 1 caractere de comprimento e sem espaços.\n";
    }
    str=document.form1.password.value.replace(/(^\s+|\s+$)/g,'');

    if (document.form1.upi.value=='1'){
        if (document.form1.password.value!=document.form1.cpassword.value){
            erros=true;
            msg +=" - As PASSWORDS não são iguais!\n";
        }

    }else{
        if (str.length<5){
            erros=true;
            msg +=" - O campo PASSWORD é obrigatório e deverá ter mais de 4 caracteres de comprimento.\n";
        }else{
            if (document.form1.password.value!=document.form1.cpassword.value){
                erros=true;
                msg +=" - As PASSWORDS não são iguais!\n";
            }
        }
    }

    if(document.form1.email){
        str=document.form1.email.value.replace(/(^\s+|\s+$)/g,'');
        if (str.length==0){
            erros=true;
            msg +=" -O campo E-MAIL é obrigatório.\n";
        }else{
            if (str.indexOf('@')<0 || str.indexOf('.')<0){
                erros=true;
                msg +=" - O E-MAIL é inválido\n";
            }
        }
    }


    if (erros){
        alert(msg);
        return false;
    }else{
        return true;
    }

}
function ask(v){

    if (confirm('Apagar/Delete ?')){
        location.href=v;
    }

}

/*
function pdvot(mm){
    var c=p=g=false;
    if (mm==1){
        alert('Atenção Utilizadores do Plano Gratuito:\nPara comentar e votar precisa de ter 1 foto enviada nos últimos 7 dias');
        return false;
    }
    p=true; // bypass obrigar a votar

    str=document.votaecomenta.votacao_comentario.value.replace(/(^\s+|\s+$)/g,'');
    if (str.length>6){
        c=true;
    }
    if (g){
        if (p && c){
            return true;
        }else{
            alert('Para poder votar, os campos comentário e votação devem ser preenchidos');
            return false;
        }
    }else{
        if (c){
            return true;
        }else {
            alert('Por favor preencha o comentário');
            return false;
        }
    }
}
*/
function check_chars(id,maxchars){
    if (document.getElementById(id).value.length>maxchars){
        document.getElementById(id).value=document.getElementById(id).value.substr(0,maxchars);
    }
    document.getElementById("i_"+id).innerHTML=document.getElementById(id).value.length;
}/*
function destaqueFotoHonra(foto){
    if (mc_Ajax){
        try{
            mc_Ajax.open("GET","jaxServ.php?action=destaques&type=honra&exid="+foto+"&rnd="+(Math.ceil(1000*Math.random())),true);
            mc_Ajax.onreadystatechange=actualizaDestaqueHonra;
            mc_Ajax.send(null);
        }catch (e){
        
        }
    }else{

}
}
function destaqueFotoMes(foto){
    if (mc_Ajax2){
        try{
            mc_Ajax2.open("GET","jaxServ.php?action=destaques&type=mes&exid="+foto+"&rnd="+(Math.ceil(1000*Math.random())),true);
            mc_Ajax2.onreadystatechange=actualizaDestaqueMes;
            mc_Ajax2.send(null);
        }catch (e){
       
        }
    }else{

}
} 
function destaqueFotoRecente(foto){
    if (mc_Ajax3){
        try{
            mc_Ajax3.open("GET","jaxServ.php?action=destaques&type=recente&exid="+foto+"&rnd="+(Math.ceil(1000*Math.random())),true);
            mc_Ajax3.onreadystatechange=actualizaDestaqueRecente;
            mc_Ajax3.send(null);
        }catch (e){
       
        }
    }else{
 
}
}
function destaqueFotoDia(foto){
    if (mc_Ajax4){
        try{
            mc_Ajax4.open("GET","jaxServ.php?action=destaques&type=dia&exid="+foto+"&rnd="+(Math.ceil(1000*Math.random())),true);
            mc_Ajax4.onreadystatechange=actualizaDestaqueDia;
            mc_Ajax4.send(null);
        }catch (e){
        
        }
    }else{
 
}
}
function destaqueFotoConcurso(foto){
    if (mc_Ajax5){
        try{
            mc_Ajax5.open("GET","jaxServ.php?action=destaques&type=concurso&exid="+foto+"&rnd="+(Math.ceil(1000*Math.random())),true);
            mc_Ajax5.onreadystatechange=actualizaDestaqueConcurso;
            mc_Ajax5.send(null);
        }catch (e){
        
        }
    }else{
 
}
}
function destaqueFotoEvento(){
    if (mc_Ajax6){
        try{
            mc_Ajax6.open("GET","jaxServ.php?action=destaques&type=evento&rnd="+(Math.ceil(1000*Math.random())),true);
            mc_Ajax6.onreadystatechange=actualizaDestaqueEvento;
            mc_Ajax6.send(null);
        }catch (e){
      
        }
    }else{
 
}
}*/
function showLayer (layer, w, h, res) {
    document.getElementById('layer'+layer).style.visibility = 'visible';
}
function hideLayer (layer) {
    document.getElementById('layer'+layer).style.visibility = 'hidden';
}

function hilight(id,bg){
    if (close!='' && close!=id) lolight(close);

    document.getElementById(id).style.backgroundColor='#'+bg;
    if (document.getElementById(id+'_down'))document.getElementById(id+'_down').style.display='block';
    close=id;
}
function lolight(id){
    if(document.getElementById(id))document.getElementById(id).style.backgroundColor='';
    if(document.getElementById(id+'_down'))document.getElementById(id+'_down').style.display='none';
    if(document.getElementById('layer_'+id+'_option'))document.getElementById('layer_'+id+'_option').style.visibility='hidden';

}
function nova(parent_id,tipo,pai){
    if (fecha_add!=''){
        document.getElementById(fecha_add).style.display='none';
    }
    if (fecha_edit!=''){
        document.getElementById(fecha_edit).innerHTML=old_edit;
        fecha_edit='';
    }
    fecha_add='n_'+parent_id;
    if (tipo=='gr'){
        document.getElementById('im_'+parent_id).src='/imagens/pasta.png';
        document.getElementById('in_'+parent_id).value='New Group';
        document.getElementById('in_'+parent_id+'_type').value='gr';
    }else if(tipo=='ga'){
        document.getElementById('im_'+parent_id).src='/imagens/image.png';
        document.getElementById('in_'+parent_id).value='New theme';
        document.getElementById('in_'+parent_id+'_type').value='ga';
    }
    document.getElementById('in_'+parent_id+'_parent').value=pai;
    document.getElementById('n_'+parent_id).style.display='block';
    hilight('n_'+parent_id,'304050');
}
function clearme(obj){
    if(obj.value=='New Group') obj.value='';
    if(obj.value=='New theme') obj.value='';
}
function pastas_sort(src,dest){
    $('sorpade').value=src;
    $('sorpapa').value=dest;
    $('sorpa').submit();
}
function clickIE4(){
    if (event.button==2){
        return false;
    }
}

function clickNS4(e){
    if (document.layers||document.getElementById&&!document.all){
        if (e.which==2||e.which==3){

            return false;
        }
    }
}/*
function destaques(fotohonra,fotomes,fotodia,fotoconcurso,fotorecente){
    Gfotohonra=fotohonra;
    Gfotomes=fotomes;
    Gfotodia=fotodia;
    Gfotoconcurso=fotoconcurso;
    Gfotorecente=fotorecente;

    window.setTimeout('destaqueFotoRecente('+fotorecente+')',4500);


}*/
function nav_autor(autor,foto){
    if (mc_Ajax){
        try{
            mc_Ajax.open("GET","jaxServ.php?action=nav_autor&autor="+autor+"&fid="+foto+"&rnd="+(Math.ceil(1000*Math.random())),true);
            mc_Ajax.onreadystatechange=actualiza_nav_autor;
            mc_Ajax.send(null);
        }catch (e){
        }
    }else{
}
}
function actualiza_nav_autor(){
    if (mc_Ajax.readyState==4){
        if (mc_Ajax.status==200){
            try{
                document.getElementById('nav_foto_autor').innerHTML=mc_Ajax.responseText;
            }catch (e){
            }
        }else{
    }
    }
}

function getclick(d){
}
function setclick(d){
}

function editar_grupo(dd,id){
    if (fecha_edit!=''){
        document.getElementById(fecha_edit).innerHTML=old_edit;
    }
    if (fecha_add!=''){
        document.getElementById(fecha_add).style.display='none';
        fecha_add='';
    }
    fecha_edit=dd+'_caption';

    old_edit=document.getElementById(dd+'_caption').innerHTML.trim();

    document.getElementById(dd+'_caption').innerHTML='<form  class="formPastas" method="POST" action=""><input class="inputPastas" id="cap_edit" name="cap_edit" type="text"  maxlength="30" value="'+old_edit+'"><input type="submit"  class="submitPastas" value="" title="Gravar/Save" onmouseover="this.style.backgroundPosition=\'left bottom\';" onmouseout="this.style.backgroundPosition=\'left top\';"><input name="cap_edit_id" type="hidden" value="'+id+'"></form>';
    document.getElementById('cap_edit').focus();

}
function val_new_grp(holder){
    if(document.getElementById('in_'+holder).value=='New theme'){
        alert('Por favor mude o nome do Novo Tema / Please rename the New Theme');
        return false;
    }
    if(document.getElementById('in_'+holder).value=='New group'){
        alert('Por favor mude o nome do Novo Grupo');
        return false;
    }
    var x=document.getElementById('in_'+holder).value;
    if(x.trim()==''){

        return false;
    }
}
function editar_gal(dd,id){
    hilight(dd,'304050');


    if (fecha_edit!=''){
        document.getElementById(fecha_edit).innerHTML=old_edit;



    }
    if (old_edit_id!=''){
        $(old_edit_id).onclick=saveclick;
    //flag_click=0;
    }

    if (fecha_add!=''){
        document.getElementById(fecha_add).style.display='none';
        fecha_add='';
    }
    fecha_edit=dd+'_caption';
    old_edit_id='gal_'+id;
    saveclick=document.getElementById(dd).onclick;
    document.getElementById(dd).onclick='';
    //dd -gal_xxxx  id - xxxxx
    old_edit=document.getElementById(dd+'_caption').innerHTML.trim();
    document.getElementById(dd+'_caption').innerHTML='<form  class="formPastas" method="POST" action=""><input class="inputPastas" id="cap_edit" name="cap_edit_gal" type="text" size="29" maxlength="30" value="'+old_edit+'"><input type="submit"  class="submitPastas" value="" title="Gravar/Save" onmouseover="this.style.backgroundPosition=\'left bottom\';" onmouseout="this.style.backgroundPosition=\'left top\';"><input name="cap_edit_id_gal" type="hidden" value="'+id+'"></form>';
    document.getElementById('cap_edit').focus();

}

function showBigLayer(ugetBIG,closerr){
    if (closerr){

    }else{
        closerr=false;
    }
    //hideFlash();
    var arrayPageSize = getPageSize();


    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','layer_mapa');
    objOverlay.style.display = 'none';
    objBody.appendChild(objOverlay);
    $("#layer_mapa").addClass('layer_overlay');
    $('#layer_mapa').height(arrayPageSize[1]);
    $('#layer_mapa').fadeIn();



    var objMapa = document.createElement("div");
    objMapa.setAttribute('id','pre_mapa');
    objMapa.style.display = 'none';
    objBody.appendChild(objMapa);
    $("#pre_mapa").addClass('pre_mapa');
    var  XX= (arrayPageSize[0] /2) -400;
    $("#pre_mapa").css('left',XX+'px');
    $("#pre_mapa").html('<iframe width="800" height="500" marginheight="0" marginwidth="0" scrolling="auto" id="imapa"  frameborder="0" src="'+ugetBIG+'" allowtransparency="false"></iframe><br><br><center><input class="submit" type="button" value="Fechar" onClick="fecha_mapa(\''+closerr+'\');"></center>');

    $('#pre_mapa').fadeIn();

}
function pop_pic_layer(img,w,h,ret){
    //hideFlash();
    var arrayPageSize = getPageSize();
    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','layer_mapa');
    objOverlay.style.display = 'none';
    objBody.appendChild(objOverlay);
    $("#layer_mapa").addClass('layer_overlay');
    $('#layer_mapa').height(arrayPageSize[1]);
    $('#layer_mapa').fadeIn();

    var objMapa = document.createElement("div");
    objMapa.setAttribute('id','holder');
    objMapa.style.display = 'none';
    objBody.appendChild(objMapa);
    var  XX= (arrayPageSize[0] /2) -(w/2);
    $("#holder").addClass('holder');
    $("#holder").css('left',XX+'px');
    $("#holder").html('<a href="#'+ret+'"><img src="'+img+'" border="0" onClick="fecha_pop_pic_layer();"></a>');
    $('#holder').fadeIn();
}

function fecha_pop_pic_layer(){
    $('#holder').remove();
    $('#layer_mapa').fadeOut('fast', function() {
        $('#layer_mapa').remove();
    });
//showFlash();
}
function msg_layer(htm,w,h){
    if (h<50) h=50;
    if (w<100) w=100;
    //hideFlash();
    var arrayPageSize = getPageSize();

    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','layer_mapa');
    objOverlay.style.display = 'none';
    objBody.appendChild(objOverlay);
    $("#layer_mapa").addClass('layer_overlay');
    $('#layer_mapa').height(arrayPageSize[1]);
    $('#layer_mapa').fadeIn();

    var objMapa = document.createElement("div");
    objMapa.setAttribute('id','pre_mapa');
    objMapa.style.display = 'none';
    objBody.appendChild(objMapa);
    $("#pre_mapa").addClass('pre_mapa');
    $("#pre_mapa").css('height',h+'px');
    $("#pre_mapa").css('width',w+'px');
    var  XX= (arrayPageSize[2] /2) - (w/2);
    var  YY=(arrayPageSize[3] /2) - (h/2);
    $("#pre_mapa").css('left',XX+'px');
    $("#pre_mapa").css('top',YY+'px');

    $("#pre_mapa").html('<table width="100%"  height="22"  cellspacing="0" border="0" cellpadding="0" id="a"><tr><td  width="20%"><div align="center">&nbsp;</div></td><td width="60%"><div align="center">Informação:</div></td><td width="20%"><div align="right"><a href="#" onclick="fecha_msg_layer();"><img border="0" src="/imagens/cancel.png" width="22" height="22"><a></div></td></tr></table><table width="100%"  height="'+(h-23)+'"  cellspacing="0" class="mensagens"><tr><td  align="center" valign="middle" id="b">'+htm+'</td></tr></table>');
    $('#pre_mapa').fadeIn();

}
function fecha_msg_layer(){
    $('#pre_mapa').remove();
    $('#layer_mapa').fadeOut('fast', function() {
        $('#layer_mapa').remove();
    });
    return false;
}
/*
function mc_fadein(ele,id){
    $('#'+ele).fadeIn(1000,function(){
        if (ele=='fotos_honra'){
            Gfotohonra=id;
            window.setTimeout('destaqueFotoConcurso('+Gfotoconcurso+')',2500);
        }
        if (ele=='fotos_mes'){
            Gfotomes=id;
            window.setTimeout('destaqueFotoHonra('+Gfotohonra+')',2500);
        }
        if (ele=='fotos_recentes'){
            Gfotorecente=id;
            window.setTimeout('destaqueFotoDia('+Gfotodia+')',2500);
        }
        if (ele=='fotos_dia'){
            Gfotodia=id;
            window.setTimeout('destaqueFotoMes('+Gfotomes+')',2500);
        }
        if (ele=='fotos_concursos'){
            Gfotoconcurso=id;
            window.setTimeout('destaqueFotoEvento()',2500);
        }
        if (ele=='fotos_eventos'){
            window.setTimeout('destaqueFotoRecente('+Gfotorecente+')',2500);
        }

    });
}
function actualizaDestaqueHonra(){
    if (mc_Ajax.readyState==4){
        if (mc_Ajax.status==200){
            try{
                eval('var jsonData='+ mc_Ajax.responseText+';');
                if (jsonData.length==1){

                    $('#fotos_honra').fadeOut(1000,function(){
                        $('#fotos_honra').html('<a href="'+jsonData[0].lnk+'"><img width="'+jsonData[0].width+'"  height="'+jsonData[0].height+'" title="'+jsonData[0].titulo+'" src="'+jsonData[0].src+'"  class="imagens"   onload="mc_fadein(\'fotos_honra\','+jsonData[0].id+');"></a><br />'+jsonData[0].legenda);
                    });
                }
            }catch (e){
            }
        }else{
    }
    }
}


function actualizaDestaqueMes(){
    if (mc_Ajax2.readyState==4){
        if (mc_Ajax2.status==200){
            try{
                eval('var jsonData='+ mc_Ajax2.responseText+';');
                if (jsonData.length==1){
                    $('#fotos_mes').fadeOut(1000,function(){
                        $('#fotos_mes').html('<a href="'+jsonData[0].lnk+'"><img width="'+jsonData[0].width+'"  height="'+jsonData[0].height+'" title="'+jsonData[0].titulo+'" src="'+jsonData[0].src+'"  class="imagens"   onload="mc_fadein(\'fotos_mes\','+jsonData[0].id+');"></a><br />'+jsonData[0].legenda);
                    });
                }
            }catch (e){
            }
        }else{
    }
    }
}
function actualizaDestaqueRecente(){
    if (mc_Ajax3.readyState==4){
        if (mc_Ajax3.status==200){
            try{
                eval('var jsonData='+ mc_Ajax3.responseText+';');
                if (jsonData.length==1){
                    $('#fotos_recentes').fadeOut(1000,function(){
                        $('#fotos_recentes').html('<a href="'+jsonData[0].lnk+'"><img width="'+jsonData[0].width+'"  height="'+jsonData[0].height+'" title="'+jsonData[0].titulo+'" src="'+jsonData[0].src+'"  class="imagens"   onload="mc_fadein(\'fotos_recentes\','+jsonData[0].id+');"></a><br />'+jsonData[0].legenda);
                    });
                }
            }catch (e){
            }
        }else{
    }
    }
}
function actualizaDestaqueDia(){
    if (mc_Ajax4.readyState==4){
        if (mc_Ajax4.status==200){
            try{
                eval('var jsonData='+ mc_Ajax4.responseText+';');
                if (jsonData.length==1){
                    $('#fotos_dia').fadeOut(1000,function(){
                        $('#fotos_dia').html('<a href="'+jsonData[0].lnk+'"><img width="'+jsonData[0].width+'"  height="'+jsonData[0].height+'" title="'+jsonData[0].titulo+'" src="'+jsonData[0].src+'"  class="imagens"   onload="mc_fadein(\'fotos_dia\','+jsonData[0].id+');"></a><br />'+jsonData[0].legenda);
                    });
                }
            }catch (e){
            }
        }else{
    }
    }
}
function actualizaDestaqueConcurso(){
    if (mc_Ajax5.readyState==4){
        if (mc_Ajax5.status==200){
            try{
                eval('var jsonData='+ mc_Ajax5.responseText+';');
                if (jsonData.length==1){
                    $('#fotos_concursos').fadeOut(1000,function(){
                        $('#fotos_concursos').html('<a href="'+jsonData[0].lnk+'"><img width="'+jsonData[0].width+'"  height="'+jsonData[0].height+'" title="'+jsonData[0].titulo+'" src="'+jsonData[0].src+'"  class="imagens"   onload="mc_fadein(\'fotos_concursos\','+jsonData[0].id+');"></a><br />'+jsonData[0].legenda);
                    });
                }
            }catch (e){
            }
        }else{
    }
    }
}
function actualizaDestaqueEvento(){
    if (mc_Ajax6.readyState==4){
        if (mc_Ajax6.status==200){
            try{
                eval('var jsonData='+ mc_Ajax6.responseText+';');
                if (jsonData.length==1){
                    $('#fotos_eventos').fadeOut(1000,function(){
                        $('#fotos_eventos').html('<a href="'+jsonData[0].lnk+'"><img width="'+jsonData[0].width+'"  height="'+jsonData[0].height+'" title="'+jsonData[0].titulo+'" src="'+jsonData[0].src+'"  class="imagens"   onload="mc_fadein(\'fotos_eventos\','+jsonData[0].id+');"></a><br />'+jsonData[0].legenda);
                    });
                }
            }catch (e){
            }
        }else{
    }
    }
}
*/

function checkAgree(){
    if ($('#agree').attr('checked')) return true;
    else $.jGrowl('You must accept the rules to be able to upload',{
        header:'Upload'
    });

    return false;


}
function checkrazao(){
    setCuratorMsg();
    var x=$("input[name=razao\\[\\]]:checked").map(function(){
        return $(this).val();
    }).get();
    if ($.isArray(x) && x.length>0) return true;
    $.jGrowl('Por favor indique a razão', {
        header: 'Voto'
    });
    return false;
}
function setCuratorMsg(){
    $('.msgadicional').val($('#mscurador').val());
}
function razoesDia(){
    $('#razoesre').dialog({
        close: function(event, ui) {
            razoesVt();
        },
        hide:'puff',
        modal: true,
        draggable: true,
        resizable: false,
        buttons: {
            "Ok": function() {
                $(this).dialog("close");
            }
        }
    });
}
function razoesVt(){
 
    var x=$("input[name=razao\\[\\]]:checked").map(function(){
        return $(this).val();
    }).get();
    if ($.isArray(x) && x.length>0){
        $('#reasonno').html(x.length);
        $('.razao').val(x.join('|'));
    }else{
        $('.razao').val('');
        $('#reasonno').html('0');
    }
       
}
function removeProfile(){
    $('#removeprofile').dialog({
        hide:'puff',
        modal: true,
        resizable: false,
        buttons: {
            'Cancel':function(){
                $(this).dialog("close");
            },
            "Ok": function(){
                $('#userremove').submit();
            }
        }
    });
}
function showSpinner(){
    if ($('#spinner').length===0) $('body').append('<div id="spinner" class="hide"><img src="/images/ajax-loader.gif"><br>Loading...</div>');
    $('#spinner').dialog({
        autoOpen: true,
        zIndex: 9999, 
        modal: true, 
        width: 100, 
        height: 60, 
        resizable: false,
        dialogClass:'spinner',
        draggable:false
    });
}
function hideSpinner(){
    $('#spinner').dialog("close");
}

function showvotedetails(inp){
    showSpinner();
    $.get("/jx.php?vdetails="+inp+"&rnd="+Math.ceil(Math.random()*10000), function(data) {
        if (data!='...'){
            $('body').append(data);
            $('input[name=token]:not(#jxtoken)').val($('#jxtoken').val());
            hideSpinner();
            $('#votedets').dialog({
                autoOpen: true, 
                modal: true, 
                width: 850, 
                minWidth: 850, 
                maxWidth: 850, 
                height: 'auto', 
                minHeight: 350, 
                maxHeight: 550, 
                resizable: true,
                hide:'puff',
                show:'drop',
                close:function(){
                    $(this).dialog( "destroy" );
                    $(this).remove()
                }
            });
        }else hideSpinner();
    });

}



 

function processUser(id){
    showSpinner();
    $.get("/jx.php?userdet="+id+"&rnd="+Math.ceil(Math.random()*10000), function(data) {
        $('body').append(data);
        $('input[name=token]:not(#jxtoken)').val($('#jxtoken').val());
        hideSpinner();
        $('#uform').dialog({
            autoOpen: true, 
            modal: true, 
            width: 800, 
            height: 400, 
            resizable:false,
            hide:'puff',
            show:'drop',
            close:function(){
                $(this).dialog( "destroy" );
                $(this).remove()
            }
        });
    });
}
function processEnc(id){
    showSpinner();
    $.get("/jx.php?encedt="+id+"&rnd="+Math.ceil(Math.random()*10000), function(data) {
        $('body').append(data);
        $('input[name=token]:not(#jxtoken)').val($('#jxtoken').val());
        hideSpinner();
        $('#uform').dialog({
            autoOpen: true, 
            modal: true, 
            width: 800, 
            height: 400, 
            resizable:false,
            hide:'puff',
            show:'drop',
            close:function(){
                $(this).dialog( "destroy" );
                $(this).remove()
            }
        });
    });
}
function finEnc(id,fim){
    var q='Processar esta pagamento?';
    if (fim=='formdeldet') q='Apagar esta Compra';
    vConfirm(q,function(){
        showSpinner();
        $.ajax({
            type: "POST",
            cache: false,
            data: $('#'+fim).serialize(),
            url: '/jx.php?finishenc='+id+'&rnd=' + Math.ceil(Math.random() * 1000),
            dataType: "json",
            success: function (data, statusText) {
                hideSpinner();    
                if (statusText == 'success') {
                    if(data.token)  $('input[name=token]').val(data.token);
                    if (data.ok) {
                        $('#uform').dialog('close');
                        if ($('#trow'+data.id).length){
                            if (fim=='formdeldet')$('#trow'+data.id).children('td').css('color','red');
                            else $('#trow'+data.id).children('td').css('color','green');
                            $('#trow'+data.id).children('td').css('text-decoration','line-through');
                            $('#opttd'+data.id).html(' ');
                        }
                        shout(data.msg,'Encomendas');
                    }else if(data.error) shout(data.msg,'Encomendas');
                } else shout('Error! Could not contact the server!','Encomendas');
            }   
        });
        
    });
    
}


function UpdateUser(id,nv,old){
    if ($(nv).val()==old) return true;
    showSpinner();
    
   
    $.getJSON("/jx.php?userup="+id+"&nv="+($(nv).val())+"&rnd="+Math.ceil(Math.random()*10000),function(data){
        if (data){
            if(data.token) $('input[name=token]').val(data.token);
            if (data.ok){
                if (data.msg) shout(data.msg,'Update User');
            }else{
                $(nv).val(old).attr('selected',true);  
            }
        }else{
            $(nv).val(old).attr('selected',true);  
        } 
        hideSpinner();
        if (data && data.error) shout(data.error,'Update User');
    });
//falta actualizar a tabela de users
}
function shout(msg,head,st){
    if (st) st=true;
    else st=false;
    if (!head) head='';
    $.jGrowl(msg, {
        header:head,
        glue: 'before',
        speed: 'fast',
        life: 5000,
        sticky: st
    });
}
function showContent(sect){
    showSpinner();
    $.get("/jxc.php?view="+sect+"&rnd="+Math.ceil(Math.random()*10000), function(data) {
        $('body').append(data);        
        $('input[name=token]:not(#tk_'+sect+')').val($('#tk_'+sect).val());
        hideSpinner();
        $('#diag_'+sect).dialog({
            autoOpen: true, 
            modal: true, 
            width: 800, 
            height: 450, 
            resizable: true,
            hide:'puff',
            show:'drop',
            close:function(){
                $(this).dialog( "destroy" );
                $(this).remove()
                }
            });
        
    });
}
function sendInvite(){
    showSpinner();
    $.post("/jx.php?rnd="+Math.ceil(Math.random()*10000), $("#forminvite").serialize(),function(data){
        hideSpinner();
        if(data.token)  $('input[name=token]').val(data.token);
        if (data.error) shout(data.error,'Invite');
        else if(data.ok){
            shout(data.ok,'Invite');
            $('#inviteeemail').val('');
            $('#inviteename').val('');
        }
    },'json');
    
}
function vConfirm(txt,fnc,params){
    if ($('#confirmdialog').length)$('#confirmdialog').html(txt);
    else $('body').append('<div id="confirmdialog" title="Por Favor Confirme"><div class="confdiag>'+txt+'</div></div>');
    $('#confirmdialog').dialog({
        autoOpen: true, 
        modal: true, 
        width: 300, 
        height: 'auto',
        zIndex: 1001, 
        resizable: false, 
        hide:'drop',
        show:'drop',
        buttons: {
            "No": function() {
                $(this).dialog("close");
            },
            "Yes": function() { 
                fnc(params);
                $(this).dialog("close");
            }
        }
    });
}

function ur(datain){
    vConfirm('Apagar este utilizador e todas as suas fotos?',function(){
        showSpinner();
        $.ajax({
            type: "POST",
            cache: false,
            data: 'uru='+datain ,
            url: '/jx.php?ur=1&rnd=' + Math.ceil(Math.random() * 1000),
            dataType: "json",
            success: function (data, statusText) {
                hideSpinner();    
                if (statusText == 'success') {
                    if(data.token)  $('input[name=token]').val(data.token);
                    if (data.ok) {
                        $('#uform').dialog('close');
                        if ($('#trow'+data.id).length){
                            $('#trow'+data.id).children('td').css('color','red');
                            $('#trow'+data.id).children('td').css('text-decoration','line-through');
                            $('#opttd'+data.id).html(' ');
                        }else window.location.reload();
                        shout('Utilizador Apagado','Users');
                    }else if(data.error) shout(data.msg,'Users');
                } else shout('Error! Could not contact the server!','Users');
            }   
        });
        
        
    });

   
}
function setPP(){
    showSpinner();
    $.ajax({
        type: "POST",
        cache: false,
        data: $('#frmdados').serialize(),
        url: '/jx.php?pay=pp&rnd=' + Math.ceil(Math.random() * 1000),
        dataType: "html",
        success: function (data, statusText) {      
            if (statusText == 'success') {
                $('#holderpp').html(data);
                if ($('#rspptk').length){
                    hideSpinner();
                    $('input[name=token]:not(#rspptk)').val($('#rspptk').val());
                    shout('Error! Cannot process your request','Payment');
                }else $('#paypalform').submit();
            }else{
                hideSpinner();
                shout('Error! Could not contact the server!','Payment');
            } 
        }   
    });
}
function mostraRazoes(id){
    showSpinner();
    $.get("/jx.php?vrazoes="+id+"&rnd="+Math.ceil(Math.random()*10000), function(data) {
        if (data!='...'){
            $('body').append(data);
            $('input[name=token]:not(#jxtoken)').val($('#jxtoken').val());
            hideSpinner();
            $('#razoesdiag').dialog({
                autoOpen: true, 
                modal: true, 
                width: 'auto', 
                height: 'auto', 
                resizable: false,
                hide:'puff',
                show:'drop',
                close:function(){
                    $(this).dialog( "destroy" );
                    $(this).remove()
                }
            });
        }else hideSpinner();
    });
}

function setupRotator(){

    if($('#VDmarquee > .Ventry').length >1){
        $('#VDmarquee > .Ventry:first').addClass('Vcurrent').fadeIn(8000);
        setInterval('textRotate()',8000);
    }else if($('#VDmarquee > .Ventry').length==1)  $('#VDmarquee > .Ventry').show();
}
function textRotate(){
    var current = $('#VDmarquee > .Vcurrent');
    
    if(current.next().length ==0) current.removeClass('Vcurrent').fadeOut(1000, function (){
        $('#VDmarquee > .Ventry:first').addClass('Vcurrent').fadeIn(100)
        });
    else current.removeClass('Vcurrent').fadeOut(1000, function (){
        current.next().addClass('Vcurrent').fadeIn(100)
        });

}

function fixWidth(classHolder){
    var availableWidht=$('.'+classHolder).width()-10;
    $('.'+classHolder+'  img').each(
        function (idx,ele){
            if ( $(ele).attr('originalwidth') && $(ele).attr('originalwidth')>availableWidht){
                var rat=$(ele).attr('originalwidth')/ $(ele).attr('orginalheight');
                ele.height=Math.floor(availableWidht/rat);
                ele.width=availableWidht;
            }
        }
        );
 
}
function fixProfile(){
    
    
}

function fixWidthDestaques(){
    fixWidth('destaq_lc');
}
function fixWidthDestaq(){
    fixWidth('destaq');
}
function lockfoto(){
    $('#mfotonav').bind("contextmenu",function(e){
        return false;
    });
    lockdrag();
}
function lockdrag(){
    $('#mfotonav').bind("select",function(e){
        return false;
    });
    $( "#mfotonav" ).draggable({
        start: function(event, ui) {
            return false;
        }
    });
    
    disableDraggingFor(document.getElementById("mfotonav"));
}
function disableDraggingFor(element) {
    element.draggable = false;
    element.onmousedown = function(event) {
        event.preventDefault();
        return false;
    };
}
function effectFadeIn(classname,speed) {
    if (!speed)  speed=800;
    $("."+classname).fadeOut(speed).fadeIn(speed, effectFadeOut(classname))
}
function effectFadeOut(classname,speed) {
     if (!speed)  speed=800;
    $("."+classname).fadeIn(speed).fadeOut(speed, effectFadeIn(classname))
}
function animBorder(){
      if ($('.borderanim').length)  window.setInterval(function(){$('.borderanim').toggleClass('borderanim2',500);}, 1000);
}
