Shadowbox.init();

window.onload = function() {
    try {
        if ((r)) {
            artigo(r);
        }
    } catch(e) {}
    try {
        if ((mostra_mensagem_activacao)) {
            mma();
        }
    } catch(e) {}
}

function mma() {
    url = URL_DIR + 'includes/clientes/conta_activa.php';
   /* Shadowbox.open({
        player: 'iframe',
        content: url,
        width: 500,
        height: 260
    });*/
}

function actualiza_carrinho(artigos, valor) {
    texto = artigos + ' artigo';
    if (artigos != 1) {
        texto += 's';
    }
    texto += ' ' + valor + ' €';
    document.getElementById('area_carrinho').innerHTML = texto;
}

function artigo(id) {
    url = URL_DIR + 'item.php?id=' + id;
    Shadowbox.open({
        player: 'iframe',
        content: url,
        width: 960,
        height: 500
    });
}

function ajaxRequest(requestURL, requestData, returnFunction) {
    http_request = false;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP")
        } catch(e1) {
            try {
                http_request = new ActiveXObject('Microsoft.XMLHTTP')
            } catch(e2) {}
        }
    }
    if (!http_request) {
        alert('Erro!');
    }
    eval('http_request.onreadystatechange=' + returnFunction + ';');
    http_request.open('POST', requestURL, true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(requestData);
}
function ajax(rU, rD, rF) {
    ajaxRequest(rU, rD, 'function(){if(http_request.readyState==4){if(http_request.status==200){' + rF + '}}}');
}


function teste() {
    requestURL = 'login.php';
    requestData = '';
    returnFunction = 'document.getElementById("form_registo").innerHTML=http_request.responseText;';
    requestType = 'POST';
    ajax(requestURL, requestData, returnFunction);
}

function procurar(palavra, e) {
    var r = document.getElementById('resultados');
    var r1 = document.getElementById('resultado_1');

    if (window.event)
    {
        x = window.event.keyCode;
    } else
    {
        x = e.which;
    }


    if (x == 40 && r1 && pos_resultados < document.getElementById('num_resultados').value) {
        pos_resultados++;
        try {
            document.getElementById('resultado_' + pos_resultados).className = 'selected';
        } catch(error) {}
        try {
            document.getElementById('resultado_' + (pos_resultados - 1)).className = 'unselected';
        } catch(error) {}
    } else if (x == 38 && r1 && pos_resultados > 0) {
        pos_resultados--;
        try {
            document.getElementById('resultado_' + pos_resultados).className = 'selected';
        } catch(error) {}
        try {
            document.getElementById('resultado_' + (pos_resultados + 1)).className = 'unselected';
        } catch(error) {}
    }
    else if (x != 13) {
        if (palavra.length > 0) {
            xmlhttp0 = null;
            if (window.XMLHttpRequest)
            {
                xmlhttp0 = new XMLHttpRequest();
            } else if (window.ActiveXObject)
            {
                xmlhttp0 = new ActiveXObject("Microsoft.XMLHTTP");
            }

            if (xmlhttp0 != null)
            {
                xmlhttp0.onreadystatechange = state_Change0;
                xmlhttp0.open("GET", 'includes/comum/procurar.php?p=' + palavra, true);
                xmlhttp0.send(null);
            } else
            {
                alert("Your browser does not support XMLHTTP.");
            }
        } else {
            r.style.display = "none";
            pos_resultados = 0;
        }
    }
}

function state_Change0() {
    if (xmlhttp0.readyState == 4) {
        var r = document.getElementById('resultados');
        if (xmlhttp0.status == 200) {
            r.style.display = 'block';
            r.innerHTML = xmlhttp0.responseText;
            pos_resultados = 0;
            Shadowbox.init({
                skipSetup: true
            });
            Shadowbox.setup();
        } else
        {
            alert("Problem retrieving data:" + xmlhttp0.statusText);
        }
    }
}

function GetXmlHttpObject()
 {
    if (window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}

function play_video(video) {
    swfobject.getObjectById('flashTV').playVideo('../media/video/publicidade/' + video);
}

function abre(j) {
    r = document.getElementById('resultados');
    r.innerHTML = '';
    r.style.display = 'none';
    Shadowbox.open({
        player: 'iframe',
        content: j,
        width: 900,
        height: 600
    });
}
function abre2(id) {
    r = document.getElementById('resultados');
    r.innerHTML = '';
    r.style.display = 'none';
    url = URL_DIR + 'item.php?id=' + id;
    Shadowbox.open({
        player: 'iframe',
        content: url,
        width: 960,
        height: 500
    });
}
