﻿// JScript File

function OnMenuClick(url, menu)
{
    var res = earthControls.earthGallery.ServiceFacade.ActiveMenu(menu);
    if(res.error == null)
        window.location = url;
    else
        alert(res.error.Message);
}
function Logout(url)
{
    var res = earthControls.earthGallery.ServiceFacade.Logout();
    if(res.error == null)
        window.location = url;
    else
        alert(res.error.Message);
}
//-------------------------------------------------------------------------------------------------
//--  Photo Upload FUNCTION  ----------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
function OnUploadPhoto()
{
    ShowProgress('Uploading images now ...<br/>This may take a while.');
    window.earthGalleryUploadIFrame.UploadPhoto(); 
}
function OnUploadWithError(originalFileList, photoFileList)
{
    if(originalFileList != "")
    {
        HideUploadForm();
        ShowProgress('Saving images now ...');
        earthControls.earthGallery.ServiceFacade.CreatePhoto(originalFileList, photoFileList, OnUploadWithError_Callback);
    }
    else
    {
        HideProgress();
        document.getElementById('earthGalleryUploadCancelId').style.display = '';
        document.getElementById('earthGalleryUploadCancelId').onclick = function()
        { 
            earthGallery_HideLayer('earthGalleryUploadLayerId'); 
            window.location = earthGallery_PhotoListPageUrl;
        };
    }
}
function OnUploadWithError_Callback(res)
{
    if(res.error != null)
        alert(res.error.Message);
    else
    {
        HideProgress();
                document.getElementById('earthGalleryUploadCancelId').style.display = '';
        document.getElementById('earthGalleryUploadCancelId').onclick = function()
        { 
            earthGallery_HideLayer('earthGalleryUploadLayerId'); 
            window.location = earthGallery_PhotoListPageUrl;
        };
    }
}
function OnUploadPhotoComplete(originalFileList, photoFileList, albumId)
{
    var url = window.location;
    window.location = url;
    
    /*if(albumId == '00000000-0000-0000-0000-000000000000')
        window.location = earthGallery_PhotoListPageUrl;
    else
        window.location = earthGallery_AlbumPageUrl + '?album=' + albumId;*/
    /*
    if(originalFileList != "")
    {
        HideUploadForm();
        ShowProgress('Saving images now ...');
        earthControls.earthGallery.ServiceFacade.CreatePhoto(originalFileList, photoFileList, OnUploadPhotoComplete_Callback);
    }*/
}
function OnUploadPhotoComplete_Callback(res)
{
    if(res.error != null)
        alert(res.error.Message);
    else
    {
        window.location = earthGallery_PhotoListPageUrl;
    }    
    HideProgress();
    HideUploadForm();
}
function ShowUploadError(err)
{
    HideProgress();
    ShowError(err);
}