// public operations
var isN4  	= (document.layers) ? true : false;
var isIE  	= (document.all) ? true : false;
var isDOM 	= (document.getElementById && !document.all) ? true : false;

/*
// reformular procedimento
for(var i=0; i < document.forms[0].elements.length; i++){
    if((document.forms[0].elements[i].type == "text") || (document.forms[0].elements[i].type == "password")){
    document.forms[0].elements[i].onkeypress = BlockEnter;
    }
}
*/

// functions
function PrintPage()
{
	if (isIE) window.print();
	else alert('Por favor selecione a opcao "Arquivo -> Imprimir" do menu superior para imprimir.');
}
function GoToNext(size,cep1,cep2)
{
   if(document.getElementById(cep1).value.length >=size)
      document.getElementById(cep2).focus();
}
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 OpenProductRememberPopup(idProduct){
    OpenPopup('productremember', 'productremember.aspx?idproduct=' + idProduct, 330, 300);
}
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=520,height=360');
    return false;
}
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;
}
function OpenPopCenter(e, w, h)
{
    u = document.forms[0].txtZip.value;
    u += document.forms[0].txtZipComplement.value;    
    window.open(e + u, 'CEP', 'width=' + w + ',height=' + h + ',left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2));
}
function GoToNext(size,cep1,cep2)
{
   if(document.getElementById(cep1.id).value.length >=size)
      document.getElementById(cep2.id).focus();
}
function BlockEnter(e){
    if (!e)
        e = window.event;
    if(e.keyCode == 13)
        return false;
}

function ClearText(e)
{
    if (e.value == "Digite o seu e-mail")
        e.value = "";
    return this;
}
function CheckText(e)
{
    if (e.value == "")
        return e.value = "Digite o seu e-mail";
}
function callcenter(parentPage)
{
    if (parentPage == null || parentPage == "")
        welcomeWindow = window.open('http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=159200749E8E80139161', 'callcenter', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=430,height=400');
    else
        welcomeWindow = window.open('http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=159200749E8E80139161&origem=' + parentPage, 'callcenter', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=430,height=400');
}
function callcenterunavailable()
{
    welcomeWindow = window.open("chat_unavailable.htm", "callcenter", "width=295,height=340");
}
function windowOnUnLoad(window, haspopup, thispage) {
    /*
      // funcionalidade de enquete desabilitada em 28/02/07 por solicitação
      
      if (window.screenTop > 9999  && thispage == 1){ 
          if(haspopup == 0)
          {                   
            return 0;
          }
          else
          {            
            window.open('popupfaq.aspx','Enquete','height=300,width=300');
            return 1;
          } 
      } 
         return 0; 
   */
}
function ValidateKeyPress(buttonPost,e)
{
   
    var impressKeyCode = true;
    if(isIE)
    {
        if(e.keyCode == 13){
            impressKeyCode = false;
            document.getElementById(buttonPost).click();
        } 
    }
    else
    {
      
        if(e.which == 13)
        {
            impressKeyCode = false;
            document.getElementById(buttonPost).click();
        }
    }
          
    return impressKeyCode;
}
function AutoPostEmail(e,url){
    if (!e)
        e = window.event;
    if (e != null && e.keyCode == 13)
    {
        window.location.replace(url + 'newsletter.aspx?email=' + document.forms[0].txtEmail.value);
        return false;
    }
}
function OpenProductPopup(idProduct){
	OpenPopupProd("productpopup","productpopup.aspx" + "?idproduct=" + idProduct , 520, 270);
}
function OpenPopupProd(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 GoToNext(size,cep1,cep2)
{
   if(document.getElementById(cep1).value.length >=size)
      document.getElementById(cep2).focus();
}
function OpenPopup(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 OpenPopCenter(e, w, h)
{
    u = document.forms[0].txtZip.value;
    u += document.forms[0].txtZipComplement.value;    
    window.open(e.href + u, 'CEP', 'width=' + w + ',height=' + h + ',left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2));
    return false;
}
// Método inútil.
function PictInt(evt)
{
    //if (evt.keyCode >=48 && evt.keyCode <= 57)  return true;
    //else event.keyCode = false;
}
function OpenPopupImageProduct(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 setVisibility(layerName, on) {
    if(document.getElementById(layerName) == null)
        return;

    if (on)
        document.getElementById(layerName).className = "visiblediv";
    else
		document.getElementById(layerName).className = "invisiblediv";
}
function BlockEnter(e){
    if (!e)
        e = window.event;
    if (e != null && e.keyCode != null && e.keyCode == 13)
        return false;
}
//Comandos usados para a exibição do PopUp de ajuda
var timeOut;
function divflutuante()
{
	timeOut = setTimeout("showDivPopUp()",420000);
	
}
function showDivPopUp()
{   
    document.getElementById('pop').style.top = ""+(eval(getScrollHeight())+ eval(document.documentElement.clientHeight)/2)+"px"; 
    setDivMaxScreenSize("trans");
    document.getElementById('pop').className='visiblediv';
	document.getElementById('trans').className='visiblediv';
	document.getElementById('trans').className='translucent';
    
       
}
function startPopUp()
{
	divflutuante();
}
function hideDivPopUp()
{
	clearTimeout(timeOut);
	document.getElementById('pop').className='invisiblediv';
	document.getElementById('trans').className='invisiblediv';
	document.getElementById('ifrHelp').src='functions.aspx?help=1';
	
	
}
function hideDivBannerFly()
{
    document.getElementById('DivBannerFly').className='invisiblediv';
}
function setDivMaxScreenSize(div)
{
    
    document.getElementById(div).style.height=getMaxScrollHeight()+"px";
    document.getElementById(div).style.width=getMaxScrollWidth()+"px";
	
}
function getMaxScrollWidth()
{
	return document.body.offsetWidth;
}
function getMaxScrollHeight()
{
	return document.body.offsetHeight;
}
function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

// Função do Totalizador flutuante


var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";
function JSFX_FloatDiv(id, sx, sy)
{
   
    var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
    window[id + "_obj"] = el;
    if(d.layers)el.style=el;    
    el.cx = el.sx = sx;
    el.cy = el.sy = sy;
    el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
    el.flt=function()
    {
        var pX, pY;
        pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
        document.documentElement && document.documentElement.clientWidth ?
        document.documentElement.clientWidth : document.body.clientWidth;
        pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
        document.documentElement.scrollTop : document.body.scrollTop;
        if(this.sy<0)
        pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
        document.documentElement.clientHeight : document.body.clientHeight;
        this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
        this.sP(this.cx, this.cy);
        setTimeout(this.id + "_obj.flt()", 20);
//       DivValue();
    }
    return el;
}
function setVideoProductViewStatus()
{
    var showVideoProduct = document.getElementById('trVideoProduct').style.display;
    var showImageProduct = document.getElementById('trImageProduct').style.display;
    
    if(showVideoProduct =='none')
    {
        document.getElementById('trVideoProduct').style.display = 'block';
        document.getElementById('trImageProduct').style.display = 'none';
    }
    else
    {
        document.getElementById('trVideoProduct').style.display = 'none';
        document.getElementById('trImageProduct').style.display = 'block';
    }
    
}
