
/**** VARIABLES - Configure these to fit your needs ****/ 
var languageFile = "efu-js/language.en.js"; // The language file - this MUST exist in the same folder as this file
var formPostURL = "efu-backend/UploadNET.aspx"; // the page where the files will be posted
var imagePath = "efu-images/"; // the folder where all the EFU related images are stored; make sure it has a trailing /
var cssPath = "efu-css/style.css"; // the path to the EFU CSS file
var afterCompletionPage = ""; // leave empty if you dont want to redirect
var onCancelPage = ""; // 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 = 10485760; // 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 = 500; // allow a maximum of 5 files to be uploaded at a time
//var allowedFileTypes = '*.jpg;*.jpeg;*.gif;*.png'; 
// allowed file types; add or delete extensions in the given format; leave it as '' if you want to allow all files




var allowedFileTypes = '*.jpg;*.jpeg;*.gif;*.png;*.txt;*.pdf;'; // 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 showPreview = true; // show preview pane; if you hide it, you will need to manually adjust the height of the swf embed tag in the html

var uploadResizedImage =  false; // resize image before uploading
var resizedHeight = 100; // in pixels
var resizedWidth = 100; // in pixels
var maintainAspectRatio = true; // maintain aspect ratio for the resized image
var resizeFormat = "jpg"; // can either be jpg or png; gif is NOT supported
var resizeQuality = 100; // from 0 to 100, 100 being the best quality
var gridRowHeight =  23; // height of each grid row in pixels
var gridRowCount = 10; // 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.
	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
	if(afterCompletionPage != '')
	{
		window.location.href = afterCompletionPage;
	}
		
	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>");
