var stop_bar=0;

/******************************************************************************
 *                         CHANGE SELECTED OPTION
 *****************************************************************************/

function updateTransform()
{
	DWREngine.beginBatch();
	machinebean.setTransform( $("transform").value, reply1 );
	machinebean.getSizeList( listSizes );
	machinebean.getScriptList( listScripts );
	machinebean.getProfileList( listProfiles );
	DWREngine.endBatch();
}

function updateSize() { machinebean.setSize( $("size").value, reply1 ); }

function updateScript() { machinebean.setScript( $("script").value, reply1 ); }

function updateProfile() { machinebean.setProfile( $("profile").value, reply1 ); }

function updateTransforms() { machinebean.getTransList( listTransforms ); }

function reply1() {}

/******************************************************************************
 *                        UPDATE SELECT BOX CONTENTS
 *****************************************************************************/

function listTransforms( data )
{
	DWRUtil.removeAllOptions("transform");
  	DWRUtil.addOptions("transform", data);
}

function listSizes( data )
{
	DWRUtil.removeAllOptions("size");
  	DWRUtil.addOptions("size", data);
}

function listScripts( data )
{
	DWRUtil.removeAllOptions("script");
  	DWRUtil.addOptions("script", data);
}

function listProfiles( data )
{
	DWRUtil.removeAllOptions("profile");
  	DWRUtil.addOptions("profile", data);
}

function restore()
{
	DWREngine.beginBatch();
	machinebean.getTransList( listTransforms );
	machinebean.getSizeList( listSizes );
	machinebean.getScriptList( listScripts );
	machinebean.getProfileList( listProfiles );
	DWREngine.endBatch();
}

function email()
{
	document.goToDisplay.action = "sendemail.jsp";
	document.goToDisplay.submit();
}


/******************************************************************************
 *                               PROGRESS BAR
 *****************************************************************************/
 
 function refreshProgress(ps)
{
    if ( stop_bar == 0 ){
     	machinebean.getDone( updateProgress, ps );
     } else {}
}

function updateProgress( done )
{
	if (done) {
		document.getElementById('progressBarText').innerHTML = 'spiral in progress: 100%';
		document.getElementById('progressBarBoxContent').style.width = (100 * 3.5) + 'px';
		doneWaiting();
	}
	else { machinebean.getProgress( updateBar ); }
	return true;
}


function updateBar( progress )
{
	document.getElementById('progressBarText').innerHTML = 'spiral in progress: ' + progress + '%';
	document.getElementById('progressBarBoxContent').style.width = (progress * 3.5) + 'px';
	
	window.setTimeout('refreshProgress('+progress+')', 1000);
}

function checkStatus( reserved )
{   
	if(reserved){
 		document.getElementById('progressBar').style.display = 'block';
    	document.getElementById('progressBarText').innerHTML = 'Server is processing another request. Your request is queued';
	} else {
		document.getElementById('progressBar').style.display = 'block';
    	document.getElementById('progressBarText').innerHTML = 'spiral in progress:';
	    window.setTimeout('refreshProgress('+ (0) + ')', 1000);
     }
    return true;
} 

function startProgress()
{
	stop_bar = 0;
	window.setTimeout('machinebean.getReserved(checkStatus)', 1000);
}
 
