    var xmlHttp = false;
    var divId;
    var valId;
    var divtblid;

    var mouseCurState;
    mouseCurState = false;

    var test;
    test = 0;

    var hideList;

    var clientbrowse=navigator.appName;
    
    // Capture the right mouse click.
	document.onmousedown=click;
	// Need belt and braces in Firefox.
	window.oncontextmenu = function () { return false; }

    function sendRequest(url, func)
    {
       try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e2)
            {
                xmlHttp = false;
            }
        }

        if(!xmlHttp)
        {
            xmlHttp = new XMLHttpRequest();
        }

        xmlHttp.open("GET", url, true);

        xmlHttp.onreadystatechange = eval(func);

        xmlHttp.send(null);
    }

    function canFillAutoText()
    {
        var spcChrAscCode = new Array(8, 27, 32, 38, 40, 41, 44, 45, 46, 47, 62);
        var hasCodeMatch = false;
        var i;
        var curkey;
        hideList = false;

       if (clientbrowse=="Microsoft Internet Explorer")
        {
            curkey = event.keyCode
        }
        else
        {
            curkey = event.which
        }

        for(i=0;i<spcChrAscCode.length;i++)
          {
            if(curkey == spcChrAscCode[i])
            {
                hasCodeMatch = true;
                break;
            }
          }

        if(hasCodeMatch == false)
        {
            if((curkey >= 48 && curkey <= 57) || (curkey >= 65 && curkey <= 90) || (curkey >= 97 && curkey <= 122))
            {
                hasCodeMatch = true;
            }
        }

        if(hasCodeMatch == false)
        {
            hideList = true;
        }
    }

    function getMatchText(val, qry, procDivId, divtbl, qryLen)
    {
        divId = procDivId;
        valId = val;
        divtblid = divtbl;

        if(qry.value.length <= qryLen)
        {
            hideList = true;
        }

        if(hideList == true)
        {
            hideDropDown();
            return;
        }

        sendRequest('ajax_autotextbox.asp?val=' + val + '&query=' + qry.value + '&test=' + test, 'fillTextBx');
    }

    function setText()
    {
        if(valId=="2")
        {
            document.getElementById("txtPostcode").value = this.innerHTML;
            document.getElementById("hirer_postcode").value = this.id;
            document.getElementById(divId).style.display = "none";
        }
        else if(valId=="1")
        {
            document.getElementById("txtHirer").value = this.innerHTML;
            document.getElementById("hirer").value = this.id;
            document.getElementById(divId).style.display = "none";
        }
    }

    function getText()
    {
        if(valId=="2")
        {
            return document.getElementById("txtPostcode").value;
        }
        else if(valId=="1")
        {
            return document.getElementById("txtHirer").value;
        }
    }

    function fillTextBx()
    {
       if(xmlHttp.readyState == 4)
        {

           var response = xmlHttp.responseText;

           if(response == "")
            {
                document.getElementById(divId).style.display = "none";
                return;
            }

           document.getElementById(divId).style.display = "inline";

           var results = response.split("~");

           if(results.length == 2)
            {
                if(getText().toLowerCase() == results[0].toLowerCase())
                {
                   document.getElementById(divId).style.display = "none";
                   return;
                }
            }

            var tab = document.getElementById(divtblid);
            if (clientbrowse=="Microsoft Internet Explorer")
             {
                tab.innerText = "";
              }
            else
             {
                tab.innerHTML = "";
             }


            var i;
            for(i = 0; i < results.length - 1; i++)
            {
                var tableRow, tableCellName;

                tableRow = document.createElement("tr");
                tableCellName = document.createElement("td");

                var record = results[i];

                var recordArr = record.split("^");

                tableCellName.innerHTML = recordArr[1];
                tableCellName.id = recordArr[0];

                tableCellName.noWrap = true;
                tableCellName.onclick = setText;
                tableCellName.onmouseover = chaneBG;
                if (clientbrowse=="Microsoft Internet Explorer")
                {
                    tableCellName.onmouseleave = changeBG1;
        	    }
        	    else
        	    {
        	        tableCellName.onmouseout = changeBG1;
        	    }
                tableRow.appendChild(tableCellName);

                tab.appendChild(tableRow);
            }
        }
        return;
    }

    function chaneBG()
    {
        this.style.backgroundColor = "silver";

         if (clientbrowse=="Microsoft Internet Explorer")
             {
                this.style.cursor = "hand";
             }
         else
             {
                this.style.cursor="pointer";
             }


        currText = this.innerHTML;
    }

    function changeBG1()
    {
        this.style.backgroundColor = "";
    }

    function hideDropDown()
    {
        var divObj = document.getElementById(divId);

        if(divObj != null)
        {
            divObj.style.display = "none";
        }
    }

    function overDiv()
    {
        mouseCurState = true;
    }

    function outDiv()
    {
        mouseCurState = false;
    }

    function txtBlur()
    {
        if(mouseCurState == true)
        {
            setFocusTxt();
        }
        else
        {
            hideDropDown();
        }
    }

    function setFocusTxt()
    {
        if(valId=="2")
        {
            document.getElementById("txtPostcode").focus();
        }
        else if(valId=="1")
        {
            document.getElementById("txtHirer").focus();
        }
    }

    function fGetPass (tURL,tEl) {
      el = document.getElementById(tEl);
      if (el) {
        if (el.value != '') {
          location.href = tURL + "?email=" + el.value;
        } else {
          location.href = tURL;
        }
      }
    }

    function GetConfirm(sMsg1,sLink) {
      s = confirm(sMsg1);
      if (s) {
        location.href = sLink;
      }
    }

    function GetParam(sMsg1,sMsg2,sLink) {
      s = prompt(sMsg1);
      if (s) {
        if (confirm(sMsg2)) {
          location.href = sLink + s;
        }
      }
    }

    function HideDiv(el) {
      obj = document.getElementById(el);
      if (obj) {
        obj.style.display = 'none';
      }
    }

    function ShowDiv(el) {
      obj = document.getElementById(el);
      if (obj) {
        obj.style.display = 'block';
      }
    }

    function update_count(a,lab,max) {
      if (a) {
        valu = a.value.length;
        if (valu > max) {
          a.value = a.value.substr(0,max);
          valu = max;
        }
      } else {
        valu = 0;
      }
      el = document.getElementById('cnt_disp');
      toreplace = lab + '<br />' + valu + '/' + max + " characters";
      if (el.innerHTML != toreplace) {
        el.innerHTML = toreplace;
      }
    }

    function SubmitFormWithNew (t_formid, t_field, t_fieldvalue) {
      thisform = document.getElementById(t_formid);
      if (document.getElementById('t_field')) {
        document.getElementById('t_field').value = t_fieldvalue;
      } else {
        var i   = document.createElement('INPUT');
        i.type  = 'hidden';
        i.name  = t_field;
        i.value = t_fieldvalue;
        thisform.appendChild(i);
      }
      thisform.submit();
    }

    function GetRadioValue (radset) {
      if (radset) {
        for (i=0;i<radset.length;i++) {
          if (radset[i].checked) {
            return radset[i].value;
          }
        }
      }
    }
    function submitter (objForm, data, returnto, source) {
      thisform = document.getElementById(objForm);

      var i = document.createElement('INPUT');
      i.type = 'hidden';
      i.name = 'special_action';
      i.value = data;
      thisform.appendChild(i);

      var i = document.createElement('INPUT');
      i.type = 'hidden';
      i.name = 'return';
      i.value = returnto;
      thisform.appendChild(i);

      document.getElementById(source).innerHTML = 'loading, please wait...';

      thisform.submit();

    }

    function ConfirmThenGo (url,prompt) {
      if (confirm(prompt)) {
        //location.href = url;
        window.location.replace(url);
      }
    }

    function ConfirmThenGoThis (aTag, url, prompt) {
      bout = false;
      if (confirm(prompt)) {
        aTag.setAttribute("href",url);
        bout = true;
      }
      return bout;
    }

    function Align (objThat, objThis) {
      elThis = document.getElementById(objThis);
      elThat = document.getElementById(objThat);

      var offset = 0;

      // New offset stuff for response boxes 
      elGood = document.getElementById("responseBoxGood");
      elBad = document.getElementById("responseBoxBad");
      if (elGood) {
        var coordsgood = getCoords(elGood);
        offset = offset + coordsgood.height;
      }
      if (elBad) {
        var coordsbad = getCoords(elBad);
        offset = offset + coordsbad.height;
      }

      var hThis;
      var coords = getCoords(elThis);

      if (coords) {
        hThis = coords.y;
        if (hThis < 400 && offset > 0) { hThis = hThis + offset; }
        hThis = hThis + 50;
        elThat.style.top = hThis.toString() + "px";
      }
    }

    function getCoords (element) {
      if (element) {
        var coords = { x: 0, y: 0, width: element.offsetWidth, height: element.offsetHeight };
        while (element) {
          coords.x += element.offsetLeft;
          coords.y += element.offsetTop;
          element = element.offsetParent;
        }
        return coords;
      } else {
        return false;
      }
    }

    function ZeroCheck(el) {
      x = document.getElementById(el);
      if (x == '[object HTMLSelectElement]') {
        if (x.options[x.selectedIndex].value==0) {
          alert ('Please select a policyholder from the dropdown list');
          return false;
        }
      }
      return true;
    }

    function GoTo(url) {
      location.href = url;
    }

    function GoToTextBoxId(url,el,errmsg) {
    	// This function expects a numeric id.
    	// Any non-numeric chars are removed.
			var strValue = el.value;
			var numValue = "";
			for (i=0; i < strValue.length; i++) {
				var tempChar = strValue.charAt(i);
				if (tempChar >= "0"
				 && tempChar <= "9"){
					numValue += tempChar;
				}	
			}    	
      var xx = parseInt(numValue);
      //alert (xx);
      if (xx != ''&& xx > 0) {
          location.href=url + xx;
      } else {
          alert (errmsg);
      }
    }
    
    function GoToDD(url,el) {
      var xx = el.options[el.selectedIndex].value;
      //alert (xx);
      if (xx != '') {
        if (xx != '-1') {
          location.href=url + xx;
        } else {
          alert ('Please choose an item from the drop-down list');
        }
      }
    }

    function submitenter(myfield,e) {
      var keycode;
      if (window.event) keycode = window.event.keyCode;
      else if (e) keycode = e.which;
      else return true;
      if (keycode == 13)
      {
        myfield.form.submit();
        return false;
      } else {
        return true;
      }
    }

    function collapse(id,caller) {
      obj = document.getElementById(id);
      objimage = document.getElementById(id + '_collapseimg');
      if (obj) {
        if (obj.style.display == 'none') {
          obj.style.display = 'inline';
          if (objimage) {objimage.src = 'images//collapse_minus.gif';}
        } else {
          obj.style.display = 'none';
          if (objimage) {objimage.src = 'images//collapse_plus.gif';}
        }
      }
    }

    function collapseblock(id,caller) {
      obj = document.getElementById(id);
      objimage = document.getElementById(id + '_collapseimg');
      if (obj) {
        if (obj.style.display == 'none') {
          obj.style.display = 'block';
          if (objimage) {objimage.src = 'images//collapse_minus.gif';}
        } else {
          obj.style.display = 'none';
          if (objimage) {objimage.src = 'images//collapse_plus.gif';}
        }
      }
    }

    function ShowHide(id) {
      el = document.getElementById(id);
      if (el) {
        if (el.style.display=='block') {
          el.style.display = 'none';
        } else {
          el.style.display = 'block';
        }
      }
    }

    function ConfirmDelete (target) {
      if (confirm("Are you sure you wish to delete the selected entry ?")) {
        location.href = target;
      } else {
        return false;
      }
    }

    function Conf(target,message) {
      if (confirm(message)) {
        location.href = target;
      } else {
        return false;
      }
    }

    function ScrollBottom() {
      setTimeout(window.location='#bottom', 250);
    }

    function Popup(URL) {
      //day = new Date();
      //id = day.getTime();
      eval("pagethumb = window.open('popup.asp?url=' + URL, 'pagethumb', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=400,height=250');");
    }

		function FullPostcode() {
			// BEE Added this function because it was missing.
			// It does nothing because I do not know what it is supposed to do.
			// Having the function avoids a js error at runtime.
    }

		function showpop(el,td) {
			topop = document.getElementById(el);
			topop.style.display = 'block';
			//a = window.setTimeout("topop.style.display = 'block';",400);
		}
		function hidepop(el) {
			topop = document.getElementById(el);
			topop.style.display = 'none';
		}

		function toggleCheckboxes(togglerElem, cbName) {
			// togglerElem is a checkbox
			var elems = document.getElementsByTagName('input');			
			for(var i = 0; i < elems.length; i++) {
				if (elems[i].type=='checkbox') {
					if (elems[i].name.indexOf(cbName)>=0) {
						elems[i].checked = (togglerElem.checked);
					}
				}
			} 
		}		
		function click(e) {
			if (navigator.appName == 'Netscape' && e.which == 3) {
				alert(rightClickMessage);
				return false;
			}
			else {
				if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
					alert(rightClickMessage)
					return false;
				}
			}
			return true;
		}
