var nombre;
var primerApellido;
var segundoApellido;
var nif;
var empresa;
var telefono;
var email;
var consulta;

function trim(a){
	var i,j;
	var b;
	i=0;
	while(i<a.length && a.charAt(i)==" "){
		i++;
	}
	j=a.length-1;
	while(j>0 && a.charAt(j)==" "){
		j--;
	}
	if(j>=i){
		b=a.substring(i,j+1);	
	}
	else{
		b="";
	}
	
	return b;
}

function enviarConsulta(){
	var n;
	var ni;
	var em;
	var t;
	var c;

    if(semaforo && semaforo2){
        n=trim(nombre.value);
        ni=trim(nif.value);
        em=trim(empresa.value);
        t=trim(telefono.value);
        c=trim(consulta.value);
	
		semaforo=false;
		if(n!="" && ni!="" && em!="" && t!="" && c!=""){
			xajax_enviarConsulta(n,primerApellido.value,segundoApellido.value,ni,em,t,email.value,c);
		}
		else{
			window.alert("Atencion. Rellene todos los datos marcados con '*' por favor.");
			semaforo=true;
		}
	}
}

function inicializarModulo(){
	nombre=document.getElementById("nombre");
	primerApellido=document.getElementById("primerApellido");
	segundoApellido=document.getElementById("segundoApellido");
	nif=document.getElementById("nif");
	empresa=document.getElementById("empresa");
	telefono=document.getElementById("telefono");
	email=document.getElementById("email");
	consulta=document.getElementById("consulta");
    semaforo2=true;
}

cargado=true;