var tic_PageGlobals =
{
    internal_globals: new Object(),

    Add:
        function(varName, varValue) 
        {
            this.internal_globals[varName] = varValue ;
        },
    Get:
        function(varName)
        {
            return this.internal_globals[varName] ;
        }        
} ;

var tic_FormUtilities = 
{
    HideField:
        function(ctl, includeFieldset)
        {
            while(ctl && (!ctl.className || ctl.className.indexOf("fieldwrapper")!=0))
                ctl = ctl.parentNode ;
                
            if (ctl)
                ctl.style.display = "none" ;                         
                
            if (includeFieldset && ctl.parentNode && ctl.parentNode.tagName == "FIELDSET")
                ctl.parentNode.style.display = "none" ;
        },
    ShowField:
        function(ctl, includeFieldset)
        {
            while(ctl && (!ctl.className || ctl.className.indexOf("fieldwrapper")!=0))
                ctl = ctl.parentNode ;
                
            if (ctl)
                ctl.style.display = "block" ;                         

            if (includeFieldset && ctl.parentNode && ctl.parentNode.tagName == "FIELDSET")
                ctl.parentNode.style.display = "block" ;
        }                
} ;

var tic_Utilities = 
{
    GetTargetCtl:
        function(evt)
        {
            if (!evt)
                evt = window.event ;

            if (evt.originalTarget)
                return evt.originalTarget;
            else if (evt.srcElement)
                return evt.srcElement;
                
            return null ;                
        },

    GetQueryStringArg:
        function()
        {
            var hashValue = null ;
            if (location.hash)
                hashValue = location.hash ;
            else if (location.search)
                hashValue = location.search ;

            return hashValue ;            
        },

    IsFirefox:
        function()
        {            
            var htmlTags = document.getElementsByTagName("HTML") ; 
            if (htmlTags && htmlTags.length  > 0)
                return tic_Utilities.HasStyle(htmlTags[0], "Firefox") ;
        },

    DisableButtons:
        function()
        {
            // WARNING: USE WITH CAUTION ON LARGE SCREENS
            var buttons = document.getElementsByTagName("INPUT") ;
            for (var ii=0 ; ii<buttons.length ; ++ii)
                if (buttons[ii].type == "button" || buttons[ii].type == "submit")
                    buttons[ii].disabled = true ;
        },
    StyleArray:
        function(ctl)
        {
            if (!ctl || !ctl.className)
                return new Array() ;
                
            return ctl.className.split(" ") ;
        },
    HasStyle:
        function (ctl, style) 
        {
            var styles = tic_Utilities.StyleArray(ctl) ;
            if (!styles || !styles.length)
                return false ;
                
            for (var ii=0 ; ii<styles.length ; ++ii)
                if (styles[ii] == style)
                    return true ; 
                    
            return false ;                                    
        },
    RemoveStyle:
        function (ctl, style) 
        {
            var styles = tic_Utilities.StyleArray(ctl) ;
            if (!styles || !styles.length)
                return false ;
            
            ctl.className = "" ;    
            var retVal = false ;
            for (var ii=0 ; ii<styles.length ; ++ii)
            {
                if (styles[ii] == style)
                    retVal = true ; 
                else
                    ctl.className += ((ctl.className?" ":"") + styles[ii]) ;
            }        
            return retVal ;                                    
        },   
    AddStyle:
        function (ctl, style)
        {
            if (!ctl)
                return ; 
            if (tic_Utilities.HasStyle(ctl, style))
                return ;                
                
            if (!ctl.className)
                ctl.className = style ;
            else
                ctl.className += " " + style ;                
        },    
    CancelBubble:
        function(evt)
        {
            if (!evt)
                evt = window.event ;
                
            if (!evt)
                return ;                
                
            evt.cancelBubble = true ;   
            evt.returnValue = false ;    

            if (evt.stopPropagation)
                evt.stopPropagation() ;     
            if (evt.preventDefault)
                evt.preventDefault() ;

            return false ;                                     
        },              
    GetWindowHeight: 
        function(minHeight)
        {
            windowHeight = window.innerHeight ; // Mozilla
            
            if (!windowHeight && document.documentElement && document.documentElement.clientHeight)
                windowHeight = document.documentElement.clientHeight ; // IE

            if (!windowHeight && document.body && document.body.clientHeight)
                windowHeight = document.body.clientHeight ; // IE
                
            if (!windowHeight || windowHeight < minHeight)
                return minHeight ;
                        
            return windowHeight ;
        },
    LeftTrim:
        function(strVal)
        {
            return strVal?strVal.replace(/^\s+/, ''):"" ;
        },        
    RightTrim:
        function(strVal)
        {
            return strVal?strVal.replace(/\s+$/, ''):"" ;
        },
    Trim:
        function(strVal)
        {
            return strVal?strVal.replace(/^\s+|\s+$/g, ''):"";
        },  

    PackageXml:
        function(tagName, data, includeCData)
        {
            var retVal = tic_Utilities.MakeXmlStartTag(tagName, includeCData) ;
            retVal += data ;
            retVal += tic_Utilities.MakeXmlEndTag(tagName, includeCData) ;
            
            return retVal ;
        },
    MakeXmlStartTag:
        function(tagName, includeCData)
        {
            if (!tagName || tagName.length == 0)
                return "" ;

            return "<" + tagName + ">" + (includeCData?"<![CDATA[":"");                 
        },
    MakeXmlEndTag:
        function(tagName, includeCData)
        {
            if (!tagName || tagName.length == 0)
                return '' 
            
            return (includeCData?"]]>":"") + "</" + tagName + ">" ;                 
        },
    ShowHideById:
        function(ctlID, doShow)
        {
            var ctl = document.getElementById(ctlID) ; 
            if (ctl)
                ctl.style.display = (doShow?"block":"none") ;
        },
    ForceVisible:
        function(id)
        {
            var item = document.getElementById(id) ;
            if (!item)
                return ; 
            item.style.display = "block" ;
            item.style.visibility = "visible" ;
        }                
} ; 

