﻿// JScript File


function isArray(obj) {
    if (obj) 
    {
       if (obj.constructor.toString().indexOf("Array") == -1)
          return false;
       else
          return true;
    } 
    return true;
}

/*  ========================================================================
    This function is called from client side from the button is first clicked
    ========================================================================
*/
function FM_watchlist_click ( elem_id, ajaxCallback ) 
{
    // Set the image to waiting ... 
    var img_elem = document.getElementById(elem_id);
    if (img_elem )
    {
        img_elem.src = img_elem.src.replace(/watchlist_save.gif/,'watchlist_saving.gif');
        img_elem.disabled=true;
        img_elem.style.cursor = "default";
    }
    
    eval(ajaxCallback);
    return false;
}

 
/*  ========================================================================
    This function is called when after the XML postback caused 
    by the  click of the "Add to Watchlist" button 
    
    .. which calls the ASP.NET page using AJAX
    .. which calls this function 
    
    event_args is an array as follows:
    EArgs[0] = not used
    EArgs[1] = new source 
    
    event_context 
        contains the element id of the button 
    ========================================================================
*/
function FM_watchlist_callback_handler (event_args, event_context) 
{ 
    var EArgs=1;
    try {    
        eval (event_args); 
        if (isArray(EArgs))
        {
            var img_elem = document.getElementById(event_context);
            if (img_elem  && EArgs[1]) 
            {
                img_elem.src = EArgs[1];
                img_elem.disabled=true;
                img_elem.style.cursor = "default";
            }
        }
    }
    catch (err)
    {
        if (err.description )
            alert ('FM_watchlist_callback_handler error:' + err.description);
        else
            alert ('FM_watchlist_callback_handler error:' + err.message);
    }
} 


/*  ========================================================================
    This function is called if an error occurs
    ======================================================================== 
*/
function FM_watchlist_error_handler (statusCodes) 
{ 
    alert ("An error occured adding the item to the watchlist:" + statusCodes);
} 

