﻿function wait(msecs)
{
    var start = new Date().getTime();
    var cur = start
    while(cur - start < msecs)
    {
    cur = new Date().getTime();
    } 
}       
        
function ProcessUploadedImages (gallery, imageid, imagename)
{
     try 
     {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
     } 
     catch (e) {}

    new Ajax.Request('/services/process_uploaded_local.ashx',
    {
        parameters: {GID: gallery, framed: 'true', watermark: 'false', IMID: imageid, imagename: imagename, update: 'false'},
        onSuccess:  function(req) {
                 var content = req.responseText; 
                 var errMsg = content.split("|")[0];
                 var imageId = content.split("|")[1]; 
                 var errorString = "Oops, an error occurred.  Please make sure your image type is JPEG, PNG or TIFF.<br/><br/>If you're sure that it was one of these file types, then make sure your image is big enough to make even a small print.  Your image MUST be at least 650 pixels on each side (e.g. 650px by 650px) to trigger the smallest print size.<br/><br/>If you know that your image met those pixel dimensions, then you should upload the image again, because sometimes the Internet doesn't reliably do what you want it to :)<div onclick=\"$(Util.getElementByEndingId('div', 'divError')).toggle();\" class='bodylink' style='text-align: right; cursor: pointer;'>close</div>" ; 
                 if (errMsg.toString() == "1" || errMsg.toString() == "0")
                 {
                     //correct or just "Go Back"
                     if (imageId) 
                     {
                        wait(1000);
                        window.location = "/create/imageimport.aspx?create=1&IMID=" + imageId + "&ims=uploader"; 
                     }
                     else 
                     {
                        try
                         {
                            Util.getElementByEndingId('div', 'divError').innerHTML = errorString ; 
                         }
                         catch(ex){}
                          
                         showError();
                     }
                 }
                 else 
                 {
                     try
                     {
                        Util.getElementByEndingId('div', 'divError').innerHTML = errorString ; 
                     }
                     catch(ex){}
                      
                     showError();                                         
                 }                                                           
            },
         onFailure:      function(req) {
             alert("Ajax error"); 
             Util.getElementByEndingId('div', 'divProcessingUploads').style.display = "none"; 
            }
    }); 
}

function showError()
{ 
  if (Util.getElementByEndingId('div', 'divProcessingUploads') != null)
    Util.getElementByEndingId('div', 'divProcessingUploads').style.display = "none"; 
  
  Util.getElementByEndingId('div', 'divError').style.display= "block" ; 
}

function rollover(obj, src)
{
    document.getElementById(obj.id).src = src;
}