﻿// JScript File -- gMapSearches.js
var appid = "1";
var mapurl = "http://maps.google.com/maps?f=d"
var emasite = "http://www.pinellascounty.org/emergency/default.htm";
var appsite = "./";

function go2EMA()
{
  window.location=emasite;
}

function go2App()
{
 window.location=appsite;
}

function showMap(saddr,daddr)
{
   window.open(mapurl+"&saddr="+saddr+"&daddr="+daddr);
}

function zoom2Location(lat,lon)
{
 
  var center = new GLatLng(lat,lon);
  parent.map.setCenter(center,18);
 
  //map.openInfoWindow(center);
  //if (currentLocMarker != null) GEvent.trigger(currentLocMarker, "click");
}

function zoom2Marker(lat,lon)
{
  //alert("Juan");
  var center = new GLatLng(lat,lon);
  map.setCenter(center,18);
  //map.openInfoWindow(center);
  //if (currentLocMarker != null) GEvent.trigger(currentLocMarker, "click");
}

function findMobileHome(facid) 
{
 //alert(appid);
 if (facid != "") {
   document.getElementById('locatorPanel').style.visibility='visible';
   $find('locatorMPE').show();
   geoLocator.FindMobileHome(facid, "", SucceededProperty, FailedCallback);
   }
  else {
    alert("Unable to locate Mobile Home");
  } 
}

function findProperty(addnum,stname,panFlag) 
{
 if (addnum != "") 
 {
  if (stname != "")
  {
   document.getElementById('locatorPanel').style.visibility='visible';
   $find('locatorMPE').show();
   
   geoLocator.FindPropertybyAddress(addnum, stname, "", "", true, SucceededProperty, FailedCallback);
  } 
  else 
  {
    alert("Please enter value for Street Name");
  } 
 }
 else 
 {
   alert("Please enter value for Street Number");
 } 
}

function findPropertyUnit(gid,addr)
{
  document.getElementById('actionPanel').style.visibility='hidden';
  $find('actionMPE').hide();
   
   document.getElementById('locatorPanel').style.visibility='visible';
   $find('locatorMPE').show();
   
   //alert("Got Here");
   
   geoLocator.GetPropertyAddressData(gid,"",addr,SucceededProperty, FailedCallback); // move to geoReporter
}

function SucceededProperty(result, eventArgs)
{
  var root = result.getElementsByTagName("Records");
  if (root.length > 0)
  {
     var roottype = root[0].getAttribute("type");
     //alert(roottype);
     if (roottype == "MULTIADD")
     {
        //alert(roottype);
        buildMultiPropertyForm(result);
     }
     else if (roottype == "CLOSESTADD")
     {
        buildClosestPropertyForm(result);
     }
     else if (roottype == "MULTIUNITADD")
     {
        //alert(roottype);
        buildMultiPropertyUnitForm(result);
     }
     else if (roottype == "ADDRESS") 
     {
      //getPropertyMarker(result);
      //alert("Forward to results page");
      //alert("Got here");
      // check for Address Record
      var field = result.getElementsByTagName("Address");
      if (field != null) 
      { 
       //*** Old way before changes to geoLocator  
       //var gid = field[0].getAttribute("prclgid");
       //var pid = field[0].getAttribute("pinnum");
       //var add = field[0].getAttribute("address");
       //var mh = field[0].getAttribute("mobilehome");
        
        var gid = field[0].getElementsByTagName("prclgid")[0].childNodes[0].nodeValue;
        var pid = field[0].getElementsByTagName("pinnum")[0].childNodes[0].nodeValue;
        var add = field[0].getElementsByTagName("address")[0].childNodes[0].nodeValue;
        var mh = "";
        
       //alert(gid);
       //alert(pid);
       //alert(add);
       //alert(mh);
       window.location = "results.aspx?pid="+pid+"&gid="+gid+"&add="+add+"&mh="+mh;
      }
      else 
      {
       alert("Unable to locate property.  Please try again.");
       document.getElementById('locatorPanel').style.visibility='hidden';
       $find('locatorMPE').hide();
      }
     }
     else if (roottype == "MOBILEHOME")
     {
      // check for Mobile Home Record
      //alert("Got to the Mobile Home check");
      var field = result.getElementsByTagName("Mobilehome");
      if (field != null) 
      { 
       //*** Old way before changes to geoLocator  
       //var gid = field[0].getAttribute("prclgid");
       //var pid = field[0].getAttribute("pinnum");
       //var add = field[0].getAttribute("address");
       //var mh = field[0].getAttribute("mobilehome");
        
        var gid = field[0].getElementsByTagName("prclgid")[0].childNodes[0].nodeValue;
        var pid = "";
        var add = field[0].getElementsByTagName("address")[0].childNodes[0].nodeValue;
        var mh = field[0].getElementsByTagName("mobilehome")[0].childNodes[0].nodeValue;
        
        //alert(gid);
        //alert(pid);
        //alert(add);
        //alert(mh);
        window.location = "results.aspx?pid="+pid+"&gid="+gid+"&add="+add+"&mh="+mh;
      }
      else 
      {
        alert("Unable to locate property.  Please try again.");
        document.getElementById('locatorPanel').style.visibility='hidden';
        $find('locatorMPE').hide();
      }
     }
     else 
     {
      alert("Unable to locate property.  Please try again.");
      document.getElementById('locatorPanel').style.visibility='hidden';
      $find('locatorMPE').hide();
     }   
   }
   else 
   {
     alert("Unable to locate property.  Please try again.");
     document.getElementById('locatorPanel').style.visibility='hidden';
     $find('locatorMPE').hide();
   }       
    //document.getElementById('locatorPanel').style.visibility='hidden';
    //$find('locatorMPE').hide();
}

//*** called from buildClosestPropertyForm function in addressLocator.js
function processMultiProperty(stnum,stname,muniname,postcode)
{
  document.getElementById('actionPanel').style.visibility='hidden';
  $find('actionMPE').hide();
  document.getElementById('locatorPanel').style.visibility='visible';
  $find('locatorMPE').show();
  //alert("Got to processMultiProperty");
  geoLocator.FindPropertybyAddress(stnum, stname, muniname, postcode, true, SucceededMultiProperty, FailedCallback)
}

function processMultiAdd(stnum,stname,muniname,postcode)
{
  document.getElementById('actionPanel').style.visibility='hidden';
  $find('actionMPE').hide();
  document.getElementById('locatorPanel').style.visibility='visible';
  $find('locatorMPE').show();
  geoLocator.checkAddressUnits(stnum, stname, muniname, postcode, appid, "0", SucceededMultiAdd, FailedCallback)
}

function SucceededMultiProperty(result, eventArgs)
{
  var root = result.getElementsByTagName("Records");
  if (root.length > 0)
  {
     //alert(root.firstChild);
     var roottype = root[0].getAttribute("type");
     if (roottype == "MULTIUNITADD")
     {
        buildMultiPropertyUnitForm(result);
     }
     else if (roottype == "ADDRESS")
     {
      var field = result.getElementsByTagName("Address");
      if (field != null) 
      {   
      //** old way before changes to geoLocator
      //        var gid = field[0].getAttribute("prclgid");
      //        var pid = field[0].getAttribute("pinnum");
      //        var add = field[0].getAttribute("address");
      //        var mh = field[0].getAttribute("mobilehome");

        var gid = field[0].getElementsByTagName("prclgid")[0].childNodes[0].nodeValue;
        var pid = field[0].getElementsByTagName("pinnum")[0].childNodes[0].nodeValue;
        var add = field[0].getElementsByTagName("address")[0].childNodes[0].nodeValue;
        var mh = "";
        
        window.location = "results.aspx?pid="+pid+"&gid="+gid+"&add="+add+"&mh="+mh;
      }
      else 
      {
       alert("Unable to locate property.  Please try again.");
      }
     }
     else 
     {
       alert("Unable to locate property.  Please try again.");
     }
  }
  else 
  {
    alert("Unable to locate property.  Please try again.");
  }
}

function SucceededMultiAdd(result, eventArgs)
{
  var root = result.getElementsByTagName("Addresses");
  if (root.firstChild != null)
  {
     //alert(root.firstChild);
     var roottype = root[0].getAttribute("type");
     if (roottype == "MULTIUNIT")
     {
        buildMultiUnitForm(result);
     }
  }
  else 
  {
    //alert("Getting to the spot");
    getResidentMarker(result);
  }
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
    // Display the error.    
//    var RsltElem = 
//        document.getElementById("ResultId");
//    RsltElem.innerHTML = 
//    "Service Error: " + error.get_message();
    
    alert("Service Error: " + error.get_message());
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();