function selectEnvio(id)
{
    switch(id)
    {
        case 1:
            document.getElementById("otro_envio_text").style.display = 'none';
            document.getElementById("opciones_envio").style.display = 'none';
            break;
        case 2:
            document.getElementById("otro_envio_text").style.display = 'none';
            document.getElementById("opciones_envio").style.display = 'inline';
            break;
        case 3:
            document.getElementById("otro_envio_text").style.display = 'inline';
            document.getElementById("opciones_envio").style.display = 'inline';
            break;
    }
}

function selectDirEnvio(id)
{
    switch(id)
    {
        case 1:
            document.getElementById("seleccionar_direccion").style.display = 'none';
            document.getElementById("especificar_otra_direccion").style.display = 'none';
            break;
        case 2:
            document.getElementById("seleccionar_direccion").style.display = 'inline';
            document.getElementById("especificar_otra_direccion").style.display = 'none';
            break;
        case 3:
            document.getElementById("seleccionar_direccion").style.display = 'none';
            document.getElementById("especificar_otra_direccion").style.display = 'inline';
            break;
    }
}

function resetBuscar()
{
    document.frmBusqueda.str.value = '';
    document.frmBusqueda.marca.value = '';
    document.frmBusqueda.familia.value = '';
    document.frmBusqueda.subfamilia.value = '';
}


function fechaSubmit()
{
    fechaini = document.formulario.fechainiDia.value + "/" + document.formulario.fechainiMes.value + "/" + document.formulario.fechainiAno.value;
    document.formulario.fechaini.value = fechaini;

    fechafin = document.formulario.fechafinDia.value + "/" + document.formulario.fechafinMes.value + "/" + document.formulario.fechafinAno.value;
    document.formulario.fechafin.value = fechafin;

    document.formulario.submit();
}

function fechaAltaSubmit()
{
    fechadesde = document.frmBusqueda.fechadesdeDia.value + "/" + document.frmBusqueda.fechadesdeMes.value + "/" + document.frmBusqueda.fechadesdeAno.value;
    document.frmBusqueda.fechadesde.value = fechadesde;

    fechahasta = document.frmBusqueda.fechahastaDia.value + "/" + document.frmBusqueda.fechahastaMes.value + "/" + document.frmBusqueda.fechahastaAno.value;
    document.frmBusqueda.fechahasta.value = fechahasta;
    document.frmBusqueda.submit();
}

function recalcular()
{
    if ((event.keyCode != 37) && (event.keyCode != 38) && (event.keyCode != 39) && (event.keyCode != 40))
    {
        document.formPedido.submit();
    }

}

function montre(id) {
	  if (document.getElementById) {
		  document.getElementById(id).style.display="block";
		} else if (document.all) {
		  document.all[id].style.display="block";
		} else if (document.layers) {
		  document.layers[id].display="block";
		} }

 function cache(id) {
	  if (document.getElementById) {
		  document.getElementById(id).style.display="none";
		} else if (document.all) {
		  document.all[id].style.display="none";
		} else if (document.layers) {
		  document.layers[id].display="none";
		} }

function activa_check_int()
{
    if (document.formulario.use_internet_check.checked==true)
    {
        document.formulario.use_internet_check_def[0].disabled = false;
        document.formulario.use_internet_check_def[1].disabled = false;
        document.formulario.use_internet_check_def[0].checked = true;
    }
    else
    {
        document.formulario.use_internet_check_def[0].disabled = true;
        document.formulario.use_internet_check_def[1].disabled = true;
    }
}

function copiarDireccion ()
{
    if (document.formPedido.igual.checked == 1)
    {
        document.formPedido.empresa2.value      = document.formPedido.empresa1.value;
        document.formPedido.universidad2.value  = document.formPedido.universidad1.value;
        document.formPedido.laboratorio2.value  = document.formPedido.laboratorio1.value;
        document.formPedido.facultad2.value     = document.formPedido.facultad1.value;
        document.formPedido.departamento2.value = document.formPedido.departamento1.value;
        document.formPedido.contacto2.value     = document.formPedido.contacto1.value;
        document.formPedido.email2.value        = document.formPedido.email1.value;
        document.formPedido.telf2.value         = document.formPedido.telf1.value;
        document.formPedido.fax2.value          = document.formPedido.fax1.value;
        document.formPedido.direccion2.value    = document.formPedido.direccion1.value;
        document.formPedido.cp2.value           = document.formPedido.cp1.value;
        document.formPedido.ciudad2.value       = document.formPedido.ciudad1.value;
        document.formPedido.provincia2.value    = document.formPedido.provincia1.value;
        document.formPedido.pais2.value         = document.formPedido.pais1.value;
        document.formPedido.proyecto2.value     = document.formPedido.proyecto1.value;
        document.formPedido.pedido2.value       = document.formPedido.pedido1.value;
        document.formPedido.poblacion2.value       = document.formPedido.poblacion1.value;
    }
    else
    {
        document.formPedido.empresa2.value      = '';
        document.formPedido.universidad2.value  = '';
        document.formPedido.laboratorio2.value  = '';
        document.formPedido.facultad2.value     = '';
        document.formPedido.departamento2.value = '';
        document.formPedido.contacto2.value     = '';
        document.formPedido.email2.value        = '';
        document.formPedido.telf2.value         = '';
        document.formPedido.fax2.value          = '';
        document.formPedido.direccion2.value    = '';
        document.formPedido.cp2.value           = '';
        document.formPedido.ciudad2.value       = '';
        document.formPedido.provincia2.value    = '';
        document.formPedido.pais2.value         = '';
        document.formPedido.proyecto2.value     = '';
        document.formPedido.pedido2.value       = '';
        document.formPedido.poblacion2.value    = '';
    }

}

function showHiddenDIV(accion)
{
    if (accion == 'visible')
    {
        document.getElementById('divPantallaNegra').style.height = document.documentElement.clientHeight+'px';
        document.getElementById('divPantallaNegra').style.width = document.documentElement.clientWidth+'px';

        var XpositionDIV = (document.documentElement.clientWidth/2) - (document.getElementById('divPantallaBlanca').clientWidth/2);
        var YpositionDIV = (document.documentElement.clientHeight/2) - (document.getElementById('divPantallaBlanca').clientHeight/2);

        document.getElementById('divPantallaBlanca').style.left = XpositionDIV+'px';
        document.getElementById('divPantallaBlanca').style.top =  (YpositionDIV)+'px';
    }

    document.getElementById('divPantallaNegra').style.visibility = accion;
    document.getElementById('divPantallaBlanca').style.visibility = accion;
}

function addCartFast (pos, codigo, session)
{
    units = $('#unidades' + pos).val();
    
    $.ajax({
        type: "POST",
        url: "ajax_fastcart.php",
        data: "PHPSESSID=" + session + "&codigo=" + escape(codigo) + "&units=" + units,
        beforeSend: function() {
            showHiddenDIV('visible');
        },
        success: function(msg) {
            showHiddenDIV('hidden');
        }
    });
}

/*
function addCartFast2 (pos, codigo, session)
{

    showHiddenDIV('visible');

    var xmlHttpReq = false;

    var self = this;

    if (window.XMLHttpRequest) // Mozilla & Safar
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) // IE
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.open('POST', 'ajax_fastcart.php', true);

    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
            textReturn = unescape(self.xmlHttpReq.responseText);

            document.getElementById('unidades'+pos).value = 1;

            showHiddenDIV('hidden');
        }
    }

    units = document.getElementById('unidades'+pos).value;

    self.xmlHttpReq.send('codigo='+ escape(codigo) +'&units='+ units +'&PHPSESSID='+ session);
}
*/

function submitRueda()
{
    //cadena = $('#ancho').val() + ' ' + $('#serie').val() + ' ' + $('#llanta').val() + ' ' + $('#velo').val();
    cadena = 'ancho' + $('#ancho').val() + ' ' + 'serie' + $('#serie').val() + ' ' + 'llanta' + $('#llanta').val() + ' ' + 'velo' + $('#velo').val() + ' ';
    $('#str').val(cadena);
    document.frmBusqueda.submit();
}

function resetBuscarRueda()
{
    document.frmBusqueda.str.value = '';
    document.frmBusqueda.marca.value = '';
    document.frmBusqueda.ancho.value = '';
    document.frmBusqueda.serie.value = '';
    document.frmBusqueda.llanta.value = '';
    document.frmBusqueda.velo.value = '';
}

function toggleNeto(col)
{
    if ($('#checkNeto:checked').length)
    {
        ver = 0;
    }
    else
    {
        ver = 1;
    }
    ocultarColumna(col - 1, ver);
    ocultarColumna(col + 1, ver);
}

function ocultarColumna(num,ver)
{
   dis= ver ? 'none' : '';
   fila=document.getElementById('nombresRegistros').getElementsByTagName('tr');
   fila[0].getElementsByTagName('th')[num].style.display=dis;
   for(i=1;i<fila.length;i++)
   {
      fila[i].getElementsByTagName('td')[num].style.display=dis;
   }
}

function ordenar(campo, accion)
{
    //funcion para ordenar las columnas del listado de artículos
    //cambiamos la accion por el tema de las ofertasdiaini (color salmon)
    document.frmBusqueda.action = accion;
    switch(campo)
    {
        case 'descripcion':
            if (document.frmBusqueda.orden.value == 'descripcionDesc' ||
                document.frmBusqueda.orden.value != 'descripcionAsc')
                document.frmBusqueda.orden.value = 'descripcionAsc';
            else
                document.frmBusqueda.orden.value = 'descripcionDesc';
            //document.frmBusqueda.submit();
            document.frmBusqueda.lastsearch.value    = '1';
            submitRueda();
            break;

        case 'precio':
            if (document.frmBusqueda.orden.value == 'precioDesc' ||
                document.frmBusqueda.orden.value != 'precioAsc')
                document.frmBusqueda.orden.value = 'precioAsc';
            else
                document.frmBusqueda.orden.value = 'precioDesc';
            //document.frmBusqueda.submit();
            document.frmBusqueda.lastsearch.value    = '1';
            submitRueda();
            break;
    }
}


$(document).ready(function() {
    if (document.getElementById('idArticulo')) document.getElementById('idArticulo').focus();
});