/* ============================================================================
 *
 * (c) Copyright SXOOP Technologies Ltd. 2005-2007
 * All rights reserved.
 *
 * This file contains code which handles saving of images
 *
 */
var PXN8 = PXN8 || {};

/*************************************************************************

SECTION: Saving edited Photos
=============================
The following functions are used for saving the edited photo to the user's
client-side storage or to the server's own storage on the web.

***/

PXN8.save = {};

/**************************************************************************

PXN8.save.toDisk()
==================
Save the photo to the user's client-side storage.

***/
PXN8.save.toDisk = function()
{
    var uncompressedImage = PXN8.getUncompressedImage();
    if (uncompressedImage){
        var newURL = PXN8.server + PXN8.root + "/save.pl?";
        
        if (typeof pxn8_original_filename == "string"){
            newURL += "originalFilename=" + pxn8_original_filename + "&";
        }
        
        newURL += "image=" + uncompressedImage;
        
        document.location = newURL;
            
    }else{
        document.location = "#";
        PXN8.show.alert("You have not changed the image !");
    }
};

/**************************************************************************

PXN8.save.toServer()
====================
Save to server is a wrapper function. It in turn will call *pxn8_save_image()* 
which is a function which must be implemented by the customer.

***/
PXN8.save.toServer = function()
{

    var relativeFilePathToUncompressedImage = PXN8.getUncompressedImage();

    /**
     * wph 20070102 : Don't prohibit the user from saving just because they haven't changed
     * the image.
     * Let the custom pxn8_save_image() function handle that case if needed.
     *
     if (!relativeFilePathToUncompressedImage){
     alert("The image has not been modified.");
     return false;
     }
    */

    if (typeof pxn8_save_image == 'function'){
        return pxn8_save_image(relativeFilePathToUncompressedImage);
    } else {
    
        alert("This feature is not available by default.\n" +
              "To enable this feature you must create a PHP,ASP or JSP page to save the image to your own server.\n" +
              "You must also create a javascript function called 'pxn8_save_image()' - it's first parameter is the URL of the changed image.\n" +
              "The path to the changed image (relative to the directory where PXN8 is installed) is " + PXN8.getUncompressedImage());
        return false;
    }
    
};

/**************************************************************************

pxn8_save_image()
=================
This function is not provided by Pixenate but must be implemented by the customer
if you want to be able to save edited photos to your own webserver.

Parameters
----------

* imagePath : A path to the image which should be saved.

The imagePath parameter will be a path relative to the directory where pixenate is installed.

For example the imagePath parameter might be *cache/03_04fbcedaf099feded02working.jpg*.
If Pixenate is installed at /var/www/html/pixenate then the actual path to the file will be...

    /var/www/html/pixenate/cache/03_04fbcedaf099feded02working.jpg

... so to save the image to your webserver's filesystem or database you need to copy the image at the 
above path to your own permanent storage.
You should provide a .PHP, .JSP, .ASP or CGI program to do just this.
Your pxn8_save_image() function should call this CGI passing the *imagePath* value as a parameter
to the server program.

***/

// 