// JavaScript Document
		
function validateEmail(valor){//function that validates the email
		re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
   			if(!re.exec(valor)){
			  mail=false;
    		}else{
       		  mail=true;
			}
		return mail;
}
		
		
	 function soloNumero(e){ // We can only type numbers in a text field, it has been used for telephone, day, month and year
	var tecla;
	var nav = navigator.appName;
	
	if(nav == "Microsoft Internet Explorer")
		tecla = e.keyCode;
	else
		tecla = e.which;

return (tecla <= 13 || (tecla >= 48 && tecla <= 57));
}
		
//function that gets the fields from the form and call to an ajax object to insert these fields to a csv file
function signupForm(){
							validateTitle=false;
							validateCountry=false;
							validateMail=false;
							validateFirstname=false;
							validateSurname=false;
							validateDay=false;
							validateMonth=false;
							validateYear=false;
							validateAdress=false;
							validateTelephone=false;
							validateCity=false;

							firstname=document.getElementById("txt_firstname").value;
							surname=document.getElementById("txt_surname").value;
							
							day=document.getElementById("txt_day").value;
							dayparsed=parseInt(day,10);

							month=document.getElementById("txt_month").value;
							monthparsed=parseInt(month,10);
							
							year=document.getElementById("txt_year").value;
							yearparsed=parseInt(year,10);
							
							city=document.getElementById("txt_city").value;
							postcode=document.getElementById("txt_postcode").value;
							
							slctitle=document.getElementById("slc_title").value;
						
							
							
	
							adress=document.getElementById("txt_adress").value;
							telephone=document.getElementById("txt_telephone").value;
							email=document.getElementById("txt_email").value.toLowerCase();
							country=document.getElementById("slc_countries").value;

							validateMail=validateEmail(email);
							
							if(country!="country"){
								validateCountry=true;
							}else{
								validateCountry=false;
							}
								
								
						  if(slctitle!="title"){
							validateTitle=true;
						  }else{
						    validateTitle=false;
							 }
								
								
							if(firstname==""){
								validateFirstname=false;
							}else{
								validateFirstname=true;
							}
							
							if(surname==""){
								validateSurname=false;
							}else{
								validateSurname=true;
							}
							
							
							if((dayparsed>=1)&&(dayparsed<=31)&&((day.length)==2)){
								validateDay=true;
							}else{
								validateDay=false;
							}
							
							if((monthparsed>=1)&&(monthparsed<=12)&&((month.length)==2)){
								validateMonth=true;
							}else{
								validateMonth=false;
							}	
							
							if((yearparsed>=1900)&&(yearparsed<=2100)&&((year.length)==4)){
								validateYear=true;
							}else{
								validateYear=false;
							}						
							
							if(adress==""){
								validateAdress=false;
							}else{
								validateAdress=true;
							}
							
							if(telephone==""){
								validateTelephone=false;
							}else{
								validateTelephone=true;
							}
							
								
			if((validateTelephone)&&(validateMail)&&(validateAdress)&&(validateYear)&&(validateMonth)&&(city!="")&&(postcode!="")&&(validateDay)&&(validateCountry)&&(validateSurname)&&(validateFirstname)&&(validateTitle)){
					
					document.getElementById("vertical_container").style.display='none';
					document.getElementById("popupchecking").style.display='block';
					

					
				var xmlhttp;
				if (window.XMLHttpRequest)
				  {// code for IE7+, Firefox, Chrome, Opera, Safari
				  xmlhttp=new XMLHttpRequest();
				  }
				else
				  {// code for IE6, IE5
				  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				  }
				xmlhttp.onreadystatechange=function()
				  {
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
					document.getElementById("popupchecking").style.display='none';
					document.getElementById("popup").style.display='block';
					}
				  }
				xmlhttp.open("GET","signup.php?mail="+email+"&firstname="+firstname+"&surname="+surname+"&day="+day+"&month="+month+"&year="+year+"&country="+country+"&telephone="+telephone+"&adress="+adress+"&city="+city+"&postcode="+postcode+"&title="+document.getElementById("slc_title").value,true);
				xmlhttp.send();
				  
			}else{
			
			
						if(city==""){
						document.getElementById("underlinecity").style.backgroundColor="#fecb00";
						}else{	
						document.getElementById("underlinecity").style.backgroundColor="#dfdfdf";
						}
						
						if(postcode==""){
						document.getElementById("underlinepostcode").style.backgroundColor="#fecb00";
						}else{	
						document.getElementById("underlinepostcode").style.backgroundColor="#dfdfdf";
						}
			
			
			
						if(validateFirstname==false){
							document.getElementById("underlinefirstname").style.backgroundColor="#fecb00";
							}else{
							document.getElementById("underlinefirstname").style.backgroundColor="#dfdfdf";
							}
							
							
							if(validateSurname==false){
							document.getElementById("underlinesurname").style.backgroundColor="#fecb00";
							}else{
							document.getElementById("underlinesurname").style.backgroundColor="#dfdfdf";
							}
						
							
							if(validateDay==true){
							
							document.getElementById("underlineday").style.backgroundColor="#dfdfdf";
							
							}else{
							document.getElementById("underlineday").style.backgroundColor="#fecb00";
							document.getElementById("txt_day").value="DD";
							}
							
							
							if(validateMonth==true){
							document.getElementById("underlinemonth").style.backgroundColor="#dfdfdf";
							}else{
							document.getElementById("underlinemonth").style.backgroundColor="#fecb00";
							document.getElementById("txt_month").value="MM";
							}
							
							if(validateYear==true){
							document.getElementById("underlineyear").style.backgroundColor="#dfdfdf";
							}else{
							document.getElementById("underlineyear").style.backgroundColor="#fecb00";
							document.getElementById("txt_year").value="YYYY";
							}
							
							
							if(validateAdress==false){
							document.getElementById("underlineadress").style.backgroundColor="#fecb00";
							}else{
							document.getElementById("underlineadress").style.backgroundColor="#dfdfdf";
							}
							
							if(validateCountry==false){
							document.getElementById("slc_countries").style.border="1px solid#fecb00";
							}else{
							document.getElementById("slc_countries").style.border="0px solid#000000";
							}
							
							
							if(validateTitle==false){
								document.getElementById("slc_title").style.border="1px solid#fecb00";
							}else{
								document.getElementById("slc_title").style.border="0px solid#000000";
							}
							
							
							if(validateTelephone==false){
								document.getElementById("underlinetelephone").style.backgroundColor="#fecb00";
							}else{
								document.getElementById("underlinetelephone").style.backgroundColor="#dfdfdf";
							}
							
							if(validateMail==false){	
								document.getElementById("underlineemail").style.backgroundColor="#fecb00";
							}else{
								document.getElementById("underlineemail").style.backgroundColor="#dfdfdf";
							}
			
					}
							
	}
		
