function Facility(facilityXML, imgroot_in)
{    
    this.guid = facilityXML.getAttribute("guid");
    this.date = facilityXML.getAttribute("date");
    this.name = facilityXML.getAttribute("name");
    this.code = facilityXML.getAttribute("code");
    this.address1 = facilityXML.getAttribute("address1");
    this.address2 = facilityXML.getAttribute("address2");
    this.address3 = facilityXML.getAttribute("address3");
    this.city = facilityXML.getAttribute("city");
    this.state_province = facilityXML.getAttribute("state_province");
    this.postal_code = facilityXML.getAttribute("postal_code");
    var c = facilityXML.getElementsByTagName("coordinates")[0];
    if (c != null)
    {
        this.latitude = parseFloat(c.getAttribute("lat"));
        this.longitude = parseFloat(c.getAttribute("lng"));
        this.dmslatitude = c.getAttribute("dmslat");
        this.dmslongitude = c.getAttribute("dmslng");
    }

    this.contactname = facilityXML.getAttribute("contactname");
    this.contacttitle = facilityXML.getAttribute("contacttitle");
    this.contactphone = facilityXML.getAttribute("contactphone");
    this.contactfax = facilityXML.getAttribute("contactfax");
    this.contactemail = facilityXML.getAttribute("contactemail");    
    this.url = facilityXML.getAttribute("url");
    this.publishsiteid = facilityXML.getAttribute("publishsiteid");
    this.externalmacaurl = facilityXML.getAttribute("externalmacaurl");
    this.organization_type = facilityXML.getAttribute("organization_type");
    this.imgroot = imgroot_in + "/images/";    

    var linkXML = facilityXML.getElementsByTagName("link");    
    if (linkXML != null && linkXML.length >0)
    {       
        this.links = linkXML;    
    }
    
    var aircraftXML = facilityXML.getElementsByTagName("aircraft");    
    if (aircraftXML != null && aircraftXML.length >0)
    {        
        this.aircrafts = aircraftXML;    
    }
    
    var nearbyairportXML = facilityXML.getElementsByTagName("nearbyairport");    
    if (nearbyairportXML != null && nearbyairportXML.length >0)
    {        
        this.nearbyairports = nearbyairportXML;    
    }
    
    var welcomemessageXML = facilityXML.getElementsByTagName("welcomemessage");        
    if (welcomemessageXML != null && welcomemessageXML.length >0)
    {        
        this.welcomemessage = welcomemessageXML[0].firstChild.data;    
    }
    
    
}

Facility.prototype.guid = null;
Facility.prototype.date = null;
Facility.prototype.name = null;
Facility.prototype.code = null;
Facility.prototype.address1 = null;
Facility.prototype.address2 = null;
Facility.prototype.address3 = null;
Facility.prototype.city = null;
Facility.prototype.state_province = null;
Facility.prototype.postal_code = null;
Facility.prototype.latitude = null;
Facility.prototype.longitude = null;
Facility.prototype.dmslatitude = null;
Facility.prototype.dmslongitude = null;
Facility.prototype.contactname = null;
Facility.prototype.contacttitle = null;
Facility.prototype.contactphone = null;
Facility.prototype.contactfax = null;
Facility.prototype.contactemail = null;
Facility.prototype.url = null;
Facility.prototype.imgroot = null;
Facility.prototype.visible = false;
Facility.prototype.publishsiteid = null;
Facility.prototype.externalmacaurl = null;
Facility.prototype.organization_type = null;
Facility.prototype.links = null;
Facility.prototype.aircrafts = null;
Facility.prototype.nearbyairports = null;
Facility.prototype.welcomemessage = null;


Facility.prototype.show = function(b_show)
{
	//if (false == this.visible)
    //{
    
        var marker = this.createMarker();
        if (null != marker)
        {
            map.addOverlay(marker);            
        }
        else
        {
            alert("In Facility.prototype.show:  the marker is null!");
        }
    //}
    this.visible = b_show;
}
Facility.prototype.setZindex = function(marker, b)
{
    return 2;
}
Facility.prototype.createMarker = function()
{
	var icon = this.createIcon();
	var marker = null;

	if (null != icon)
	{
		marker = new GMarker(new GLatLng(this.latitude, this.longitude), { title: this.name, icon: icon, zIndexProcess: this.setZindex });


		if (facility_markers)
		{
			facility_markers[facility_markers.length] = marker;
			facility_guids[this.guid] = this.guid;
		}

		// Our info window content               
		// alert('psiteid:' + this.publishsiteid);
		if (this.publishsiteid != null && this.publishsiteid != '')
		{

			if (this.state_province == "US")
			{
				//setup display to show published site data and links
				var html = this.getInfoWindowPublishedSite();
				var related = this.getInfoWindowRelatedLinks();
				var airports = this.getInfoWindowAirport();
				var infoTabs = [
              new GInfoWindowTab("General", html),
              new GInfoWindowTab("Related", related),
              new GInfoWindowTab("Airports", airports)
            ];

				GEvent.addListener(marker, "click", function()
				{
					marker.openInfoWindowTabsHtml(infoTabs);
				});
			}
			else
			{
				//setup display to show published site data and links
				var html = this.getInfoWindowPublishedSite();
				var related = this.getInfoWindowRelatedLinks();
				
				var infoTabs = [
              new GInfoWindowTab("General", html),
              new GInfoWindowTab("Related", related)
            ];

				GEvent.addListener(marker, "click", function()
				{
					marker.openInfoWindowTabsHtml(infoTabs);
				});
			}
		}
		else
		{

			var html = null;
			//Check to see if an external link is posted
			if (this.externalmacaurl != null && this.externalmacaurl != '')
			{
				//setup display to link to external site
				html = this.getInfoWindowExternalMacaSite();
			}
			else
			{
				//setup display to display generic info
				html = this.getInfoWindowNonPublishedSite();
			}

			GEvent.addListener(marker, "click", function()
			{
				marker.openInfoWindowHtml(html);
			});
		}
	}
	else
	{
		alert("In Facility.prototype.createMarker:  the icon is null!");
	}

	return marker;
}

Facility.prototype.createIcon = function()
{
    var baseIcon = new GIcon();
    baseIcon.shadow = this.imgroot + "google/shadow.png";
	baseIcon.iconSize = new GSize(20, 20);
	baseIcon.shadowSize = new GSize(37, 17);
	baseIcon.iconAnchor = new GPoint(10, 10);
	baseIcon.infoWindowAnchor = new GPoint(10, 10);
	baseIcon.infoShadowAnchor = new GPoint(10, 10);
	
    var icon = new GIcon(baseIcon);
    icon.image = this.imgroot + "google/" + this.getIconImage();
    
    return icon;
}

Facility.prototype.getIconImage = function()
{
	var icon = null;

	switch (this.organization_type)
	{
		case "Army":
			icon = "green_sign.png";
			break;
		case "JointUse":
			icon = "yellow_blue_sign.png";
			break;
		case "ArmyGuard":
			icon = "white_green_sign.png";
			break;
		case "AirGuard":
			icon = "white_blue_sign.png";
			break;
		case "AirForce":
			icon = "blue_sign.png";
			break;
		case "Marines":
			icon = "white_sign.png";
			break;
		case "Navy":
			icon = "red_sign.png";
			break;
		default:
			icon = "blue_sign.png";
			break;
	}
	return icon;
}

Facility.prototype.getInfoWindowPublishedSite = function()
{
	
	var html = this.createGeneralTabContents();
	//html += "<a href='javascript:void(0);' onclick=\"loadFacility('" + this.guid + "');\" onmouseover=\"this.style.cursor='pointer';\">View Site Details</a>";
	    	    
	return html;
}

Facility.prototype.getInfoWindowNonPublishedSite = function()
{
    var html = null;
    html = "<table id=\"bubbleGeneralTab\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" \">";
		
	html += "<tr valign=\"top\">";	    
    html += "<td colspan=\"2\"><h4>" + this.name + "</h4></td>";
    html += "</tr>";
    
    html += "<tr valign=\"top\">";
    html += "<td>FAA Identifier:</td>";
    html += "<td>" + this.code + "</td>";
    html += "</tr>";
    
    html += "<tr valign=\"top\">";
    html += "<td>State:</td>";
    html += "<td>" + this.state_province + "</td>";
    html += "</tr>";
    
    /*
    html += "<tr valign=\"top\">";
    html += "<td>Zip code:</td>";
    html += "<td>" + this.postal_code + "</td>";
    html += "</tr>";
    */
    html += "<tr valign=\"top\">";
    html += "<td>Latitude:</td>";
    html += "<td>" + this.dmslatitude + "</td>";
    html += "</tr>";
    
    html += "<tr valign=\"top\">";
    html += "<td>Longitude:</td>";
    html += "<td>" + this.dmslongitude + "</td>";
    html += "</tr>";	   	    	    
    
    html += "<tr valign=\"top\">";	    
    html += "<td colspan=\"2\"><p>No information has been published for this base.</p></td>";
    html += "</tr>";	   	 	    
    html += "</table>";
    //html += "No information has been published for this base."; 		    
	return html;
}


Facility.prototype.getInfoWindowExternalMacaSite = function()
{
    var html = null;
    html = "<table id=\"bubbleGeneralTab\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" \">";
		
	html += "<tr valign=\"top\">";	    
    html += "<td colspan=\"2\"><h4>" + this.name + "</h4></td>";
    html += "</tr>";
    
    html += "<tr valign=\"top\">";
    html += "<td>FAA Identifier:</td>";
    html += "<td>" + this.code + "</td>";
    html += "</tr>";
    
    html += "<tr valign=\"top\">";
    html += "<td>State:</td>";
    html += "<td>" + this.state_province + "</td>";
    html += "</tr>";
    
    /*
    html += "<tr valign=\"top\">";
    html += "<td>Zip code:</td>";
    html += "<td>" + this.postal_code + "</td>";
    html += "</tr>";
    */
    
    html += "<tr valign=\"top\">";
    html += "<td>Latitude:</td>";
    html += "<td>" + this.dmslatitude + "</td>";
    html += "</tr>";
    
    html += "<tr valign=\"top\">";
    html += "<td>Longitude:</td>";
    html += "<td>" + this.dmslongitude + "</td>";
    html += "</tr>";	   	    	    
    
    html += "<tr valign=\"top\">";	    
    html += "<td colspan=\"2\"><p><a href=\"" + this.externalmacaurl + "\" target=\"_blank\">View Site Details</a></p></td>";
    html += "</tr>";	   	 	    
    html += "</table>";
    //html += "<a href='" + this.externalmacaurl + "' target='_blank'>View Site Details</a>";  	    
	return html;
}

Facility.prototype.getInfoWindowRelatedLinks = function()
{	
    var html = this.createLinksTabContents();    	    
	return html;
}

Facility.prototype.getInfoWindowAirport = function()
{	
    var html = this.createAirportTabContents();    	    
	return html;
}

Facility.prototype.createGeneralTabContents = function()
{
    var ret = "";
    if (null != this.guid)
    {                      	    
        
        ret += "<table id=\"bubbleGeneralTab\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" \">";
		
		ret += "<tr valign=\"top\">";	    
	    ret += "<td colspan=\"2\"><h4>" + this.name + "</h4></td>";
	    ret += "</tr>";
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>FAA Identifier:</td>";
	    ret += "<td>" + this.code + "</td>";
	    ret += "</tr>";
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>State:</td>";
	    ret += "<td>" + this.state_province + "</td>";
	    ret += "</tr>";
	    
	    /*
	    ret += "<tr valign=\"top\">";
	    ret += "<td>Zip code:</td>";
	    ret += "<td>" + this.postal_code + "</td>";
	    ret += "</tr>";
	    */
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>Latitude:</td>";
	    ret += "<td>" + this.dmslatitude + "</td>";
	    ret += "</tr>";
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>Longitude:</td>";
	    ret += "<td>" + this.dmslongitude + "</td>";
	    ret += "</tr>";	   	    	    
	    
	    ret += "<tr valign=\"top\">";	    
	    ret += "<td colspan=\"2\"><p style=\"overflow:auto;height:100px;\">" + this.welcomemessage + "</p></td>";
	    ret += "</tr>";	   	 
	    
        ret += "<tr><td colspan=\"2\">";
        if (this.aircrafts != null)
        {	    
            for(var i=0;i<this.aircrafts.length;i++)
	        {
                ret += "<img onclick=\"displayImage('ajax/popupdetail.aspx?t=2&id=" + this.aircrafts[i].getAttribute("guid") + "', this)\" title=\"" + this.aircrafts[i].getAttribute("shortname") + "\" src=\"" + this.imgroot + "aircraft/" + this.aircrafts[i].getAttribute("thumbnailurl") + "\" /> ";	        
            }
        }
	    ret += "</td></tr>";
	    
	    ret += "<tr valign=\"top\">";	    
	    ret += "<td colspan=\"2\"><p><a href=\"javascript:void(0);\" onclick=\"loadFacility('" + this.guid + "');\" onmouseover=\"this.style.cursor='pointer';\">View Site Details</a></p></td>";
	    ret += "</tr>";	   	 	    	    
	    	    	     	    	    	    		        
	    ret += "</table>";
	    	    
	}
	
	return ret;
}

Facility.prototype.createLinksTabContents = function()
{
    var ret = "";
    if (null != this.guid)
    {                      	    
        
        ret += "<table id=\"bubbleGeneralTab\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" \">";
		
		ret += "<tr valign=\"top\">";	    
	    ret += "<td colspan=\"2\"><h4>Related Links</h4></td>";
	    ret += "</tr>";
	    //alert(this.links.length);
	    if (this.links != null)
	    {
	        for(var i=0;i<this.links.length;i++)
	        {	    
	            ret += "<tr valign=\"top\">";
	            ret += "<td colspan=\"2\"><a href=\"" + this.links[i].getAttribute("linkurl") + "\" target=\"_blank\">" + this.links[i].getAttribute("linkname") + "</a></td>";	        
	            ret += "</tr>";	    	     	    
	        }
	    }	    		        
	    ret += "</table>";
	    	    
	}
	
	return ret;
}

Facility.prototype.createAirportTabContents = function()
{
    var ret = "";
    if (null != this.guid)
    {                      	    
        
        ret += "<table id=\"bubbleGeneralTab\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" \">";
		
		ret += "<tr valign=\"top\">";	    
	    ret += "<td colspan=\"2\"><h4>Airports Nearby</h4></td>";
	    ret += "</tr>";
	    
	    ret += "<tr valign=\"top\">";
        ret += "<td colspan=\"2\"><a target=\"_blank\" href=\"http://airnav.com/airport/" + this.code + "\">" + this.code + " - " + this.name + "</a></td>";
        ret += "</tr>";	  
	    //alert(this.nearbyairports.length);
	    if (this.nearbyairports != null)
	    {
	        for(var i=0;i<this.nearbyairports.length;i++)
	        {	    
	            ret += "<tr valign=\"top\">";
	            ret += "<td colspan=\"2\"><a target=\"_blank\" href=\"http://airnav.com/airport/" + this.nearbyairports[i].getAttribute("faaidentifier") + "\">" + this.nearbyairports[i].getAttribute("faaidentifier") + " - " + this.nearbyairports[i].getAttribute("airportname") + "</a> (" + this.nearbyairports[i].getAttribute("distance") + ")</td>";
	            ret += "</tr>";	    	     	    
	        }
	    }	    		        
	    ret += "</table>";
	    	    
	}
	
	return ret;
}