ar = new Array(
"kings","bead","harley","jesmond","dubarry","grecian","chester","rat tail","old english reeded handle","athenian","fiddle thread shell","la regence","jester","glacier","sirocco","festival","silver dawn","valiant","jubilee","president","mirage","maestro","romany","infinity","mystere","sandtone"
)

function matchFieldSelect (field, select, value) {
// this function auto-completes the field with one of the values in the array above.

  var property = value ? 'value' : 'text';
  var found = false;
  for (var i = 0; i < 29; i++) // i < the number of elements in the array
    if ((found = select[i].indexOf(field.value) == 0))
    {
      break;
    }
  if (field.createTextRange) {
    var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;" 
    if (cursorKeys.indexOf(event.keyCode+";") == -1) { // prevents script from firing when non-alphanumeric keys are hit e.g. delete
      var r1 = field.createTextRange()
      var oldValue = r1.text;
      var newValue = found ? select[i] : oldValue;
      if (newValue != field.value) {
        field.value = newValue
        var rNew = field.createTextRange()

//			toUpper(field) // script which converts string to sentence case
		
		
        rNew.moveStart('character', oldValue.length) // ensures that the select highlight starts after the last inputted character
		rNew.select() // select highlights the rest
	  }
    }
  }

}

function toUpper(field) { // changes a field value to Sentence Case and writes it in the field
    var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 

    var a = field.value.split(/\s+/g); // split the sentence into an array of words

    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }
    
    field.value = a.join(' '); // join it back together

}

function ReturnToUCase(string){ // changes a string to Sentence Case and returns the new string value
  	var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 

    var a = string.split(/\s+/g); // split the sentence into an array of words

    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }
    
    return a.join(' '); // join it back together

}

function noEnter() { // prevents the form from being when the Enter key is pressed
  return !(window.event && window.event.keyCode == 13); }
