/* FUNCIONES JAVASCRIPT */

// Muestra emails por pantalla
// con cierta seguridad contra Spambots
function showEmail(user,domain,extension){
    email=user + "@" + domain + "." + extension;
    document.write('<a href="mailto:'+email+'">'+email+'</a>');
}

// Cambia estado botones
function resetBtnGaleria() {
    var botonera = document.getElementById("galeria");
    
    var thumbs = botonera.getElementsByTagName("div");
    var cont = 0;
    for (x = 0; x < thumbs.length; x++) {
        if (cont != 3) {
            thumbs[cont].className = "thumb";
            cont ++;
        } else {
            thumbs[cont].className = "thumb last";
            cont = 0;
        }      
    }
}

// Validar Confirmacion pedido
function validarPedido() {
    var elemento = document.getElementById("select_paises");
    if (elemento.value == "0") {
        alert(MSG_ALERT_SELECT_DESTINO);    
    } else {
        document.location.href = "http://" + sHttpHost + "/validar-cesta/login.html";
    }
}

// Validar campo cesta en Listado productos carrito
function validarCampoCestaListado(form, numero, nombre, precio) {
    if(isNaN(numero) || numero == 0) {
        alert (MSG_ALERT_NUMBER_NOOK);
        return false;
    } else {
        var frm = document.getElementById(form);
        frm.submit();
    }
}


// Eliminar línea de la cesta
function eliminarLinea(form) {
    var conf = confirm(MSG_CONFIRM_DEL_REFERENCIA);    
    
    if (conf) {
        var frm = document.getElementById(form);
        
        var del = frm.del;
        del.value = "delete";
        
        frm.submit();
    }
}


// Validar campo numérico cesta
function validarCampoCesta (numero) {
    if(isNaN(numero) || numero == 0) {
        alert (MSG_ALERT_NUMBER_NOOK);
        return false;
    } else {
        return true
    }
}


// Asignar decimales y redondear
function redondear(cantidad, decimales) {
    var cantidad = parseFloat(cantidad);
    var decimales = parseFloat(decimales);
    decimales = (!decimales ? 2 : decimales);
    return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
} 
