"use strict";
var iFrameElement = null;
var curLocation = document.location.href === 'http://lusopresse.com/index.htm' ? '' : '../../';
function loadArticle(url) {
    if (iFrameElement === null) {
        iFrameElement = document.getElementById('ifArticle');
    }
    iFrameElement.src = url;
    // setTimeout("self.scrollTo(0,0)",2);

}

function PortugueseDate() {
    var day_nme = ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"];
    var month_name = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
    var now = new Date();
    var nowDay = now.getDay();
    var nowDate = now.getDate();
    var nowMonth = now.getMonth();
    var nowYear = now.getFullYear();
    var data = day_nme[nowDay] + ', ' + nowDate + ' de ' + month_name[nowMonth] + ' de ' + nowYear;
    return data;
}
function callHome() {
    document.location = "http://lusopresse.com/index.htm";
}
function setCookie(name, value, days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = date.toGMTString();
    }
    else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) === 0) {
            return c.substring(nameEQ.length, c.length);
        }
    }
    return null;
}

function getHttpRequest() {
    var req = null;
    try {
        req = new XMLHttpRequest();
    }
    catch (e) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (er) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (err) {
                req = false;
            }
        }
    }
    return req;
}
function requestServer(url, callback, errMsg) {
    errMsg = errMsg || "ERROR";
    var httpRequest = getHttpRequest();
    if (httpRequest) {
        var asyncFnc = function() {
            if (httpRequest.readyState == 4) {
                if (httpRequest.status === 200 || httpRequest.status === 0) {
                    callback(httpRequest.responseText);
                }
                else {
                    callback(errMsg);
                }
            }
        };
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange = asyncFnc;
        httpRequest.send("");
    }
    else {
        callback("HTTP_ERROR");
    }
}

function weatherExchange() {
    var meteoExchangeDiv = document.getElementById("weather_exchange");
    var showWeatherExchange = function(txt) {
        if (txt.indexOf("ERROR") === 0) {
            txt = "";
        }
        meteoExchangeDiv.innerHTML = txt;
    };
    if (meteoExchangeDiv) {
        var url = curLocation + "inc/CambiosTempo.aspx";
        requestServer(url, showWeatherExchange);
    }

}

function pensamento() {
    var pensamentoDiv = document.getElementById("pensamentos");
    // var refreshPensamento= 15000;
    var showPensamento = function(txt) {
        if (txt.indexOf("ERROR") === 0) {
            txt = "A educação é aquilo que permanece depois de esquecermos tudo o que nos foi ensinado. <br>(Autor Halifax )";
        }
        pensamentoDiv.innerHTML = txt;
    };
    if (pensamentoDiv) {

        var url = curLocation + "inc/GetPensamento.aspx";
        var err = "ERROR";
        requestServer(url, showPensamento, err); //
        //  timerVar = setTimeout("pensamento()", refreshPensamento)
    }
}

function popup(sw) {
    if (sw == 1) {
        // Show popup
        document.getElementById('blackout').style.visibility = 'visible';
        document.getElementById('divpopup').style.visibility = 'visible';
        document.getElementById('blackout').style.display = 'block';
        document.getElementById('divpopup').style.display = 'block';
    } else {
        // Hide popup
        document.getElementById('blackout').style.visibility = 'hidden';
        document.getElementById('divpopup').style.visibility = 'hidden';
        document.getElementById('blackout').style.display = 'none';
        document.getElementById('divpopup').style.display = 'none';
    }
}
function imagePopup(img) {
    var src = img.src.replace(/\/thumbs/i, '');
    document.getElementById('pop_content').innerHTML = '<img style="border-bottom: 0px; border-left: 0px; border-top: 0px; width: 100%; border-right: 0px" alt="foto"  onclick="popup(0)" src="' + src + '"><br>'
    popup(1);
} 

function CleanPhotoName(str) {
  var pos = str.lastIndexOf("/");
  var s = str.substring(pos + 1).replace(/%20/g, '');
  return s.replace(/[^a-z0-9]+/ig, '');
}
       
function imageTextPopup(img) {
    var src = img.src.replace(/\/thumbs/i, '');
    var id = CleanPhotoName(src);
    document.getElementById('pop_content').innerHTML = '<img style="border-bottom: 0px; border-left: 0px; border-top: 0px; width: 100%; border-right: 0px" alt="foto"  onclick="popup(0)" src="' + src + '"><br>'
    var desc = document.getElementById(id);
    if (desc) {
        document.getElementById('pop_img_text').innerHTML = desc.innerHTML;
    }
    popup(1);
}

