var search_helper;



function advancedSearchHelper()
{
    var _this= this;
    

    this.updateInputs= function( node )
    {
        var inputs= node.getElementsByTagName( 'input' );

        for( var itr= 0; itr < inputs.length; itr++ )
        {
            if( inputs[ itr ].type == 'checkbox')
            {                    
                var cp= document.getElementById( inputs[ itr ].name );
                if( cp )
                {
                    if(inputs[ itr ].checked == true)
                    {
                        cp.value= inputs[ itr ].value;
                        cp.name= inputs[ itr ].name;
                    }
                    else
                    {
                        cp.value = '';
                        cp.name= inputs[ itr ].name;
                    }
                }
            }

        }

    }

    this.handleShow= function( event )
    {
        var sender= getEventTarget( event );
        sender.style.display= "none";
        
        node= sender;
        
        while( node.nodeName != 'DIV' )
            node= node.nextSibling;

        node.style.display= "block";

        node= sender;
        
        while( node.nodeName != 'B' )
            node= node.previousSibling;

        var tmp= node.getElementsByTagName( 'a' );
        
        tmp[ 0 ].style.display= "inline-block";
    }


    this.handleHide= function( event )
    {
        var sender= getEventTarget( event );
        sender.style.display= "none";
        
        
        var node= sender.parentNode;


        while( node.nodeName != 'A' )
            node= node.nextSibling;
        
        node.style.display= "inline-block";
        
        while( node.nodeName != 'DIV' )
            node= node.nextSibling;

        this.updateInputs( node );
        
        node.style.display= "none";


        
    }

    
    this.setFoldingSwitches= function()
    {
        var on_switches= document.getElementsByClassName( 'showLink' );
        
        for( var itr= 0; itr < on_switches.length; itr++ )
        {
            on_switches[ itr ].style.display= "none";
            addPortableEventListener( on_switches[ itr ], 'click', function( event ){ _this.handleShow( event ); } );
        }

        var off_switches= document.getElementsByClassName( 'hideLink' );

        for( var itr= 0; itr < off_switches.length; itr++ )
        {
            off_switches[ itr ].style.display= "inline-block";
            addPortableEventListener( off_switches[ itr ], 'click', function( event ){ _this.handleHide( event ); } );
        }
    }


    
    this.setFoldingSwitches();
    
    return this;

}


function initSearchHelper()
{
    console.log( 'here' );
    search_helper= new advancedSearchHelper();
    
}




runOnLoad( initSearchHelper );

