function isset(variable_name) {
    variable_name = document.getElementById(variable_name).value;
    try {
	if (typeof(eval(variable_name)) != 'undefined')
	if (eval(variable_name) != null)
	    return true;
    } catch(e) { }
    return false;
    }

//validar correo electronico
function isEmailAddress( id_elemento ){
    var s = document.getElementById(id_elemento).value;
    var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    if (filter.test(s))
        return true;
    else
        return false;
	}        
        
$(document).ready(function(){
    $("ul#dropdown li ul").hide();
    $("ul#dropdown > li > a").hover(function(){
	$(this).next("ul").show();  
    }, function(){
	$(this).next("ul").hide(); 
    });
    
    $("ul#dropdown li ul").hover(function(){
	$(this).show();    
    }, function(){
	$(this).hide();    
    });
});


function aumentar_cantidad( id ){
    var pattern = new RegExp('tienda_on_line');
    var cant = parseInt( $('#cant_' + id).val() ) + 1;
    if ( pattern.test( window.location ) )
        xajax_actualizar_precio( id, cant );
    return $('#cant_' + id).val( cant );
    }

function reducir_cantidad( id ){
    var cant = parseInt( $('#cant_' + id).val() ) - 1;
    if ( cant > 1 ){
        var pattern = new RegExp('tienda_on_line');
        if ( pattern.test( window.location ) )
            xajax_actualizar_precio( id, cant );
       return $('#cant_' + id).val( cant );
    } else{
	return alert('El pedido mínimo es de 2 cajas');
	}
    }

var nav4 = window.Event ? true : false;
function acceptNum(evt){	
    var key = nav4 ? evt.which : evt.keyCode;	
    return (key <= 13 || (key >= 48 && key <= 57));
    }
    
var string;
function empty( string ){
        var campo = document.getElementById( string ).value;
        if ( campo.length == 0 )
            return true;
        else
            return false;
        }
    
function validar_formulario(){
        //Comprobamos si vienen todos los datos
        var mensaje = "Debe completar los siguentes datos: ";
        var count = mensaje.length;
        if ( empty('email') || !isEmailAddress('email') )
              mensaje += "\n   - Su correo electrónico.";
        if ( empty( 'nombre' ) )
              mensaje += "\n   - Su nombre.";
        if ( empty( 'apellidos' ) )
              mensaje += "\n   - Sus apellidos.";
        if ( empty( 'direccion' ) )
              mensaje += "\n   - Su dirección.";
        if ( empty( 'cp' ) )
              mensaje += "\n   - Su código postal.";
        if ( empty( 'ciudad' ) )
              mensaje += "\n   - Su ciudad.";
        if ( empty( 'provincia' ) )
              mensaje += "\n   - Su provincia.";
        if ( empty( 'telefono' ) )
              mensaje += "\n   - Su teléfono.";
        //Ahora o avisamos o enviamos
            if ( mensaje.length != count )
                alert( mensaje );
            else
                document.enviar_pedido.submit(); 
        }
