// 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;
    }
}
*/
function callPostBack() {
    
    var boleanValue
    for (i = 0; i < document.aspnetForm.Radio1.length; i++) {
        if (document.aspnetForm.Radio1[i].checked) {             
           boleanValue = true;    
            break;
        }
        else {
            document.getElementById('divErrorRadio').className = 'visiblediv'; 
            //divErrorRadio.className = 'visiblediv'; 
            boleanValue = false;
        }
    }
  
   return boleanValue;
}
// 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=no,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=498,height=395')
    return false;
}
function oPenPopupExpressDelivery() {
    window.open('PopUpExpressDelivery.htm', null, 'width=500,height=280')
    return false;
}
function oPopUpSecurityCode() {
    window.open('PopUpSecurityCode.htm', null, 'width=450,height=552')
    return false;
}
function oPenPopUpCustomerComment() {
    window.open('PopUpCustomerComment.aspx', null, 'width=426,height=350')
    return false;
}
function ValidateNumberOfChars2(textBox, limit, divResponse,e)
{
	var validKey = true;
	var obj = document.getElementById(textBox);
	var divResponse = document.getElementById(divResponse);
	var diff = limit - obj.value.length;
	var e= (window.event)? event : e;
	var intKeyCode = (e.keyCode)? e.keyCode: e.charCode;
	
    if(diff < 0 && intKeyCode != 8 && intKeyCode != 17 &&	!(intKeyCode >= 33 && intKeyCode <= 40) && intKeyCode != 46)
    {
	    obj.value = obj.value.substr(0, limit);
	    alert('Atenção: Você não pode exceder ' + limit + ' caracteres neste campo!');
	    validKey = false;
    }
	
	divResponse.innerHTML = "<span class='font_12_cinza_claro_pontos_referencia'>Total de &nbsp;</span><span class='font_12_vermelho_pontos_referencia'>" + obj.value.length + " </span><span class='font_12_cinza_claro_pontos_referencia'> caracteres digitados de no m&#225;ximo </span><span class='font_12_preto_pontos_referencia'>" + limit + "</span>.";
	return validKey;
}
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 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 alertkey()
{
window.alert("a");
}
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)
{    
    var u = document.forms[0].txtZip.value;
    alert(u);
    u = u.replace("-","");
    alert(u);
    window.open(e.href + u, 'CEP', 'width=' + w + ',height=' + h + ',left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2));
    return false;
}
function PictInt(evt)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode>=48 && keyCode <= 57)  return true;
    else event.returnValue = false; 
}
function callcenter(parentPage){
    if (parentPage == null || parentPage == "")
        welcomeWindow = window.open('http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=9F940074906BA01386A3', '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=9F940074906BA01386A3&origem=' + parentPage, 'callcenter', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=430,height=400');
    //welcomeWindow = window.open('popupchat.htm', 'callcenter','width=430,height=400');
    //welcomeWindow = window.open('chat_unavailable.htm', 'callcenter', "width=295,height=250');
    
}
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 callcenterunavailable(){
    welcomeWindow = window.open("chat_unavailable.htm", "callcenter", "width=295,height=340");
}

function setVisibility(layerName, on) {
    if(document.getElementById(layerName) == null)
        return;

    if (on)
        document.getElementById(layerName).className = "visiblediv";
    else
		document.getElementById(layerName).className = "invisiblediv";
}
//Comandos usados para a exibição do PopUp de ajuda
var timeOut;
function divflutuante()
{
	timeOut = setTimeout("showDiv()",420000);
	
}
function showDiv()
{   
    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 start()
{
	divflutuante();
}
function hideDiv()
{
	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);this.cy += (pY + this.sy - this.cy);
        this.sP(this.cx, this.cy);
        setTimeout(this.id + "_obj.flt()", 0);
        //DivValue();
    }
    return el;
}

$(function() {

    var $ = jQuery.noConflict();
    // Evento responsável por expandir o menu horizontal
    $('ul#menu > li').mouseenter
    (
        function() 
        {    
            var subMenu = $('ul#menu li > ul');
        
            if(subMenu.length > 0)
            {
                $(this).addClass('aberto');
                $('ul#menu li.aberto ul.sub-menu').addClass('sub-menu-aberto');
            }
        }
    );   
    // Evento responsável por retrair o menu horizontal
    $('ul#menu > li').mouseleave
    (
        function() 
        {
            $('ul#menu li.aberto ul.sub-menu-aberto').removeClass('sub-menu-aberto');
            $(this).removeClass('aberto');
        }
    );
    //usada para remover o style dos validationsSummary do site
    $(function() {

        var $ = jQuery.noConflict();
        
        
        $("div.validationSummaryError").removeAttr("style");
        
    });
});

