function Moa(moaXML, imgroot_in)
{    
    this.guid = moaXML.getAttribute("guid");
    this.date = moaXML.getAttribute("date");
    this.name = moaXML.getAttribute("name");
    this.code = moaXML.getAttribute("code");
    this.strokecolor = moaXML.getAttribute("strokecolor");
    this.strokeweight = moaXML.getAttribute("strokeweight");
    this.strokeopacity = moaXML.getAttribute("strokeopacity");
    this.fillcolor = moaXML.getAttribute("fillcolor");
    this.fillopacity = moaXML.getAttribute("fillopacity");
    this.loweralt = moaXML.getAttribute("loweralt");
    this.upperalt = moaXML.getAttribute("upperalt");
    this.efftimes = moaXML.getAttribute("efftimes");
    this.wx = moaXML.getAttribute("wx");
    this.commname = moaXML.getAttribute("commname");
    this.freq1 = moaXML.getAttribute("freq1");
    this.freq2 = moaXML.getAttribute("freq2");
    this.airspaceStatus = moaXML.getAttribute("airspaceStatus");
    this.startTime = moaXML.getAttribute("startTime");
    this.endTime = moaXML.getAttribute("endTime");
    
    var coordinatesXMLElements = moaXML.getElementsByTagName("coordinates");
    if (coordinatesXMLElements != null && coordinatesXMLElements.length != 1)
    {
        alert('Improper number of <coordinates> elements in the Moa XML');
    }
    else
    {
        this.coordinatesXMLElement = coordinatesXMLElements[0];
    }
}

Moa.prototype.guid = null;
Moa.prototype.date = null;
Moa.prototype.name = null;
Moa.prototype.code = null;
Moa.prototype.visible = false;
Moa.prototype.strokecolor = null;
Moa.prototype.strokeweight = null;
Moa.prototype.strokeopacity = null;
Moa.prototype.fillcolor = null;
Moa.prototype.fillopacity = null;
Moa.prototype.coordinatesXMLElement = null;
Moa.prototype.points = null;
Moa.prototype.loweralt = null;
Moa.prototype.upperalt = null;
Moa.prototype.efftimes = null;
Moa.prototype.wx = null;
Moa.prototype.commname = null;
Moa.prototype.freq1 = null;
Moa.prototype.freq2 = null;
Moa.prototype.airspaceStatus = null;
Moa.prototype.startTime = null;
Moa.prototype.endTime = null;

Moa.prototype.show = function(b_show)
{
    
        this.createPointsArray();
        var moa = this.createmoa();
        if (moa != null)
        {
            map.addOverlay(moa);            
        }
        else
        {
            alert("In Moa.prototype.show:  the moa is null!");
        }
    
    this.visible = b_show;
}

Moa.prototype.createPointsArray = function()
{    
    this.points = new Array();
    if (null == this.points)
    {
        alert('points is null in createPointsArray()');
    }
    
    if (this.coordinatesXMLElement != null)
    {
        var lat = null;
        var lng = null;
        var first_lat = null;
        var first_lng = null;
        var coordinateXMLElements = this.coordinatesXMLElement.getElementsByTagName("coordinate");
        var coordinateXMLElement = null;
        
        if (coordinateXMLElements != null)
        {
            for(var i = 0; i < coordinateXMLElements.length; i++)
            {
                coordinateXMLElement = coordinateXMLElements[i];
                if (null != coordinateXMLElement)
                {
                    lat = parseFloat(coordinateXMLElement.getAttribute("lat"));
                    lng = parseFloat(coordinateXMLElement.getAttribute("lng"));
                    if (null != lat && null != lng)
                    {
                        this.points.push(new GLatLng(lat, lng));
                        if (0 == i)
                        {
                            first_lat = lat;
                            first_lng = lng;
                        }
                    }
                    else
                    {
                        alert('lat or lng is null');
                    }
                }
            }
        }
        // add first point again to close the polygon's border
        this.points.push(new GLatLng(first_lat, first_lng));
    }
    else
    {
        alert('coordinatesXMLElement is null in createPointsArray()');
    }
    
}

//add a new field to gpolygon to store the moa info
GPolygon.prototype.sua = null;

Moa.prototype.createmoa = function()
{   
    
    var moa = null;      
    //alert('points:' + this.points + ' color:' +  this.strokecolor + ' weight:' + this.strokeweight + ' sopacity:' + this.strokeopacity + ' fill: ' + this.fillcolor + ' fopac:' + this.fillopacity);
	moa = new GPolygon(this.points, this.strokecolor, this.strokeweight, this.strokeopacity, this.fillcolor, this.fillopacity);
    
    if (moa != null)
    {
        if (moa_markers)
        {        
            moa.sua = this; //store the object into the property of the subclassed gpolygon
            moa_markers[moa_markers.length] = moa;	
            moa_guids[this.guid] = this.guid;
                              
	    }
	}
    
    return moa;
}

