$(document).ready(function() {
    $("#runeffect-size1").click(function() {
        runEffect_size(1);
        return false;
    });
    runEffect_size(1);
    $("#runeffect-size2").click(function() {
        runEffect_size(2);
        return false;
    });
    runEffect_size(2);
    $("#bgswitch1").click(function() {
        setBG("transparent", "url(/images/general/hatter1.jpg)");
    });
    $("#bgswitch2").click(function() {
        setBG("white", "none");
    });
    $("#bgswitch3").click(function() {
        setBG("red", "none");
    });
    $("#bgswitch4").click(function() {
        setBG("black", "none");
    });
});

function setCookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function setBG(bc, bi) {
    $("body").css("background-color", bc);
    $("body").css("background-image", bi);
    setCookie('bgcolor', bc);
    setCookie('bgimage', bi);
}

function runEffect_size(id) {
    if ($("#runeffect-size"+id).attr("class") == "more up") {
        $("#runeffect-size"+id).removeClass("more up");
        $("#runeffect-size"+id).addClass("more down");
    } else {
        $("#runeffect-size"+id).removeClass("more down");
        $("#runeffect-size"+id).addClass("more up");
    }
    var selectedEffect = 'blind';
    var options;
    if (id == 1) {
        options = {
            to: {
                height: 46
            }
        };
    } else if (id == 2) {
        options = {
            to: {
                height: 34
            }
        };
    }
    $(".effect-size"+id).toggle(selectedEffect,options,300);
}

function pager(actual) {
    document.getElementById('pageractual').value = actual;
    document.getElementById('pagerform').submit();
}
function pager2(actual) {
    document.getElementById('p').value = actual;
    document.getElementById('pagerform').submit();
}
function roundToXDigits(n,x)
{
    if (x < 0) x = 0;
    temp = n;
    for (i=1; i<=x; i++) temp = temp *10;
    temp = Math.round(temp);
    strTemp = "" + temp;
    if (x == 0)
    {
        return strTemp;
    }
    else
    {
        len = strTemp.length;
        return strTemp.substring(0, len-x) + "." + strTemp.substring(len-x, len);
    }
}
//-----------------------------------------
function computeAGE(form)
{
    AGE = eval (form.AGE.value);
    AScore = 0;
    if (AGE <= 56) AScore = AScore+0
    if (AGE > 56) AScore = AScore+1
    if (AGE >= 60) AScore = AScore+1
    if (AGE >= 63) AScore = AScore+1
    if (AGE >= 66) AScore = AScore+1
    if (AGE >= 69) AScore = AScore+1
    if (AGE >= 72) AScore = AScore+1
    if (AGE >= 75) AScore = AScore+1
    if (AGE >= 78) AScore = AScore+1
    if (AGE >= 81) AScore = AScore+1
    if (AGE >= 84) AScore = AScore+1
    return AScore;
}
//-----------------------------------------
function computeSTRM(form)
{
    TotalScore = computeAGE(form);
    BScore = 0;
    SBPM = eval (form.SBPM.value);
    if (SBPM >= 106) BScore = BScore+1
    if (SBPM >= 117) BScore = BScore+1
    if (SBPM >= 127) BScore = BScore+1
    if (SBPM >= 138) BScore = BScore+1
    if (SBPM >= 149) BScore = BScore+1
    if (SBPM >= 160) BScore = BScore+1
    if (SBPM >= 171) BScore = BScore+1
    if (SBPM >= 182) BScore = BScore+1
    if (SBPM >= 192) BScore = BScore+1
    if (SBPM >= 203) BScore = BScore+1
    TotalScore = TotalScore + BScore;
    if (form.SR03[0].checked) TotalScore = TotalScore + 2;
    if (form.SR04[0].checked) TotalScore = TotalScore + 2;
    if (form.SR05[0].checked) TotalScore = TotalScore + 3;
    if (form.SR06[0].checked) TotalScore = TotalScore + 3;
    if (form.SR07[0].checked) TotalScore = TotalScore + 4;
    if (form.SR08[0].checked) TotalScore = TotalScore + 6;
    return TotalScore;
}
//-----------------------------------------
function computeSTRF(form)
{
    TotalScore = computeAGE(form);
    BScore = 0;
    SBPF = eval (form.SBPM.value);
    if (SBPF <= 104)
    {
        if (form.SR03[0].checked)
            BScore = BScore+6;
    }
    else if (SBPF >= 105 && SBPF <= 114)
    {
        BScore = 1;
        if (form.SR03[0].checked)
            BScore = BScore+5;
    }
    else if (SBPF >= 115 && SBPF <= 124)
    {
        BScore = 2;
        if (form.SR03[0].checked)
            BScore = BScore+5;
    }
    else if (SBPF >= 125 && SBPF <= 134)
    {
        BScore = 3;
        if (form.SR03[0].checked)
            BScore = BScore+4;
    }
    else if (SBPF >= 135 && SBPF <= 144)
    {
        BScore = 4;
        if (form.SR03[0].checked)
            BScore = BScore+3;
    }
    else if (SBPF >= 145 && SBPF <= 154)
    {
        BScore = 5;
        if (form.SR03[0].checked)
            BScore = BScore+3;
    }
    else if (SBPF >= 155 && SBPF <= 164)
    {
        BScore = 6;
        if (form.SR03[0].checked)
            BScore = BScore+2;
    }
    else if (SBPF >= 165 && SBPF <= 174)
    {
        BScore = 7;
        if (form.SR03[0].checked)
            BScore = BScore+1;
    }
    else if (SBPF >= 175 && SBPF <= 184)
    {
        BScore = 8;
        if (form.SR03[0].checked)
            BScore = BScore+5;
    }
    else if (SBPF >= 185 && SBPF <= 194)
    {
        BScore = 9;
    }
    else if (SBPF >= 195)
    {
        BScore = 10;
    }
    TotalScore = TotalScore + BScore;
    if (form.SR04[0].checked)
    {
        TotalScore = TotalScore + 3;
    }
    if (form.SR05[0].checked)
    {
        TotalScore = TotalScore + 3;
    }
    if (form.SR06[0].checked)
    {
        TotalScore = TotalScore + 2;
    }
    if (form.SR07[0].checked)
    {
        TotalScore = TotalScore + 6;
    }
    if (form.SR08[0].checked)
    {
        TotalScore = TotalScore + 4;
    }
    return TotalScore;
}
//-----------------------------------------
function computeSTR(form)
{
    if (form.SR00[0].checked)
    {
        STR = computeSTRM(form);
        form.STR.value = roundToXDigits(STR,0);
        x = computePRB(form);
    }
    else if (form.SR00[1].checked)
    {
        STR = computeSTRF(form);
        form.STR.value = roundToXDigits(STR,0);
        x = computePRB(form);
    }
    else
    {
        alert("A korrekt eredmény érdekében meg kell adnia a nemét!");
    }
}
//-----------------------------------------
function computePRB(form)
{
    var PRB;
    var AVG;
    a = eval (form.AGE.value);
    STR = eval(form.STR.value);
    if (form.SR00[0].checked)
    {
        if (STR == 1)
        {
            PRB = "2.6%"
        }
        if (STR == 2)
        {
            PRB = "3.0%"
        }
        if (STR == 3)
        {
            PRB = "3.5%"
        }
        if (STR == 4)
        {
            PRB = "4.0%"
        }
        if (STR == 5)
        {
            PRB = "4.7%"
        }
        if (STR == 6)
        {
            PRB = "5.4%"
        }
        if (STR == 7)
        {
            PRB = "6.3%"
        }
        if (STR == 8)
        {
            PRB = "7.3%"
        }
        if (STR == 9)
        {
            PRB = "8.4%"
        }
        if (STR == 10)
        {
            PRB = "9.7%"
        }
        if (STR == 11)
        {
            PRB = "11.2%"
        }
        if (STR == 12)
        {
            PRB = "12.9%"
        }
        if (STR == 13)
        {
            PRB = "14.8%"
        }
        if (STR == 14)
        {
            PRB = "17.0%"
        }
        if (STR == 15)
        {
            PRB = "19.5%"
        }
        if (STR == 16)
        {
            PRB = "22.4%"
        }
        if (STR == 17)
        {
            PRB = "25.5%"
        }
        if (STR == 18)
        {
            PRB = "29.0%"
        }
        if (STR == 19)
        {
            PRB = "32.9%"
        }
        if (STR == 20)
        {
            PRB = "37.1%"
        }
        if (STR == 21)
        {
            PRB = "41.7%"
        }
        if (STR == 22)
        {
            PRB = "46.6%"
        }
        if (STR == 23)
        {
            PRB = "51.8%"
        }
        if (STR == 24)
        {
            PRB = "57.3%"
        }
        if (STR == 25)
        {
            PRB = "62.8%"
        }
        if (STR == 26)
        {
            PRB = "68.4%"
        }
        if (STR == 27)
        {
            PRB = "73.8%"
        }
        if (STR == 28)
        {
            PRB = "79.0%"
        }
        if (STR == 29)
        {
            PRB = "83.7%"
        }
        if (STR == 30)
        {
            PRB = "87.9%"
        }
        if (STR > 30)
        {
            PRB = ">87.9%"
        }
        if (a < 55)
        {
            AVG = "<5.9%"
        }
        if (a >= 55 && a <= 59)
        {
            AVG = "5.9%"
        }
        if (a >= 60 && a <= 64)
        {
            AVG = "7.8%"
        }
        if (a >= 65 && a <= 69)
        {
            AVG = "11.0%"
        }
        if (a >= 70 && a <= 74)
        {
            AVG = "13.7%"
        }
        if (a >= 75 && a <= 99)
        {
            AVG = "18.0%"
        }
        if (a >= 80 && a <= 84)
        {
            AVG = "22.3%"
        }
        if (a > 85)
        {
            AVG = ">22.3%"
        }
    }
    else
    {
        if (STR == 1)
        {
            PRB = "1.1%"
        }
        if (STR == 2)
        {
            PRB = "1.3%"
        }
        if (STR == 3)
        {
            PRB = "1.6%"
        }
        if (STR == 4)
        {
            PRB = "2.0%"
        }
        if (STR == 5)
        {
            PRB = "2.4%"
        }
        if (STR == 6)
        {
            PRB = "2.9%"
        }
        if (STR == 7)
        {
            PRB = "3.5%"
        }
        if (STR == 8)
        {
            PRB = "4.3%"
        }
        if (STR == 9)
        {
            PRB = "5.2%"
        }
        if (STR == 10)
        {
            PRB = "6.3%"
        }
        if (STR == 11)
        {
            PRB = "7.6%"
        }
        if (STR == 12)
        {
            PRB = "9.2%"
        }
        if (STR == 13)
        {
            PRB = "11.1%"
        }
        if (STR == 14)
        {
            PRB = "13.3%"
        }
        if (STR == 15)
        {
            PRB = "16.0%"
        }
        if (STR == 16)
        {
            PRB = "19.1%"
        }
        if (STR == 17)
        {
            PRB = "22.8%"
        }
        if (STR == 18)
        {
            PRB = "27.0%"
        }
        if (STR == 19)
        {
            PRB = "31.9%"
        }
        if (STR == 20)
        {
            PRB = "37.3%"
        }
        if (STR == 21)
        {
            PRB = "43.4%"
        }
        if (STR == 22)
        {
            PRB = "50.0%"
        }
        if (STR == 23)
        {
            PRB = "57.0%"
        }
        if (STR == 24)
        {
            PRB = "64.2%"
        }
        if (STR == 25)
        {
            PRB = "71.4%"
        }
        if (STR == 26)
        {
            PRB = "78.2%"
        }
        if (STR == 27)
        {
            PRB = "84.4%"
        }
        if (STR > 27)
        {
            PRB = ">84.4%"
        }
        if (a < 55)
        {
            AVG = "<3.0%"
        }
        if (a >= 55 && a <= 59)
        {
            AVG = "3.0%"
        }
        if (a >= 60 && a <= 64)
        {
            AVG = "4.7%"
        }
        if (a >= 65 && a <= 69)
        {
            AVG = "7.2%"
        }
        if (a >= 70 && a <= 74)
        {
            AVG = "10.9%"
        }
        if (a >= 75 && a <= 99)
        {
            AVG = "15.5%"
        }
        if (a >= 80 && a <= 84)
        {
            AVG = "23.9%"
        }
        if (a > 85)
        {
            AVG = ">23.9%"
        }
    }
    form.AVG.value = AVG;
    form.PRB.value = PRB;
}
function initForm() {
    document.getElementById("txtMgdl").value = "";
    document.getElementById("txtMmoll").value = "";
    document.getElementById("txtMgdl").focus();
}
/*
   convert
   =======
   purpose: converts mg/dl to mmol/l, and vice versa.
   trigger: clicking either arrow
   returns: conversion result into the output text field.
   notes:
    - to change the conversion factors, adjust the variable "numFactor" below.
    - user's input is validated: they must enter a valid, non-zero number
  */
function convert(strAction) {
    var objInput ;    // the input, determined by requested action
    var objOutput ;   // the output, determined by requested action
    var numFactor ;   // the multiplier, determined by requested action
    // Determine action
    if (strAction == "to_mmol") {
        objInput = document.getElementById("txtMgdl") ;
        objOutput = document.getElementById("txtMmoll") ;
        numFactor = 1/18 ;
    }
    else {
        objInput = document.getElementById("txtMmoll") ;
        objOutput = document.getElementById("txtMgdl") ;
        numFactor = 18 ;
    }
    // Do the math
    objOutput.value = (parseFloat(objInput.value) + 0) * numFactor;
    if (objOutput.value == "NaN" || objOutput.value == 0) {
        objOutput.value = "";
        alert("Please enter a non-zero number.");
        objInput.value = "";
        objInput.focus();
    }
}
// matyi rakta be, bocs ha rossz helyen van :)
$(document).ready(function() {
    $('.scrollable').scrollable({
        size: 1,
        clickable: false
    });
    $('.scrollable .items div img').click(function() {
        $('.big_image img').attr('src', $(this).attr('src'));
        $('.big_image img').attr('alt', $(this).attr('alt'));
        $('.big_image img').attr('title', $(this).attr('title'));
        $('.image_description').html($(this).attr('alt'));
    });
});