// Lecture Add/Update Javascript Control for LectureShare

// Nathan Carnes



$().ready(function() {

					

	$('.addAnnouncement').tabs({ 

	remote: true,

	

	onShow: function() {

        	//create text editors

			 $("textarea.wymeditor").wymeditor({

				  basePath: "http://www.lectureshare.com/js/wymeditor/",

				  jQueryPath: "http://www.lectureshare.com/js/jquery.pack.js",

				  cssPath: "http://www.lectureshare.com/css/wymeditor.css",

				  classesHtml: '',

				  containersHtml: ''

			});

			

			$("textarea").removeClass("wymeditor");

			

			$("#audioUpload").jqUploader({

				src: '/jqUploader.swf', 

				background: "FFFFFF", 

				barColor: "8194A6", 

				allowedExt: "*.mp3; *.wav; *.WAV; *.MP3", 

				allowedExtDescr: "Supported Audio Files (MP3 and WAV)", 

				params: {quality:'low'}, 

				validFileMessage: 'File selected. Please hit Upload to continue.', 

				endMessage: '', 

				hideSubmit: true, 

				endHtml: '<strong>Upload complete!</strong>' 

				}); 

						

			$("#videoUpload").jqUploader({

				src: '/jqUploader.swf', 

				background: "FFFFFF", 

				barColor: "8194A6", 

				allowedExt: "*.wmv; *.avi; *.WMV; *.AVI", 

				allowedExtDescr: "Supported Video Files (WMV and AVI)", 

				params: {quality:'low'}, 

				validFileMessage: 'File selected. Please hit Upload to continue.', 

				endMessage: '', 

				hideSubmit: true, 

				endHtml: '<strong>Upload complete!</strong>' 

				}); 

				

			$("#docUpload").jqUploader({

				src: '/jqUploader.swf', 

				background: "FFFFFF", 

				barColor: "8194A6", 

				allowedExt: "*.pdf; *.doc; *.docx; *.PDF; *.zip; *.xls; *.xlsx; *.odt; *.ppt; *.pptx; *.rtf; *.txt; *.svg; *.jpg; *.gif; *.png", 

				allowedExtDescr: "Supported Document Files", 

				params: {quality:'low'}, 

				validFileMessage: 'File selected. Please hit Upload to continue.', 

				endMessage: '', 

				hideSubmit: true, 

				endHtml: '<strong>Upload complete!</strong>' 

				}); 

				

			

			}

	});

	

	$("a.post").click( function() { 

		$parent = $(this).parent();

		$($parent).children(".addAnnouncement").toggle();

		

			 $("textarea.wymeditor").wymeditor({

				  basePath: "http://www.lectureshare.com/js/wymeditor/",

				  jQueryPath: "http://www.lectureshare.com/js/jquery.pack.js",

				  cssPath: "http://www.lectureshare.com/css/wymeditor.css",

				  classesHtml: '',

				  containersHtml: ''

			});

			

			$("textarea").removeClass("wymeditor");

		

		return false; 

		});

		

	$("a.more").click( function() { 

		$parent = $(this).parent();

		$($parent).children("ul.more").toggle();

		return false; 

		});

		

	$("a.prev").click( function() { 

		$parent = $(this).parent();

		$($parent).children("ul.prev").toggle();

		return false; 

		});		

		

	$("a.add").click( function() { 

		$("#addCourse").toggle();

		return false; 

		});

		

	$("a.deleteCourse").click( function() { 

		var dlg = confirm ("Are you sure you want to PERMANENTLY remove this course? This will delete all course documents and announcements and unenroll any enrolled students.");

		

		if (dlg)

			return true;

		else

			return false; 

		});

		

	$("a.annDelete").click( function() { 

		var dlg = confirm ("Are you sure you want to PERMANENTLY remove this announcement?");

		

		if (dlg)

			return true;

		else

			return false; 

		});		

	

		

	$("#class_start").calendar({autoPopUp: 'focus', dateFormat: 'MDY/'});

	$("#class_end").calendar({autoPopUp: 'focus', dateFormat: 'MDY/'});

	

	$("#addCourse").validate({

		rules: {

			name: {

				required: true,

				minLength: 3

			},

			

			school: {

				required: true,

				minLength: 2

			},

			

			subject: {

				required: true,

				minLength: 2

			},

			

			description: {

				required: true,

				minLength: 6

			},

			

			teacher: {

				required: true,

				minLength: 6

			}									

		},

   

		messages: {

			name: {

				required: "You must provide a course name.",

				minLength: "Please provide a longer course name."

			},

			

			school: {

				required: "You must provide the name of your institution.",

				minLength: "Please provide a longer institution name."

			},

			

			subject: {

				required: "Please provide an academic subject.",

				minLength: "Please provide an academic subject."

			},

			

			description: {

				required: "Please provide a course description.",

				minLength: "Please provide a longer description."

			},

			

			teacher: {

				required: "Please provide your name as you would like it to appear on course listings.",

				minLength: "Please provide your name as you would like it to appear on course listings."

			}			

   

		}

	});	

	

});


