/*     Script by Johan Lundgren for Airliners.net Electronic Postcard Service     */

function ignoreSpaces(string)
{
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	temp += splitstring[i];
	return temp;
}

function emc()
{

var alstitle = document.ALSxUK.Title.value
if (alstitle.length<2)
/*		if (document.ALSxUK.Title.value == "")     This line can replace the above two lines if necessary  */
		{
		alert("Please input your title in the \"Title\" field.   IE Ms, Miss, Mr, Mrs, Messrs, Dr, Captain, etc");
		return false;
		}

	var alsmsg = document.ALSxUK.Surname.value
	if (alsmsg.length<3)
		{
		alert("Please input your name in the \"Surname\" field.   We need to know who to reply to.");
		return false;
		}

	var emailStr = document.ALSxUK.EmailAddress.value
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) 
		{
		alert("The email address in the \"Your Email\" field is not correct. Please correct the entry.")
		return false
		}

	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null)
		{
		alert("The email address in the \"Your Email\" field is not correct. Please correct the entry.")
		return false
		}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
		{
		for (var i=1;i<=4;i++) 

			{
			if (IPArray[i]>255)
				{
				alert("The email address in the \"Your Email\" field is not correct. Please correct the entry.")
				return false
				}
			}
		return true
		}
 
	var domainArray=domain.match(domainPat)
	if (domainArray==null)
		{
		alert("The email address in the \"Your Email\" field is not correct. Please correct the entry.")
		return false
		}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
		{
		alert("The email address in the \"Your Email\" field is not correct. Please correct the entry.")
		return false
		}

	if (len<2)
		{
		alert("The email address in the \"Your Email\" field is not correct. Please correct the entry.")
		return false
		}

	var bla = document.ALSxUK.Message.value
	if (bla.length<3)
		{
		alert("You need to write your enquiry in the message field.");
		return false;
		}

	}