var objActiveX;

$(function() {
    try {
        objActiveX = document.getElementById("IntraClipboardActiveX");
        var date = new Date();
        //задаём дату в инвариантном формате
        $('#name').val('Screenshot ' + date.print('%Y-%m-%d %k:%M:%S'));
        copyScreenshot();
    } catch (ex) {
        alert(ScreenshotResources.CannotLoadActiveX);
    }
});

function copyScreenshot() {
    if (!objActiveX.CopyScreenshot()) {      
        alert(ScreenshotResources.NoImageInClipboard);
    }
}

function cropImage() {
    if (objActiveX.CropSelection() == "ERR1") {
        alert(ScreenshotResources.FirstSelectRegion);
    };
    return false;
}

function drawRectangle() {
    if (objActiveX.DrawSelection() == "ERR1") {
        alert(ScreenshotResources.FirstSelectRegion);
    };
    return false;
}

function uploadImage() {
    var response;
    try {
        response = objActiveX.Send2Server(base + 'screenshot.ivp/uploadimage', $('#name').val() + '.jpg'); ;
        var screenshotId = parseInt(response, 10);
        if (screenshotId > 0) {
            window.returnValue = new Array(screenshotId, $('#name').val() + '.jpg');
        }
        else {
            alert(ScreenshotResources.FailedToSaveScreenshot);
            alert(response);
            window.returnValue = new Array(0);
        }
    }
    catch (ex) {
        alert(ScreenshotResources.FailedToSaveScreenshot);
        alert(response);
        window.returnValue = new Array(0);
    }
    window.close();
}
     