fontsize_base = 83;
fontsize_add = 0;

function enable_font_resize_buttons()
{
    document.getElementById('fontsize_increase').onclick = function() { change_font_size(1); }
    document.getElementById('fontsize_decrease').onclick = function() { change_font_size(-1); }
    document.getElementById('fontsize_reset').onclick = function() { change_font_size(0); }
}


function change_font_size(change)
{
    if (Math.abs(fontsize_add + change) < 3)
    {
        if(change == 0)
        {
            document.body.style.fontSize = fontsize_base + '%';
            fontsize_add = 0;
        }
        else
        {
            fontsize_add += change;
            document.body.style.fontSize = fontsize_base + fontsize_add * 15 + '%';
        }
        
        document.cookie = 'fontsize_add=' + fontsize_add + ';path=/';
    }
}


function enable_textinput_clear_onclick()
{
    INPUTs = document.getElementsByTagName('input');

    if (INPUTs.length > 0)
    {
        for(i = 0; i < INPUTs.length; i++)
        {
            if (INPUTs[i].className == 'onclick_clear')
            {
                INPUTs[i].original_value = INPUTs[i].value;

                INPUTs[i].onclick = function()
                {
                    if (this.value == this.original_value) this.value = '';
                }

                INPUTs[i].onblur = function()
                {
                    if (this.value == '') this.value = this.original_value;
                }
            }
        }
    }
}


function enableLinksToNewWindows()
{
    anchors = document.getElementsByTagName('A');

    for(i = 0; i < anchors.length; i++)
    {
        if (anchors[i].rel == 'external')
        {
            anchors[i].target = '_blank';
        }
    }
}


function get_val_from_cookie(key)
{
    definitions = document.cookie.split(';');

    for(i = 0; i < definitions.length; i++)
    {
        def = definitions[i].split('=');
        if(def[0].replace(/ /, '') == key) return def[1];
    }
}


window.onload = function()
{
    enable_font_resize_buttons();
    enable_textinput_clear_onclick();
	enableLinksToNewWindows();
}
