/*
variáveis globais
*/
// variáveis determinantes de browsers
var isN4 = (document.layers) ? true : false;
var isIE = (document.all) ? true : false;
var isDOM = (document.getElementById && !document.all) ? true : false;

/*
PrintPage()
função responsável por chamar a caixa de diálogo do navegador para impressão.
*/
function PrintPage() {
    if (isIE)
        window.print();
    else
        alert('Por favor selecione a opcao "Arquivo -> Imprimir" do menu superior para imprimir.');
}

/*
função que avança o focus de uma caixa de texto para a seguinte 

*/
function GoToNext(size, obj1, obj2) {
    if (document.getElementById(obj1.id).value.length >= size) {
        document.getElementById(obj2.id).focus();

    }

}

/*
OpenPopup()
função genérica para abertura de popups no site.
*/
function OpenPopup(idPopup, url, popupW, popupH) {
    window.open(url, idPopup, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + popupW + ',height=' + popupH + ',top=55,left=55');
}

//function OpenPopupRemenber(url)
//{
//    window.open(url,'ProductRemember','toolbar=no,status=no,menubar=no,scrollbars=no,resizeable=no,top=100,left=50,width=320,height=480');
//}

function OpenPopupRemenber(url) {
    window.open(url, 'ProductRemember', 'toolbar=no,status=no,menubar=no,scrollbars=no,resizeable=no,top=100,left=50,width=432,height=375');
}



function OpenGiftCardPopup(idPopup, url, popupW, popupH) {
    window.open(url, idPopup, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + popupW + ',height=' + popupH + ',top=55,left=55');
}



function oPenPopupShipCost(zipCode, zipCodeComplement) {
    var zipfull = zipCode + zipCodeComplement;
    window.open('popupshipcost.aspx?zip=' + zipfull, null, 'width=500,height=200')
    return false;
}

/*
ValidateNumberOfChars()
função responsável por validar a quantidade de caracteres dentro de uma área de texto.
*/
function ValidateNumberOfChars(textBox, limit, divResponse) {

    var validKey = true;
    var obj = document.getElementById(textBox);
    var divResponse = document.getElementById(divResponse);
    var diff = limit - obj.value.length;

    if (diff < 0 &&
		window.event.keyCode != 8 &&
		window.event.keyCode != 17 &&
		!(window.event.keyCode >= 33 && window.event.keyCode <= 40) &&
		window.event.keyCode != 46
		) {
        obj.value = obj.value.substr(0, limit);
        alert('Atenção: Você não pode exceder ' + limit + ' caracteres neste campo!');
        validKey = false;
    }

    divResponse.innerHTML = "Total de <font color=\"red\"><strong>" + obj.value.length + "</strong></font> caracteres digitados de no máximo <strong>" + limit + "</strong>.";

    return validKey;
}

//// Abre popup de zoom de imagem.
//function ProductZoom(imageUrl, fgType, idProduct)
//{                                     
//    pLX = 625;
//	pAY = 560;
//	xx=parseInt(((screen.width-pLX-8)/2));
//	yy=parseInt(((screen.height-pAY-15)/2));
//	pUrl = 'iframe_productZoom.aspx?productId=' + idProduct + '&img=' + imageUrl + '&type=' + fgType;
//	pTit = 'Vertico20';

//	s = window.open(pUrl, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + pLX + ', height=' + pAY + ', top=' + yy + ', left=' + xx + ', screenX=' + xx + ', screenY=' + yy);		
//}

// Abre popup de zoom de imagem.
function ProductEvaluationPopUp(imageUrl, fgType, idProduct) {
    pLX = 640;
    pAY = 560;
    xx = parseInt(((screen.width - pLX - 8) / 2));
    yy = parseInt(((screen.height - pAY - 15) / 2));
    pUrl = 'iframe_productevaluation.aspx?productId=' + idProduct;
    pTit = 'Vertico20';

    s = window.open(pUrl, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + pLX + ', height=' + pAY + ', top=' + yy + ', left=' + xx + ', screenX=' + xx + ', screenY=' + yy);
}

/* Imagens nao utilizam mais o WebPath, pois o caminho esta no campo da tabela */
function ChangeImage(sWebPath, sImgBig, sImgZoom, idProduct) {

    var imgBig;
    var refProduct;

    if (isDOM) {
        imgBig = document.getElementById("ctl00_ContentSite_imgProductImgBig");
        imgBig.src = sImgBig;
        refProduct = document.getElementById("ctl00_ContentSite_refProduct");
        refProduct.href = "javascript:ProductZoom('" + sImgBig + "',0,'" + idProduct + "');";
    }
    else if (isN4) {
        //document.layers["imgBig"].src = sWebPath + "images/product/" + sImgBig;
        document.layers["imgBig"].src = sImgBig;
        document.layers["imgProductZoom"].src = sImgZoom;

        if (sImgZoom != "") {
            //document.layers["imgProductBig"].src = "images/product/" + sImgBig;
            document.layers["imgProductBig"].src = sImgBig;
            document.layers["ctl00$ContentSite$hdnFgZoom"].value = "true";
            document.layers["dvImageBig"].style.display = "none";
            document.layers["dvImageBig"].style.visibility = "hidden";
            document.layers["dvImageZoom"].style.display = "block";
            document.layers["dvImageZoom"].style.visibility = "visible";
            document.layers["dvZoomViewer"].style.display = "block";
            document.layers["dvZoomViewer"].style.visibility = "visible";

        }
        else {
            document.layers["ctl00$ContentSite$hdnFgZoom"].value = "false";
            document.layers["dvImageBig"].style.display = "block";
            document.layers["dvImageBig"].style.visibility = "visible";
            //document.layers["imgBig"].src = sWebPath + "images/product/" + sImgBig;
            document.layers["imgBig"].src = sImgBig;
            document.layers["dvImageZoom"].style.display = "none";
            document.layers["dvImageZoom"].style.visibility = "hidden";
            document.layers["dvZoomViewer"].style.display = "none";
            document.layers["dvZoomViewer"].style.visibility = "hidden";
        }
    }
    else if (isIE) {
        imgBig = document.all["ctl00_ContentSite_imgProductImgBig"];
        imgBig.src = sImgBig;
        refProduct = document.all["ctl00_ContentSite_refProduct"];
        refProduct.href = "javascript:ProductZoom('" + sImgBig + "',0,'" + idProduct + "');";
    }

    //this.sImgBig = sImgBig;
}

// Muda a imagem de Zoom do produto de acordo com a imagem adicional escolhida.
function ChangeZoomImage(sPath, sImgZoomName, oImgZoom) {
    if (isDOM) {
        document.getElementById(oImgZoom).src = sPath + sImgZoomName;
    }
    else if (isN4) {
        document.layers[oImgZoom].src = sPath + sImgZoomName;
    }
    else if (isIE) {
        document.all[oImgZoom].src = sPath + sImgZoomName;
    }
}

function TopSellersVisibleDiv(obj1, obj2, obj3) {
    obj1.className = 'visiblediv';
    obj2.className = 'invisiblediv';
    obj3.className = 'invisiblediv';
}



function ProductStatus(obj1, obj2, obj3, obj4, obj5, callerButton) {

    obj1.className = 'visiblediv conteudo_abas_detalhe';
    obj2.className = 'invisiblediv';
    obj3.className = 'invisiblediv';
    obj4.className = 'invisiblediv';
    obj5.className = 'invisiblediv';

    if (isDOM) {
        document.getElementById('btnjali').src = "images/bt_ja_li.gif";
        document.getElementById('btnqueroler').src = "images/bt_quero_ler.gif";
        document.getElementById('btnestoulendo').src = "images/bt_estou_lendo.gif";
        document.getElementById('btnfavorito').src = "images/bt_favoritos.gif";
        document.getElementById('btncomentados').src = "images/bt_livros_comentados.gif";
    }
    else {
        document.all['btnjali'].src = "images/bt_ja_li.gif";
        document.all['btnqueroler'].src = "images/bt_quero_ler.gif";
        document.all['btnestoulendo'].src = "images/bt_estou_lendo.gif";
        document.all['btnfavorito'].src = "images/bt_favoritos.gif";
        document.all['btncomentados'].src = "images/bt_livros_comentados.gif";
    }
    switch (callerButton.id) {
        case 'btnjali': callerButton.src = "images/bt_ja_li_2.gif"; break;
        case 'btnqueroler': callerButton.src = "images/bt_quero_ler_2.gif"; break;
        case 'btnestoulendo': callerButton.src = "images/bt_estou_lendo_2.gif"; break;
        case 'btnfavorito': callerButton.src = "images/bt_favoritos_2.gif"; break;
        case 'btncomentados': callerButton.src = "images/bt_livros_comentados_2.gif"; break;
    }
}

function ProductDescriptionDetail(obj1, obj2, obj3, obj4, obj5, callerButton, idProductType) {

    document.getElementById(obj1).className = 'visiblediv conteudo_abas_detalhe';
    document.getElementById(obj2).className = 'invisiblediv';
    document.getElementById(obj3).className = 'invisiblediv';
    document.getElementById(obj4).className = 'invisiblediv';
    document.getElementById(obj5).className = 'invisiblediv';

    var btnBoxGeneric = document.getElementById('ctl00_ContentSite_btnBoxGeneric');

    if (isDOM) {
        // Se o produto for livro, DVD, blu-ray ou e-Book exibe a aba sinopse, se não, exibe a aba descrição
        if (idProductType == 1 || idProductType == 3 || idProductType == 4 || idProductType == 10)
            document.getElementById('ctl00_ContentSite_btnFirstTabButton').src = "images/bt_sinopse.gif";
        else
            document.getElementById('ctl00_ContentSite_btnFirstTabButton').src = "images/bt_descricao.gif";

        document.getElementById('ctl00_ContentSite_btnEspecificacoesProduct').src = "images/bt_especificacoes.gif";
        document.getElementById('ctl00_ContentSite_btnOpiniaoProduct').src = "images/bt_opiniao.gif";
        document.getElementById('ctl00_ContentSite_btnTagsProduct').src = "images/bt_tag.gif";

        if (btnBoxGeneric != null)
            if (idProductType == 1)
                btnBoxGeneric.src = "images/bt_primeiro_capit_1.gif";
            else
                btnBoxGeneric.src = "images/bt_veja_mais_1.gif";
    }
    else if (isN4) {
        document.layers['ctl00_ContentSite_btnSinopseProduct'].src = "images/bt_sinopse.gif";
        document.layers['btnDescricaoProduct'].src = "images/bt_descricao.gif";
        document.layers['btnOpiniaoProduct'].src = "images/bt_opiniao.gif";
        document.layers['ctl00_ContentSite_btnTagsProduct'].src = "images/bt_tag.gif";

        if (btnBoxGeneric != null) {
            document.layers['btnBoxGeneric'].src = "images/bt_veja_mais_1.gif";
        }

        if (capituloImage != null) {
            document.layers['btnLivroPDF'].src = "images/bt_primeiro_capit_1.gif";
        }
    }
    else if (isIE) {
        // Se o produto for livro, DVD,  blu-ray ou e-Book exibe a aba sinopse, se não, exibe a aba descrição
    if (idProductType == 1 || idProductType == 3 || idProductType == 4 || idProductType == 10)
            document.all['ctl00_ContentSite_btnFirstTabButton'].src = "images/bt_sinopse.gif";
        else
            document.all['ctl00_ContentSite_btnFirstTabButton'].src = "images/bt_descricao.gif";

        document.all['ctl00_ContentSite_btnEspecificacoesProduct'].src = "images/bt_especificacoes.gif";
        document.all['ctl00_ContentSite_btnOpiniaoProduct'].src = "images/bt_opiniao.gif";
        document.all['ctl00_ContentSite_btnTagsProduct'].src = "images/bt_tag.gif";

        if (btnBoxGeneric != null)
            if (idProductType == 1)
                btnBoxGeneric.src = "images/bt_primeiro_capit_1.gif";
            else
                btnBoxGeneric.src = "images/bt_veja_mais_1.gif";
    }

    switch (callerButton.id) {
        case 'ctl00_ContentSite_btnFirstTabButton':
            if (idProductType == 1 || idProductType == 3 || idProductType == 4 || idProductType == 10)
                callerButton.src = "images/bt_sinopse_2.gif";
            else
                callerButton.src = "images/bt_descricao_2.gif";
            break;
        case 'ctl00_ContentSite_btnEspecificacoesProduct': callerButton.src = "images/bt_especificacoes_2.gif"; break;
        case 'ctl00_ContentSite_btnOpiniaoProduct': callerButton.src = "images/bt_opiniao_2.gif"; break;
        case 'ctl00_ContentSite_btnTagsProduct': callerButton.src = "images/bt_tag_2.gif"; break;
        case 'ctl00_ContentSite_btnBoxGeneric':
            if (idProductType == 1)
                callerButton.src = "images/bt_primeiro_capit_2.gif";
            else
                callerButton.src = "images/bt_veja_mais_2.gif";
            break;
    }
}

function ShowProductEvaluation(link, div) {
    document.getElementById(link).style.visibility = "hidden";
    document.getElementById(link).style.display = "none"
    document.getElementById(div).style.visibility = "visible";
    document.getElementById(div).style.display = "block";
}

