function swfUploadLoaded() {
	var btnSubmit = document.getElementById("btnSubmit");
	btnSubmit.onclick = doSubmit;
}

function doSubmit() {

	try {

		var error = '';

		var nume 		 = $('#nume').val();
		var mail 		 = $('#mail').val();
		var telefon 	 = $('#telefon').val();
		var pagini 		 = $('#pagini').val();
		var pachet 		 = $("input[name='pachet']").is(":checked")?$("input[name='pachet']:checked").val():'';

		if(nume.length==0 || mail.length==0 || telefon.length==0 || pagini.length==0 || pachet.length==0) error = 1;

		if(error.length==0 && $('#uploadInfo').is(':hidden') && swfu.getStats().files_queued>0) {

			$.scrollTo('#uploadFisier',800);
			swfu.startUpload();
			$('#uploadInfo').fadeIn('fast');

			$('#error').fadeOut('fast');
			$('#btnSubmit').val('Va rugam asteptati ...');

			$('input,textarea').attr("disabled",true);

		} else {

			$('#error').fadeIn('fast');
			$.scrollTo('#meniujos',800);

		}

	} catch (ex) {
		this.debug(ex);
	}

	return false;
}

function fileQueued(file) {

	try {

		this.customSettings.tdFilesQueued.innerHTML = this.getStats().files_queued;

		var targetID = this.customSettings.progressTarget;
		var fileName = file.name;
		fileName = (fileName.length>=25)?fileName.substr(0,25)+' ...':fileName;

		jQuery('#'+targetID).append('<li class="colored" style="display:none" id="'+file.id+'"><span>'+fileName+'</span> <a>Sterge</a> <input type="hidden" name="fileID[]" value="" /></li>');
		jQuery('#'+file.id).fadeIn('fast');
		jQuery('#'+file.id+' a').click(function(){

			swfu.cancelUpload(file.id);

			jQuery('#'+file.id).fadeOut('fast',function(){
				jQuery('#'+file.id).remove();
			});

			if(swfu.getStats().files_queued<=0) {

				$('#btnSubmit').val('COMANDA ACUM');
				$.scrollTo('#meniujos',800);
				$('#uploadInfo').fadeOut('fast');

				$('#error').fadeIn('fast');

				$('input,textarea').removeAttr("disabled");

			}

		});

	} catch (ex) {
		this.debug(ex);
	}

}

function uploadSuccess(file, serverData) {

	try {

		jQuery('#'+file.id+' input').val(serverData);
		jQuery('#'+file.id).addClass('done');
		jQuery('#'+file.id+' a').fadeOut('fast',function(){
			jQuery('#'+file.id+' a').remove();
			jQuery('#'+file.id+' em.start').remove();
			jQuery('#'+file.id).append('<em></em>');
		});

		if(swfu.getStats().files_queued>0) {

			swfu.customSettings.tdFilesQueued.innerHTML = swfu.getStats().files_queued;
			swfu.customSettings.tdFilesUploaded.innerHTML = swfu.getStats().successful_uploads;
			swfu.customSettings.tdErrors.innerHTML = swfu.getStats().upload_errors;

			swfu.startUpload();

		} else {

			document.forms[0].submit();

		}

	} catch (ex) {
		this.debug(ex);
	}

}

function uploadStart(file) {

	try {
		jQuery('#'+file.id).addClass('start');
		jQuery('#'+file.id+' a').after('<em class="start"></em>');

		this.customSettings.progressCount = 0;
		updateDisplay.call(this, file);
	}
	catch (ex) {
	}

}

function uploadProgress(file, bytesLoaded, bytesTotal) {

	try {
		this.customSettings.progressCount++;
		updateDisplay.call(this, file);
	} catch (ex) {
		this.debug(ex);
	}

}

function updateDisplay(file) {
	this.customSettings.tdCurrentSpeed.innerHTML = SWFUpload.speed.formatBPS(file.currentSpeed);
	this.customSettings.tdAverageSpeed.innerHTML = SWFUpload.speed.formatBPS(file.averageSpeed);
	this.customSettings.tdTimeRemaining.innerHTML = SWFUpload.speed.formatTime(file.timeRemaining);
	this.customSettings.tdTimeElapsed.innerHTML = SWFUpload.speed.formatTime(file.timeElapsed);
	this.customSettings.tdPercentUploaded.innerHTML = SWFUpload.speed.formatPercent(file.percentUploaded);
	this.customSettings.tdSizeUploaded.innerHTML = SWFUpload.speed.formatBytes(file.sizeUploaded);
	this.customSettings.tdProgressEventCount.innerHTML = this.customSettings.progressCount;
}