﻿// Add common toolkit scripts here.  To consume the scripts on a control add
// 
//      <RequiredScript(GetType(CommonScripts))>_ 
//      public class SomeExtender : ...
// 
// to the controls extender class declaration.
Type.registerNamespace('Liquid.LiquidWebControls');

Liquid.LiquidWebControls._CommonLiquidScripts = function() {
    /// <summary>
    /// The _CommonLiquidScripts class contains functionality utilized across a number
    /// of controls (but not universally)
    /// </summary>
    /// <remarks>
    /// You should not create new instances of _CommonToolkitScripts.  Instead you should use the shared instance CommonToolkitScripts (or AjaxControlToolkit.CommonToolkitScripts).
    /// </remarks>
};

Liquid.LiquidWebControls._CommonLiquidScripts.prototype= {
    
   
    startsWith : function(s1,s2) {
        return s1.indexOf(s2)===0;     
    },
    
    getHeight : function(e,excludeInternalHeight) {
        var ch = e.clientHeight;
        var oh = e.offsetHeight;
        //if overflow is hidden on a containing div then scroll width gives the real internal width
        if (!oh||e.scrollHeight>oh) {
            oh = e.scrollHeight + e.offsetHeight - e.clientHeight;
            ch = e.scrollWidth - oh + ch;
        }   
        if (excludeInternalHeight) {
            return oh - ch;
        }
        else {
            return oh;
        }       
       
    },  
    
    //return the width of an element, exclude internal width for just border and margin
    getWidth : function(e,excludeInternalWidth) { 
        var cw = e.clientWidth;
        var ow = e.offsetWidth;
        //if overflow is hidden on a containing div then scroll width gives the real internal width       
        if (!ow||e.scrollWidth>ow) {
            ow = e.scrollWidth ;
            cw = e.scrollWidth - ow + cw;
        }   
        if (excludeInternalWidth) {
            return ow - cw;
        }
        else {
            return ow;
        }         
    } ,
    /// <summary>
    /// Return the first ancestor element with the specified tag name. If no tag
    /// name is specified then just returns the parent node. 
    /// </summary>
    /// <param name="node" type="Sys.UI.DomElement" domElement="true">
    /// The DOM element to search up the Dom tree from
    /// </param>
    /// <param name="tagName" type="string" domElement="false">
    /// The tagName to search the ancestor elements for
    /// </param>  
    /// <returns type="Object" desc="the javascript prototype that represents the Dom element" />
    getParentObjectByTagName : function(node,tagName) {        
        if (!node) {
            return node;
        } 
        else {
            if (!tagName) {
                return node.parentNode;
            }
            else {
                if (node.tagName==tagName) {
                    return $find(node.id);      
                } 
                else {                   
                    return this.getParentObjectByTagName(node.parentNode,tagName);
                } 
            }
        }       
    },  
      
    /// <summary>
    /// Return the first child element with the specified tag name. If no tag
    /// name is specified then just returns the node. 
    /// </summary>
    /// <param name="node" type="Sys.UI.DomElement" domElement="true">
    /// The DOM element to search the children of.
    /// </param>
    /// <param name="tagName" type="string" domElement="false">
    /// The tagName to search the child elements for
    /// </param>  
    /// <returns type="Object" desc="the javascript prototype that represents the Dom element" />
    getChildObjectByTagName : function(node,tagName) {
        if (!node||!tagName) {
            return node;
        } 
        else { 
            for (var i = 0; i < node.childNodes.length; i++) {
                if (node.childNodes[i].tagName == tagName) {return $find(node.childNodes[i].id);}
            }       
        }              
    } ,
    
    /// <summary>
    /// Return the first child element with the specified tag name. If no tag
    /// name is specified then just returns the node. 
    /// </summary>
    /// <param name="node" type="Sys.UI.DomElement" domElement="true">
    /// The DOM element to search the children of.
    /// </param>
    /// <param name="tagName" type="string" domElement="false">
    /// The tagName to search the child elements for
    /// </param>  
    /// <returns type="HTML" desc="the Dom element" />
    getChildElementByTagName : function(node,tagName) {
        if (!node||!tagName) {
            return node;
        } 
        else { 
            for (var i = 0; i < node.childNodes.length; i++) {
                if (node.childNodes[i].tagName == tagName) {return node.childNodes[i];}
            }       
        }              
    },
     
    /// <summary>
    /// Return the first ancestor element with the specified tag name. If no tag
    /// name is specified then just returns the parent node. 
    /// </summary>
    /// <param name="node" type="Sys.UI.DomElement" domElement="true">
    /// The DOM element to search up the Dom tree from
    /// </param>
    /// <param name="tagName" type="string" domElement="false">
    /// The tagName to search the ancestor elements for
    /// </param>  
    /// <returns type="HTML" desc="the Dom element" />
    getParentElementByTagName : function(node,tagName) {        
        if (!node) {
            return node;
        } 
        else {
            if (!tagName) {
                return node.parentNode;
            }
            else {
                if (node.tagName==tagName) {
                    return node;      
                } 
                else {                   
                    return this.getParentObjectByTagName(node.parentNode,tagName);
                } 
            }
        }       
    }  
};

// Create the singleton instance of the CommonToolkitScripts
var CommonLiquidScripts = Liquid.LiquidWebControls.CommonLiquidScripts = new Liquid.LiquidWebControls._CommonLiquidScripts();
var $commonLiquid = CommonLiquidScripts;

//////////////////////////////////////////////////////////////////////////////////////////////////////

Liquid.LiquidWebControls.Orientation = function() { };
Liquid.LiquidWebControls.Orientation.prototype = {
    Horizontal : 0x01,
    Vertical : 0x02
};
Liquid.LiquidWebControls.Orientation.registerEnum("Liquid.LiquidWebControls.Orientation", true);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();