"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)
   }
}
