//initialise
var themeBodyBackgroundColor = '';
var arrValidFileExtensions = new Array();
var isIE = false;
var isMediaUpload = false;

//check if flash supported in this browser
//if (FlashDetect.installed && FlashDetect.versionAtLeast(1)) {
//	flashEnabled = true;
//}
if (FlashDetect.installed) flashEnabled = true;

//validate the video filetype (client-side)
function fn_ValidFileType() {
    var fileTypeValid = false;
	document.getElementById('videoFileCheck').value = document.getElementById('videoFile').value;
	fileCheck = document.getElementById("videoFileCheck").value;

	//check file is selected
	if (fileCheck == '') {
		alert ('You need to select your file to upload');
		document.getElementById("videoFile").focus();
		return false;
	}

	//check file type is valid
	while (fileCheck.indexOf("\\") != -1) {
		fileCheck = fileCheck.slice(fileCheck.indexOf("\\") + 1);
	}
	ext = fileCheck.slice(fileCheck.indexOf(".")).toLowerCase();
	for (var i = 0; i < arrValidFileExtensions.length; i++) {
		if (arrValidFileExtensions[i] == ext) { fileTypeValid = true; break; }
  	}

	if (!fileTypeValid) {
		alert ('You have not selected an acceptable video format');
		document.getElementById("videoFile").focus();
		return false;
	}
	return true;
}

//start the upload
function fn_StartUpload() {
	//disable the save button
	document.getElementById("btnSave").disabled = true;
	document.body.style.cursor = "wait";
	if (isMediaUpload) {
		document.getElementById("spanMediaUploadProcess").style.visibility = "hidden";
		document.getElementById("editMediaUploadProcess").style.visibility = "visible";
		if (isIE) document.status.location.href = 'uploading.cfm?bgcolor=' + themeBodyBackgroundColor;  // this next line in IE ensures the animated gif actually animates.  this line MUST only be used for IE and must not use the getElementById approach.  the getElementById causes the page to not submit and if this line is used for FireFox, the page also hangs.
		document.getElementById("command").value='save';
		document.form.submit();
	} else if (flashEnabled) {
		//flash upload
		var flash;
		flash = document.getElementById("ProFlashUpload1");
		flash.upload();
	} else {
		//file upload
		document.getElementById("spanFileUpload").style.visibility = "hidden";
		document.getElementById("editFlashUpload").style.visibility = "visible";
		if (isIE) document.status.location.href = 'uploading.cfm?bgcolor=' + themeBodyBackgroundColor;  // this next line in IE ensures the animated gif actually animates.  this line MUST only be used for IE and must not use the getElementById approach.  the getElementById causes the page to not submit and if this line is used for FireFox, the page also hangs.
		document.getElementById("videoFileCheck").value = document.getElementById("videoFile").value;
		document.getElementById("uploadMethod").value='File';
		document.getElementById("command").value='save';
		document.form.submit();
	}
}

//runs after all the file(s) have been uploaded using the flash uploader
function fn_OnComplete( numFiles, numSuccessful, numFailed ) {
	if (numFiles == 0) {
		alert ("You have not chosen a file to upload");
		fn_FormReset();
	} else {
		//update the screen display to show files being converted
		document.getElementById("spanFlashUpload").style.visibility = "hidden";
		document.getElementById("editFlashUpload").style.visibility = "visible";
		if (isIE) document.status.location.href = 'uploading.cfm?bgcolor=' + themeBodyBackgroundColor;  // this next line in IE ensures the animated gif actually animates.  this line MUST only be used for IE and must not use the getElementById approach.  the getElementById causes the page to not submit and if this line is used for FireFox, the page also hangs.
		//submit form containing data
		document.form.command.value='save';
		document.form.submit();
	}
}

//reset the form
function fn_FormReset() {
	document.getElementById("btnSave").disabled = false;
	document.body.style.cursor = "";
}

