// JavaScript Document

function removeChars(thisField)
{

var entered;
entered = theForm.loan_amount.value;
entered = entered.replace("£", "");
entered = entered.replace(",", "");
entered = entered.replace("$", "");
entered = entered.replace(".", "");
entered = entered.replace(" ", "");
thisField.value = entered;

}

function clearHelpText(thisField)
{
  if (thisField.value == thisField.defaultValue)
	{
	thisField.value = ''; 
	thisField.focus();
	}

}


function Validate(theform) 

{

//set all the bgs to white - as any mistake will be highlighted red.
theform.size.style.background='#ffffff' ;
theform.title.style.background='#ffffff' ;
theform.first_name.style.background='#ffffff' ;
theform.surname.style.background='#ffffff' ;
theform.postcode2.style.background='#ffffff' ;
theform.foundedaddress2.style.background='#ffffff' ;
theform.tele.style.background='#ffffff' ;
theform.email.style.background='#ffffff' ;
theform.dd.style.background='#ffffff' ;
theform.mm.style.background='#ffffff' ;
theform.yyyy.style.background='#ffffff' ;
theform.dd2.style.background='#ffffff' ;
theform.mm2.style.background='#ffffff' ;
theform.yyyy2.style.background='#ffffff' ;
theform.dd3.style.background='#ffffff' ;
theform.mm3.style.background='#ffffff' ;
theform.yyyy3.style.background='#ffffff' ;


	
//validate size

var checkDIS = "()+0123456789- ";

	var checkStr = theform.size.value;
	//alert(checkStr);
	
	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "Select")
		allValid = false;

	if (checkStr == "0")
		allValid = false;
		
		if (checkStr == "")
		allValid = false;
	
			if (!allValid)
			{
				alert("Please select package");
				theform.size.focus();
				//theform.emp_status.style.background='#FFA74F';
				return false;
			}
	
	
	//Validate title

	var checkDIS = "()+0123456789- ";

	var checkStr = theform.title.value;
	//alert(checkStr);
	
	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "Select")
		allValid = false;

	if (checkStr == "0")
		allValid = false;
	
			if (!allValid)
			{
				alert("Please select Title");
				theform.title.focus();
				//theform.title.style.background='#FFA74F';
				return false;
			}

//firstname

var checkDIS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,'- ";

	var checkStr = theform.first_name.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
		
	if (checkStr == "first name")
		allValid = false;
		
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your First Name");
				theform.first_name.focus();
				theform.first_name.style.background='#FFA74F';
				return (false);
			}


//validate Surname

var checkDIS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,'- ";

	var checkStr = theform.surname.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
if (checkStr == "surname")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your Surname");
				theform.surname.style.background='#FFA74F';
				theform.surname.focus();
				return (false);
			}



			
			//validate postcode

var checkDIS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,- ";

	var checkStr = theform.postcode2.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
if (checkStr == "postcode")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your postcode");
				theform.postcode2.style.background='#FFA74F';
				theform.postcode2.focus();
				return (false);
			}
			
//validate foundedaddress


	var checkDIS = "()+0123456789- ";

	var checkStr = theform.foundedaddress2.value;
	//alert(checkStr);
	
	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "Select")
		allValid = false;

	if (checkStr == "0")
		allValid = false;
		
	
	
			if (!allValid)
			{
				alert("Please select your address from the list");
				theform.foundedaddress2.focus();
				//theform.title.style.background='#FFA74F';
				return false;
			}



//validate HomeTel

var checkDIS = "()+0123456789- ";

	var checkStr = theform.tele.value;

	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "")
		allValid = false;

	if (checkStr.length < 8)
		allValid = false;
  
if (checkStr == "telephone no")
		allValid = false;
		
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if (ch == "(")
				openBrace = true;

			if ((ch == ")") && !openBrace)
			{
				allValid = false;
				break;
			}

			if (ch == ")")
			{
				closeBrace = true;
				openBrace = false;
			}

			if ((ch == "+") && (i != 0))
			{
				allValid = false;
				break;
			}

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}

			if (openBrace)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter a Daytime Telephone Number (Please ensure it is valid)");
				theform.tele.focus();
				theform.tele.style.background='#FFA74F';
				return (false);
			}

			//validate Email

var checkDIS = "-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@.";

	var checkStr = theform.email.value;

	var allValid = true;

	var atSign = false;

	var dotOk = false;

	if (checkStr == "")
		allValid = false;
		
		if (checkStr == "you@here.co.uk")
		allValid = false;
		

	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if ((ch == "@") && (i > 0))
				atSign = true;

			if ((ch == ".") && (atSign == true) && (i < (checkStr.length - 1)))
				dotOk = true;

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;

			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!dotOk)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter a valid Email Address i.e. j.smith@dogs.co.uk");
				theform.email.focus();
				theform.email.style.background='#FFA74F';
				return (false);
			}
			
			
			//validate dd

var checkDIS = "()+0123456789- ";

	var checkStr = theform.dd.value;
	//alert(checkStr);
	
	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "Select")
		allValid = false;

	if (checkStr == "0")
		allValid = false;
		
		if (checkStr == "")
		allValid = false;
	
			if (!allValid)
			{
				alert("Please select day of your reserve date");
				theform.dd.focus();
				//theform.emp_status.style.background='#FFA74F';
				return false;
			}
			
			
			//validate mm

var checkDIS = "()+0123456789- ";

	var checkStr = theform.mm.value;
	//alert(checkStr);
	
	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "Select")
		allValid = false;

	if (checkStr == "0")
		allValid = false;
		
		if (checkStr == "")
		allValid = false;
	
			if (!allValid)
			{
				alert("Please select month of your reserve date");
				theform.mm.focus();
				//theform.emp_status.style.background='#FFA74F';
				return false;
			}
			
			//validate yyyy

var checkDIS = "()+0123456789- ";

	var checkStr = theform.yyyy.value;
	//alert(checkStr);
	
	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "Select")
		allValid = false;

	if (checkStr == "0")
		allValid = false;
		
		if (checkStr == "")
		allValid = false;
	
			if (!allValid)
			{
				alert("Please select year of your reserve date");
				theform.yyyy.focus();
				//theform.emp_status.style.background='#FFA74F';
				return false;
			}
			
			
			
return (true);

}




