 $(document).ready(function() {

	  $('#upload-video-form').submit(function() {
		var upFormFileSel 	= $('#upload-video-form input[name=mediafile]');
		var upFormCaptureSel= $('#upload-video-form input[name=capture]');
		var upFormCategorySel = $('#upload-video-form select[name=category]');
		var upFormTitleSel	= $('#upload-video-form input[name=video_title]');
		var upFormArtistSel	= $('#upload-video-form input[name=artist]');
		var upFormFile		= upFormFileSel.val();
		var upFormCapture	= upFormCaptureSel.val();
		var upFormCategory	= upFormCategorySel.val();
		var upFormTitle 	= upFormTitleSel.val();
		var upFormArtist	= upFormArtistSel.val();
		var allow 	= new Array('flv', 'mov', 'avi', 'divx', 'mp4', 'wmv', 'mkv', 'asf', 'wma', 'mp3', 'm4v', 'm4a', '3gp', '3g2');
		var ext 	= upFormFile.split('.').pop().toLowerCase();
		var allowCapture = new Array('jpg', 'jpeg', 'gif', 'png');
		var extCapture	= upFormCapture.split('.').pop().toLowerCase();

		if (upFormFile.length == 0 || upFormCapture.length == 0 || upFormCategory == "-1" || upFormTitle.length == 0 || upFormArtist.length == 0) {
			if (upFormFile.length == 0) {
				// EDITME use a general class to highlight important fields; in combination with removeClass() 
				// FOR EACH LINE below.
				upFormFileSel.css({'background-color':'#FD8888'});
			} else {
				upFormFileSel.css({'background-color':'#FFFFFF'});
			}
			if (upFormCapture.length == 0) {
				upFormCaptureSel.css({'background-color':'#FD8888'});
			} else {
				upFormCaptureSel.css({'background-color':'#FFFFFF'});
			}
			if (upFormCategory == "-1")	{
				upFormCategorySel.css({'background-color':'#FD8888'});
			} else {
				upFormCategorySel.css({'background-color':'#FFFFFF'});
			}			
			if (upFormTitle.length == 0) {
				upFormTitleSel.css({'background-color':'#FD8888'});
			} else {
				upFormTitleSel.css({'background-color':'#FFFFFF'});
			}
			if (upFormArtist.length == 0) {
				upFormArtistSel.css({'background-color':'#FD8888'});
			} else {
				upFormArtistSel.css({'background-color':'#FFFFFF'});
			}			
			alert("Please fill in the required, highlighted fields.");
			
			return false;
		} else {
			upFormFileSel.css({'background-color':'#FFFFFF'});
			upFormCategorySel.css({'background-color':'#FFFFFF'});
			upFormTitleSel.css({'background-color':'#FFFFFF'});
			upFormArtistSel.css({'background-color':'#FFFFFF'});
		}		

		if(jQuery.inArray(ext, allow) == -1) {
			upFormFileSel.css({'background-color':'#FD8888'});
		    alert('Invalid extension!');
			return false;
		}
					
		if(jQuery.inArray(extCapture, allowCapture) == -1) {
			upFormCaptureSel.css({'background-color':'#FD8888'});
		    alert('Invalid extension!');
			return false;
		}		
		
		$('#Submit').hide();
		$('#uploading_gif').html('<img src="'+ TemplateP +'/images/ajax-loader.gif" id="loading" /> Uploading...').show();
	
		return true;
	  });
	
  });