/**
 * @author Shuku.Torabi <shtorabi@yahoo.com>
 * 
 * This file includes general use javascript function that are used across different
 * parts of the website.
 * 
 * 
 * 
 */
	var selectedModuleId ; 
	var selectedModuleItem ; 
	var selectedModuleItemPS ;
	
	/** marks an item in the page as selected 
	 * 
	 * @param {Object} moduleTRItem  Table row item.
	 * @param {Object} id ID of the selected item in the table row.
	 */
	function selectItem(moduleTRItem, id , publishStatus){	
		if ( selectedModuleItem != null) {
			selectedModuleItem.className='' ; 
		}

		selectedModuleItem = moduleTRItem ;
		selectedModuleId = id ;		
		moduleTRItem.className = 'highlighted' ;
		
		selectedModuleItemPS = publishStatus ;
		publishButton = document.getElementById('publishButton') ; 
		unpublishButton = document.getElementById('unpublishButton') ; 
		
		if ( publishStatus == 'published') {
			if ( publishButton != null)
				publishButton.className='disabled' ; 
			
			if ( unpublishButton != null)	
				unpublishButton.className='' ; 
		} else {
			if ( unpublishButton != null)
				unpublishButton.className='disabled' ; 
	
			if ( publishButton != null)
				publishButton.className='' ; 			
		}
		
	}
	
	/** performs an action by redirecting the page to the given url */	
	function perform_action(action, url) {
		if (selectedModuleId == null && action != 'create') {
			alert('Please select an item first.');
		}
		else if (action == 'delete') {
			if (confirm("Are you sure you would like to delete this item ?")) {
				window.location = url  + selectedModuleId;
			}
		} else {
			window.location = url  + selectedModuleId;
		}			
	}

	/**
	 * hides operations for the given row of the table.
	 * @param row
	 * @return
	 */
	function hideOperations(row) {
		showHideOperations(row, "hide") ; 		
	}

	/**
	 * shows the operations for the given row of the table.
	 * @param row
	 * @return
	 */
	function showOperations(row) {
		showHideOperations(row, "show") ; 
	}
	
	
	/**
	 * 
	 * This is a shorthand method called by showOperations and hideOperations.
	 * 
	 * @param rowId tr rowId for the row to show operations for
	 * @param action 'show' or 'hide' indicating whether to show or hide operations.
	 * @return
	 */
	
	function showHideOperations(row , action) {
		var rowId = row.id ;  
		var operationsSpan = $("tr#"+rowId+">td>span") ;  
		if ( action == "show" ) {
			operationsSpan.css("visibility","visible") ;
		}
		else {
			operationsSpan.css("visibility","hidden");
		}
	}
	
	
	
	
