
var intApplet;
var cancelled = false;
var prefix = "";
var count = 0;
/*
 * Called by the applet to notify the page of the processes progress
 * @param processDescription - A description of the current process
 * @param processPercentage - the percentage completed of the current process  
 */
function notifyProgress(processDescription, total, completed)
{
	var process = popupFrame.document.getElementById("currentProcess");	
	var progress = popupFrame.document.getElementById("progress");
	var numTotal = parseInt(total);
	var numCompleted = parseInt(completed);
	if(process)
	{
		count++;
		if(count % 100 == 0)
		{
			callSite();			
		}

		var percentComp = (numCompleted / numTotal) * 100; 
		var processPercentage = Math.round((300 / 100) * Math.ceil(percentComp));
		process.innerHTML = processDescription;
		var progress = popupFrame.document.getElementById("progress");
		progress.style.width = processPercentage + 'px';
	}
}

/*
 * Called by the applet to notify the start of processing
 */
function notifyStarted()
{
	showPopWin('/modal_upload_progress.jsp', 382, 125, null);
}

function callSite()
{

	var keepAlive = new sack();
	keepAlive.requestFile = '/modal_keepAlive.jsp';
	keepAlive.runAJAX();
	keepAlive = null;
}

/*
 * Called by the applet to notify the finishing of processing
 */
function notifyFinished(finishedOk, filename)
{
	//alert('notifyFinished:' + filename + ' - ' + finishedOk);
	if(finishedOk == 'false' && !cancelled)
	{
		alert("file upload failed");
		return;
	}
	else if(filename == '' || filename == null)
	{
		alert("file upload failed");
		return;
	}
	else if(!cancelled)
	{
		var videoFileName = document.getElementById(prefix + "videoFileName");
		if(videoFileName)
		{
			videoFileName.value = filename;
			//alert(prefix + "videoFileName:" + videoFileName.value);
		}
		// submit local form
		document.forms["contentEdit"].submit();
	}
	toggleSWF();
	hidePopWin(false);
}

function notifyNoFile()
{
	//alert('no file to upload');
	toggleSWF();
	document.forms["contentEdit"].submit();
}

/*
 * Returns true if all required data is present and correct 
 */
function validateData()
{
	return validateFormData(document.forms["contentEdit"]);
}

/*
 * Called by the applet to get startup parameters 
 */
function getInputData(){}

/*
 * Calls cancelProcess on the applet 
 */
function cancelProcess()
{
	// call applet
	cancelled = true;
	getApplet().cancelProcess();
	hidePopWin(false);
	toggleSWF();
}

/*
 * Calls startProcess on the applet 
 */
function startProcess()
{
	cancelled = false;
	// call applet
	getApplet().startProcess();
}

function getApplet()
{
	if(intApplet == null)
	{
		var applarr = document.getElementsByName("uploadapplet");
		for(var i = 0 ; i < applarr.length ; i++)
		{
			try
			{
				applarr[i].getName();
				intApplet = applarr[i];
			}
			catch(err)
			{
				//alert('err:' + err)
			}
		}
	}
	return intApplet;
}