﻿var PSctrl = "ParcelSearch1_";
var Active_ps;
var Exact_ps;

//Init.
function initParcelSearch() {
   if (WebsiteLoaded) {
      var obj = $get(PSctrl + "ps_TextBox0");
      if (obj) {
         obj.focus();
         Active_ps = obj;
      }
   }
}
//Send to server.
function SubmitParcelSearch() {
   var srCtrl = "SelectResults1_";
   showBusy("ParcelSearch");

   var sv,obj;
   sv = "";
   for (i=0; i<20; i++) {
      obj = $get(PSctrl + "ps_TextBox" + i);
      if (obj) {
         if (i > 0) {
            sv += "|";
         }
         sv += cleanUp(obj.value);
      }
   }
   $get(srCtrl + "TaskName_hid").value = "ParcelSearch";
   $get(srCtrl + "GeomStr_hid").value = "-";
   $get(srCtrl + "SearchValues_hid").value = sv;
   $get(srCtrl + "Command_hid").value = Exact_ps;

   obj = $get(srCtrl + "SelectableLayers_DropDownList");
   hid = $get(srCtrl + "SelectLayer_hid");
   hid.value = obj.value;

   obj = $get(srCtrl + "SelectMode_DropDownList");
   hid = $get(srCtrl + "SelectMode_hid");
   hid.value = obj.value;

   //Submit.
   obj = $get(srCtrl + "CallbackButton1");
   obj.click();
}
//Autocomplete item select event.
function ItemSelected_ps(source, eventArgs) {
   Exact_ps = true;
}
//Process enter key.
function EnterKey_ps(e, evt) {
   if (evt.keyCode == 13) {
      SubmitParcelSearch();
      evt.returnValue = false;
   } else {
      Exact_ps = false;
   }
}
//Process delete keys.
function Backspa_ps(e, evt) {
   if (evt.keyCode == 8 || evt.keyCode == 46) {
      Exact_ps = false;
   }
}
//Clear all but clicked.
function Clear_ps(e) {
   var i,obj;
   Active_ps = e;
   for (i=0; i<20; i++) {
      obj = $get(PSctrl + "ps_TextBox" + i);
      if (obj) {
         if (obj.id != e.id) {
            obj.value = "";
         }
      }
   }
}
//Clear all.
function ClearAll_ps() {
   var i, obj;

   for (i = 0; i < 20; i++) {
      obj = $get(PSctrl + "ps_TextBox" + i);
      if (obj) {
         obj.value = "";
      }
   }
   if (Active_ps) {
      Active_ps.focus();
   }
}
//Process property card request.
function SubmitPropertyCard(pin, xMin, yMin, xMax, yMax) {
   if (!pw || pw.closed) {
      var pw = window.open("Busy.aspx?msg=Getting%20Property%20Card...", "PropertyCardWindow");
   }
   if (pw == null) {
      alert("Cannot display property card window. Disable pop-up blockers for this website.");
   } else {
      $get(PSctrl + "pin_hid").value = pin;
      $get(PSctrl + "mbr_hid").value = xMin + "," + yMin + "," + xMax + "," + yMax;

      var obj = $get(PSctrl + "CallbackButton1");
      obj.click();
   }
}
