	function createBookmarkLink() 
	{
		 title = "Robins and Day";
		 url = "http://www.robinsandday.com/";

		if (window.sidebar) 
		{
			window.sidebar.addPanel(title, url, "");
		} 
		else if (window.external)
		{
			window.external.AddFavorite(url, title); 
		}
		else if (window.opera && window.print) 
		{
			return true; 
		}
	}

	function checkForm(mainSearch)
	{
		if (document.usedCarSearch.manufacturer.selectedIndex == 0)
			{
				alert("Please select a manufacturer");
				element = document.getElementById("selectManufacturer");
				highlight(element, true);
				document.usedCarSearch.manufacturer.focus();

				return false;
			}
			else
			{
				element = document.getElementById("selectManufacturer");
				highlight(element, false);
			}

			if (document.usedCarSearch.manufacturer.selectedIndex == 1 && document.usedCarSearch.model.selectedIndex == 0)
			{
				alert("Please select a model");
				element = document.getElementById("selectModel");
				highlight(element, true);
				document.usedCarSearch.model.focus();

				return false;
			}
			else
			{
				element = document.getElementById("selectModel");
				highlight(element, false);
			}

			if (mainSearch)
			{
				if (document.usedCarSearch.dealerCode.value == '')
				{
					if (document.usedCarSearch.postcode.value == '' || document.usedCarSearch.postcode.value == 'Required')
					{
						alert("Please enter your postcode");
						element = document.getElementById("textPostcode");
						highlight(element, true);
						document.usedCarSearch.postcode.focus();

						return false;
					}
					else
					{
						element = document.getElementById("textPostcode");
						highlight(element, false);
					}
				}
			}
			else
			{
				if (document.usedCarSearch.postcode.value == '' || document.usedCarSearch.postcode.value == 'Required')
				{
					alert("Please enter your postcode");
					element = document.getElementById("textPostcode");
					highlight(element, true);
					document.usedCarSearch.postcode.focus();

					return false;
				}
				else
				{
					element = document.getElementById("textPostcode");
					highlight(element, false);
				}
			}

			if (mainSearch)
			{
				document.usedCarSearch.start.value = '0';
				document.usedCarSearch.page.value = 'usedCarSearch';
				document.usedCarSearch.action="index.php";

				showHeader(true);
			}

			return true;
	}

function validateItem(formArray)
{
	returnValue = true;

	for (i=0; i<formArray.length; i++)
	{
		if (returnValue)
		{
			element = document.getElementById(formArray[i][0]);
			switch (formArray[i][1])
			{
				case 'text':
				case 'password':	
				case 'textarea':

					if ((formArray[i][2] == 'STRING' && element.value != '') || (formArray[i][2] == 'NUMBER' && isNumeric(element.value)))
					{
						highlightElement(formArray[i][0], false);
					}
					else
					{

						alert(formArray[i][3]);
						highlightElement(formArray[i][0], true);
						focusElement(element);
						returnValue = false;
					}

					continue;

				case 'hidden':

					if ((formArray[i][2] == 'STRING' && element.value != '') || (formArray[i][2] == 'NUMBER' && isNumeric(element.value)))
					{
					}
					else
					{
						alert(formArray[i][3]);
						returnValue = false;
					}

					continue;

				case 'radio':

					var element = eval('document.forms[0].' + formArray[i][0]);
					
					for (i=0; i<element.length; i++) 
					{
						if (element[i].checked) 
						{
							highlightElement(formArray[i][0] + 'Border', false);						
							continue;
						}
					}

					alert(formArray[i][3]);
					highlightElement(formArray[i][0] + 'Border', true);
					focusElement(element);
					returnValue = false;

					continue;

				case 'check':
					
					if (element.checked)
					{
						highlightElement(formArray[i][0] + 'Border', false);
					}
					else
					{
						alert(formArray[i][3]);
						highlightElement(formArray[i][0] + 'Border', true);
						focusElement(element);
						returnValue = false;
					}

					continue;

				case 'select':

					if (element.selectedIndex != 0)
					{
						highlightElement(formArray[i][0] + 'Border', false);
					}
					else
					{
						alert(formArray[i][3]);
						highlightElement(formArray[i][0] + 'Border', true);
						focusElement(element);
						returnValue = false;
					}

					continue;

				case 'date':

					continue;
			}
		}		
	}

	return returnValue;
}

function validateForm(formArray)
{
	returnValue = true;

	for (i=0; i<formArray.length; i++)
	{
//		alert(i + ' ' + formArray.length);
//		if (returnValue)
	//	{
			element = document.getElementById(formArray[i][0]);
			switch (formArray[i][1])
			{
				case 'text':
				case 'password':	
				case 'textarea':
				case 'hidden':

					if ((formArray[i][2] == 'STRING' && element.value != '') || (formArray[i][2] == 'NUMBER' && isNumeric(element.value)))
					{
						highlightElement(formArray[i][0], false);
					}
					else
					{

//						alert(formArray[i][3]);
						highlightElement(formArray[i][0], true);
						focusElement(element);
						returnValue = false;
					}

					continue;

				case 'radio':

					var element = eval('document.forms[0].' + formArray[i][0]);
					
					for (j=0; j<element.length; j++) 
					{
						if (element[j].checked) 
						{
							highlightElement(formArray[i][0] + 'Border', false);						
							continue;
						}
					}

	//				alert(formArray[i][3]);
					highlightElement(formArray[i][0] + 'Border', true);
					focusElement(element);
					returnValue = false;

					continue;

				case 'check':
					
					if (element.checked)
					{
						highlightElement(formArray[i][0] + 'Border', false);
					}
					else
					{
//						alert(formArray[i][3]);
						highlightElement(formArray[i][0] + 'Border', true);
						focusElement(element);
						returnValue = false;
					}

					continue;

				case 'select':

					if (element.selectedIndex != 0)
					{
						highlightElement(formArray[i][0] + 'Border', false);
					}
					else
					{
//						alert(formArray[i][3]);
						highlightElement(formArray[i][0] + 'Border', true);
						focusElement(element);
						returnValue = false;
					}

					continue;

				case 'date':

					continue;
			}
//		}		
	}
	if(!returnValue)
	{
		alert('Please fill in the required fields');
	}

	return returnValue;
}

function highlightElement(id, status)
{
	element = document.getElementById(id);

	if (status)
	{
		element.style.borderColor = '#0058DD';
		element.style.borderWidth = '2px';
		element.style.borderStyle = 'solid';
	}
	else
	{
		element.style.borderColor = '';
		element.style.borderWidth = '';
		element.style.borderStyle = '';
		//element.style.background = 'transparent';
	}
}

function focusElement(element)
{
	element.focus();
}

	function validateField(element, isNumericCheck, errorMessage)
	{
		if (element)
		{
			if (isNumericCheck)
			{
				if (isNumeric(element.value))
				{
					highlight(element, false);
					return true;
				}
				else
				{
					highlight(element, true);
					element.focus();
					alert(errorMessage);
					return false;
				}
			}
			else
			{
				if (element.value != '')
				{
					highlight(element, false);
					return true;
				}
				else
				{
					highlight(element, true);
					element.focus();
					alert(errorMessage);
					return false;
				}
			}
		}
		else
		{
			return false;
		}
	}

	function highlight(element, onOff)
	{
		if (onOff)
		{
			element.style.borderColor = 'red';
			element.style.borderWidth = '2px';
			element.style.borderStyle = 'solid';
		}
		else
		{
			element.style.borderColor = '';
			element.style.borderWidth = '';
			element.style.borderStyle = '';
		}
	}

	function isNumeric(number)
	{
		validNumbers = "0123456789";
		singleChar = '';

		if (number.length == 0) 
		{
		   return false;
		}

		for (k=0; k<number.length; k++)
		{
			singleChar = number.charAt(k);

			if (validNumbers.indexOf(singleChar) == -1)
			{
				return false;
			}
		}

		return true;
	}

	function checkManufacturer()
	{
		if (document.usedCarSearch.manufacturer.selectedIndex == 1)
		{
			document.getElementById('model').disabled = false;
			document.getElementById('bodyStyle').disabled = false;
		}
		else
		{
			document.getElementById('model').selectedIndex = 1;
			document.getElementById('bodyStyle').selectedIndex = 0;
			document.getElementById('model').disabled = true;
			document.getElementById('bodyStyle').disabled = true;
		}
	}

	function clearField(element, normalValue)
	{
		if (element.value == normalValue)
		{
			element.value = '';
		}				
	}

	function selectBox(name)
	{
		formItem = document.getElementById(name);
		divImage = document.getElementById(name + "Box");

		if (formItem.value == 0)
		{
			image = "on";
			hiddenValue = 1;
		}
		else
		{
			image = "off";
			hiddenValue = 0;
		}

		divImage.src = "images/" + image + ".gif";

		formItem.value = hiddenValue;
	}

	function changePage(start)
	{
		document.usedCarSearch.start.value = start;
		document.usedCarSearch.method="get";
		document.usedCarSearch.action="index.php";
		document.usedCarSearch.submit();
	}

	function showDetails(vehicleID)
	{
		showHeader(false);

		document.usedCarSearch.vehicleID.value = vehicleID;
		document.usedCarSearch.page.value = 'usedVehicleDetail';
		document.usedCarSearch.method="get";
		document.usedCarSearch.action="index.php";
		document.usedCarSearch.submit();
	}

	function backToSearch()
	{
		showHeader(true);

		document.usedCarSearch.action="index.php";
		document.usedCarSearch.submit();
	}

	function doCompare()
	{
		showHeader(false);
		document.usedCarSearch.page.value = 'carSearchCompare';
		document.usedCarSearch.action="index.php";
		document.usedCarSearch.method="get";
		document.usedCarSearch.submit();
	}

	function showHeader(status)
	{
		if (status)
		{
			style = "block";
			
			document.usedCarSearch.page.value = 'usedCarSearch';
			document.usedCarSearch.action="index.php";
		}
		else
		{
			style = "none";
		}

	}

	function considerThese(minPrice, maxPrice)
	{
		showHeader(true);

		findValue(document.usedCarSearch.manufacturer, 'peugeot');
		findValue(document.usedCarSearch.model, 'any');
		findValue(document.usedCarSearch.minPrice, minPrice);
		findValue(document.usedCarSearch.maxPrice, maxPrice);

		document.usedCarSearch.bodyStyle.disabled = false;

		document.usedCarSearch.action="index.php";
		document.usedCarSearch.submit();			
	}

	function findValue(formItem, value)
	{
		for (i=0; i<formItem.length; i++)
		{
			if (formItem[i].value == value)
			{
				formItem.selectedIndex = i;
				break;
			}
		}
	}

	function checkCustom()
	{
		if (document.usedCarSearch.model[document.usedCarSearch.model.selectedIndex].value == 'custom')
		{
			document.usedCarSearch.bodyStyle.disabled = true;
		}
		else
		{
			document.usedCarSearch.bodyStyle.disabled = false;
		}
	}

	function checkUsedVehicleForm()
	{
		checkChoice = false;

		for (var i=0; i < document.usedVehicles.elements.length; i++)
		{
			var element = document.usedVehicles.elements[i];
				
			if (element.type == 'checkbox' && element.checked)
			{
				checkChoice = true;
			}
		}
		
		if (!checkChoice)
		{
			alert("Please select a car derivative.")
			return false;
		}
		
		if (document.usedVehicles.postcode.value == '' || document.usedVehicles.postcode.value == 'Required')
		{
			alert("Please enter your postcode");
			element = document.getElementById("textPostcode");
			highlight(element, true);
			document.usedVehicles.postcode.focus();

			return false;
		}
		
		return true;
	}

	function resetForm()
	{
		document.usedCarSearch.bodyStyle.selectedIndex = 0;
		document.usedCarSearch.minPrice.selectedIndex = 0;
		document.usedCarSearch.maxPrice.selectedIndex = 0;
		document.usedCarSearch.maxMileage.selectedIndex = 0;
		document.usedCarSearch.bodyStyle.selectedIndex = 0;
		document.usedCarSearch.fuelType.selectedIndex = 0;
		document.usedCarSearch.variant.value = 'Variants (e.g. 1.9 HDi)';
		document.usedCarSearch.transmission.selectedIndex = 0;
		document.usedCarSearch.colourSelect.selectedIndex = 0;

		document.getElementById('aircon').checked = 0;
		document.getElementById('cdplayer').checked = 0;
		document.getElementById('leather').checked = 0;
		document.getElementById('sunroof').checked = 0;
		document.getElementById('satnav').checked = 0;
		document.getElementById('alloywheels').checked = 0;

		document.getElementById('grey').checked = 0;
		document.getElementById('silver').checked = 0;
		document.getElementById('yellow').checked = 0;
		document.getElementById('white').checked = 0;
		document.getElementById('blue').checked = 0;
		document.getElementById('green').checked = 0;
		document.getElementById('black').checked = 0;
		document.getElementById('orange').checked = 0;
		document.getElementById('red').checked = 0;
		document.getElementById('other').checked = 0;
	}