//Variables for checking that fields have the right sort of characters in them
	var numeric="0123456789- "
	var digits="0123456789"
	var alphapure="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var alphabetic=alphapure+"- .,'#" + '"'
	var mixed=digits+alphabetic
	var emailchars=digits+alphapure+"@-._"

function isName(input,type)
//function to make sure that there is something at least prima facie valid input in the Name and address fields
	{
	if (input.value=="")
		{
		alert("**** You must give us your complete " + type + " in order for us to get back to you! *****" + 
		"\n" + "Please press OK to return to the form, and complete all the information.");
		return false;
		}

	var error=ValidateCharsName(input.value);
	if (error!="OK")
		{
		if (error!=" ")	//i.e. if the error returned is a space that's OK, otherwise return the error
			{
			alert("The " + type + " you have input seems to have a problem." + "\n" + "The character " + error + " is invalid.");
			return false;
			}
		}
	}

function ValidateCharsName(input)
//Validate for email characters - alphanumeric plus @, dot and dash and comma
	{
	for  (var i=0; i<=(input.length-1); i++)
		{
		if (mixed.indexOf(input.charAt(i)) == -1)
			{
			return input.charAt(i);
			}
		}
	return "OK";
	}

function ValidateChars(input)
//Validate for email characters - alphanumeric plus @, dot and dash and underline
	{
	for  (var i=0; i<=(input.length-1); i++)
		{
		if (emailchars.indexOf(input.charAt(i)) == -1)
			{
			return input.charAt(i);
			}
		}
	return "OK";
	}

function ValidateDigits(input)
//Validate for valid characters in a phone number
	{
	for  (var i=0; i<=(input.length-1); i++)
		{
		if (numeric.indexOf(input.charAt(i)) == -1)
			{
			return input.charAt(i);
			}
		}
	return "OK";
	}

function isEmailOK(input,index)
// Description : Checks if given email address is prima facie valid
	{
	var Temp = input
	Temp = Temp.value
	var AtSym = Temp.indexOf('@')
	var AtSym2 = Temp.lastIndexOf('@')
	var Period = Temp.lastIndexOf('.')
	var Space = Temp.indexOf(' ')
	var Length = Temp.length - 1   // Array is from 0 to length-1
	if (Temp=="")
		{
		alert("**** You must give us your e-mail address in order for us to get back to you! *****" + 
		"\n\n" + "Please press OK to return to the form, and complete all the information.");
		return false;
		}
	if (Length <5)
		{
		alert("Your e-mail address is incorrect - it is too short")
		return false;
		}
	if (AtSym < 1)
		{
		alert("Your e-mail address is incorrect." + "\n" + "There must be an \'@\', which cannot be in the first position.");
		return false;
		}
	if (Period == -1)
		{
		alert("Your e-mail address is incorrect." + "\n" + "There must be \'dot\' character in the address.");
		return false;
		}
	if (Period <= AtSym+1)
		{
		alert("Your e-mail address is incorrect." + "\n" + "There must be at least one character between the \'@\' and the \'dot\'.");
		return false;
		}
	if (Period == Length )
		{
		alert("Your e-mail address is incorrect." + "\n" + "There must be at least one character after the \'dot\' - usually .com or .co.uk");
		return false;
		}
	if (Space  != -1)
		{
		alert("Your e-mail address is incorrect." + "\n" + "There should be no spaces in the address.");
		return false;
		}
	if (AtSym != AtSym2)
		{
		alert("Your e-mail address is incorrect." + "\n" + "You can\'t have more than one \'@\' sign.");
		return false;
		}
	var error=ValidateChars(Temp);
	if (error!="OK")
		{
		alert("Your e-mail address is incorrect." + "\n" + "The character " + error + " is invalid.");
		return false;
		}
	// alert ('Your e-mail address is probably OK');
	return true;
	}

//Function to produce javascript confirm alert
function confirmOrder(queryForm)
{

var nameWarning=""
//Check name
	if (isName(queryForm.realname,"name")==false)
		{
		return false;
		}

//Check Email address
	if (isEmailOK(queryForm.email)==false) 
		{
		return false;
		}

//Check Phone number
	if (queryForm.phone.value=="")
		{
		alert("**** You must give us your telephone number in order for us to get back to you! *****" + 
		"\n\n" + "Please press OK to return to the form, and complete all the information.");
		return false;
		}

	var phoneTest=ValidateDigits(queryForm.phone.value)
	if (phoneTest!="OK")
		{
		alert("The character '" + phoneTest + "' you have included in the phone number you have input is not valid." + 
		"\n\n" + "Please press OK to return to the form, and correct the phone number.");
		return false;
		}

//Check Address
	for (var i=1;i<7;i++)
		{
		var holder=eval("queryForm.address"+ i)
		if (isName(holder,"address")==false)
			{
			return false;
			}
		}	

var WantTo=""

//alert(queryForm.Intent.length)
//alert(queryForm.Intent[0].value)
//WantTo=queryForm.Intent[0].value

for (var i=0;i<(queryForm.Intent.length);i++)
	{
	if (queryForm.Intent[i].checked)
		{
		WantTo=queryForm.Intent[i].value
		}
	}

//Check it there's a title name input
if (WantTo=="BuyOne")
	{
	if (queryForm.TitleToBuy[0].selected==true)
		{
		alert("Please select the name of the title you wish to purchase from the pull-down list")
		return false;
		}
	else
		queryForm.Query_Request.value="";
	}

//check if there's a query input
if (WantTo=="Query")
	{
	if (queryForm.TitleToBuy[0].selected!=true)
		{
		queryForm.TitleToBuy[0].selected=true
		}
	if (queryForm.Query_Request.value=="")
		{
		alert("You haven't asked for more information or entered a query!");
		return false;
		}
	}

//a few checks on the source of the visitor
if (queryForm.Source[0].selected==true)
	{
	var check=confirm("We would really like to know where you found out about Noble Titles." + "\n" +
	"If you'd like to tell us, please press CANCEL and choose from the pull-down list. " + "\n" +
	"If you'd rather just continue with your order or query, simply press OK." + "\n" +
	"Thank you")
	if (check==false) return false;
	}

if ((queryForm.Source[0].selected!=true) && ((queryForm.SourceDetail.value=="Please give us details ...") || (queryForm.SourceDetail.value="")))
	{
	var check=confirm("We'd like to know a bit more about where you found out about Noble Titles." + "\n" +
	"If you'd like to give us details, please press CANCEL and complete the details. " + "\n" +
	"If you'd rather just continue with your order or query, simply press OK." + "\n" +
	"Thank you")
	if (check==false) return false;
	}

//alert("Thank you for your interest in Noble Titles.  We will contact you shortly")
}

