// JavaScript Document

var ibIsReady = false;

var activeLoginForm = null;

var ibLoginWrapCount = new Array();
function ibLoginWrap( ibLoginFunc, ibStatVar, ibLoginForm, force )
{
	/* initialize for new stat variables */
	if ( ! ibLoginWrapCount[ ibStatVar ] )
		{ ibLoginWrapCount[ ibStatVar ] = 0; }
	else if ( ! force )
		{ 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 100th iteration, try again */
	else if ( ibLoginWrapCount[ ibStatVar ] <= 100 )
	{
		/*
		// every 10th loop, with 3 second delay between loops =~ 30 seconds
		// modify the message as needed
		*/
		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
	// modify the message as needed
	*/
	else
		{ alert( 'request timeout: please try again in a few minutes' ); }

	/* default is to return false */
	return( false );
}
