﻿function combo_onchange(tipo) 
{
    document.getElementById('aspnetForm').action = tipo;
    document.getElementById('aspnetForm').submit();
}

function updateNum(direccion, cantidadId)
{
    var valor = document.getElementById(cantidadId).value;
    var num = 0;
    try
    {
        if (valor.length == 0) {valor=0;}
        num = parseInt(valor);
        if (direccion == 1)
        {
            if (num >= 0 ) { num +=1; }
        }
        if (direccion == 2)
        {
            if (num > 0 ) { num -=1; }
        }
        if (num < 0) {num=0;}
        document.getElementById(cantidadId).value = num;
    } 
    catch (err) { alert("Error en lin. 27: " + err.message);}
}


function submitForm(tipo)
{
    document.getElementById("hiddenDato").value = tipo;
    document.getElementById('aspnetForm').submit();
}

function guardarDato(dato)
{
    if (dato != 'act' )
    {
         document.getElementById("hiddenDato").value = dato;
         document.getElementById('aspnetForm').submit();    
    }
    else
    {
        var objs = document.getElementsByTagName("input");
        var aux = "";
        var id = "";
        var value = 0;
        
        for (var i=0; i<objs.length; i++)
        {
            if ( ( objs(i).getAttribute("type") == "text" ) && (objs(i).id.indexOf("cantidad") != -1 ) )
            {
                id = objs(i).id;
                value = 0;
                try
                {
                    if (objs(i).value != "") { value = parseInt(objs(i).value); }
                } catch (err) {alert("Error en lin. 70: " + err.message);}
                if (aux.length != 0 ) { aux += "&";}
                aux += id + "," + value ;
            }
        }
        
        document.getElementById("hiddenDato").value = dato + "&" + aux;
        document.getElementById('aspnetForm').submit();    
    }
        
}

function ocultarProvincia(combo){
    var afectaA;
    
    
    if (combo=="paisFacturacion")
    {
        afectaA = "provinciaFacturacion";
    }
    else
    {
        afectaA = "provinciaEnvio";
    }
    if (combo=="pais")
    {
        afectaA = "provincia";
    }
    try
    {
        if (document.getElementById(combo)[document.getElementById(combo).selectedIndex].text!="ESPAÑA")
        {
            document.getElementById(afectaA).disabled = "disabled";
            document.getElementById(afectaA).value = "";
        }
        else
        {
            document.getElementById(afectaA).disabled = "";
        }
    } catch(err){}
}

function borrarSel(sInput,textoOriginal,hacerCaso){
    if (hacerCaso){
        if (sInput.value==textoOriginal){
            sInput.value="";
        }
    }

}
