var nav4 = window.Event ? true : false;
function acceptNum(evt){	
    var key = nav4 ? evt.which : evt.keyCode;	
    return (key <= 13 || (key >= 48 && key <= 57));
    }
    
function anadir_articulo( id ){
    return xajax_anadirArticuloPedido( id, $('#cant_' + id).val() ); 
    }
    
function actualizar_precios( id ){
    return xajax_actualizar_precios( id, $('#cant_' + id).val() );    
    }
    
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;
        }
        
//  Formulario producto
function validar_formulario(){
    //Comprobamos si vienen todos los datos
    var mensaje = "Debe completar los siguentes datos:";
    var count = mensaje.length;
    if ( empty( 'str_referencia' ) )
          mensaje += "\n   - Referencia del producto.";
    if ( empty('str_nombre') )
          mensaje += "\n   - Nombre del producto.";
    if ( empty('str_descripcion') )
          mensaje += "\n   - Descripción del producto.";
    if ( empty('int_categoria') )
          mensaje += "\n   - Categoría a la que pertenece.";
    if ( empty('str_precio') )
          mensaje += "\n   - Precio del producto.";
    //Ahora o avisamos o enviamos
        if ( mensaje.length != count )
            alert( mensaje );
        else
            document.nuevo_articulo.submit(); 
    }
    
//  Formulario vehiculos
function validar_formulario_vehiculos(){
    //Comprobamos si vienen todos los datos
    var mensaje = "Debe completar los siguentes datos:";
    var count = mensaje.length;
    if ( empty('str_nombre') )
          mensaje += "\n   - Nombre del vehiculo.";
    if ( empty('str_color') )
          mensaje += "\n   - Color del vehiculo.";
    if ( empty('int_plazas') )
          mensaje += "\n   - Número de plazas.";
    if ( empty('id_marca') )
          mensaje += "\n   - Marca.";
    //if ( empty('id_modelo') )
          //mensaje += "\n   - Modelo.";
    if ( empty('str_caracteristicas') )
          mensaje += "\n   - Características del vehículo.";
    if ( empty('int_categoria') )
          mensaje += "\n   - Categoría a la que pertenece.";
    if ( empty('int_precio') )
          mensaje += "\n   - Precio del vehiculo.";
    //Ahora o avisamos o enviamos
        if ( mensaje.length != count )
            alert( mensaje );
        else
            document.nuevo_vehiculo.submit(); 
    }
    
function validar_formulario_transformacion(){
    //Comprobamos si vienen todos los datos
    var mensaje = "Debe completar los siguentes datos:";
    var count = mensaje.length;
    if ( empty('str_nombre') )
          mensaje += "\n   - Nombre de la transformación.";
    if ( empty('str_descripcion') )
          mensaje += "\n   - Características de la transformacion.";
    //Ahora o avisamos o enviamos
        if ( mensaje.length != count )
            alert( mensaje );
        else
            document.nueva_transformacion.submit(); 
    }
    
function anadir( id1, id2){
    var select1=document.getElementById(id1);
    var select2=document.getElementById(id2);
    var opcion_antigua=select1.options[select1.selectedIndex];
    select1.options[select1.selectedIndex]=null;
    var opcion = new Option(opcion_antigua.text,opcion_antigua.value);
    select2.options[select2.options.length]=opcion;
    }
		
function eliminar( id1, id2 ) {
    var select1 = document.getElementById( id1 );
    var select2 = document.getElementById( id2 );
    if( select2.options.length > 0 ){
            var opcion_antigua= select2.options[select2.selectedIndex];
            select2.options[select2.selectedIndex] = null;
            var opcion = new Option(opcion_antigua.text,opcion_antigua.value);
            select1.options[select1.options.length] = opcion;
        }
    }

function select( id1 ){
    var select1 = document.getElementById(id1);
    for( i = 0; i< select1.options.length; i++ ){
            select1.options[i].selected=true;
            }
    }
    
function enviar_formulario( cual, form_name ){
    if ( isEmailAddress( cual ) )
        return document.getElementById(form_name).submit();
    else{
        document.getElementById(cual).focus();
        alert("Por favor ingrese una dirección de correo válida");
        return false;
	}
    }

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;
	}
