/*
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=350,height=335');
}


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 = 'productpopup.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);

}

//Altera a imagem selecionada, exibindo ou escondendo as divs de imgBig, imgZoom e do ícone da lupa
function ChangeImage(sWebPath, sImgBig, sImgZoom, idProduct) {

    var imgBig;
    var imgZoom;

    if (isDOM) {    
        imgBig = document.getElementById("ctl00_ContentSite_imgBig");
        imgZoom = document.getElementById("imgProductZoom");

        if (imgBig != null)
            imgBig.src = sWebPath + "images/product/" + sImgBig;

        if (imgZoom != null) {
            imgZoom.src = sWebPath + "images/product/" + sImgZoom;
        }

        document.getElementById("imgProductBig").src = "images/product/" + sImgBig;
        document.getElementById("imgProductBig").width = 295;
        document.getElementById("imgProductBig").height = 295;

        if (sImgZoom != "") {
            
            document.getElementById("dvImageBig").style.display = "none";
            document.getElementById("dvImageBig").style.visibility = "hidden";
            document.getElementById("ctl00_ContentSite_dvImageZoom").style.display = "block";
            document.getElementById("ctl00_ContentSite_dvImageZoom").style.visibility = "visible";
            document.getElementById("dvZoomViewer").style.display = "block";
            document.getElementById("dvZoomViewer").style.visibility = "visible";
            document.getElementById("ctl00_ContentSite_dvZoomIcon").style.visibility = "visible";
        }
        else {
            document.getElementById("ctl00_ContentSite_hdnFgZoom").value = "false";
            document.getElementById("dvImageBig").style.display = "block";
            document.getElementById("dvImageBig").style.visibility = "visible";
            document.getElementById("ctl00_ContentSite_dvImageZoom").style.display = "none";
            document.getElementById("ctl00_ContentSite_dvImageZoom").style.visibility = "hidden";
            document.getElementById("dvZoomViewer").style.display = "none";
            document.getElementById("dvZoomViewer").style.visibility = "hidden";
            document.getElementById("ctl00_ContentSite_dvZoomIcon").style.visibility = "hidden";
        }
    }
    else if (isN4) {
        document.layers["imgBig"].src = sWebPath + "images/product/" + sImgBig;
        document.layers["imgProductZoom"].src = sWebPath + "images/product/" + sImgZoom;

        if (sImgZoom != "") {
            document.layers["imgProductBig"].src = "images/product/" + 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";
            document.layers["ctl00_ContentSite_dvZoomIcon"].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["dvImageZoom"].style.display = "none";
            document.layers["dvImageZoom"].style.visibility = "hidden";
            document.layers["dvZoomViewer"].style.display = "none";
            document.layers["dvZoomViewer"].style.visibility = "hidden";
            document.layers["ctl00_ContentSite_dvZoomIcon"].style.visibility = "hidden";
        }
    }
    else if (isIE) {

        imgBig = document.all["ctl00_ContentSite_imgBig"];
        imgZoom = document.all["imgProductZoom"];

        if (imgBig != null)
            imgBig.src = sWebPath + "images/product/" + sImgBig;

        if (imgZoom != null)
            imgZoom.src = sWebPath + "images/product/" + sImgZoom;

        if (sImgZoom != "") {
            document.all["imgProductBig"].src = "images/product/" + sImgBig;
            document.all["dvImageBig"].style.display = "none";
            document.all["dvImageBig"].style.visibility = "hidden";
            document.all["ctl00_ContentSite_dvImageZoom"].style.display = "block";
            document.all["ctl00_ContentSite_dvImageZoom"].style.visibility = "visible";
            document.all["dvZoomViewer"].style.display = "block";
            document.all["dvZoomViewer"].style.visibility = "visible";
            document.all["ctl00_ContentSite_dvZoomIcon"].style.visibility = "visible";
        }
        else {
            document.all["ctl00_ContentSite_hdnFgZoom"].value = "false";
            document.all["dvImageBig"].style.display = "block";
            document.all["dvImageBig"].style.visibility = "visible";
            document.all["ctl00_ContentSite_dvImageZoom"].style.display = "none";
            document.all["ctl00_ContentSite_dvImageZoom"].style.visibility = "hidden";
            document.all["dvZoomViewer"].style.display = "none";
            document.all["dvZoomViewer"].style.visibility = "hidden";
            document.all["ctl00_ContentSite_dvZoomIcon"].style.visibility = "hidden";
        }
    }

    //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 + "/images/product/" + sImgZoomName;
    }
    else if (isN4) {
        document.layers[oImgZoom].src = sPath + "/images/product/" + sImgZoomName;
    }
    else if (isIE) {
        document.all[oImgZoom].src = sPath + "/images/product/" + sImgZoomName;
    }
}*/