//======================================
wrsProvide("citation_progress");
wrsRequire("citation",  SCRIPT_DIR, "citation_progress");
//======================================

function cancelProgress(dialog) 
{       
    if (dialog) 
    {
        var form = document.getElementById('progressCancelForm');
        if (form != null) 
        {
            //originally -> "cancelWait.do?"+ProgressCancelAction.TARGET_ID_KEY+"="+targetProgressID;"
            form.action = "cancelWait.do";
            form.target = "handleProgressResultsFrame";
	        form.submit();
	        showDebugMsgs('cancelProgress', 'Submitted the progressCancel form [form.action = '+form.action+'], [form.target ='+form.target+']');

	    }
        window.setTimeout("self.close()", 500);
    } 
    else 
    {	    
        var form = document.getElementById('progressCancelForm');
	    if (form != null) 
	    {
	        form.action = "cancelRecovery.do";
	        form.target = "_self";
	        form.submit();
	        showDebugMsgs('cancelProgress', 'Submitted the progressCancel form [form.action = '+form.action+'], [form.target ='+form.target+']');
	    }
        
        //form submission can cause the progress animation to stop
        //start it back up
        var progressIndicator = findDOM('progressIndicator');
        if(progressIndicator != null) 
        {
	        suppressCancelButtonAndChangeText();
	    }
    }
}



function suppressCancelButtonAndChangeText()
{
    var cancelProgressButtonElement = findDOM('cancelProgressButton');
    if(cancelProgressButtonElement != null)
    {
	    findDOM('cancelProgressButton').style.visibility = 'hidden';
	    reloadAnimatedImage('progressIndicatorImage');
	    
	    if(cancelMessage != null) {
	    	// (S0348464 - don't use .innerText, its IE-only property):
	        //findDOM('progressMessage').innerText = cancelMessage;
	        replaceFirstTextNode('progressMessage', cancelMessage);
	    }
	}
}

function enableCancelButtonAndChangeText()
{
    try
    {
        // Note found interesting problem here. Originally in suppressCancelButtonAndChangeText
        // the cancel button was disabled and then hidden. In enableCancelButtonAndChangeText
        // the button was enabled and then made visible. In certain test cases the calls in
        // (see S0340780 for one) enableCancelButtonAndChangeText made the main page background
        // go completely black with only the spinning coin visible in a small white background.
        // The problem that for some unknown reason made the page background black was when in the
		// enableCancelButtonAndChangeText the button was enabled and then made visible.
        // By simply making the button hidden in suppressCancelButtonAndChangeText (and removing 
        // button disable) and then visible in enableCancelButtonAndChangeText (and removing 
        // button enable) the problem goes away.
	    var cancelProgressButtonElement = findDOM('cancelProgressButton');
	    if(typeof cancelProgressButtonElement != "undefined")
	        cancelProgressButtonElement.style.visibility = 'visible';
	    reloadAnimatedImage('progressIndicatorImage');
	    if(cancelMessage != null) {
	        //findDOM('progressMessage').innerText = originalCancelMessage;
	        replaceFirstTextNode('progressMessage', originalCancelMessage);
	    }
	}
	catch(e)
	{
	    showDebugMsgs("enableCancelButtonAndChangeText", "exception: " + e);
	}
}

function getProgressInfo() {
    // NO-OP
}
function updateProgressInfo(done,msg) {
    var progress = findDOM('progressIndicator');
    if (progress != null && progress.style.visibility == 'visible') {
        if (msg != null) {
            // changeLabel('progressMessage', msg);
            window.status = msg;
        }
        if (! done) {
            // find next progress
            getProgressInfo();
        }
    }
}

