//Postcode Anywhere Javascript Popup Service
//Version 3.0 (SlipStream engine enabled)
//Automatically generated on 15/09/2009 13:37:30 from WEB02
//(c) 2001-2009 Postcode Anywhere (Europe) Ltd

if (self.location.protocol=='https:')
  {
      var pcaBaseUrlRN17 = 'https://services.postcodeanywhere.co.uk/popups';
  }
else
  {
      var pcaBaseUrlRN17 = 'http://services.postcodeanywhere.co.uk/popups';
  }
var pcaLicenseKeyRN17 = 'rn17-gz82-uu49-hu16';
var pcaAccountCodeRN17 = 'ACTIO11127';
var pcaMachineIdRN17 = '';
var pcaPopupServiceRN17 = pcaBaseUrlRN17 + '/popup.aspx';
var pcaSetupServiceRN17 = pcaBaseUrlRN17 + '/setup.aspx';
var pcaInlineServiceRN17 = pcaBaseUrlRN17 + '/inline.aspx';
var pcaReturnUrlRN17 = self.location;
var pcaTokenRN17 = 'RN17';
var pcaPopupRN17 = window.opener;
var pcaNextStepRN17 = '';

var prefixRN17 = 'address';
var lineTokenRN17 = 'line';

var detect = navigator.userAgent.toLowerCase();
var isSafari;

if (checkIt('safari')) isSafari = "True";

function checkIt(string)
{
  place = detect.indexOf(string) + 1;
  return place;
}


function pcaButtonsRN17()
  {

                  document.write(" <a href='Javascript:pcaFindRN17()'><img src='" + pcaBaseUrlRN17 + "/picture.aspx?account_code=ACTIO11127&license_key="+pcaLicenseKeyRN17+"&type=button' id=pcaButtonRN17 border=0 alt='Click to automatically complete your address'></a>");

              if (isSafari=="True"){
                 document.write ("<select ID=pcaSelectRN17 onchange='pcaDoSelectRN17()' style='width:0px; height:0px; visibility:hidden;'></select>");
                  }
              else{
                  document.write ("<div ID=pcaDivRN17 style='display:none; padding-top: 5px; padding-bottom: 5px;'>");
                  document.write ("<select ID=pcaSelectRN17 onchange='pcaDoSelectRN17()' size=10 style='width:100%'></select>");

                  document.write ("<br><a href='http://www.postcodeanywhere.co.uk/' target=_blank><img src='" + pcaBaseUrlRN17 + "/pca_powered.png' border=0 width=119 height=27 alt='Powered by Postcode Anywhere&trade;' align=right></a>");

                  document.write ("</div>");
                  }


  };

function pcaSetupRN17()
  {
      if (document.forms.length == 0)
          {
              alert("Your must have at least one HTML FORM tag on your page before you can set up Postcode Anywhere.");
          }
      else
          {
              pcaOpenSetupPopupRN17(pcaSetupServiceRN17+'?account_code='+escape(pcaAccountCodeRN17)+'&license_key='+escape(pcaLicenseKeyRN17)+'&token='+escape(pcaTokenRN17)+'&machineId='+escape(pcaMachineIdRN17)+pcaFormFieldsRN17()+'&return_to='+escape(pcaReturnUrlRN17));
          };
  };

function pcaGetFieldRN17(what)
  {
      var intFieldCounter=0;

      for (intFormCounter=0; intFormCounter <= document.forms.length-1 ; intFormCounter++)
          {
              for (elementCounter=0; elementCounter <= document.forms[intFormCounter].length-1 ; elementCounter++)
                  {
                      if (document.forms[intFormCounter].elements[elementCounter].name==what)
                          {
                              return document.forms[intFormCounter].elements[elementCounter].value;
                          };
                  };
          };
  };

function pcaOpenPopupRN17(what)
  {
      var objWindow;
      var strOptions;

      objWindow='PCA';
      strOptions='toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=690,height=470';
      window.open(what, objWindow, strOptions);
  };

function pcaOpenSetupPopupRN17(what)
  {
      var objWindow;
      var strOptions;

      objWindow='PCA';
      strOptions='toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=580,height=550';
      window.open(what, objWindow, strOptions);
  };

function pcaFormFieldsRN17()
  {
      var strFieldList = "";
      var intFieldCounter=0;

      for (intFormCounter=0; intFormCounter <= document.forms.length-1 ; intFormCounter++)
          {
              for (elementCounter=0; elementCounter <= document.forms[intFormCounter].length-1 ; elementCounter++)
                  {
                      strFieldList = strFieldList + "&field" + intFieldCounter + "=" + escape(document.forms[intFormCounter].elements[elementCounter].name);
                      intFieldCounter++;
                  };
          };
      return (strFieldList);
  }



//Inline service component

function pcaFindRN17(prefix, lineToken)
  {
    if(prefix != null){
        prefixRN17 = prefix;
    }
    
    if(lineToken != null){
        lineTokenRN17 = lineToken;
    }
    
      var strPostcode = pcaGetFieldRN17(prefixRN17 + '_pcode');

      //Select which search type to use

      if (strPostcode.length<=4)
          {
              pcaByOutcodeBeginRN17(strPostcode);
          }
      else
          {
              pcaByPostcodeBeginRN17(strPostcode);
          }


  }

function pcaIsZipRN17(what)
  {
      var objRegExp  = /(^\d{5}$)/;
      return objRegExp.test(what);
  }

function pcaIsZip4RN17(what)
  {
      var objRegExp  = /(^\d{5}-\d{4}$)/;
      return objRegExp.test(what);
  }

function pcaIsPostcodeRN17(what)
  {
      var objRegExp  = /(^[A-Z]{1,2}\d{1,2}[A-Z]? ?\d[A-Z]{2}$)/;
      return objRegExp.test(what.toUpperCase());
  }

function pcaIsOutcodeRN17(what)
  {
      var objRegExp  = /(^[A-Z]{1,2}\d{1,2}[A-Z]?$)/;
      return objRegExp.test(what.toUpperCase());
  }

function pcaByPostcodeBeginRN17(postcode)
  {
      var scriptTag = document.getElementById('pcaScript');
      var headTag = document.getElementsByTagName('head').item(0);
      var strUrl = "";

      //Build the url
      strUrl = pcaInlineServiceRN17 + "?account_code=" + escape(pcaAccountCodeRN17) + "&license_code=" + escape(pcaLicenseKeyRN17) + "&machine_id=" + escape(pcaMachineIdRN17) + "&return_to=" + escape(pcaReturnUrlRN17) + "&action=lookup&type=by_postcode&callback=pcaByPostcodeEndRN17&postcode=" + escape(postcode);

      //Clear the list
      document.getElementById("pcaSelectRN17").length=0;

      //Set the next step
      pcaNextStepRN17 = "FETCH";

      //Make the request
      if (scriptTag)
          {
              try
                  {
                      headTag.removeChild(scriptTag);
                  }
              catch(ex)
                  {
                      //Ignore
                  }
          }
      scriptTag = document.createElement('script');
      scriptTag.src = strUrl
      scriptTag.type = 'text/javascript';
      scriptTag.id = 'pcaScript';
      headTag.appendChild(scriptTag);
  }

function pcaByPostcodeEndRN17()
  {
      var intCounter=0;

      //Test for an error
      if(pcaSchema.length==2)
          {
              //Show the error message
              alert(pca_message[0]);
          }
      else
          {
              //Add the items to the list
              document.getElementById("pcaSelectRN17").length=pcaRecordCount;
              for (intCounter=0; intCounter < pcaRecordCount; intCounter++)
                  {
                      document.getElementById("pcaSelectRN17").options[intCounter].text = pca_description[intCounter];
                      document.getElementById("pcaSelectRN17").options[intCounter].value = pca_id[intCounter];
                  }

              //Check if there were any items listed
              if (pcaRecordCount==0)
                  {
                      document.getElementById("pcaSelectRN17").length = 1;
                      document.getElementById("pcaSelectRN17").options[intCounter].text = "No matching items were found.";
                      document.getElementById("pcaSelectRN17").options[intCounter].value = "";
                      document.getElementById("pcaSelectRN17").disabled=true;
                  }
              else
                  {
                      document.getElementById("pcaSelectRN17").disabled=false;
                  }

              //Show the list
              if (isSafari=="True"){
                  document.getElementById("pcaSelectRN17").style.visibility='visible';
                  document.getElementById("pcaSelectRN17").style.width='100%';
                  document.getElementById("pcaSelectRN17").style.height='162px';
                  document.getElementById("pcaSelectRN17").size='10';
                  }
              else{
                  document.getElementById("pcaDivRN17").style.display='';
                  }
          }
  }

function pcaByOutcodeBeginRN17(outcode)
  {
      var scriptTag = document.getElementById('pcaScript');
      var headTag = document.getElementsByTagName('head').item(0);
      var strUrl = "";

      //Build the url
      strUrl = pcaInlineServiceRN17 + "?account_code=" + escape(pcaAccountCodeRN17) + "&license_code=" + escape(pcaLicenseKeyRN17) + "&machine_id=" + escape(pcaMachineIdRN17) + "&return_to=" + escape(pcaReturnUrlRN17) + "&action=lookup&type=by_outcode&callback=pcaByOutcodeEndRN17&outcode=" + escape(outcode);

      //Clear the list
      document.getElementById("pcaSelectRN17").length=0;

      //Set the next step
      pcaNextStepRN17 = "BY_LOCALITYKEY";

      //Make the request
      if (scriptTag)
          {
              try
                  {
                      headTag.removeChild(scriptTag);
                  }
              catch(ex)
                  {
                      //Ignore
                  }
          }
      scriptTag = document.createElement('script');
      scriptTag.src = strUrl
      scriptTag.type = 'text/javascript';
      scriptTag.id = 'pcaScript';
      headTag.appendChild(scriptTag);
  }

function pcaByOutcodeEndRN17()
  {
      var intCounter=0;

      //Test for an error
      if(pcaSchema.length==2)
          {
              //Show the error message
              alert(pca_message[0]);
          }
      else
          {
              //Add the items to the list
              document.getElementById("pcaSelectRN17").length=pcaRecordCount;
              for (intCounter=0; intCounter < pcaRecordCount; intCounter++)
                  {
                      document.getElementById("pcaSelectRN17").options[intCounter].text = pca_description[intCounter];
                      document.getElementById("pcaSelectRN17").options[intCounter].value = pca_id[intCounter];
                  }

              //Check if there were any items listed
              if (pcaRecordCount==0)
                  {
                      document.getElementById("pcaSelectRN17").length = 1;
                      document.getElementById("pcaSelectRN17").options[intCounter].text = "No matching items were found.";
                      document.getElementById("pcaSelectRN17").options[intCounter].value = "";
                      document.getElementById("pcaSelectRN17").disabled=true;
                  }
              else
                  {
                      document.getElementById("pcaSelectRN17").disabled=false;
                  }

              //Show the list
              if (isSafari=="True"){
                  document.getElementById("pcaSelectRN17").style.visibility='visible';
                  document.getElementById("pcaSelectRN17").style.width='100%';
                  document.getElementById("pcaSelectRN17").style.height='162px';
                  document.getElementById("pcaSelectRN17").size='10';
                  }
              else{
                  document.getElementById("pcaDivRN17").style.display='';
                  }
          }
  }


function pcaByLocalityKeyBeginRN17(localityKey)
  {
      var scriptTag = document.getElementById('pcaScript');
      var headTag = document.getElementsByTagName('head').item(0);
      var strUrl = "";

      //Build the url
      strUrl = pcaInlineServiceRN17 + "?account_code=" + escape(pcaAccountCodeRN17) + "&license_code=" + escape(pcaLicenseKeyRN17) + "&machine_id=" + escape(pcaMachineIdRN17) + "&return_to=" + escape(pcaReturnUrlRN17) + "&action=lookup&type=by_localitykey&callback=pcaByLocalityKeyEndRN17&localitykey=" + escape(localityKey);

      //Clear the list
      document.getElementById("pcaSelectRN17").length=0;

      //Set the next step
      pcaNextStepRN17 = "BY_STREETKEY";

      //Make the request
      if (scriptTag)
          {
              try
                  {
                      headTag.removeChild(scriptTag);
                  }
              catch(ex)
                  {
                      //Ignore
                  }
          }
      scriptTag = document.createElement('script');
      scriptTag.src = strUrl
      scriptTag.type = 'text/javascript';
      scriptTag.id = 'pcaScript';
      headTag.appendChild(scriptTag);
  }

function pcaByLocalityKeyEndRN17()
  {
      var intCounter=0;

      //Test for an error
      if(pcaSchema.length==2)
          {
              //Show the error message
              alert(pca_message[0]);
          }
      else
          {
              //Add the items to the list
              document.getElementById("pcaSelectRN17").length=pcaRecordCount;
              for (intCounter=0; intCounter < pcaRecordCount; intCounter++)
                  {
                      document.getElementById("pcaSelectRN17").options[intCounter].text = pca_description[intCounter];
                      document.getElementById("pcaSelectRN17").options[intCounter].value = pca_id[intCounter];
                  }

              //Check if there were any items listed
              if (pcaRecordCount==0)
                  {
                      document.getElementById("pcaSelectRN17").length = 1;
                      document.getElementById("pcaSelectRN17").options[intCounter].text = "No matching items were found.";
                      document.getElementById("pcaSelectRN17").options[intCounter].value = "";
                      document.getElementById("pcaSelectRN17").disabled=true;
                  }
              else
                  {
                      document.getElementById("pcaSelectRN17").disabled=false;
                  }

              //Show the list
              if (isSafari=="True"){
                  document.getElementById("pcaSelectRN17").style.visibility='visible';
                  document.getElementById("pcaSelectRN17").style.width='100%';
                  document.getElementById("pcaSelectRN17").style.height='162px';
                  document.getElementById("pcaSelectRN17").size='10';
                  }
              else{
                  document.getElementById("pcaDivRN17").style.display='';
                  }
          }
  }

function pcaByStreetKeyBeginRN17(streetKey)
  {
      var scriptTag = document.getElementById('pcaScript');
      var headTag = document.getElementsByTagName('head').item(0);
      var strUrl = "";

      //Build the url
      strUrl = pcaInlineServiceRN17 + "?account_code=" + escape(pcaAccountCodeRN17) + "&license_code=" + escape(pcaLicenseKeyRN17) + "&machine_id=" + escape(pcaMachineIdRN17) + "&return_to=" + escape(pcaReturnUrlRN17) + "&action=lookup&type=by_streetkey&callback=pcaByStreetKeyEndRN17&streetkey=" + escape(streetKey);

      //Clear the list
      document.getElementById("pcaSelectRN17").length=0;

      //Set the next step
      pcaNextStepRN17 = "FETCH";

      //Make the request
      if (scriptTag)
          {
              try
                  {
                      headTag.removeChild(scriptTag);
                  }
              catch(ex)
                  {
                      //Ignore
                  }
          }
      scriptTag = document.createElement('script');
      scriptTag.src = strUrl
      scriptTag.type = 'text/javascript';
      scriptTag.id = 'pcaScript';
      headTag.appendChild(scriptTag);
  }

function pcaByStreetKeyEndRN17()
  {
      var intCounter=0;

      //Test for an error
      if(pcaSchema.length==2)
          {
              //Show the error message
              alert(pca_message[0]);
          }
      else
          {
              //Add the items to the list
              document.getElementById("pcaSelectRN17").length=pcaRecordCount;
              for (intCounter=0; intCounter < pcaRecordCount; intCounter++)
                  {
                      document.getElementById("pcaSelectRN17").options[intCounter].text = pca_description[intCounter];
                      document.getElementById("pcaSelectRN17").options[intCounter].value = pca_id[intCounter];
                  }

              //Check if there were any items listed
              if (pcaRecordCount==0)
                  {
                      document.getElementById("pcaSelectRN17").length = 1;
                      document.getElementById("pcaSelectRN17").options[intCounter].text = "No matching items were found.";
                      document.getElementById("pcaSelectRN17").options[intCounter].value = "";
                      document.getElementById("pcaSelectRN17").disabled=true;
                  }
              else
                  {
                      document.getElementById("pcaSelectRN17").disabled=false;
                  }

              //Show the list
              if (isSafari=="True"){
                  document.getElementById("pcaSelectRN17").style.visibility='visible';
                  document.getElementById("pcaSelectRN17").style.width='100%';
                  document.getElementById("pcaSelectRN17").style.height='162px';
                  document.getElementById("pcaSelectRN17").size='10';
                  }
              else{
                  document.getElementById("pcaDivRN17").style.display='';
                  }
          }
  }

function pcaDoSelectRN17()
  {
      switch (pcaNextStepRN17)
          {
              case "FETCH":
                  pcaFetchBeginRN17(document.getElementById("pcaSelectRN17").value);
                  break;
              case "BY_LOCALITYKEY":
                  pcaByLocalityKeyBeginRN17(document.getElementById("pcaSelectRN17").value);
                  break;
              case "BY_STREETKEY":
                  pcaByStreetKeyBeginRN17(document.getElementById("pcaSelectRN17").value);
                  break;
              case "US_FETCH":
                  pcaUSFetchBeginRN17(document.getElementById("pcaSelectRN17").value);
                  break;
              case "US_BYZIP":
                  pcaUSByZipBeginRN17('', document.getElementById("pcaSelectRN17").value.substring(5), document.getElementById("pcaSelectRN17").value.substring(0,5));
                  break;
          }
  }

function pcaFetchBeginRN17(addressId)
  {
      var scriptTag = document.getElementById('pcaScript');
      var headTag = document.getElementsByTagName('head').item(0);
      var strUrl = "";

      //Hide the list
      if (isSafari=="True"){
          while (document.getElementById("pcaSelectRN17").options.length > 0) {
              document.getElementById("pcaSelectRN17").options[0] = null;
              }
          document.getElementById("pcaSelectRN17").style.height='0px';
          document.getElementById("pcaSelectRN17").style.visibility='hidden';
          }
      else{
          document.getElementById("pcaDivRN17").style.display='none';
          }

      //Build the url
      strUrl = pcaInlineServiceRN17 + "?account_code=" + escape(pcaAccountCodeRN17) + "&license_code=" + escape(pcaLicenseKeyRN17) + "&machine_id=" + escape(pcaMachineIdRN17) + "&return_to=" + escape(pcaReturnUrlRN17) + "&action=fetch&callback=pcaFetchEndRN17&id=" + escape(addressId);

      //Make the request
      if (scriptTag)
          {
              try
                  {
                      headTag.removeChild(scriptTag);
                  }
              catch(ex)
                  {
                      //Ignore
                  }
          }
      scriptTag = document.createElement('script');
      scriptTag.src = strUrl
      scriptTag.type = 'text/javascript';
      scriptTag.id = 'pcaScript';
      headTag.appendChild(scriptTag);
  }

function pcaFetchEndRN17()
  {
      var intCounter=0;

      //Test for an error
      if(pcaSchema.length==2)
          {
              //Show the error message
              alert(pca_message[0]);
          }
      else
          {
              //Copy the items to the form

              pcaSetFieldRN17(prefixRN17 + "_country", pca_PAF_COUNTRY[0]);

              pcaSetFieldRN17(prefixRN17 + "_" + lineTokenRN17 + "_1", pca_PAF_LINE_1_2_CO[0]);

              pcaSetFieldRN17(prefixRN17 + "_" + lineTokenRN17 + "_2", pca_PAF_LINE_2_2_CO[0]);

              pcaSetFieldRN17(prefixRN17 + "_pcode", pca_PAF_POSTCODE[0]);

              pcaSetFieldRN17(prefixRN17 + "_town", pca_PAF_TOWN[0]);

          }
  }



function pcaSetFieldRN17(what, newValue)
  {
      var intFieldCounter=0;

      for (intFormCounter=0; intFormCounter <= document.forms.length-1 ; intFormCounter++)
          {
              for (elementCounter=0; elementCounter <= document.forms[intFormCounter].length-1 ; elementCounter++)
                  {
                      if (document.forms[intFormCounter].elements[elementCounter].name==what)
                          {
                              document.forms[intFormCounter].elements[elementCounter].value = newValue;
                          }
                  };
          };
  };