﻿// JScript File
var ChangesMade = 0;
var Unleash = 0;
var ClickCount = 0;
var IgnoreTrapEnter = 0;

function StopMultiClick()
{
    ClickCount += 1;
    if (ClickCount == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//Specifikt för rappInlasning.aspx
function InlasningEnableRun()
{
    var e;
    var Enable = true;
    
    e = document.getElementById("ctl00_CPH1_divRun1");
    if (e != null)
    {
        e = document.getElementById("ctl00_CPH1_cbRun1");
        if (e != null)
        {
            Enable = e.checked;
        }        
    }
    
    if (Enable == true)
    {
        e = document.getElementById("ctl00_CPH1_divRun2");
        if (e != null)
        {
            e = document.getElementById("ctl00_CPH1_cbRun2");
            if (e != null)
            {
                Enable = e.checked;
            }        
        }    
    }
    
    if (Enable == true)
    {
        e = document.getElementById("ctl00_CPH1_divRun3");
        if (e != null)
        {
            e = document.getElementById("ctl00_CPH1_cbRun3");
            if (e != null)
            {
                Enable = e.checked;
            }        
        }    
    }
    
    if (Enable != true)
    {
        alert("Du har inte godkänt inläsningen!");
    }
    
    return Enable;
}

function VisaBytForetag()
{
    var e;
    e = document.getElementById("divBytForetag");
    if (e != null)
    {
        e.style.display = "block";
        e = document.getElementById("divAnvandarInfo");
        if (e != null)
        {
            e.style.display = "none";
        }            
    }
}
function RevealS()
{
    Unleash = 2;
    return false;
}
function UnleashSysAdm()
{
    if (Unleash == 2)
    {
        return true;
    }
    else
    {
        Unleash = 1;
        return false;
    }
}
function RemindToSave()
{
    var Continue = true;
    if (ChangesMade > 0)
    {
        var Meddelande;
        Meddelande = "\nDu har gjort ändringar men inte sparat!"
        Meddelande += "\n\nOm du vill gå vidare utan att spara din ändringar så klickar du på OK."
        Meddelande += "\n\nOm du vill spara så klickar du på AVBRYT."
        if (!window.confirm(Meddelande))
        {
            Continue = false;
        }
    }
    
    return Continue;
}
function ToggleSaveReminder()
{
    var e;
    if (ChangesMade > 0)
    {
        e = document.getElementById("SaveReminder");
        if (e != null)
        {
            if (e.style.display == "none")
            {
                e.style.display = "block";
            }
            else
            {
                e.style.display = "none";
            }
        }
    }
}
function InactivityCountdown(Minuter)
{
    window.setTimeout("InactiveVarning(" + Minuter + ");", Minuter * 60 * 1000 * 0.8);
}
function InactiveVarning(Minuter)
{
    window.setTimeout("InactiveKickedOut(" + Minuter + ");", Minuter * 60 * 1000 * 0.2);
    alert("Du har varit inaktiv i " + Minuter * 0.8 + " minuter. Om du inte laddar om en sida inom " + Minuter * 0.2 + " minuter så tappar du din inloggning och blir utkastad!");
}
function InactiveKickedOut(Minuter)
{
    alert("Du har varit inaktiv i " + Minuter + " minuter och är därmed inte längre inloggad och blir utkastad så fort du laddar om en sida.");
}
function IsClosed()
{
    alert('Målarwebben stängs pga underhåll. Logga ut snarast! \n\n Du riskerar att bli automatiskt utloggad och därmed eventuellt förlora det du registrerat.');
}
function TrapEnter(e) 
{
    if (IgnoreTrapEnter == 0)
    {
        if (window.event) 
        {
            if (window.event.keyCode == 13)
            {
                window.event.keyCode = 9;
            }    
        }
        else if (e)
        {
            if (e.which == 13)
            {
                //e.which = 9;
                e.preventDefault();
            }        
        }
    }
    else
    {
        IgnoreTrapEnter = 0;
    }
}
function TrapEnterUndantag(e)
{
    if (window.event) 
    {
        if (window.event.keyCode == 13)
        {
            IgnoreTrapEnter = 1;
        }    
    }
    else if (e)
    {
        if (e.which == 13)
        {
            IgnoreTrapEnter = 1;
        }        
    }
}
function PrintNumber(n)
{
    if (n > 0)
    {
        return n;
    }
    else
    {
        return "";
    }
}
function CInt007(str)
{
    if (isNaN(parseInt(str)))
    {
        return 0;
    }
    else
    {
        return parseInt(CDec007(str) + 0.5);
    }
}
function CDec007(str)
{
    if (isNaN(parseFloat(str)))
    {
        return 0;
    }
    else
    {
        return parseFloat(str);
    }
}
function CDec007Strict(str)
{
    var d = CDec007(str);
    var i = CInt007(str);
    if ((d-i) >= 0.75)
    {
        return i + 1;
    }
    else if ((d-i) < 0.25)
    {
        return i;
    }
    else
    {
        return i + 0.5;
    }
}
function GiveFocusToNext(MyId)
{
    var e = document.documentElement.getElementsByTagName("input");

    for(var i=0;i<e.length;i++)
    {
        if (e[i].id.indexOf(MyId) > 0)
        {
            e[i+1].focus();
            break;
        }
    }        
}
