
/**
     *  This function will update an elements style display attribute toggling
     *  it between hidden and (by default) block, although this can be overwritten 
     *  by passing inline or another string as the showState variable
     *
     *  @author Dave Folan
     *  @param (String) OR (Object) targetId    Id or HtmlElement that needs toggling.
     *  @param (String) showState               The showState to use (defaults to block) 
     **/
     function toggleHidden(targetId, showState)
     {
         if(showState == undefined) { showState='block'; }
         if(typeof targetId != 'object') { 
             var targetElement = document.getElementById(targetId);
             if (targetElement == null) { return false; }
         }else{
             var targetElement = targetId;
         }
         
         if(targetElement.style.display == 'none'){
             targetElement.style.display = showState;
         }else{
             targetElement.style.display = 'none';
         }
     }

     /**
     *  This function toggles an elements className between open and closed 
     *
     *  @author Dave Folan
     *  @param (String) targetId Id of the element to toggle.
     **/
     
     function toggleOpenClose(targetId)
     {
         var targetElement  = document.getElementById(targetId);
         if(targetElement == null) { return false; }
         
         if(targetElement.className.search(/open/i) > 0){
             targetElement.className = targetElement.className.replace(/open/i, "closed");
         }else{
             targetElement.className = targetElement.className.replace(/closed/i, "open");
         }
     }
     
     /**
     *  Function to open and close facets. When facets are in this stucture:
     *   <headerElement id="ID" onclick="toggleFacetOpenClose(ID)">Header</headerElement>
     *   <listContainer id="childof-ID">
     *       <listItem>1</listItem>
     *       <listItem>2</listItem>
     *       <listItem>3</listItem>
     *   </listContainer>
     *
     *  @TODO: create two functions from this: toggleOpenClose and toggleHidden(targetId, showState = 'block')
     *  @author Dave Folan
     *  @param (String) headerId Id of the facet to close.
     **/
     function toggleFacet( facetId )
     {
         toggleOpenClose( facetId );
         toggleHidden( 'childof-' + facetId );
     }

    /**
     *  This function is to override the function above when trying to click the link of the parent element,
     *  as clicking on the link will trigger the li's event.
     *  So by using this the toggleOpenClose function wont work!
     *
     *  @author Dave Folan
     *  @param (String) headerId Id of the element to override onclick functionality of.
     **/
    function overrideToggleOpenClose(headerId) {
        var target = document.getElementById(headerId);
        target.id = 'empty';
        var listElement  = document.getElementById('childof-' + headerId);
        listElement.id = 'childof-empty';
    }
        
