function printEtiqueta()
{
    var rad_val = 0;
    for (var i=0; i < document.formEtiquetas.tipoetiqueta.length; i++)
    {
        if (document.formEtiquetas.tipoetiqueta[i].checked)
        {
            rad_val = document.formEtiquetas.tipoetiqueta[i].value;
        }
    }
    if (rad_val == 0)
    {
        alert('Debe seleccionar un modelo de etiqueta para continuar.');
    }
    else
    {
        document.formEtiquetas.submit();
    }
}




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 'codigo':            
            if (document.frmBusqueda.orden.value == 'codigoDesc' || 
                document.frmBusqueda.orden.value != 'codigoAsc')
                document.frmBusqueda.orden.value = 'codigoAsc';
            else
                document.frmBusqueda.orden.value = 'codigoDesc';
            document.frmBusqueda.submit();
            break;
        
        case 'marca':
            if (document.frmBusqueda.orden.value == 'marcaDesc' || 
                document.frmBusqueda.orden.value != 'marcaAsc')
                document.frmBusqueda.orden.value = 'marcaAsc';
            else
                document.frmBusqueda.orden.value = 'marcaDesc';
            document.frmBusqueda.submit();
            break;
        
        case 'pvpprov':
            if (document.frmBusqueda.orden.value == 'pvpprovDesc' || 
                document.frmBusqueda.orden.value != 'pvpprovAsc')
                document.frmBusqueda.orden.value = 'pvpprovAsc';
            else
                document.frmBusqueda.orden.value = 'pvpprovDesc';
            document.frmBusqueda.submit();
            break;
            
        case 'tarifa_oferta':
            if (document.frmBusqueda.orden.value == 'tarifa_ofertaDesc' || 
                document.frmBusqueda.orden.value != 'tarifa_ofertaAsc')
                document.frmBusqueda.orden.value = 'tarifa_ofertaAsc';
            else
                document.frmBusqueda.orden.value = 'tarifa_ofertaDesc';
            document.frmBusqueda.submit();
            break;
            
        case 'tarifa':
            if (document.frmBusqueda.orden.value == 'tarifaDesc' || 
                document.frmBusqueda.orden.value != 'tarifaAsc')
                document.frmBusqueda.orden.value = 'tarifaAsc';
            else
                document.frmBusqueda.orden.value = 'tarifaDesc';
            document.frmBusqueda.submit();
            break;
    }
}

function fechaSubmit()
{
    fechaini = document.formulario.fechainiAno.value + "/" + document.formulario.fechainiMes.value + "/" + document.formulario.fechainiDia.value;        
    document.formulario.fechaini.value = fechaini;   
    
    fechafin = document.formulario.fechafinAno.value + "/" + document.formulario.fechafinMes.value + "/" + document.formulario.fechafinDia.value;
    document.formulario.fechafin.value = fechafin;
    
    document.formulario.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 modalOpen (dialog) {
	dialog.overlay.fadeIn('slow', function () {
		dialog.container.fadeIn('slow', function () {
			dialog.data.hide().slideDown('slow');
		});
	});
}

function modalClose (dialog) {        
    dialog.data.slideUp('slow', function () {
	    dialog.container.fadeOut('slow', function () {
		    dialog.overlay.fadeOut('slow');
	    });
	});	
}

function ajaxCapturar() {
   $.ajax({
    type: 'POST',
    url: 'buy_ajax.php',
    data: $("#form1").serialize(),
    beforeSend: function() {
        showHiddenDIV('visible');
    },
    success: function(msg) {
        _retorno = unescape(msg);
        _retorno = _retorno.replace(/\+/gi,' ');
        showHiddenDIV('hidden');
        if (_retorno == "KO")
        {
            alert('Ha caducado su sesión por inactividad. Por favor recargue la página');
        }                
        $('.unitsBox').val('0');
    }
});
}

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;
}

