efAJAX = Class.create();
efAJAX.prototype = Object.extend( Ajax.Request.prototype, {
   
   initialize: function( action, field, param, method ) {

      // setup the base url
      var url = 'ajax_versatile.php';
      
      // make sure all basic inputs are correct
      if( !field ) field = action;
   	
      // update the params list as required
      var params = 'action=' + action;
      if( param ) {
          param.each( function( item ) {
            params = params + '&' + item;
          } );
      }
      
      //alert( params );
      
      if( action == 'changeImageComment' ){
      	showUpdatingInfoDiv( 1 ); 
      }
      if( action == 'populateImageList' ){
      	showLoadingInfo( 1 );
      }
		
      // prepare the transport object
      this.transport = Ajax.getTransport();
      this.method = method;
      this.field = field;
      this.action = action;
      
      // setup the options for the request
      var options = { method: 'get',
                      parameters: params,
                      onComplete: Prototype.emptyFunction
                    }
      
      // setup the onComplete event, binding it to this instance
      options.onComplete = (function ( res ) {
                            
                              if( this.method == 'push' ) {
                                 
                               
                                 if( document.getElementById( 'processinginfo' ) ){
                                    if( document.getElementById( 'processinginfo' ).style.visibility == 'visible' ){
                                       toggleDisplay( 'processinginfo' );  
                                    }
                                 }
                           
                                 if( this.action == 'removeOrderImages' ){
                                    document.location.href = 'order_prints_select4.php';
                                 }
                                 
                                 if( this.action == 'removeImagesFromOrder' ){
                                    document.location.href = 'order_prints_select5.php';
                                 }
                                 
                              }
                              else if( this.method == 'innerhtml' ) {
                       		     $(this.field).innerHTML = res.responseText;
                       		     
                                 // Shuts down Waiting box ( div )
                       		     if( action == 'populateImageList' ){
      					             showLoadingInfo( 0 );
      				              }
                              }
                              else {
                                 $(this.field).value = res.responseText;
                              	if( action == 'changeImageComment' ){
                              	  showUpdatingInfoDiv( 0 );
                                 }
                              }
                        }).bind( this );
      
      // configure the AJAX Request
      this.setOptions( options );
      
      
    
      // execute the request
      this.request( url );
      
   }
   
} );



