function enviar()
{
	var F = document.express;
	if (trim(F.nombre.value + F.apellido1.value) == '')
	{
		alert('Debe rellenar el nombre o el 1º apellido.');
		F.nombre.focus();
		return;
	}
	if (trim(F.telefono.value) == '')
	{
		alert('Debe rellenar el teléfono.');
		F.telefono.focus();
		return;
	}
	else if (!validTel(F.telefono))
	{
		alert("El telefono no es válido.");
		F.telefono.focus();
		F.telefono.select();
		return;
	}
	if (trim(F.email.value) != '' && !esEmail(F.email.value))
	{
		alert("El e-mail no es válido.");
		F.email.focus();
		F.email.select();
		return;
	}
	if (F.comentarios.value.length > 2000)
	{
		alert('El texto del mensaje no puede sobrepasar los 2.000 caracteres.');
		F.comentarios.focus();
		F.comentarios.select();
		return;
	}
	
	var FORM_TARGET_WIN = 'expressform';
	openTargetWin(FORM_TARGET_WIN);
	F.target = FORM_TARGET_WIN;
	F.submit();
}

function openTargetWin(winname)
{
	var tw = window.open('', winname, 'top=50,left=50,width=370,height=280,resizable=1;scroll=auto');
	tw.focus();
	return tw;
}

function isEmpty(s){return ((s == null) || (s.length == 0));}
function trim(s){return s.replace(/(^\s*)|(\s*$)/g, '');}
function esNumero(dato){dato = '' + dato;return (!isEmpty(dato) && !isNaN(dato) && dato.indexOf('E') == -1 && dato.indexOf('e') == -1);}
function validTel(obj)
{
	var val = stripCharsInBag(obj.value, " .-\t");
	if (val == '' || (esNumero(val) && val.length == 9 && (val.substr(0,1) == '6' || val.substr(0,1) == '9' || val.substr(0,1) == '8')))
		return true;
	return false;
}
function stripCharsInBag (s, bag)
{
	s += '';
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}
function esEmail(s)
{
	s = '' + s;
   var r, re;
   re = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z0-9_]+$/g;
   r = s.match(re);
   return (r != null);
}
function restrTextMax(max)
{
	var obj = event.srcElement;
	if (obj.value.length < max || event.keyCode == 13)
		return true;

	alert('Ha alcanzado la longitud máxima.No puede \nsobrepasar los ' + max + ' caracteres.\n');
	event.returnValue = false;
}

