/*
	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=auto,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=483,height=544');
} 


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);
		
}

//// Muda a imagem do produto de acordo com a imagem adicional clicada.
//function ChangeImage(sWebPath, sImgBig, oImgBig, sImgZoom, oAImgSmall, idProduct)
//{

//    if (isDOM)
//    {
//        document.getElementById(oImgBig).src = sWebPath + "/images/product/" + sImgBig
//        if (sImgZoom != "")
//            document.getElementById(oAImgSmall).setAttribute("href", "javascript:ProductZoom('" + sImgZoom + "','1', '" + idProduct + "');");
//        else
//            document.getElementById(oAImgSmall).removeAttribute("href");
//    }
//    else if (isN4)
//    {
//        document.layers[oImgBig].src = sWebPath + "/images/product/" + sImgBig
//        if (sImgZoom != "")
//            document.layers[oAImgSmall].setAttribute("href", "javascript:ProductZoom('" + sImgZoom + "','1', '" + idProduct + "');");
//        else
//            document.layers[oAImgSmall].removeAttribute("href");
//    }
//    else if (isIE)
//    {
//        document.all[oImgBig].src = sWebPath + "/images/product/" + sImgBig
//        if (sImgZoom != "")
//            document.all[oAImgSmall].setAttribute("href", "javascript:ProductZoom('" + sImgZoom + "','1', '" + idProduct + "');");
//        else
//            document.all[oAImgSmall].removeAttribute("href");
//    }
//          
//}


// Muda a imagem do produto de acordo com a imagem adicional clicada.
function ChangeImage(sWebPath, sImgBig, sImgZoom, idProduct) {
    
    $("imgProductBig").attr('src', sWebPath + "/images/product/" + sImgBig);
    $("imgProductZoom").attr('src', sWebPath + "/images/product/" + sImgZoom);
    this.sImgBig = sImgBig;

    return false;

}

function ChangeImage2(sWebPath, sImgBig, sImgZoom, idProduct) {
    
    if(document.getElementById)
        document.getElementById("imgProductBig").src = sWebPath + "/images/product/" + sImgBig;
    if(document.layers)
        document.layers["imgProductBig"].src = sWebPath + "/images/product/" + sImgBig;
    if(document.all)
        document.all["imgProductBig"].src = sWebPath + "/images/product/" + 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;
    }
}

function OpenPopupEvaluation(url)
{
    window.open(url,'ProductEvaluation','toolbar=no,status=no,menubar=no,scrollbars=yes,resizeable=no,top=100,left=50,width=330,height=360');
} 

function OpenPopupIndicate(idProduct) {
    pLX  = 483;
    pAY  = 584;
    xx   = parseInt(((screen.width-pLX-8)/2));
    yy   = parseInt(((screen.height-pAY-15)/2));
	pUrl = 'productpopupindicate.aspx?idproduct=' + idProduct;
    		
	s = window.open(pUrl, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + pLX + ', height=' + pAY + ', top=' + yy + ', left=' + xx + ', screenX=' + xx + ', screenY=' + yy);		
}

function ClearField(field, text)
{          
    if (isDOM) 
    {      
        if (document.getElementById(field) != null && document.getElementById(field).value == text) 
            document.getElementById(field).value = '';                          
    }     
    else if (isN4) 
    {
        if (document.layers[field] != null && document.layers[field].value == text) 
            document.layers[field].value = '';    
    }        
    else if (isIE)
    {               
        if (document.all[field] != null && document.all[field].value == text) 
            document.all[field].value = '';        
    } 
} 

function FillField(field, text)
{          
    if (isDOM) 
    {   
        if (document.getElementById(field) != null && document.getElementById(field).value == '') 
            document.getElementById(field).value = text;                          
    }     
    else if (isN4) 
    {
        if (document.layers[field] != null && document.layers[field].value == '') 
            document.layers[field].value = text;    
    }        
    else if (isIE)
    {           
        if (document.all[field] != null && document.all[field].value == '') 
            document.all[field].value = text;        
    } 
} 

function OpenPopupStaticText( url, vwidth, vheight )
{
    window.open(url,'StaticText','toolbar=no,status=no,menubar=no,scrollbars=yes,resizeable=no,top=100,left=50,width='+vwidth+',height='+ vheight + '');
}

function pegarPosicaoX(objeto) {
    var atual_left = 0;
    if (objeto.offsetParent) {
        while (objeto.offsetParent) {
            atual_left += objeto.offsetLeft
            objeto = objeto.offsetParent;
        }
    }
    return atual_left;
}

function pegarPosicaoY(objeto) {
    var atual_top = 0;
    if (objeto.offsetParent) {
        while (objeto.offsetParent) {
            atual_top += objeto.offsetTop
            objeto = objeto.offsetParent;
        }
    }
    return atual_top;
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

// Converte uma string para um tipo bool
String.prototype.bool = function() {
    return (/^true$/i).test(this);
};
// EX: var x = 'true'; var y = x.bool(); Resultado: x !== true && y === true

// Funções abstratas (implementadas pelo controlador de histórico, quando necessário)
function RequestSetHash() { }

// Atalho para a função "document.getElementById"
var $get = function(x) { return document.getElementById(x); }

// INÍCIO :: Funções para Centralização de Elementos na tela
// Uso: Estas funções são utilizadas principalmente para "centralizar" o "QuickLook" 
// **********************************************************************************************
/*
Function:
$hCenterAbsolute
Center an object with an absolut positioning (horizontal)
	
Returns:
if reValue is true will return the left position to center the object
otherwise center the object horizontally
	
Arguments:
obj is the object to be centerd
reValue boolean value to either return the left position if true
or move the object if false
	
Example:
HTML: <div id="div1" style="position:absolute;">Test object</div>
... later
Script:
$hCenterAbsolut("div1");
*/
var $hCenterAbsolute = function(obj, reValue) {
    var elm = obj;
    obj = $(elm);

    if (obj && elm) {
        var x = obj.width(), y = obj.height();
        var sx = $(window).scrollLeft();
        var wx = $(document).width();

        var isRelative = false;
        var offsetLeft = 0;
        var parentNode = elm.parentNode;
        while (parentNode) {
            if (parentNode.offsetLeft)
                offsetLeft += parseInt(parentNode.offsetLeft, 10);

            parentNode = parentNode.parentNode;
        }

        var l = ((wx - x) / 2) - offsetLeft + sx;

        if (reValue) return l;
        else elm.style.left = l + "px";
    }
};
/*
Function:
$vCenterAbsolute
Center an object with an absolut positioning (verticlly)
	
Returns:
if reValue is true will return the top position to center the object
otherwise center the object verticlly
	
Arguments:
obj is the object to be centerd
reValue boolean value to either return the top position if true
or move the object if false
	
Example:
HTML: <div id="div1" style="position:absolute;">Test object</div>
... later
Script:
$vCenterAbsolute("div1");
*/
var $vCenterAbsolute = function(obj, reValue) {
    var elm = obj;
    obj = $(elm);

    if (obj && elm) {
        var x = obj.width(), y = obj.height();
        var sy = $(window).scrollTop();
        var wy = $(window).height();

        var offsetTop = 0;
        var parentNode = elm.parentNode;
        while (parentNode) {
            if (parentNode.offsetTop)
                offsetTop += parseInt(parentNode.offsetTop, 10);

            parentNode = parentNode.parentNode;
        }

        var t = ((wy - y) / 2) - offsetTop + sy;

        if (reValue) return t;
        else elm.style.top = t + "px";
    }
};
/*
Function:
$centerAbsolute
Center an object with an absolut positioning on the screen
	
Returns:
if reValue is true will return the object's top and left (as an object)
position to center on the screen
otherwise center the object on the screen
	
Arguments:
obj is the object to be centerd
reValue boolean value to either return the object's top and left (as an object)
position to center on the screen
or move the object if false
	
Example:
HTML: <div id="div1" style="position:absolute;">Test object</div>
... later
Script:
$centerAbsolute("div1");
*/
var $centerAbsolute = function(obj, reValue) {
    if (reValue) {
        return { 'left': $hCenterAbsolute(obj, true),
            'top': $vCenterAbsolute(obj, true)
        };
    }
    else {
        $hCenterAbsolute(obj, false);
        $vCenterAbsolute(obj, false);
    }
};
// FIM :: Centralização de Elementos
// **********************************************************************************************

$(document).ready(function(){
	pegaAltura('.conteudo_miolo_geral');
	pegaAltura('.conteudo_detalhe_produto_geral');
	//pegaAltura('.conteudo_detalhe_produto');
	detectFirula()
});
function pegaAltura(elemento) {
    if (elemento == '.conteudo_detalhe_produto_geral') {
        $(elemento).height($('.conteudo_detalhe_produto').height() + $('.listagem_compre_tambem').height() + $('.texto_abas').height() + 70);
    }
    else {
        if (($(elemento).height()) < ($('.coluna_banners_direita').height())) {
            $(elemento).height($('.coluna_banners_direita').height());
        }
    }
	//alert($('.coluna_banners_direita').height());
}
function detectFirula(){
	if($("*").hasClass('firula_home_banners_bot')){
		$('.banner_conteudo_717_listagem').css({'padding-top':90});
	}
}
