// application.js
// Place application=specific JavaScript functions and classes in this file
function _filter( data )
{
	var container = $('filter_results');
	
	if( container )
	{
		container.innerHTML = _filter_spinner( {message: 'Please wait while your results are filtered.'} );
		
		new Ajax.Updater( container, '/admin/' + data.name + '/_filter_results?' + data.form );
	}
}
function _filter_reset( data )
{	
	function completer()
	{
		window.location.href = '/admin/' + data.name;
	}
	
	var container = $('filter_results');
	
	if( container )
	{
		container.innerHTML = _filter_spinner( {message: 'Please wait while your results are reset.'} );
		
		new Ajax.Updater( container, '/admin/' + data.name + '/_filter_results?' + data.form, {onSuccess:completer} );
	}
}
function _filter_sortby( data )
{
  var container = $('form_flash_for');
  
  if( container )
  {
    new Ajax.Updater( container, '/admin/' + data.name + '/_filter_sortby?' + data.sortby );
  }
  
  /*
  function completer()
	{
	  new Effect.Opacity( container, {duration:2, from:1, to:0, 
		  afterFinish:function(){ container.style.display = "none"; }} );//new Effect.SlideUp( container ); }} );
	}
	
	var container = $('form_flash_for');
	
	if( container )
	{
	  container.style.display = 'block';
	  container.innerHTML = '';
		
		new Ajax.Updater( container, '/admin/' + data.name + '/_filter_sortby?' + data.sortby, {onSuccess:completer} );
	}
	*/
}
function _filter_spinner( data )
{
	tempHTML = '';
	
	tempHTML = tempHTML + '<div style=\"margin: 0 auto; text-align: center; width: 100%;\"><div class="filter_loading">';
	
	tempHTML = tempHTML + '<img src="/images/forms/spinner.gif" alt="Processing.." />';
	tempHTML = tempHTML + '<br />';
	tempHTML = tempHTML + data.message;
	
	tempHTML = tempHTML + '</div></div>';
	
	return tempHTML;
}
function _filter_directors( data )
{
  if( data )
  {
    if( data >= 1 )
    {
      window.location.href = '/admin/projects?directors_id=' + data;
    }
    else
    {
      alert( 'Please select one of the Directors' );
    }
  }
  else
  {
    alert( 'Please select one of the Directors' );
  }
}


function admin_delete_attachment( divname )
{
	docstring = document.getElementById( divname );

	if( docstring )
	{
		docstring.innerHTML = "<div class=\"notice2\"><ul><li>The Attachment has been successfully destroyed.</li></ul></div>";
		
		new Effect.Pulsate( divname, { duration:1.5 } );
	}
}