// Common Functions

	// Confirm Cancel on forms
	function cancel(target) {
		if ( confirm("You sure you want to cancel?") ) {
			window.location=target;
		} 
	}
	
	function addToggleOptions() {
		$('.collapsable').each(function() {
			var title = $(this).attr("title");
			if (title.length <= 0) { title = 'More Info.' }
			$(this).before('<div class="toggle">' + title + '</div>');
			$('.toggle').click(toggleOptions);
			$(this).hide();
		});
	}
	
	function toggleOptions() {
		$(this).toggleClass("expanded");
		$(this).next('.collapsable').slideToggle("normal");
	}
	
	function loadHooks() {
		// load js toggle
		addToggleOptions();

		// load js date picker
		$(".date_input").date_input();
		
		// load js tabs
		$(".ui-tabs > ul").tabs();
		
		// fade away ok messages after a few seconds.
		$('.okmsg').animate( {opacity: "1.0"}, 3000 ).fadeOut(1000);
		
		// flash error messages
		$(".errormsg").animate({ top: "0px" }, 100 ).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
		
		// Thickbox close actions
		$('#TB_close').click(function(){
			self.parent.location.reload(true); 
			self.parent.tb_remove();
		});

		//checkbox select all toggle
		$('input[name=chk-toggle]').click(function() {
			if ( $(this).attr('checked') ) 
				$('input[name=' + $(this).val() + ']').attr('checked', 'checked');
			else
				$('input[name=' + $(this).val() + ']').removeAttr('checked');
		});
		
		// popup windows
		$('A[rel="popup"]').click(function() {
			var win;
			var top = 0;
			var left = 0;
			var width = 600;
			var height = 400;
		
			if (screen.width > width) left = (screen.width - width) / 2;
			if (screen.height > height) top = (screen.height - height) / 2;
		
			win = window.open($(this).attr('href'), 'popup', 'left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top + ',width=' + width + ',height=' + height + ',scrollbars=1,location=0');
			
			if (navigator.appName != 'Microsoft Internet Explorer')  { if ( window.focus )  win.focus()};
			
			return false;
		});	
	}
	
// jQuery equivalent of onLoad event
// put anything in here that you would like to load on all pages.
$(document).ready(function() {
	loadHooks();
});
