﻿// ---------------------------------------------------------------------
// Description:		ResultListExtendedSearch.js
//					ClientSide Script for ResultListExtendedSearch.cs
// 
// Autor:			Herbert Granofszky
// Date:			25.09.2007
// 
// (c) by team ModulAcht. All rights reserved
// ---------------------------------------------------------------------

var ResultListExtendedSearch =
{
    searchDialogId : null,
    detailsDialogId : null,
    changeSearchButtonId : null,
    
    _detailButtons : new Array(),
    
    initialize : function()
    {
        // hook into changeSearchButtons on click event
        Event.observe(this.changeSearchButtonId, 'click', this._onChangeButtonPressed.bindAsEventListener(this));
    },
    
    registerShowDetailsDialogButton : function(argButtonId, argOfferId)
    {
        this._detailButtons[argButtonId] = argOfferId;
        Event.observe(argButtonId, 'click', this._onShowDetailsButtonClick.bindAsEventListener(this));
    },
    
    _onShowDetailsButtonClick : function(e)
    {
        var sourceElement = Event.element(e);
        
        var buttonId = null;
        if (sourceElement.tagName.toLowerCase() == "img")
        {
            // when user clicked on an image button use the id of the surrounding anchor
            buttonId = sourceElement.up().id;
        }
        else
        {
            buttonId = sourceElement.id;
        }
        var offerId = this._detailButtons[buttonId];
        var detailsDialog = document['dlg_' + this.detailsDialogId];
        detailsDialog.addDemandArgument('offerid', offerId);
        detailsDialog.showDialog();
        
        // prevent postback
        Event.stop(e);
        return false;
    },
    
    _onChangeButtonPressed : function(e)
    {
        eval(this.searchDialogId + ".showDialog();");
        Event.stop(e);
    }
};
