function adicionarFavoritos(root_path, prod1_cod){
    $.ajax({
        url: root_path + "/ajax/addFavoritos/"+prod1_cod+"/",
        cache: false,
        success: function(html){
            alert(html);
        }
    });
}

function changeAction(select){

    if($('#secao').val() == 'novi') {
        $('.formBusca').attr('action', window.root_path + '/novidades/index/busca');
    } else {
        $('.formBusca').attr('action', window.root_path + '/produtos/index/busca');
    }
    
}

function validaAddProduto(){
    var boolRet = false;

    $('input.qtd-cor').each( function(){
        if($(this).val() != '' && $(this).val() > 0){
            boolRet = true;
        }
    });

    if(! boolRet){
        alert('Você precisa escolher uma quantidade para pelo menos um tamanho do produto.');
    }

    return boolRet;
}

function confirma(hp, strMsg){
    if(strMsg ==  undefined){
        strMsg = 'Deseja realmente excluir este registro?';
    }
    if (confirm(strMsg)){
        document.location = hp;
    }
}

 function novaJanela(pagina, nome, w, h, scroll){
        var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        var settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';

        window.open(pagina, nome, settings);
}

function rastreio_correios(rastreio) {
    window.open("http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI="+rastreio, "Boutique das Flores", "status=no, width=500, height=500");
}

function togle(id) {

    $('#clique' + id).each(function(){
        
        if($('#ANDAMENTO' + id).is(':visible')){
            $('#ico' + id).html('+');
            $('#ANDAMENTO' + id).hide();
        } else {
            $('#ico' + id).html('-');
            $('#ANDAMENTO' + id).show();
        }

    });

}

function initPlaceholder(){
    // PLACEHOLDER
    $(".placeholder").focus(function(){
        if ($(this).attr('title') == $(this).attr('value')){
            $(this).attr('value','');
        }
    }).blur(function(){
        if ($(this).attr('value') == ''){
            $(this).attr('value',$(this).attr('title'));
        }
    })
}

function validaData(campo)
{
    if (campo.value != '')
    {
        erro = 0;
        hoje = new Date();
        anoAtual = hoje.getFullYear();
        barras = campo.value.split('/');
        if (barras.length == 3)
        {
            dia = barras[0];
            mes = barras[1];
            ano = barras[2];
            resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual && ano >= 1900));
            if (!resultado)
            {
                campo.value = '';
                campo.focus();
                return false;
            }
        }
        else
        {
            campo.value = '';
            campo.focus();
            return false;
        }
        return true;
    }
}

function campoData(objeto, e){
    var retorno;
    var tecla = (window.event) ? event.keyCode : e.which;

    if(tecla == 8 || tecla == 13) return true;

    if((tecla > 47 && tecla < 58) || (tecla == 0)) retorno = true;
    else{
        retorno = false;
    }

    if (objeto.value.length == 2 || objeto.value.length == 5 && retorno){
        objeto.value = objeto.value + '/';
    }

    return retorno;
}

// cria mascaras para inputs
function initMasks(){
    // retiro todas as mascaras, por causa de bug se criar uma mascara que já existe
    $("input.tel-mask").unmask();
    $("input.cnpj-mask").unmask();
    $("input.cpf-mask").unmask();
    $("input.data-mask").unmask();
    $("input.cep-mask").unmask();
    $("input.hora-mask").unmask();
    /**
     *  criando as mascaras para formulários
     */
    $("input.tel-mask").mask('(99) 9999-9999');
    $("input.cnpj-mask").mask('99.999.999/9999-99');
    $("input.cpf-mask").mask('999.999.999-99');
    $("input.data-mask").mask('99/99/9999');
    $("input.cep-mask").mask('99999-999');
    $("input.hora-mask").mask('99:99');
}
