﻿/*<![CDATA[*/
var isProduct = true;

$(document).ready(function() {
    new AjaxUpload('#browse1', {
        action: imageUploadPath,
        onSubmit: function(file, ext) {
            if (ext && /^(jpg|png|jpeg|gif)$/.test(ext)) {
                //$('#browse1progress').val('Uploading ' + file);
                $('#browse1progress').toggle();
            } else {

                // extension is not allowed
                alert('Sorry, only jpg, png and gif images are allowed');

                // cancel upload
                return false;
            }

        },
        onComplete: function(file, response) {

            if (response.toString().indexOf("error") < 0) {


                if (isProduct) {
                
                    file = file.split('.')[0] + ".png";

                    var count = $('#files').find('.photoadd').length;

                    $('#files').append('<p class="photoadd" id="photoadd' + count.toString() + '" name="photoadd' + count.toString() + '"></p>');
                    $('#files #photoadd' + count.toString()).append('<input class="check ExclusiveImageDefault"  type="checkbox" id="chkimagedefault"' + count.toString() + ' value="1" />');
                    $('#files #photoadd' + count.toString()).append('<span title="' + file + '">...' + file.toString().substring(file.toString().length - Math.min(10, file.toString().length), file.toString().length) + '</span>');
                    $('#files #photoadd' + count.toString()).append('<a class="preview" onclick="$(\'#imgPreview\').attr(\'src\',\'' + response + '\'); return false;" href="">preview</a>');
                    $('#files #photoadd' + count.toString()).append('<a onclick="DeleteUpload(\'#photoadd' + count.toString() + '\'); return false;" href="">remove</a>');
                    $('#files #photoadd' + count.toString()).append('<input type="hidden" id="image' + count.toString() + '" name="image' + count.toString() + '" value="' + response + '" />');

                    ResetImageDefaultExclusiveCheck();

                }
                
                $('#imgPreview').attr('src', response);
                $('#browse1progress').toggle();

            }
            else {
                alert("Sorry, there was a problem uploading your file.  Please try again or try another file.");
            }
        }
    });
});
    /*]]>*/

    function DeleteUpload(el) {
        if (confirm('Are you sure you do not want to use this picture?')) {
            $(el).empty()
        }
    }    
    