﻿/***********************************************************
***Variaveis a alterar consoante o background e o link******
***********************************************************/

//var newBodyImg = "/images/_skin.jpg";
//var newBodyUrl = "http://www.abola.pt";

//var inicio = new Date(2010, 11, 24, 10, 40, 0);
//inicio.setFullYear(2010, 11, 24);
//var fim = new Date(2010, 11, 25, 20, 00, 00);
//fim.setFullYear(2010, 11, 25);

/*****************************************************
*****************************************************
*****************************************************/



function goUrl() {
    window.open(newBodyUrl);
}

window.onload = initBody;

function initBody() {

    $.ajax({url:"/ajax/masterpage.aspx", 
    type:"POST",
    dataType:"text",
    data:{request: "currentDate"},
    success:function(result){	
    var current = result;
    var arraySplit = current.split(' ');
    var datepSplit = arraySplit[0].split('-');
    var hoursSplit = arraySplit[1].split(':');
    var currentDate = new Date(datepSplit[2], datepSplit[1], datepSplit[0], hoursSplit[0], hoursSplit[1], hoursSplit[2]);
    currentDate.setFullYear(datepSplit[2], datepSplit[1], datepSplit[0]);
   
    if (currentDate >= inicio && currentDate <= fim && window.location.pathname=="/") {
    
        //document.body.style.backgroundColor = "red";
        document.body.style.background = "#FFF url('" + newBodyImg + "') no-repeat center top";
        $(".ojeSite").css("width", "1280px");
       
        //document.body.innerHTML = "<div style='margin:auto;'><table border='0' cellspacing='0' cellpadding='0' width='1280'><tr><td style='width:145px;cursor:pointer;position:absolute;height:1024px;' id='div1Pub' onclick='goUrl();' align='right'></td><td align='center' style='width:990px'>" + document.body.innerHTML + "</td><td style='width:145px;cursor:pointer;position:absolute;height:1024px;' id='div2Pub' onclick='goUrl();'></td></tr></table>";
        //document.body.innerHTML = "<table border='0' cellspacing='0' cellpadding='0' width='1280'><tr><td style='width:1280px;height:150px;cursor:pointer;' onclick='goUrl();'></td></tr></table>" + document.body.innerHTML+"</div>";

    
     }
    
    },
    error:function(req,error,ex){
    }
  });
}


function bodyPub(af_backclick_url) {
    var af_backclick_isHome = true, af_backclick_isV1 = true;
    var af_backclick_mmove = document.onmousemove;
    document.onmousemove = function (e) {
        if (af_backclick_mmove) af_backclick_mmove(e);
        if (!e) var e = window.event; var t = (e.srcElement ? e.srcElement : e.target);
        if (t && !t.af_backclick_set) {
            if (af_backclick_isBackground(t) || 1 == 1) {
                t.style.cursor = 'pointer';
                t.af_backclick_preclick = t.onclick;
                t.onclick = function (e) {
                    if (this.af_backclick_preclick) this.af_backclick_preclick(e);
                    if (!e) var e = window.event; var t = (e.srcElement ? e.srcElement : e.target);
                    if (t && this == t && (e.button == 0 || e.button == 1)) { wo = window.open(af_backclick_url); return false; }
                };
            } else
                if (t.style.cursor == '') {
                    var p = t; while (p.parentNode && p.nodeName && p.nodeName.toLowerCase() != 'a') p = p.parentNode;
                    t.style.cursor = (p.href && p.href != '' ? 'pointer' : 'auto');
                }
            t.af_backclick_set = true;
        }
        return true;
    }

    function af_backclick_isBackground(o) {
        if (!o.af_backclick_isBg)
            o.af_backclick_isBg = (af_backclick_isBg_allV(o) ? 1 : -1);
        return (o.af_backclick_isBg > 0);
    }

    function af_backclick_isBg_allV(o) {
        //if (o==document.body || (o.nodeName && o.nodeName.toLowerCase()=='center' && o.parentNode==document.body))
        if (o.id == "div1Pub" || o.id == "div2Pub")
            return true;
        else
            return false;

    }

}
