var precio_espana = 0;
var precio_gastos = 0;

function desplegar_MRW(id_activacion, precio)
{
    if (id_activacion == 1)
    {
        document.getElementById("MRW_invisible").style.visibility='visible';
        precio_espana = precio;
        
        //alert(precio_espana);
    }
    else
    {
        document.getElementById("MRW_invisible").style.visibility='hidden';
    }
    
}

function imprimir()
{
    window.print();
}

function irBuscador(url)
{

    //alert(url);
    window.location  = url;
        //'http://'+window.location.hostname+'/icaria/contenido/buscador.php';
    
}

function regresar()
{
    history.back();
}

function recalcular_valor_total(valor_gastos_envio)
{
    
    var valor_total = document.getElementById("valor_total");
    var cantidad = document.getElementsByName("cantidad");
    var precio_libro = document.getElementsByName("precio_libro");
    var vt_gastos_envio = document.getElementById("vt_gastos_envio");
    //alert('precio '+precio_libro);

    valor_total.value = 0;

    var y=0;
    var valor = 0;
    for (y=0; y< precio_libro.length; y++)
    {
        valor = parseFloat(precio_libro[y].value) * parseInt(cantidad[y].value);
        //alert(precio_libro[y].value+" cantidad precios "+precio_libro.length);
        valor_total.value = parseFloat(valor_total.value) + parseFloat(valor);
        //alert(valor_total.value);
    }

    if(valor_gastos_envio == null)
    {
        
        valor_gastos_envio = precio_gastos;
        vt_gastos_envio.value = valor_gastos_envio;
        
    }
    else
    {
        if( parseFloat(valor_gastos_envio) < 0)
        {
            //alert('hi');
            valor_gastos_envio = precio_espana;
            vt_gastos_envio.value = valor_gastos_envio;
            precio_gastos = valor_gastos_envio;

        }
        else
        {
            //alert('hi else  '+valor_gastos_envio);
            vt_gastos_envio.value = valor_gastos_envio;
            precio_gastos = valor_gastos_envio;
        }
    }
    

    valor_total.value = parseFloat(valor_total.value) + parseFloat(valor_gastos_envio);

    
    //alert($valor_gastos_envio);

    

}

function guardarCantidades()
{
    var cantidad = document.getElementsByName("cantidad");
    sessionStorage.setItem(cantidades, cantidad);
}

function mostrar_forma_pago(name_show , name_hide)
{
    var tr = document.getElementById(name_show);
    tr.style.visibility='visible';
    tr = document.getElementById(name_hide);
    tr.style.visibility='collapse';
}

function mostrar_forma_pago_revistas(name_show , name_hide1, name_hide2, name_hide3)
{
    var tr = document.getElementById(name_show);
    tr.style.visibility='visible';
    tr = document.getElementById(name_hide1);
    tr.style.visibility='collapse';
    tr = document.getElementById(name_hide2);
    tr.style.visibility='collapse';
    tr = document.getElementById(name_hide3);
    tr.style.visibility='collapse';
}

function finalizarCompra()
{
    var form = document.form1;
    form.action = 'comprar3.php';
    form.submit();
}

function finalizar_compra_revista(url)
{
    var form = document.form1;
    form.action = url;
    form.submit();
}

function enviar_amigo(url)
{
    window.showModalDialog(url, "","dialogWidth:370px; dialogHeight:450px; dialogLeft:450px; dialogTop:200px");
}

function cargar()
{
    
    /*var medio = document.getElementById('medio_gris');
    alert("cargando"+medio.style.width);*/
}

