// JavaScript Document

//VALIDACION DE FORMULARIOS

function validacion(formulario) {
    
	var er_nombre = /^([a-z]|[A-Z]|á|é|í|ó|ú|ñ|ü|\s|\.|-)+$/			//letras, '.' y '-' o vacio
	var er_telefono = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
	//fechas, formato dd/mm/aaaa o d/m/aa
	var er_mes31dias = /^([1-3]0|[0-2][1-9]|31|[0-9])\/(1|01|3|03|5|05|7|07|8|08|10|12)\/(1999|20[0-1][0-9]|2020)$/
	var er_mes30dias = /^([1-3]0|[0-2][1-9]|[0-9])\/(4|04|6|06|9|09|11)\/(1999|20[0-1][0-9]|2020)$/
	var er_mes28dias = /^([1-2]0|[0-2][1-8]|[0-1]9|[0-9])\/(02|2)\/(1999|200[1-3]|200[5-7]|2009|201[0-1]|201[3-5]|201[7-9])$/
	var er_mes29dias = /^([1-2]0|[0-2][1-9]|[0-9])\/(02|2)\/(2000|2004|2008|2012|2016|2020)$/
	//direccion de correo electronico
	var er_email = /^(.+\@.+\..+)$/
	var x
   	
	//comprueba 50 caracteres maximo
	for(x = 1; x < 5; x++) {
		if (formulario.elements[x].value.length > 50) {
			alert('La lontitud máxima permitida para cualquier campo es de 10 caracteres.')
			return false
		}
	}   	
      	
	//comprueba campo de NAME
	if(!er_nombre.test(formulario.NAME.value)) { 
		alert('Content of the field NAME not valid.')
		return false
	}   	
   	//comprueba campo de TITLE
	if(!er_nombre.test(formulario.TITLE.value)) { 
		alert('Content of the field Your Title Name not valid.')
		return false
	}   	
	//comprueba campo de COMPANY_NAME
	if(!er_nombre.test(formulario.COMPANY_NAME.value)) { 
		alert('Content of the field Your Company Name not valid.')
		return false
	} 
	/*
	//comprueba campo de ADDRESS
	if(!er_nombre.test(formulario.ADDRESS.value)) { 
		alert('Content of the field Address not valid.')
		return false
	}   
	//comprueba campo de City
	if(!er_nombre.test(formulario.CITY.value)) { 
		alert('Content of the field City not valid.')
		return false
	}  
	//comprueba campo de STATE
	if(!er_nombre.test(formulario.STATE.value)) { 
		alert('Content of the field State not valid.')
		return false
	}  
	//comprueba campos de Zip Code
	if( !er_telefono.test(formulario.ZIP.value) ) {
		alert('Content of the field Zip Code not valid.')
		return false
	}
	//comprueba campos de telefonos 
	if( !er_telefono.test(formulario.PHONE.value) ) {
		alert('Content of the field Phone not valid.')
		return false
	}
   //comprueba campos de fax
	if( !er_telefono.test(formulario.FAX.value) ) {
		alert('Content of the field Fax  not valid.')
		return false
	}
   
	//comprueba la fecha segun calendario (hasta el 2020, ojo)
	/*if (!(er_mes31dias.test(formulario.fecha.value) || 
   			er_mes30dias.test(formulario.fecha.value) ||
      		er_mes29dias.test(formulario.fecha.value) ||
      		er_mes28dias.test(formulario.fecha.value))) {
		alert('Contenido del campo FECHA no válido.')
		return false
	}*/

	//comprueba campo de email
	if(!er_email.test(formulario.email.value)) { 
		alert('Content of the field Email  not valid.')
		return false
	} 
	/*
	//comprueba campo de comments
	if(!er_nombre.test(formulario.COMMENTS.value)) { 
		alert('Content of the field Comments  not valid.')
		return false
	}  
*/
	/*alert('The introduced fields are CORRECT.')
	return false			//cambiar por return true para ejecutar la accion del formulario
	*/
}




