window.onload = new function() {
    
    qtdCarrinho();
    StatusChat();
}


function StatusChat() {    
    
    $.post('handler/chat_status.ashx', function(data) {
    
        $('#lblStatusChat').html(data)
    });

    window.setTimeout("StatusChat()", 4000);
}

function url(link_url) {
    location.href = link_url;
}

function abrirLogin() {

    jQuery.facebox({ div: '#divLoginClienteBox' });
    recuperarLipar();
}

function verificaLogin() {

    $.ajax(
			{
			    type: "POST",
			    url: "handler/login.ashx",
			    data: "email=" + $('#facebox .content #txtLoginEmail').val() + "&senha=" + $('#facebox .content #txtLoginSenha').val(),
			    beforeSend: function() {
			        // enquanto a função esta sendo processada, você
			        // pode exibir na tela uma
			        $('#divLoginClienteBox #lblLoginStatus').html('Processando... ');
			        // msg de carregando
			    },
			    success: function(txt) {

			        if (txt != "ERRO") {
			            location.href = window.location.pathname + window.location.search;
			        } else {

			        $('#divLoginClienteBox #lblLoginStatus').html("<hr /><b>Login ou senha errado</b>");
			        }

			    },
			    error: function(txt) {
			        // em caso de erro você pode dar um alert('erro');
			        alert('Houve um problema interno. tente novamente mais tarde.');
			    }
			}
		);
}

function recuperarLimpar() {

    $('#divLoginClienteBox #lblLoginStatus').html("");
}
function loginMostrar() {

    $('#facebox .content #recuperarSenha').hide();
    $('#facebox .content #verificarLogin').show('slow');
    recuperarLipar();
}

function recuperarMostrar() {

    $('#facebox .content #recuperarSenha').show('slow');
    $('#facebox .content #verificarLogin').hide();
    recuperarLipar();
}


function recuperarLogin() {

    if ($('#facebox .content #txtLoginEmailRecuperar').val() == "") {
        alert('Preecha o campo e-mail.');
        return;
    }
    
    
    $.ajax(
			{
			    type: "POST",
			    url: "handler/recuperar.ashx",
			    data: "email=" + $('#facebox .content #txtLoginEmailRecuperar').val(),
			    beforeSend: function() {
			        // enquanto a função esta sendo processada, você
			        // pode exibir na tela uma
			        $('#divLoginClienteBox #lblLoginStatus').html('Processando... ');
			        // msg de carregando
			    },
			    success: function(txt) {

			       $('#divLoginClienteBox #lblLoginStatus').html('<hr /><b>' + txt + '</b>');

			    },
			    error: function(txt) {
			        // em caso de erro você pode dar um alert('erro');
			        alert('Houve um problema interno. tente novamente mais tarde.');
			    }
			}
		);
}


function addCarrinho(id) {

    var controle = "#txtQtdProduto_" + id;
    var qtd = $(controle).val();
    var div = "#divAddCarrinho_" + id;
    

    $.ajax(
			{
			    type: "POST",
			    url: "handler/add_carrinho.ashx",
			    data: "idProduto=" + id + "&qtd=" + qtd,
			    beforeSend: function() {
			        // enquanto a função esta sendo processada, você
			        // pode exibir na tela uma
			        //$('#divLoginClienteBox #lblLoginStatus').html('Processando... ');
			        // msg de carregando
			    },
			    success: function(txt) {

			        if (txt != "ERRO") {
			            $(div).html('<img src="images/img_btn_comprar_ok.gif" width="14" height="13" />');
			            $(controle).attr('disabled', true);
			            qtdCarrinho();

			        } else {
			            alert("ERRO");
			        }

			    },
			    error: function(txt) {
			        // em caso de erro você pode dar um alert('erro');
			        alert('Houve um problema interno. Verifique a quantidade de produtos ou tente novamente mais tarde.');
			    }
			}
		);
}

function qtdCarrinho() {    
    
    $.ajax(
			{
			    type: "POST",
			    url: "handler/qtd_carrinho.ashx",
			    //data: "idProduto=" + id + "&qtd=" + qtd,
			    beforeSend: function() {
			        // enquanto a função esta sendo processada, você
			        // pode exibir na tela uma
			        //$('#divLoginClienteBox #lblLoginStatus').html('Processando... ');
			        // msg de carregando
			    },
			    success: function(txt) {

			        if (txt != "ERRO") {
			            $("#top_meu_pedido").html(txt);
			        } else {
			            alert("ERRO");
			        }			        
			    },
			    error: function(txt) {
			        // em caso de erro você pode dar um alert('erro');
			        alert('Houve um problema interno. tente novamente mais tarde.');
			    }
			}
		);
}

function carrinhoSomarLinha() {

    alert("ok");

}




function qtdMais(id) {
    var controle = "#txtQtdProduto_" + id;
    var qtd = $(controle).val();
    qtd++;
    $(controle).val(qtd);
}

function qtdMenos(id) {
    var controle = "#txtQtdProduto_" + id;
    var qtd = $(controle).val();
    qtd--;
    if (qtd > 0)
        $(controle).val(qtd);
}

function alterarImagemProduto(img) {

    ("imgProduto").html("<img src=\"img_produtos/photo/09092010114553.jpg\" width=\"300\" style=\"cursor:pointer;\"/> ");
    
}



function url(link_url) {
    location.href = link_url;
}


//Inicio script ativar botão disparo
var NomeBotaoDefault = "";

function gravaDisparo(btn) {
    NomeBotaoDefault = btn;
}

function pegaTecla(event) {

    if (NomeBotaoDefault == "ctl00_ibtnBusca") {
        if (document.getElementById('ctl00_txtBuscaTop').value == "") {
            event.cancelBubble = true;
            //event.returnValue = false; 
            return;
        }
    }
    

    var c = event.keyCode;

    if (c == 13) {

        if (NomeBotaoDefault != null) {

            if (NomeBotaoDefault == '' || NomeBotaoDefault == null) {
                return true;
            }

            event.cancelBubble = true;
            event.returnValue = false;

            var oBotao = document.getElementById(NomeBotaoDefault);

            if (oBotao != null) {
                oBotao.click();
            }
        }
    }
}
//Fim script ativar botão disparo

function Verifica(event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    var caract = new RegExp(/[0-9,','{1}]+$/i);
    var caract = caract.test(String.fromCharCode(keyCode));    

    if (!caract) {
        //alert("Caracter inválido: " + String.fromCharCode(keyCode));
        alert("Digite somente números.");
        keyCode = 0;        
        return false;
    }
}


//foto produto
function trocarFoto(img, zoom) {

    $('#imgProduto').html("<div style=\"background:url(img_produtos/photo/" + img + ") no-repeat center center;width:300px;height:300px;cursor:pointer;\" onclick=\"ampliarFoto('" + img + "','" + zoom + "');\"></div>").fadeIn('slow');
}


function ampliarTecnica() {
    jQuery.facebox({ div: '#popAmpliarTecnica' });
}

function ampliarFoto(Foto, Zoom) {
    var sUrl = "img_produtos/photo_G/" + Foto;
    var sUrlPop = "produto_zoom.aspx?img=" + Foto;

    if (Zoom == 1) {
        $('#popAmpliarFoto').empty().html("<object width=\"500\" height=\"500\" type=\"application/x-shockwave-flash\" data=\"swf/zoom.swf\"><param name=\"FLASHVARS\" value=\"imgUrl=" + sUrl + "\" /><param name=\"movie\" value=\"swf/zoom.swf\" /><param name=\"BGCOLOR\" value=\"#ffffff\" /><param name=\"MENU\" value=\"false\" /><param name=\"QUALITY\" value=\"HIGH\" /><a title=\"You must install the Flash Plugin for your Browser in order to view this movie\"  href=\"http://www.macromedia.com/shockwave/download/alternates/\"><img src=\"needplugin.gif\" width=\"431\" height=\"68\"  alt=\"placeholder for flash movie\" /></a></object>");
        window.open(sUrlPop, 'page', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=500');
    }
    else {
        $('#popAmpliarFoto').empty().html("<img src='img_produtos/photo_G/" + Foto + "' />");
        jQuery.facebox({ div: '#popAmpliarFoto' });
    }
}

function abrirShowroom(Foto) {

    jQuery.facebox({ image: Foto });
}

function textoBusca() {


    var texto = document.getElementById('ctl00_txtBuscaTop').value;

    if (texto == 'Palavra-chave') 
    {
        document.getElementById('ctl00_txtBuscaTop').value = '';
    }

    if (texto == '') {
        document.getElementById('ctl00_txtBuscaTop').value = 'Palavra-chave';
    } 
}
