// Sitewide Admin scripts using jquery
$(document).ready(function() {
//jquery Datepicker
	Date.firstDayOfWeek = 7; //show sunday through saturday
	Date.format = 'mm/dd/yyyy'; //show desired date format
	$('.form_date').datePicker({startDate:'01/01/1996'});
	//validate date using validate_date.js
	$(".form_date").blur(function() {
		checkdate(this);
	});
	
//jquery tablesorter
    $(".tablesorter").tablesorter({widgets: ['zebra']});
	$(".tablesorter tbody tr").hover(function() {$(this).addClass("over");}, function() {$(this).removeClass("over");});

//folder select for fileupload
	$("#folder_select").change(function() {
		$(this).parent("form").submit();
	});

//reload folders for fileupload
	$("#reload").click(function() {
		location.reload(true);
		return false;
	});

//upload window for fileupload
	$('#upload_window a').click(function() {
		window.open(this.href,'Upload','width=550,height=200,scrollbars=1,resizable=1,status=0,toolbar=0');
		return false;
	});
	
//show upload graphic
	$("#upload").submit(function() {
		$("#progress").show();
	});

//refresh file admin page when upload is complete
	if ($("div").hasClass(".uploaded")) {
		window.opener.location.reload(true);
	}

//Confirm Delete
	$(".delete_item").click(function() {
		var answer = confirm('Are you sure you want to delete?');
		return answer // answer is a boolean
	});
	
//add tooltip to files to show preview
	$("a.preview").filetip();

//password recovery display
	$("#recover_pw").click(function() {
		$("#recover_box").toggle();
		return false;
	});

//multifile plugin
	$(".multifile").multifile();
	
//WYSIWYG Rich Text Editor using HtmlBox
	if ($("textarea").hasClass("form_rte")) {
		$(".form_rte").htmlbox()
			// Bold, Italic, Underline
			.separator("dots").button("bold").button("italic").button("underline")	
			// Left, Right, Center, Justify
			.separator("dots").button("left").button("center").button("right").button("justify")
			// Ordered List, Unordered List, Indent, Outdent
			.separator("dots").button("ol").button("ul").button("indent").button("outdent")
			// Hyperlink, Image
			.separator("dots").button("hyperlink").button("unlink").button("image")
			// Undo, Redo
			.separator("dots").button("undo").button("redo")
			// HTML code view
			.separator("dots").button("code")
			.init();
	}
	
//limit text length
	$("#meta_keywords, #meta_description").keyup(function() {
		var limit = $(this).val();
		if (limit.length > 250) {
			var maxtext = limit.slice(0, 250);
			$(this).val(maxtext);
		}
	});
});