﻿// JScript File

function Help(Page, Chapter){
    var win = window.open("Help.aspx?Page="+Page+"&Chapter="+Chapter, "HelpWindow", "toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,width=400,height=400");
    win.focus();
}

function ResizeImageToFit(Image, MaxWidth, MaxHeight){
    if(Image.width > MaxWidth){
        var quota = 1-((Image.width - MaxWidth) / Image.width);
        Image.width = Image.width * quota;
        //Image.height = Image.height * quota;
    }
    if(Image.height > MaxHeight){
        var quota = 1-((Image.height - MaxHeight) / Image.height);
        Image.height = Image.height * quota;
        Image.width = Image.width * quota;
    }
}

function SizeEmbroideryViewer(Aspect, EmbroideryViewerId) {
    
    var MaxWidth = parseInt(document.getElementById(EmbroideryViewerId).width.replace(/px/,""));
    var MaxHeight = parseInt(document.getElementById(EmbroideryViewerId).height.replace(/px/, ""));

    var NewSize = new Object();

    if (MaxWidth / MaxHeight > Aspect) {
        // Höjden går till max
        NewSize.Height = MaxHeight;
        NewSize.Width = NewSize.Height * Aspect + 5 / Aspect;
    } else {
        // Bredden går till max
        NewSize.Width = MaxWidth;
        NewSize.Height = NewSize.Width / Aspect + 5 / Aspect;
    }

    document.getElementById(EmbroideryViewerId).width = NewSize.Width;
    document.getElementById(EmbroideryViewerId).height = NewSize.Height;

    return NewSize;
}
