
/**** VARIABLES - Configure these to fit your needs ****/ 
var languageFile = "/efu/efu-js/language.en.js"; // The language file - this MUST exist in the same folder as this file
var formPostURL = "/efu/efu-backend/upload.php"; // the page where the files will be posted
var cssPath = "/efu/efu-css/style.css"; // the path to the EFU CSS file
var afterCompletionPage = "/includes/process_upload.php"; // leave empty if you dont want to redirect
var onCancelPage = "/?m=cancel"; // page where you want to take the user if they cancel upload
var flashMovieObjectEmbedID = "FileUploader"; // the html tag "id" for the flash <object> and <embed> tags
var maxUploadSize = 104857600; // maximum allowed upload size in bytes; also see useTotalsForCalc
var minUploadSize = 0; // minimum allowed upload size bin bytes; also see useTotalsForCalc
var useTotalsForCalc = false; // use the total of all the file(s) size instead of individual file size to compare against maxUploadSize or minUploadSize
var maxFiles = 5; // allow a maximum of 5 files to be uploaded at a time
var allowedFileTypes = ''; // allowed file types; add or delete extensions in the given format; leave it as '' if you want to allow all files
var showAlert = true; // will not show any alert if set to false - set to false when you want to surpress any error message
var showFlashAlert = false; // will show javascript based alert by default; set true to show flash alert for validation
var gridRowHeight =  23; // height of each grid row in pixels
var gridRowCount = 5; // number of rows in the grid; you will need to manually adjust the height of the swf embed tag in the html for this to work without scrollbars

/**** Callbacks/Events - modify these if needed ****/
// Modify if you want to validate html form - called before the form is submitted
function efuValidateForm()
{
	// Put javascript form validation code here if you want
	// This function must return true for the Flash to work
	// If there is a validation issue, show js alert box and return false.
	var Name=document.UploadForm.uploadName.value
	var Email=document.UploadForm.uploadEmail.value
	var Project=document.UploadForm.uploadProject.value
	if(Name==""){
	alert("Please enter your name")
	document.UploadForm.uploadName.focus();return false;}
	if(Email==""){
	alert("Please enter your email address")
	document.UploadForm.uploadEmail.focus();return false;}
	if(!checkemail(Email)){
	alert("Please check your email address")
	document.UploadForm.uploadEmail.focus();return false;}
	if(Project==""){
	alert("Please enter a project title/description")
	document.UploadForm.uploadProject.focus();return false;}

	return true;	
}

function efuOnUploadError(fileName,errorString)
{
	// Put javascript here if you would like to do something when error occurs
	// Not really necessary in most basic cases
	// You can even put a code for redirection if you want
	
	if(showAlert)
	{
		alert(errorString);
	}
		
	return;	
}

// This function is called when uploads are done
// This function is not called incase of an upload error
function efuOnUploadsFinished()
{
	// Put your code here if required
	var Name=encodeURIComponent(document.UploadForm.uploadName.value)
	var Email=encodeURIComponent(document.UploadForm.uploadEmail.value)
	var Project=encodeURIComponent(document.UploadForm.uploadProject.value)

if(afterCompletionPage != '')
	{
		window.location.href = afterCompletionPage + "?e=" + Email + "&n=" + Name + "&p=" + Project;
	}
		
	return;
}

// This function is called when upload is canceled
function efuOnCanceled()
{
	if(onCancelPage!='')
	{
		location.href = onCancelPage;
	}
}

/**** DO NOT MODIFY BEYOND THIS POINT - UNLESS YOU KNOW WHAT YOU ARE DOING ****/
var formValues = '';
// Submit form and upload files - Called by HTML form
function efuDoSubmit(objCaller)
{
	var flash;
	if (window.document[flashMovieObjectEmbedID]) 
	{
		flash = window.document[flashMovieObjectEmbedID];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[flashMovieObjectEmbedID])
			flash = document.embeds[flashMovieObjectEmbedID]; 
	}
	else
	{
		flash = document.getElementById(flashMovieObjectEmbedID);
	}	
	
	if(efuValidateForm())
	{
		formValues = '';
		var formObj = objCaller.form;

		var serial = [], i, j, first;
		var add = function (name, value) {
			serial.push(encodeURIComponent(name) + '=' + encodeURIComponent(value));	
		}
			
		var elems = formObj.elements;
		for (i = 0; i < elems.length; i += 1, first = false) {
		  if (elems[i].name.length > 0) { 
		    switch (elems[i].type) {
		      case 'select-one': first = true;
		      case 'select-multiple':
		        for (j = 0; j < elems[i].options.length; j += 1)
		          if (elems[i].options[j].selected) {
		            add(elems[i].name, elems[i].options[j].value);
		            if (first) break; 
		          }
		        break;
		      case 'checkbox':
		      case 'radio': if (!elems[i].checked) break;
		      default: add(elems[i].name, elems[i].value); break;
		    }
		  }
		}
		
		formValues = serial.join('&');	
		flash.startUpload();
	}
}

// Cancel the upload - called by HTML form
function efuCancelUpload(objCaller)
{
	var flash;
	if (window.document[flashMovieObjectEmbedID]) 
	{
		flash = window.document[flashMovieObjectEmbedID];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[flashMovieObjectEmbedID])
			flash = document.embeds[flashMovieObjectEmbedID]; 
	}
	else
	{
		flash = document.getElementById(flashMovieObjectEmbedID);
	}

	flash.cancelUpload();
	efuOnCanceled();
}

// Get the language string - called by Flash
function getLanguageString(ident)
{
	return LANG[ident];
}

// Include the language file
document.write("<script language=\"javascript\" src=\"" + languageFile + "\"></script>");