﻿
var ibIsReady = false;
//var ibDiscIsReady = false;
/*
// initialize this variable to null indicating that a loginForm has not been
// submitted. this form initially returns false, stopping the form submission
// which is later submitted after 2 second polls of the loaded status.
**
** DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING
**
*/
var activeLoginForm = null;
/*
// generic wrapper function that will suspend the call of the given function
// name until after Internet Banking is ready for a "login" request.
*/
var ibLoginWrapCount = new Array();

function ibLoginWrap( ibLoginFunc, ibStatVar, ibLoginForm, force )
{
    /* initialize for new stat variables */
    if ( ! ibLoginWrapCount[ ibStatVar ] )
    {
        ibLoginWrapCount[ ibStatVar ] = 0; 
    }
    else if ( ! force ) 
    { 
        alert( "double click" ); 
        return( false ); 
    }
    
    /* increment the number of attempts */
    ibLoginWrapCount[ ibStatVar ]++;
    
    /* if we don't have an active form, we need one */
    if ( (activeLoginForm == null) && ibLoginForm )
    {
        activeLoginForm = ibLoginForm; 
    }
    
    /* if we don't have the form here, bad function call; return false */
    if ( activeLoginForm == null )
    { 
        return( false ); 
    }
    
    /* if the function is visible and the stat variable is true */
    if ( eval( "window."+ ibLoginFunc ) && eval( "ibStatVar" ) )
    {
    
        /* reset counter, function has been called */
        ibLoginWrapCount[ ibStatVar ] = null;
        
        /* call function, pass activeLoginForm */
        var ibLoginFuncReturn = eval( ibLoginFunc +"( activeLoginForm )" );
        
        /* if function returned true, submit the form */
        if( ibLoginFuncReturn )
        { 
            activeLoginForm.submit(); 
        }
        
        /* pass on the function return */
        return( ibLoginFuncReturn );
    }
    /* less than 40th iteration, try again */
    else if ( ibLoginWrapCount[ ibStatVar ] <= 40 )
    {
    
        /* every 10th loop, with 3 second delay between loops =~ 30 seconds */
        if ( (ibLoginWrapCount[ ibStatVar ] % 10) == 0 )
        { 
            alert('Your request will be sent soon.'); 
        }
        
        /* wait 3 seconds and try again */
        window.setTimeout( "ibLoginWrap('"+ ibLoginFunc +"', '"+ ibStatVar +"', "+ null +", 1)", 3000 );
    }
    /* more than 100th iteration, timeout */
    else
    { 
        alert( 'request timeout: please try again in a few minutes' ); 
    }
    
    /* default is to return false */
    return( false ); 
}