/*
 * jQuery 1.2.6 - New Wave Javascript
 *
 * Copyright (c) 2008 Dean Layton-James
 * Copyright (c) 2008 Digital Marmalade Ltd
 * Commercial License - Copying prohibited without express written permission
 *
 * $Date: 2008-07-01 08:22:17 GMT (Tue, 01 July 2008) $
 * $Rev: 68 $
 */

function JQABBsInit()
{
    // Standard jQuery wrapper
    $(document).ready(function() {
        // Make sure errors div is hidden when page loads
        $('#errors').hide();
    });
}

function JQABBsAddError( errString )
{
    // Standard jQuery wrapper
    $(document).ready(function() {
        // Add span to error div
        $("#errors").append('<span class="error_text">' + errString + '</span>');
        // show errors
        $('#errors').show('show');
        // fade it down
        // commented out, crashes in IE
        // $('#errors').vkfade('eee000');

    });
}


function JQABBsPreviewImage( sForm, sPreviewInput, sPreviewOutput, sDetailsHide )
{
    // Config block for the ajax submit
    var aImgPreviewOptions = { url: '/admin-preview-upload.php', type: 'post', success: JQABBsSetPreviewImage } ;

    // bind form using 'ajaxForm'
    $(document).ready(function() {
        // set loading image
        $('#' + sPreviewOutput).attr("src","/_global/images/abbs/ajax-loader.gif");

        // requires field plugin
        // set previewInput field to let php script know which file field to handle
        $( "input[@name='previewInput']" ).setValue( sPreviewInput + '::' + sPreviewOutput );

        $('#' + sDetailsHide ).fadeOut();
		
		// requires form plugin
        // do an ajax submit
        $( sForm ).ajaxSubmit( aImgPreviewOptions ) ;
		
		

        return false ;
    } );
}

function JQABBsSetPreviewImage( imagePreviewInfo )
{
    // Split the return data from the backend
    var aInfo = imagePreviewInfo.split('::') ;
    var sErr = 'An unkown error has ocurred' ;

    if( aInfo[0] == 'ERROR' ) {
        if( aInfo[1] == 'FILEUPLOAD' || aInfo[1] == 'FILEMOVE'  ) {
            sErr = 'Unable to preview the image' ;
        }
        if( aInfo[1] == 'FILESIZE' ) {
            sErr = 'The image is too large to upload or preview' ;
        }
        if( aInfo[1] == 'FILETYPE' ) {
            sErr = 'The file selected is not an image' ;
        }
        $('#' + aInfo[1]).attr("src","/_global/images/abbs/preview_not_available.gif");
        JQABBsAddError( sErr ) ;
        return false ;
    }

    // set image source to tmp uploaded file
    $('#' + aInfo[1]).attr("src","/abbsimagepreview.php?pi=" + aInfo[0]);
    return false ;
}
