function abreVisita1(url){
        var windowprops = "width=750,height=500,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";
        window.open (url, '' , windowprops)
}
function abreVisita2(url){
        var windowprops = "width=780,height=600,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";
        window.open (url, '' , windowprops)
}
function abrePopup(url){
        var windowprops = "width=500,height=310,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";
        window.open (url, '' , windowprops)
}
function abreModalidades(url){
        var windowprops = "width=500,height=400,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";
        window.open (url, '' , windowprops)
}
function abrePrecoBaixo(url){
        var windowprops = "width=545,height=645,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";
        window.open (url, '' , windowprops)
}
function abreMelhorCompra(url){
        var windowprops = "width=650,height=500,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";
        window.open (url, '', windowprops)
}
function openBigImage(imagem,num,id){
    var windowprops = "width=600,height=625,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no,top=10,left=10";
    var win = window.open ('imagem.php?id='+ id +'&imagem='+imagem+'&num='+num, 'imagens' , windowprops)
    win.focus();
}

var inicio = 1;

function abreCreditoOnLoad(nome){
    if(inicio == 1){
        inicio = 0;
        abreCredito(nome);
    }
}

function abreCredito(nome){
    var style;

    if (document.getElementById) {
        style = document.getElementById("simuladorCredito").style.display;
    }else{
        if (document.layers) { // Netscape 4
            style = document.hideShow.display;
        }else{
            style = document.all.hideShow.style.display;
        }
    }

    if(style == 'none'){
        showdiv(nome);
    }else{
        hidediv(nome);
    }
}

function hidediv(nome) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(nome).style.visibility = 'hidden';
        document.getElementById(nome).style.display = 'none';
        document.getElementById("cross").src = '/skins/2008/carrinho/cross.gif';
    } else {
        if (document.layers) { // Netscape 4
            document.hideShow.visibility = 'hidden';
            document.hideShow.display = 'none';
            document.cross.src = '/skins/2008/carrinho/cross.gif';
        } else { // IE 4
            document.all.hideShow.style.visibility = 'hidden';
            document.all.hideShow.style.display = 'none';
            document.all.cross.src = '/skins/2008/carrinho/cross.gif';
        }
    }
}

function showdiv(nome) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(nome).style.visibility = 'visible';
        document.getElementById(nome).style.display = 'block';
        document.getElementById("cross").src = '/skins/2008/carrinho/minus.gif';
    } else {
        if (document.layers) { // Netscape 4
            document.hideShow.visibility = 'visible';
            document.hideShow.display = 'block';
            document.cross.src = '/skins/2008/carrinho/minus.gif';
        } else { // IE 4
            document.all.hideShow.style.visibility = 'visible';
            document.all.hideShow.style.display = 'block';
            document.all.cross.src = '/skins/2008/carrinho/minus.gif';
        }
    }
}



var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)

var tempX   = 0;
var tempY   = 0;
var idImg   = "img-pequena-2"; // id da imagem a ampliar
var moveDiv = "img-popup-2";
var idImgG  = "img-grande-2";
var idPremios = "premios-0";
var divPremios = "premios0";
var onDrag  = false;

function mudaId(id){
    stopDrag(moveDiv);
    onDrag = false;

    idImg = "img-pequena-" + id;
    moveDiv = "img-popup-" + id;
    idImgG  = "img-grande-" + id;
}

function mudaPremiosId(id){
    idPremios = "premios-" + id;
    divPremios = "premios" + id;
}

function getOffsetLeft (el) {
    var ol = el.offsetLeft;
    while ((el = el.offsetParent) != null)
        ol += el.offsetLeft;
    return ol;
}
function getOffsetTop (el) {
    var ot = el.offsetTop;
    while((el = el.offsetParent) != null)
        ot += el.offsetTop;
    return ot;
}

function getMouseXY(e) {

    if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.scrollTop;
    } else {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
    }
    if (tempX < 0){tempX = 0;}
    if (tempY < 0){tempY = 0;}

    dragExec(e);

    return true;
}

function dragExec(e) {
    var el = IE ? event.srcElement : e.target;
    var top, left;

    if( el.id == idImg ) { // se o id corresponder a ao da imagem a ampliar entao mostra popup
        startDrag(moveDiv);
        dMove = document.getElementById(moveDiv);
        dImgG = document.getElementById(idImgG);

        if(IE && document.body.clientHeight) hgt = document.body.clientHeight;
        else hgt = (IE)?document.documentElement.clientHeight:window.innerHeight;

        hgt = hgt / 2;

        if(IE && document.body.scrollTop) sclTop = document.body.scrollTop;
        else sclTop = (IE)?document.documentElement.scrollTop:window.pageYOffset;

        dMove.style.top = sclTop + hgt - (dImgG.height/2);

        if(IE && document.body.clientWidth) wdt = document.body.clientWidth;
        else wdt = (IE)?document.documentElement.clientWidth:window.innerWidth;

        wdt = wdt / 2;

        if((tempX) < wdt)
            dMove.style.left  = (tempX + 25) + "px";
        else
            dMove.style.left  = (tempX - 25 - (dImgG.width)) + "px";

        onDrag = true;
    } else {
        stopDrag(moveDiv);
        onDrag = false;
    }

    // div premios
    if(el.id == idPremios) {
        startDrag(divPremios);
        dMove = document.getElementById(divPremios);
        dImgG = document.getElementById(idPremios);

        if(IE && document.body.clientHeight) hgt = document.body.clientHeight;
        else hgt = (IE)?document.documentElement.clientHeight:window.innerHeight;

        if(IE && document.body.scrollTop) sclTop = document.body.scrollTop;
        else sclTop = (IE)?document.documentElement.scrollTop:window.pageYOffset;

        top = getOffsetTop(dImgG) + (parseInt(dImgG.height)/2);
        if(parseInt(top-sclTop+250) > hgt){
            top = top - 250;
        }
        dMove.style.top = top + "px";

        if(IE && document.body.clientWidth) wdt = document.body.clientWidth;
        else wdt = (IE)?document.documentElement.clientWidth:window.innerWidth;

        //dMove.style.left = tempX + (parseInt(dImgG.width)/2) + "px";
        left = tempX + (parseInt(dImgG.width)/2);
        if(parseInt(left+250+20) > wdt){
            left = left - 250 - (parseInt(dImgG.width));
        }
        dMove.style.left = left + "px";

        onDrag = true;
    } else {
        stopDrag(divPremios);
        onDrag = false;
    }
}

function startDrag(div) {
    if(!onDrag) {
        var elMove = document.getElementById(div);

        if(elMove){
            elMove.style.display    = "block";
            elMove.style.visibility = "visible";
        }
    }
    return false;
}


function stopDrag(div) {
    var elMove = document.getElementById(div);

    if(elMove){
        elMove.style.display    = "none";
        elMove.style.visibility = "hidden";
    }

    return false;
}

document.onmousemove = getMouseXY;
//if(!IE) document.onscroll = getMouseXY;
//else window.onscroll = getMouseXY;


function hideRow(id){
    var obj = document.getElementById(id);

    if(obj){
        obj.style.visibility = 'hidden';
        obj.style.display = 'none';
    }

}

function imprimir(id,mostra){
  if(mostra)
        window.open ('imprime.php?id='+id+'&tab=fichatecnica', '');
  else
        window.open ('imprime.php?id='+id+'&tab=', '');
}

function validaCampos(){
    if(document.frm.email.value==""){
        alert("Por favor indique o seu email.");
        return;
    }
    document.frm.submit();
}