function validChars(string) 
{

    var valid="  0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-?!*(),£/"
    var blnValid

    blnValid = true;

    for (var i=0; i<string.length; i++) {
        if (valid.indexOf(string.charAt(i)) < 0) {
            
            blnValid = false;
        }
    }


    return blnValid;
}

function validNumber(string) 
{

    var valid="0123456789"
    var blnValid

    blnValid = true;

    for (var i=0; i<string.length; i++) {
        if (valid.indexOf(string.charAt(i)) < 0) {
            
            blnValid = false;
        }
    }


    return blnValid;
}




function AddMake()		<!--- addcar1.asp for adding new makes--->
{

         if(document.AddMake.NewMake.value=='')
         {
                 alert("Nothing entered.");
                 document.AddMake.NewMake.focus();
         }
         else
         {

	(validChars(document.AddMake.NewMake.value));

                 if(validChars(document.AddMake.NewMake.value)==true)
                 {
                         document.AddMake.submit();
                }
		else
		{
			alert('New MAKE contains invalid characters.');
		}
         	}
}



function AddModel()		<!--- addcar1.asp for adding new models--->
{

         if(document.AddModel.NewModel.value=='')
         {
                 alert("Nothing entered.");
                 document.AddModel.NewModel.focus();
         }
         else
         {

	(validChars(document.AddModel.NewModel.value));

                 if(validChars(document.AddModel.NewModel.value)==true)
                 {
                         document.AddModel.submit();
                }
		else
		{
			alert('New MODEL contains invalid characters.');
		}
         	}
}


function CheckMake()		<!--- addcar1.asp for selecting make--->
{

         if(document.PickMake.Make.value=='')
         {
                 alert("Nothing entered.");
                 document.PickMake.Make.focus();
         }
         else
         {

	(validChars(document.PickMake.Make.value));

                 if(validChars(document.PickMake.Make.value)==true)
                 {
                         document.PickMake.submit();
                }
		else
		{
			alert('New MAKE contains invalid characters.');
		}
         	}
}


function CheckModel()		<!--- addcar2.asp for selecting model--->
{

         if(document.PickModel.Model.value=='')
         {
                 alert("Nothing entered.");
                 document.PickModel.Model.focus();
         }
         else
         {

	(validChars(document.PickModel.Model.value));

                 if(validChars(document.PickModel.Model.value)==true)
                 {
                         document.PickModel.submit();
                }
		else
		{
			alert('New MODEL contains invalid characters.');
		}
         	}
}




function UserLogin()	

{	
	if (document.login.username.value =="")
	{	alert("Please enter your Account ID");
		document.login.username.focus();
	}
	else
	{	if (document.login.password.value =="")
		{	alert("Please enter your Password");
			document.login.password.focus();
		}
		else
		{
			document.login.submit();
		}
	}
}



function AddCar()		<!--- addcar3.asp for adding new car and editcars1.asp for amendments--->


{
	if(document.AddCar.ModelSpec.value=='')

	{
		alert("Please enter the Vehicle Spec. e.g. 1.8 LX");
		document.AddCar.ModelSpec.focus();
	}

	else

	{
		(validChars(document.AddCar.ModelSpec.value));

		if(validChars(document.AddCar.ModelSpec.value)==false)

		{
			alert('Vehicle Specification contains invalid characters.');
		}

		else

		if(document.AddCar.EngineSize.value=='')

		{
			alert("Please enter the Engine Size.");
			document.AddCar.EngineSize.focus();
		}

		else

		{
			(validNumber(document.AddCar.EngineSize.value));

               			if(validNumber(document.AddCar.EngineSize.value)==false)

			{
				alert('Engine Size should contain numbers only. e.g. 1800');
			}	

			else

			if(document.AddCar.Price.value=='')

			{
				alert("Please enter the Vehicle Price.");
				document.AddCar.Price.focus();
			}

			else

			{

				(validNumber(document.AddCar.Price.value));

				if(validNumber(document.AddCar.Price.value)==false)

				{
					alert('Price should contain numbers only. e.g. 9995');
				}	
	
				else

				{

					(validChars(document.AddCar.Description.value));
	
					if(validChars(document.AddCar.Description.value)==false)
	
					{
						alert('Description contains invalid characters.');
					}

					else

					if(document.AddCar.Year.value == '')

					{
						alert("Please enter the Year in FULL.");
						document.AddCar.Year.focus();

					}

					else

         					{
						(validNumber(document.AddCar.Year.value));

						if(validNumber(document.AddCar.Year.value)==false)

						{
							alert('Year must contain numbers only. e.g. 2000');
						}

						else

						var Year = new String(document.AddCar.Year.value);

						if (Year.length < 4)

						{
							alert("Please enter the Year in FULL");
							document.AddCar.Year.focus();
		        				}

						else

						{
							if(document.AddCar.RegMark.value=='')

							{
								alert("Please enter the Vehicle registration.");
								document.AddCar.Description.focus();

        							}

							else

							{

								(validChars(document.AddCar.RegMark.value));

								if(validChars(document.AddCar.RegMark.value)==false)

								{
									alert('Vehicle registration contains invalid characters.');
								}

								else

         								{
									if(document.AddCar.Colour.value=='')
	
									{
										alert("Please enter the Vehicle colour.");
										document.AddCar.Colour.focus();

        									}

									else

									{
										(validChars(document.AddCar.Colour.value));
	
										if(validChars(document.AddCar.Colour.value)==false)

										{
											alert('Vehicle colour contains invalid characters.');
										}

										else

										if(document.AddCar.Mileage.value == '')
	
										{
											alert("Please enter the mileage.");
											document.AddCar.Mileage.focus();
        										}

         										else

         										{

											(validNumber(document.AddCar.Mileage.value));

               											if(validNumber(document.AddCar.Mileage.value)==false)
	
											{
												alert('Mileage must contain only numbers.');
											}

											else
		
											{
		                        									document.AddCar.submit();
											}
										}
									}
								}
							}
						}
					}
                			}
			}
		}
         	}
}

function UploadImage()	

{	
	if (document.Upload.File1.value =="")
	{	alert("Please select a file to upload.");
		document.Upload.File1.focus();
	}

	else
	{
		document.Upload.submit();
	}
}



function InfoRequest()		<!--- newcars.asp for requesting brochure--->
{
	if(document.NEWCAR.Enq_Name.value=='')


	{	alert("Please enter your name.");
		document.NEWCAR.Enq_Name.focus();
	}

	else

	{
		if(document.NEWCAR.Enq_Address1.value=='')

		{	alert("Please provide your address.");
			document.NEWCAR.Enq_Address1.focus();
		}

		else

		{	if(document.NEWCAR.Enq_PostCode.value=='')

			{	alert("Please provide your Post Code.");
				document.NEWCAR.Enq_PostCode.focus();
			}

			else

			{
				document.NEWCAR.submit();
			}
		}
                }
}

function SendEmail()		<!--- contact.asp for contacting Holders--->
{
	if(document.NEWCAR.Enq_Name.value=='')


	{	alert("Please enter your name.");
		document.NEWCAR.Enq_Name.focus();
	}

	else

	{
		if(document.NEWCAR.Description.value=='')

		{	alert("Please type your message in the box provided.");
			document.NEWCAR.Description.focus();
		}

		else

		{	if(document.NEWCAR.Enq_Email.value=='')

			{	alert("Please provide your Email address.");
				document.NEWCAR.Enq_Email.focus();
			}

			else

			{
				document.NEWCAR.submit();
			}
		}
                }
}
