// JavaScript Document
jQuery(document).ready(function(){       
// BROWSER Detection //						   
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

// Using browser detection to disable the jQuery Blend effect on the main menu in IE6 and Opera - z-index issues //

if (b_version.indexOf("MSIE 6.0")==-1 && browser.indexOf("Opera")==-1 && b_version.indexOf("MSIE 7.0")==-1) {
        jQuery("#menu_group_main a").blend();       
}    

// I have used IF statements to avoid missing elements or functions on pages. //
// The effects will work only if the linked element exists in the document    //

if ( jQuery(".column").length > 0 ) {

// We make the .column divs sortable //
		/*jQuery(".column").sortable({
			connectWith: '.column',
			// We make the .portlet-header to act as a handle for moving portlets //
			handle: '.portlet-header'
		});*/
		// We create the protlets and style them accordingly by script //
		jQuery(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
			.find(".portlet-header")
				.addClass("ui-widget-header ui-corner-top")
				.prepend('<span class="ui-icon ui-icon-triangle-1-n"></span>')
				.end()
			.find(".portlet-content");
		// We make arrow button on any portlet header to act as a switch for sliding up and down the portlet content //
		jQuery(".portlet-header .ui-icon").click(function() {
			jQuery(this).parents(".portlet:first").find(".portlet-content").slideToggle("fast");
			jQuery(this).toggleClass("ui-icon-triangle-1-s"); 
			return false;	
		});
		// We disable the mouse selection on .column divs //
		//jQuery(".column").disableSelection();
}
		// This function is making the info messages to slide up when the X is clicked //
		jQuery(".info").click(function() {
			jQuery(this).slideUp("fast");							 	  
		});
		// This is creating a modal box from a hidden element on the page with id #inline_example1 //
		jQuery("#inline_example1").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true
		});	
		// This is creating a modal box from a hidden element on the page with id #inline_example2 //
		jQuery("#inline_example2").dialog({
			bgiframe: false,
			autoOpen: false,
			modal: true
		});		
		// This triggers the modal dialog box //
		jQuery('.mail').click(function() {
			jQuery('#inline_example1').dialog('open');
		})
		// This toggles the color changer menu //
		jQuery(".dropdown").click(function() { 
			jQuery("#colorchanger").slideToggle("fast");	
		});	

// The functions below are made as FX for table operations //
if ( jQuery(".approve_icon").length > 0 ) {		
		jQuery(".approve_icon").click(function() { 
			jQuery(this).parents("tr").css({ "background-color" : "#e1fbcd" }, 'fast'); 
				// THE ALERT BELOW CAN BE REMOVED - you can put any function here linked to the approve icon link in the table //
				alert('this is approved');
			});
}
if ( jQuery(".reject_icon").length > 0 ) {	
		jQuery(".reject_icon").click(function() { 
			jQuery(this).parents("tr").css({ "background-color" : "#fbcdcd" }, 'fast'); 	
				// THE ALERT BELOW CAN BE REMOVED - you can put any function here linked to the reject icon link in the table //
			alert('this is rejected');
			});
}
if ( jQuery(".delete_icon").length > 0 ) {	
		jQuery(".delete_icon").click(function() { 
			jQuery(this).parents("tr").css({ "background-color" : "#fbcdcd" }, 'fast'); 
			// THE ALERT BELOW CAN BE REMOVED - you can put any function here linked to the delete icon link in the table //
			alert('this is deleted!');
			// And we make the deleted row to dissapear! //
			jQuery(this).parents("tr").fadeOut("fast");
			});
}
// This function serves the More submenu ideea - you can attach the class .more to any tabbed link and you will trigger the hidden sub-sub menu to appear when clicked - this can be developed in a nice way if you have an enormous amount of links //
if ( jQuery(".more").length > 0 ) {	
		jQuery("#tabs .more").click(function() { 
			jQuery("#hidden_submenu").slideToggle("fast");
			jQuery(this).toggleClass("current"); return false;								 			
		});
}
// This triggers the calendar when clicked on the event tip on the right of the title - dashboard.html - it can be used anywhere in the page //
if ( jQuery(".hidden_calendar").length > 0 ) {
		jQuery(".hidden_calendar").datepicker();
		jQuery(".inline_calendar").click(function() { 
			jQuery(".hidden_calendar").toggle("fast");
		});		
}
// This triggers the 2nd modal box when clicked on the TIP link on the right of the title - forms.html //
if ( jQuery(".inline_tip").length > 0 ) {
		jQuery(".inline_tip").click(function() { 
			jQuery("#inline_example2").dialog('open');
		});
}
});
// THE jQuery scripts end here //

// Below is the "allbox" script for selecting all checkboxes in a table by clicking one of them - usualy the on in the table heading //

if ( jQuery("#allbox").length > 0 ) {		
	function checkAll(){
		for (var i=0;i<document.forms[0].elements.length;i++)
		{
			var e=document.forms[0].elements[i];
			if ((e.name != 'allbox') && (e.type=='checkbox'))
			{
				e.checked=document.forms[0].allbox.checked;
			}
		}
	}
}