	//----------------------------------------------------------
	// Name		: ltrim
	// Purpose	: Removes leading spaces from start of string
	//----------------------------------------------------------
	//
	function ltrim(strText)
	{
		while (strText.charAt(0)==" ")
		{
			strText = strText.substring(1);
		}
		return strText;
	}

	//----------------------------------------------------------
	// Name		: rtrim
	// Purpose	: Remove trailing spaces from end of string
	//----------------------------------------------------------
	//
	function rtrim(strText)
	{
		while (strText.charAt( strText.length-1 )==" ")
		{
			strText = strText.substring(0, strText.length-1);
		}
		return strText;
	}

	//----------------------------------------------------------
	// Name		: trim
	// Purpose	: Removes any leading or trailing spaces from a string.
	//----------------------------------------------------------
	//
	function trim(strText)
	{
		strText = ltrim(strText);
		strText = rtrim(strText);
		return strText;
	}

	//----------------------------------------------------------
	// Name		: isEmailAddr
	// Purpose	: Checks for correct email syntax
	//----------------------------------------------------------
	//
	function isEmailAddr(email)
	{
		var result = false;
		var theStr = new String(email)
		var index = theStr.indexOf("@");
		if (index > 0)
		{
			var pindex = theStr.indexOf(".",index);
			if ((pindex > index+1) && (theStr.length > pindex+1))
				result = true;
		}
		return result;
	}

	//----------------------------------------------------------
	// Name		: validateDetails
	// Purpose	: Standard Personal Details Form Validation
	//----------------------------------------------------------
	//
	function validateDetails(theForm)
	{
		var strTitle = new String(trim(theForm.txtTitle.value));
		var strForename = new String(trim(theForm.txtForename.value));
		var strSurname = new String(trim(theForm.txtSurname.value));
		var strAddress = new String(trim(theForm.txtAddress.value));
		var strPostcode = new String(trim(theForm.txtPostcode.value));
		var strEmail = new String(trim(theForm.txtEmail.value));
		
		if ((strTitle.length == "") || (strForename.length == "") || (strSurname.length == "") || (strAddress.length == "") || (strPostcode.length == "") || (strEmail.length == ""))
		{
			alert("Please complete all compulsory fields.");
			theForm.txtTitle.focus();
			return false;
		}
	
		if ((!isEmailAddr(strEmail)) || (strEmail.length < 3))
		{
			alert("Please enter a complete email address in the format 'yourname@yourdomain.com'.");
			theForm.txtEmail.focus();
			return false;
		}

		return true;	
	}

        //----------------------------------------------------------
	// Name		: validateEconRepDetails
	// Purpose	: Specific Economic Reports CSV Request Form Validation
	//----------------------------------------------------------
	//
	function validateEconRepDetails(theForm)
	{
		var strName = new String(trim(theForm.q1.value));
		var strEmail = new String(trim(theForm.q2.value));
		
		if ((strName.length == "") || (strEmail.length == ""))
		{
			alert("Please complete the required fields.");
			theForm.q1.focus();
			return false;
		}
	
		if ((!isEmailAddr(strEmail)) || (strEmail.length < 3))
		{
			alert("Please enter a complete email address in the format 'yourname@yourdomain.com'.");
			theForm.q2.focus();
			return false;
		}

		return true;	
	}

	//----------------------------------------------------------
	// Name		: validateRadioButtons2
	// Purpose	: Standard Radio Button Form Validation
	//----------------------------------------------------------
	//
	function validateRadioButtons2(name)
	{
		var radioSelected = false;
		for (i = 0;  i < name.length;  i++)
		{
			if (name[i].checked)
			radioSelected = true;
		}

		return radioSelected;
	}

	//----------------------------------------------------------
	// Name		: validateOilGasRegistrationDetails
	// Purpose	: Specific CSV Form Validation (O & G 2006)
	//----------------------------------------------------------
   	//
	function validateOilGasRegistrationDetails(theForm)
	{
		var strTitle = new String(trim(theForm.q1.value));
		var strForename = new String(trim(theForm.q2.value));
		var strSurname = new String(trim(theForm.q3.value));
		var strJob = new String(trim(theForm.q4.value));
		var strCompany = new String(trim(theForm.q5.value));
		var strDept = new String(trim(theForm.q6.value));
		
		
		var strAdd1 = new String(trim(theForm.q9.value));
		var strCity = new String(trim(theForm.q10.value));
		var strPostcode = new String(trim(theForm.q11.value));
		var strCountry = new String(trim(theForm.q12.value));
		var strEmail = new String(trim(theForm.q13.value));
		var strTelephoneNo = new String(trim(theForm.q14.value));
				

		if ((strTitle.length == "") || (strForename.length == "") || (strSurname.length == ""))
		{
			alert("Please complete your Title and both Name fields.");
			theForm.q1.focus();
			return false;
		}


		if ((strJob.length == ""))
		{
			alert("Please complete the Job title field.");
			theForm.q4.focus();
			return false;
		}

		if ((strCompany.length == ""))
		{
			alert("Please enter the name of your Company.");
			theForm.q5.focus();
			return false;
		}

		if ((strDept.length == ""))
		{
			alert("Please enter the name of your Department.");
			theForm.q6.focus();
			return false;
		}

		if (!validateRadioButtons2(theForm.q7))
		{
			alert("Please select your Sector.");
			theForm.q7[0].focus();
			return false;
		}


		if ((strAdd1.length == ""))
		{
			alert("Please enter your Address details.");
			theForm.q9.focus();
			return false;
		}

		if ((strCity.length == ""))
		{
			alert("Please enter the City where you are based.");
			theForm.q10.focus();
			return false;
		}


		if ((strPostcode.length == ""))
		{
			alert("Please enter your Company's postcode.");
			theForm.q11.focus();
			return false;
		}

		if ((strCountry.length == ""))
		{
			alert("Please enter the Country where you are based.");
			theForm.q12.focus();
			return false;
		}

		if ((!isEmailAddr(strEmail)) || (strEmail.length < 3))
		{
			alert("Please enter a complete email address in the format 'yourname@yourdomain.com'.");
			theForm.q13.focus();
			return false;
		}

		if ((strTelephoneNo.length == ""))
		{
			alert("Please enter a Contact telephone number.");
			theForm.q14.focus();
			return false;
		}

		if (!validateRadioButtons2(theForm.q18))
		{
			alert("Please respond to the question: Have you received an invitation direct from RBS?");
			theForm.q18[0].focus();
			return false;
		}

		return true;	
	}
 	//----------------------------------------------------------
	// Name		: validateRenewalDetails
	// Purpose	: Specific Insurance Renewal CSV Form Validation (promotions 03)
	//----------------------------------------------------------
   	//
	function validateRenewalDetails(theForm)
	{
		var strForename = new String(trim(theForm.q4.value));
		var strSurname = new String(trim(theForm.q5.value));
		var strHouseNameNum = new String(trim(theForm.q6.value));
		var strStreet = new String(trim(theForm.q7.value));
		var strPostcode = new String(trim(theForm.q10.value));
		var strTelephoneNo = new String(trim(theForm.q12.value));
		
		if ((strForename.length == "") || (strSurname.length == ""))
		{
			alert("Please complete both of the name fields.");
			theForm.q4.focus();
			return false;
		}

		if ((strHouseNameNum.length == "") || (strStreet.length == ""))
		{
			alert("Please complete the entries for both your house name/number and your street.");
			theForm.q6.focus();
			return false;
		}

		if ((strPostcode.length == "") || (strTelephoneNo.length == ""))
		{
			alert("Please complete the entries for both your postcode and your telephone number.");
			theForm.q10.focus();
			return false;
		}

		return true;	
	}

	//----------------------------------------------------------
	// Name		: validateLoansFourDetails
	// Purpose	: Specific Online loans CSV Form Validation (promotions 04)
	//----------------------------------------------------------
   	//
	function validateLoansFourDetails(theForm)
	{
		var strTieBreaker = new String(trim(theForm.q2.value));
		var strSurname = new String(trim(theForm.q4.value));
		var strForename = new String(trim(theForm.q5.value));
		var strAddressOne = new String(trim(theForm.q6.value));		
		var strPostcode = new String(trim(theForm.q8.value));
		var strTelephoneNo = new String(trim(theForm.q10.value));
		
		if ((strTieBreaker.length == ""))
		{
			alert("Please complete the tie-breaker question.");
			theForm.q2.focus();
			return false;
		}		

		if ((strSurname.length == "") || (strForename.length == ""))
		{
			alert("Please complete both of the name fields.");
			theForm.q4.focus();
			return false;
		}

		if ((strAddressOne.length == ""))
		{
			alert("Please complete the entry for the first line of your address.");
			theForm.q6.focus();
			return false;
		}

		if ((strPostcode.length == "") || (strTelephoneNo.length == ""))
		{
			alert("Please complete the entries for both your postcode and your contact number.");
			theForm.q8.focus();
			return false;
		}

		return true;	
	}


	//----------------------------------------------------------
	// Name		: validateGetInTouch
	// Purpose	: Standard Personal Details Form Validation
	//----------------------------------------------------------
	//
	function validateGetInTouch(theForm)
	{
		var strTitle = new String(trim(theForm.txtTitle.value));
		var strForename = new String(trim(theForm.txtForename.value));
		var strSurname = new String(trim(theForm.txtSurname.value));
		var strAddress = new String(trim(theForm.txtAddress.value));
		var strPostcode = new String(trim(theForm.txtPostcode.value));
		var strEmail = new String(trim(theForm.txtEmail.value));
		var strReferer = new String(trim(theForm.txtReferer.value));
		
		if ((strTitle.length == "") || (strForename.length == "") || (strSurname.length == "") || (strAddress.length == "") || (strPostcode.length == "") || (strEmail.length == ""))
		{
			alert("Please complete all compulsory fields.");
			theForm.txtTitle.focus();
			return false;
		}
	
		if ((!isEmailAddr(strEmail)) || (strEmail.length < 3))
		{
			alert("Please enter a complete email address in the format 'yourname@yourdomain.com'.");
			theForm.txtEmail.focus();
			return false;
		}
	
		if (strReferer=="")
		{
			alert("How did you find out about us?");
			theForm.txtReferer.focus();
			return false;
		}

		return true;	
	}
	//----------------------------------------------------------
	// Name		: validateCheckboxes
	// Purpose	: Standard Checkbox Form Validation
	//----------------------------------------------------------
	//
	function validateCheckboxes(theForm)
	{
		var boxchecked = false
		for (var m = 0; m < theForm.elements.length; m++)
		{
			if (theForm.elements[m].checked == true)
			{
				boxchecked = true
			}
		}

		if (boxchecked == false)
		{
			window.alert("Please select an option.");
			return false;
		}
	}

	//----------------------------------------------------------
	// Name		: validateCheckboxes2
	// Purpose	: Standard Checkbox Form Validation
	//----------------------------------------------------------
	//
	function validateCheckboxes2(theForm)
	{
		var boxchecked = false
		var count = 0
		for (var m = 0; m < theForm.elements.length; m++)
		{
			if (theForm.elements[m].checked == true)
			{
				count++
				boxchecked = true
			}
		}

		if (boxchecked == false)
		{
			window.alert("Please select an option.");
			return false;
		}

		if (count > 5)
		{
			alert("We notice that you are requesting a large variety of information booklets from us. It might be beneficial for you to speak to one of our dedicated Business Relationship Managers at your local branch. Each Relationship Manager has the experience and expertise to create the best banking package to suit your business needs and will be pleased to talk to you about the range of products and services we offer.");
			return false;
		}
	}

	//----------------------------------------------------------
	// Name		: validateCheckboxes3
	// Purpose	: Standard Checkbox Form Validation
	//----------------------------------------------------------
	//
	function validateCheckboxes3(theForm)
	{
		var boxchecked = false
		var count = 0
		for (var m = 0; m < theForm.elements.length; m++)
		{
			if (theForm.elements[m].checked == true)
			{
				count++
				boxchecked = true
			}
		}

		if (boxchecked == false)
		{
			window.alert("Please select an option.");
			return false;
		}

		if (count > 5)
		{
			alert("We notice that you are requesting a large variety of information brochures from us. It might be beneficial for you to speak to one of our Customer Advisors at your local branch. Each Customer Advisor has the experience and expertise to create the best banking package to suit your needs and will be pleased to talk to you about the range of products and service we offer.");
			return false;
		}
	}

	//----------------------------------------------------------
	// Name		: validateRadioButtons
	// Purpose	: Standard Radio Button Form Validation
	//----------------------------------------------------------
	//
	function validateRadioButtons(theForm)
	{
		var radioSelected = false;
		for (i = 0;  i < theForm.btnEnquiry.length;  i++)
		{
			if (theForm.btnEnquiry[i].checked)
			radioSelected = true;
		}

		if (!radioSelected)
		{
			alert("Please select an option.");
			return false;
		}
		return true;
	}

	//----------------------------------------------------------
	// Name		: validateNumberTextBox
	// Purpose	: Standard Form Numeric Textbox Validation
	//----------------------------------------------------------
	//
	function validateNumberTextBox(theForm)
	{
		var checkStr = new String(trim(theForm.txtInput.value));

		if ((checkStr == "") || (checkStr.length < 1))
		{
			alert("Please enter a value.");
			theForm.txtInput.focus();
			return false;
		}

		var checkOK = "£,.0123456789 \t\r\n\f";
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
					if (j == checkOK.length)
					{
						allValid = false;
						break;
					}
		}
	
		if (!allValid)
		{
			alert("Please enter numbers only.");
			theForm.txtInput.focus();
			return false;
		}
		return true;
	}

	//----------------------------------------------------------
	// Name		: validateNumberTextBox1
	// Purpose	: Standard Form Numeric Textbox Validation
	//----------------------------------------------------------
	//
	function validateNumberTextBox1(theForm)
	{
		var checkStr = new String(trim(theForm.txtInput1.value));

		if ((checkStr == "") || (checkStr.length < 1))
		{
			alert("Please enter a value.");
			theForm.txtInput1.focus();
			return false;
		}

		var checkOK = "£,.0123456789 \t\r\n\f";
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
					if (j == checkOK.length)
					{
						allValid = false;
						break;
					}
		}
	
		if (!allValid)
		{
			alert("Please enter numbers only.");
			theForm.txtInput1.focus();
			return false;
		}
		return true;
	}

	//----------------------------------------------------------
	// Name		: validateNumberTextBoxes
	// Purpose	: Standard Form Numeric Textbox Validation
	//----------------------------------------------------------
	//
	function validateNumberTextBoxes(theForm)
	{
		return validateNumberTextBox(theForm);

		var checkStr1 = new String(trim(theForm.txtInput1.value));		

		if (checkStr1.length > 0)
		{
			return validateNumberTextBox1(theForm);
		}
	}

	//----------------------------------------------------------
	// Name		: validateSearch
	// Purpose	: Search Engine Validation
	//----------------------------------------------------------
	//
	function validateSearch(theForm)
	{
		var checkStr = new String(trim(theForm.SearchString.value));
	
		if ((checkStr == "") || (checkStr.length < 2))
		{
			alert("Please enter at least 2 characters for your search words or phrases.");
			theForm.SearchString.focus();
			return false;
		}

		if ((checkStr.length == 2) && (checkStr.indexOf("-", 1) == 1))
		{
			alert("Please enter more information.");
			theForm.SearchString.focus();
			return false;
		}

		var checkOK = "£,.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒšœŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789- \t\r\n\f";
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
					if (j == checkOK.length)
					{
						allValid = false;
						break;
					}
		}
	
		if (!allValid)
		{
			alert("Please enter only letters or numbers for your search words or phrases.");
			theForm.SearchString.focus();
			return (false);
		}
		return true;
	}

	//----------------------------------------------------------
	// Name		: validatePaymentCalc
	// Purpose	: Mortgage Payment Calculator Validation
	//----------------------------------------------------------
	//
	function validatePaymentCalc(theForm)
	{
		var str1 = new String(theForm.txt1.value);
		var str2 = new String(theForm.txt2.value);
		var str3 = new String(theForm.txt3.value);
		var str4 = new String(theForm.txt4.value);
		var str5 = new String(theForm.txt5.value);
		var checkOK = "0123456789-";
		var checkStr = theForm.txt5.value;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
	
		if ((str1.length == "") || (str2.length == "")|| (str3.length == "") || (str4.length == "") || (str5.length == ""))
		{
			alert("Please complete all fields before selecting the calculate button.");
			theForm.txt1.focus();
			return false;
		}

		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
			allNum += ch;
		}

		if (!allValid)
		{
			alert("The loan term must be a whole number.");
			theForm.txt5.focus();
			return (false);
		}
	
		return (true);
	}

	//----------------------------------------------------------
	// Name		: validateFlexibleCalc
	// Purpose	: Mortgage Payment Calculator Flexible Options Validation
	//----------------------------------------------------------
	//
	function validateFlexibleCalc(theForm)
	{
		var strFlexi1 = new String(theForm.txtFlexi1.value);
		var strFlexi2 = new String(theForm.txtFlexi2.value);
		var strFlexi3 = new String(theForm.txtFlexi3.value);
		var strFlexi4 = new String(theForm.txtFlexi4.value);

		if ((strFlexi1.length == "") && (strFlexi2.length == "") && (strFlexi3.length == "") && (strFlexi4.length == ""))
		{
			alert("Please complete one field.");
			theForm.txtFlexi1.focus();
			return false;
		}

		if ((strFlexi1.length != "") && !(strFlexi1 > "0"))
		{
			alert("Monthly Payments must be greater than £0.");
			theForm.txtFlexi1.focus();
			return false;
		}
	
		if ((strFlexi2.length != "") && !(strFlexi2 > "0"))
		{
			alert("Monthly Payments must be greater than £0.");
			theForm.txtFlexi2.focus();
			return false;
		}

		if ((strFlexi3.length != "") && !(strFlexi3 > "0"))
		{
			alert("Lump sum payments must be greater than £0.");
			theForm.txtFlexi3.focus();
			return false;
		}

		if ((strFlexi3.length != "") && (strFlexi4.length == ""))
		{

			alert("Please complete the lump sum payment year details.");
			theForm.txtFlexi4.focus();
			return false;
		}


		if ((strFlexi3.length == "") && (strFlexi4.length != ""))
		{

			alert("Please complete the lump sum details.");
			theForm.txtFlexi3.focus();
			return false;
		}
	
		return true;	
}

	//----------------------------------------------------------
	// Name		: validateBBDForm
	// Purpose	: Standard BBD Details Form Validation
	//----------------------------------------------------------
	//
	function validateBBDForm(theForm)
	{
		var strTitle = new String(trim(theForm.txtTitle.value));
		var strForename = new String(trim(theForm.txtForename.value));
		var strSurname = new String(trim(theForm.txtSurname.value));
		var strPhone = new String(trim(theForm.txtPhone.value));
		var strEmail = new String(trim(theForm.txtEmail.value));
		var strCompany = new String(trim(theForm.txtCompany.value));
		var strCompanyAddress = new String(trim(theForm.txtCompanyAddress.value));
		var strCompanyPostcode = new String(trim(theForm.txtCompanyPostcode.value));
		var strCompanyBusiness = new String(trim(theForm.txtCompanyBusiness.value));
		var strCompanyOwners = new String(trim(theForm.txtCompanyOwners.value));
		var strCompanyLegalStatus = new String(trim(theForm.txtCompanyLegalStatus.value));
		var strTurnover = new String(trim(theForm.txtTurnover.value));
		var strCustomer = new String(trim(theForm.txtCustomer.value));

		if ((strTitle.length == "") || (strForename.length == "") || (strSurname.length == "") || (strPhone.length == "") || (strEmail.length == "") || (strCompany.length == "") || (strCompanyAddress.length == "") || (strCompanyPostcode.length == "") || (strCompanyBusiness.length == "") || (strCompanyOwners.length == "") || (strCompanyLegalStatus.length == "") || (strTurnover.length == "") || (strCustomer.length == ""))
		{
			alert("Please complete all compulsory fields.");
			theForm.txtTitle.focus();
			return false;
		}
	
		if ((!isEmailAddr(strEmail)) || (strEmail.length < 3))
		{
			alert("Please enter a complete email address in the format 'yourname@yourdomain.com'.");
			theForm.txtEmail.focus();
			return false;
		}

		return true;	
	}

	//----------------------------------------------------------
	// Name		: limitText
	// Purpose	: Limits text in a text area. See oil & gas survey 2003
	//		  example of use
	//----------------------------------------------------------
	//

	function limitText(textArea, length) 
	{
    		if (textArea.value.length > length) 
		{
       		 textArea.value = textArea.value.substr(0,length);
    		}
	}


