

SocialEngineAPI.Jobpost = new Class({
  
  // Class
	Implements: [Options],
  
  
  
  // Properties
  Base: {},
  
  
  options: {
    'ajaxURL' : 'jobpost_ajax.php',
    'ajaxMethod' : 'post',
    'ajaxSecure' : false,
    
    'defaultView' : false
  },
  
  
  jobpostExists: false,
  
  
  jobpostInfo: {},
  
  
  
  
  visibleTab: 0,
  
  
  rsvpLanguageVars: {
    '-1'  : 11250080,
    '0'   : 11250081,
    '1'   : 11250082,
    '2'   : 11250083,
    '3'   : 11250084,
    '4'   : 11250085
  },
  
  
  
  
  // Initialize
  initialize: function(jobpostInfo, options)
  {
    var bind = this;
    
    // Options
    if( $type(options)=="object" )
    {
      if( $type(options.defaultView) && options.defaultView=='' )
        delete options.defaultView;
      
      this.setOptions(options);
    }
    
    // Jobpost info stuff
    if( jobpostInfo && $type(jobpostInfo)=="object" )
    {
      this.jobpostExists = jobpostInfo.jobpost_exists;
      delete jobpostInfo.jobpost_exists;
      
      this.jobpostInfo = jobpostInfo;
    }
    
    // Load currently visible tab
    var currentVisibleTab = Cookie.read('jobpostVisibleTab');
    
    if( this.options.defaultView )
      currentVisibleTab = this.options.defaultView;
    else if( !$type(currentVisibleTab) || !currentVisibleTab )
      currentVisibleTab = 'profile';
    
    window.addEvent('domready', function()
    {
      if( $('jobpost_tab_table') ) bind.loadProfileTab(currentVisibleTab);
    });
    
  },
  
  
  
  
  // Profile Tabs
  loadProfileTab: function(tabName)
  {
    var bind = this;
    $('jobpost_tab_table').getElements('.jobpost_tab').each(function(tabElement)
    {
      if( tabElement.id=='jobpost_tabs_'+tabName )
      {
        if( !tabElement.hasClass('jobpost_tab_active') )
          tabElement.addClass('jobpost_tab_active');
        
        $('jobpost_' + tabName).style.display = "block";
        Cookie.write('jobpostVisibleTab', bind.visibleTab = tabName);
      }
      else
      {
        if( tabElement.hasClass('jobpost_tab_active') )
          tabElement.removeClass('jobpost_tab_active');
        
        var otherTabName = tabElement.id.replace('_tabs_', '_');
        $(otherTabName).style.display = "none";
      }
    });
  },
  
  
  
  
  // Delete
  deleteShow: function(jobpostID)
  {
    this.currentConfirmID = ( jobpostID || this.jobpostInfo.jobpost_id );
    TB_show(this.Base.Language.Translate(11250093), '#TB_inline?height=100&width=300&inlineId=confirmjobpostdelete', '', '../images/trans.gif');
  },
  
  
  deleteConfirm: function()
  {
    jobpostID = this.currentConfirmID;
    
    // Remove Smoothbox
    TB_remove();
    
    // Ajax
    var bind = this;
    var request = new Request.JSON({
      'method' : 'post',
      'url' : this.options.ajaxURL,
      'data' : {
        'task' : 'jobpostdelete',
        'jobpost_id' : jobpostID
      },
      'onComplete':function(responseObject)
      {
        //alert($type(window.redirectOnDelete) + ' ' + $type(parent.window.redirectOnDelete) + ' ' + $type(parent.redirectOnDelete));
        
        if( $type(responseObject)!="object" || !responseObject.result || responseObject.result=="failure" )
        {
          alert(bind.Base.Language.Translate(11250153));
        }
        
        else
        {
          // jobpost, user_jobpost_edit - Redirect on delete
          if( $type(window.redirectOnDelete)=="function" )
          {
            window.redirectOnDelete();
          }
          
          // user_jobpost - Remove row
          if( $('seJobpost_' + jobpostID) )
          {
            $('seJobpost_' + jobpostID).destroy();
            
            // Display no jobpost message
            if( !$$('.seJobpost').length && $('seJobpostNullMessage') )
            {
              $('seJobpostNullMessage').style.display = 'block';
            }
          }
          

        }
      }
    });
    
    request.send();
    
    // Reset
    currentConfirmDeleteID = 0;
  }
  
});
