﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("AirQuestSite");

AirQuestSite._DomUtility = function() {
    /// <summary>
    /// Utility functions for manipulating the DOM
    /// </summary>
}
AirQuestSite._DomUtility.prototype = {
    isDescendant: function(ancestor, descendant) {
        /// <summary>
        /// Whether the specified element is a descendant of the ancestor
        /// </summary>
        /// <param name="ancestor" type="Sys.UI.DomElement">Ancestor node</param>
        /// <param name="descendant" type="Sys.UI.DomElement">Possible descendant node</param>
        /// <returns type="Boolean" />

        for(var n = descendant.parentNode; n != null; n = n.parentNode) {
            if(n == ancestor) return true;
        }
        return false;
    },
    isDescendantOrSelf: function(ancestor, descendant) {
        /// <summary>
        /// Whether the specified element is a descendant of the ancestor or the same as the ancestor
        /// </summary>
        /// <param name="ancestor" type="Sys.UI.DomElement">Ancestor node</param>
        /// <param name="descendant" type="Sys.UI.DomElement">Possible descendant node</param>
        /// <returns type="Boolean" />

        if(ancestor === descendant)
            return true;
        return AirQuestSite.DomUtility.isDescendant(ancestor, descendant);
    },
    isAncestor: function(descendant, ancestor) {
        /// <summary>
        /// Whether the specified element is an ancestor of the descendant
        /// </summary>
        /// <param name="descendant" type="Sys.UI.DomElement">Descendant node</param>
        /// <param name="ancestor" type="Sys.UI.DomElement">Possible ancestor node</param>
        /// <returns type="Boolean" />

        return AirQuestSite.DomUtility.isDescendant(ancestor, descendant);
    },
    isAncestorOrSelf: function(descendant, ancestor) {
        /// <summary>
        /// Whether the specified element is an ancestor of the descendant or the same as the descendant
        /// </summary>
        /// <param name="descendant" type="Sys.UI.DomElement">Descendant node</param>
        /// <param name="ancestor" type="Sys.UI.DomElement">Possible ancestor node</param>
        /// <returns type="Boolean" />

        if(descendant === ancestor)
            return true;

        return AirQuestSite.DomUtility.isDescendant(ancestor, descendant);
    },
    isSibling: function(self, sibling) {
        /// <summary>
        /// Whether the specified element is a sibling of the self element
        /// </summary>
        /// <param name="self" type="Sys.UI.DomElement">Self node</param>
        /// <param name="sibling" type="Sys.UI.DomElement">Possible sibling node</param>
        /// <returns type="Boolean" />

        var parent = self.parentNode;
        for(var i = 0; i < parent.childNodes.length; i++) {
            if(parent.childNodes[i] == sibling) return true;
        }
        return false;
    },
    clearNode: function(node) {
        while(node.childNodes.length > 0) {
            node.removeChild(node.childNodes[node.childNodes.length - 1]);
        }
    },
    populateMembers: function(target, properties) {
        for(var k in properties) {
            target[k] = properties[k];
        }
    }
}
AirQuestSite._DomUtility.registerClass("AirQuestSite._DomUtility");
AirQuestSite.DomUtility = new AirQuestSite._DomUtility();



/*
AirQuestSite.MarkerContext = function(marker) {

    AirQuestSite.MarkerContext.initializeBase(this);
    this._theMarker = marker;
};

AirQuestSite.MarkerContext.prototype = {

    _theMarker: null,
    onClick$listener: null,

    initialize: function() {
        AirQuestSite.MarkerContext.callBaseMethod(this, "initialize");

        // bind click
        this._theMarker.__markerContext = this;
        this.get_events();
        this.onClick$listener = google.maps.Event.addListener(this._theMarker, "click", Function.createDelegate(this, this.onClick));
    },

    add_click: function(handler) {
        this.get_events().addHandler("click", handler);
    },

    remove_click: function(handler) {
        this.get_events().removeHandler("click", handler);
    },

    onClick: function(pt) {
        var args = new AirQuestSite.MapPointerEventArgs(pt);
        var h = this.get_events().getHandler('click');
        if(h) {
            h(this, args);
        }
    },

    dispose: function() {

        google.maps.Event.removeListener(this.onClick$listener);

        AirQuestSite.MarkerContext.callBaseMethod(this, "dispose");
    }

};

AirQuestSite.MarkerContext.getFromMarker = function(marker) {
    return marker.__markerContext;
};

AirQuestSite.MarkerContext.registerClass('AirQuestSite.MarkerContext', Sys.Component);

/////////////////////////////////////////////////////////////

AirQuestSite.MapPointerEventArgs = function(point) {    
    
    AirQuestSite.MapPointerEventArgs.initializeBase(this);
    
    this._point = point;
}

AirQuestSite.MapPointerEventArgs.prototype = {
    _point: null,
    
    get_point: function() {
        return this._point;
    }
}
AirQuestSite.MapPointerEventArgs.registerClass('AirQuestSite.MapPointerEventArgs', Sys.EventArgs);
*/

if(typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

