  var win = null;
  function newWindow(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/0;
  var wint = (screen.height-h)/0;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
  }

  var win = null;
  function newWindow2(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/1;
  var wint = (screen.height-h)/0;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
  }

  function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
  }

  function GoCheck_onclick() {
  if(PCcheck.value.length==0){return}
  areas = fillarray();
  var chValue = PCcheck.value;
  chValue = chValue.toUpperCase();

  if (chValue.indexOf(" ")!=-1)
  {var temparray = chValue.split(" ");
  var PC = temparray[0];
  PC = PC.concat(":");}

  else
  if(chValue.length==7)
    {var PC= chValue.slice(0,4);
    PC = PC.concat(":")}
  else
    {var PC= chValue.slice(0,3);
    PC = PC.concat(":")}

  var locale=areas.indexOf(PC);

  if(locale!=-1)
  {OP1.value = 'Service is available in this area!';
  OP2.value = "";
  }
  else{OP1.value = 'Service is unavailable in this area';
  OP2.value = "";
  }
  }
  function FP_callJS(e) {//v1.0
  if( e.keyCode == 13)
  {if(PCcheck.value.length>0)
    {(GoCheck_onclick());}}
  }
  // -->
  //]]>
  
  function characterCounter(field, countfield, maxlimit) {
		if (field.value.length > maxlimit) { // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
			alert("Sorry! You have exceeded the limit of "+maxlimit+" characters!");
			// otherwise, update 'characters left' counter
		}
		countfield.value = maxlimit - field.value.length;
	}

var swear_words_arr=new Array("fuck","bloody","twat","cunt","cock","ass","arse","wank","dick","asshole","piss","fanny","minge","knob","bastard","shit","bugger","turd");
var swear_alert_arr=new Array();
var swear_alert_count=0;

function reset_alert_count()
{
 swear_alert_count=0;
}

function wordFilter(form,fields)
{
	reset_alert_count();
	var compare_text;
	var fieldErrArr=new Array();
	var fieldErrIndex=0;
	for(var i=0; i<fields.length; i++)
	{
		eval('compare_text=document.' + form + '.' + fields[i] + '.value;');
		for(var j=0; j<swear_words_arr.length; j++)
		{
			for(var k=0; k<(compare_text.length); k++)
			{
				if(swear_words_arr[j]==compare_text.substring(k,(k+swear_words_arr[j].length)).toLowerCase())
				{
					swear_alert_arr[swear_alert_count]=compare_text.substring(k,(k+swear_words_arr[j].length));
					swear_alert_count++;
					fieldErrArr[fieldErrIndex]=i;
					fieldErrIndex++;
				}
			}
		}
	}
	var alert_text="";
	for(var k=1; k<=swear_alert_count; k++)
	{
		alert_text+="\n" + "(" + k + ")  " + swear_alert_arr[k-1];
		eval('compare_text=document.' + form + '.' + fields[fieldErrArr[0]] + '.focus();');
		eval('compare_text=document.' + form + '.' + fields[fieldErrArr[0]] + '.select();');
	}
	if(swear_alert_count>0)
	{
		alert("The form cannot be submitted.\nThe following words may be found offensive:\n_______________________________\n" + alert_text + "\n_______________________________");
		return false;
	}
	else
	{
		return true;
	}
}

	function checkorder(){
		
		if (VehicleDescription.T19.selectedIndex == 0){
			alert('Please enter the vehicle\'s colour\nin the \"Colour\" field.');
			VehicleDescription.T19.focus();
			return false;
		}
		
		if (VehicleDescription.metallic.selectedIndex == 0){
			alert('Please select if the vehicle has Metallic Paint\nin the \"Metallic\" field.');
			VehicleDescription.metallic.focus();
			return false;
		 } 

		if (VehicleDescription.T18.selectedIndex == 0){
			alert('Please enter the vehicle\'s year of registration\nin the \"Year Of Registration\" field.');
			VehicleDescription.T18.focus();
			return false;
			
		}
		
		if (VehicleDescription.RegLetter.selectedIndex == 0){
			alert('Please select the vehicle\'s registration Letter or Number\nin the \"Registration\" field.');
			VehicleDescription.RegLetter.focus();
			return false;
		 } 
	
		if (VehicleDescription.T14.selectedIndex == 0){
			alert('Please select the vehicle\'s milage\nin the \"Indicated Mileage\" field.');
			VehicleDescription.T14.focus();
			return false;
		}
		if (VehicleDescription.History.selectedIndex == 0){
			alert('Please select the vehicle\'s Service History\nin the \"Service History\" field.');
			VehicleDescription.History.focus();
			return false;
		}

		if (VehicleDescription.T3.value.length < 2){
			alert('Please enter the asking price for your vehicle\nin the \"Price\" field.');
			VehicleDescription.T3.focus();
			return false;

		}
		if (VehicleDescription.D325.selectedIndex == 0){
			alert('Please select the vehicle\'s Remaining MOT\nin the \"Remaining MOT\" field.');
			VehicleDescription.D325.focus();
			return false;
		}
        if (VehicleDescription.D326.selectedIndex == 0){
			alert('Please select the vehicle\'s Remaining Tax\nin the \"Remaining Tax\" field.');
			VehicleDescription.D325.focus();
			return false;
		}

		
	}
	
function checkorder2(){
	
	    if (drop_list.Make.selectedIndex == 0){
			alert('Please select the vehicle Make and Model \"Make and Model\" fields.');
			drop_list.Make.focus();
			return false;
		 } 

		if (drop_list.description.value.length < 1){
			alert('Please enter the vehicles description e.g GTI, XLDT in the \"Vehicle Description\" field.');
			drop_list.description.focus();
			return false;
		 }

        if (drop_list.VRM_ProductName.value.length < 3){
			alert('Please enter the vehicles registration number in the \"VRM Registration number\" field.');
			drop_list.VRM_ProductName.focus();
			return false;
         }
         
        if (drop_list.Chk1.checked == 0){
			alert('Please confirm you have read and agree to the terms and conditions and the terms of service.');
			drop_list.Chk1.focus();
			return false;	
        
	 }	
	}

function checkorder3(){
	
	    if (drop_list.Make.selectedIndex == 0){
			alert('Please select the vehicle Make and Model \"Make and Model\" fields.');
			drop_list.Make.focus();
			return false;
		 } 

		if (drop_list.description.value.length < 1){
			alert('Please enter the vehicles description e.g GTI, XLDT in the \"Vehicle Description\" field.');
			drop_list.description.focus();
			return false;
		 }

        if (drop_list.VRM_ProductName.value.length < 3){
			alert('Please enter the vehicles registration number in the \"VRM Registration number\" field.');
			drop_list.VRM_ProductName.focus();
			return false;
         }
         
         if (drop_list.Mileage_ProductName.value.length < 2){
			alert('Please enter the vehicles current mileage in the \"Current mileage\" field.');
			drop_list.Mileage_ProductName.focus();
			return false;
		 }   
         
        if (drop_list.Chk1.checked == 0){
			alert('Please confirm you have read and agree to the terms and conditions and the terms of service.');
			drop_list.Chk1.focus();
			return false;	
        
	 }	
	}


function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
  }

function formValidator(){
  // Make quick references to our fields
  var firstname = document.getElementById('firstname');
  var lastname = document.getElementById('lastname');
  var email = document.getElementById('email');
  var postcode = document.getElementById('postcode');
  var subject = document.getElementById('subject');
  var T3 = document.getElementById('T3');

  // Check each input in the order that it appears in the form!
  if(isAlphanumeric(firstname, "Please enter a contact name. No brackets, square brackets or quotation marks please.")){
    if(isAlphanumeric(lastname, "Please enter your company name. No brackets, square brackets or quotation marks please.")){
      if(emailValidator(email, "Please enter a valid email address")){
        if(isAlphanumeric(postcode, "Please enter your website URL. If you do not have a website type None. No brackets, square brackets or quotation marks please.")){
          if(madeSelection(subject, "Please select a subject for your message")){
            if(isNumbers(T3, "Please enter only numbers 0-9 in the price field")){

              return true;
            }
          }
        }
      }
    }
  }
  return false;

  }

  function isEmpty(elem, helperMsg){
  if(elem.value.length == 0){
    alert(helperMsg);
    elem.focus(); // set the focus to this input
    return true;
  }
  return false;
  }


  function isAlphabet(elem, helperMsg){
  var alphaExp = /^[a-zA-Z]+$/;
  if(elem.value.match(alphaExp)){
    return true;
  }else{
    alert(helperMsg);
    elem.focus();
    return false;
  }
  }

  function isAlphanumeric(elem, helperMsg){
  var alphaExp = /^[0-9.;£@{}\£#$_\*\+\<\>\%\=\&\!\?\:\/\,\-\ ]+$/;
  if(elem.value.match(alphaExp)){
    return true;
  }else{
    alert(helperMsg);
    elem.focus();
    return false;
  }
  }


  function madeSelection(elem, helperMsg){
  if(elem.selectedIndex == 0){
    alert(helperMsg);
    elem.focus();
    return false;
  }else{
    return true;
  }
  }

  function emailValidator(elem, helperMsg){
  var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
  if(elem.value.match(emailExp)){
    return true;
  }else{
    alert(helperMsg);
    elem.focus();
    return false;
  }
  }

  function isNumbers(elem, helperMsg){
  var alphaExp = /^[0-9£]+$/;
  if(elem.value.match(alphaExp)){
    return true;
  }else{
    alert(helperMsg);
    elem.focus();
    return false;
  }
  }

