$(document).ready(function() {
	$('#filenames').val("");
	$("#appForm").validate({focusCleanup:true});
	
	function cancelError(id) {
		$('#uploadify').uploadifyCancel(id);
	}

	$("#uploadify").uploadify({
		'uploader'       : 'scripts/uploadify.swf',
		'script'         : 'scripts/uploadify.php',
		'cancelImg'      : 'cancel.png',
		'sizeLimit'		 : 8000000,
		'folder'         : 'uploads/2011',
		'queueID'        : 'fileQueue',
		'auto'           : true,
		'multi'          : true,
		'fileExt'		 : '*.jpg;*.png;*.doc;*.docx;*.pdf;*.zip',
		'fileDesc'		 : 'Documents of Type: (*.jpg;*.png;*.doc;*.docx;*.pdf;*.zip)',
		'onComplete': function(event,queueID,fileObj,response,data) {
				
			 $('#filenames').val($("#filenames").val() + response+",");
			 $('.percentage').html(" - <span class=\"complete\">UPLOAD COMPLETE</span>");
			 return(false);
		},
		'queueSizeLimit' : 5,
		'onAllComplete' : function(event, data) {
			
			var totalErrors=($(".uploadifyError").size());

			if (totalErrors==0) {
				//$("#appForm").submit();
			}
			
		}
		
	});
	
	$("#submitButton").click(function () {
//		var totalFiles=($(".fileName").size());
	//	if (totalFiles > 0 && $("#appForm").valid()) {
		//	$("#uploadify").uploadifyUpload();
			
//		} else {
			$("#appForm").submit();
	//	}

	
//	return(false);
	});
	

	
	
});


function printApplication() {
		window.print();
	}



