var size = 100;
var scale = 100;

var is_ie = (navigator.appName == 'Microsoft Internet Explorer' && navigator.appCodeName == 'Mozilla' && navigator.userAgent.indexOf("Opera")==-1);
var is_safari = (document.childNodes && !document.all && !navigator.taintEnabled)

// Safari often doesn't redraw the window correctly
function window_fix() {
    if (is_safari)
    {
        window.resizeTo(window.outerWidth+1, window.outerHeight);
        setTimeout(function(){window.resizeTo(window.outerWidth-1, window.outerHeight);}, 1);
    }
}

function getCookie(name)
{
    var cookies = document.cookie.split(';');
    var c = Array();
    for(var i=0;i < cookies.length;i++)
    {
        var cookie = cookies[i];
        while (cookie.charAt(0)==' ')
            cookie = cookie.substring(1,cookie.length);
        var pair = cookie.split('=');
        //alert(pair[0]+' '+pair[1]);
        c[pair[0]] = pair[1];
    }
    return c[name];
}
function setRelativeSize(s)
{
    scale = s;
    setSize(size);
}

function setSize(add){
    size = add;
    if (!document.layers)
        document.getElementsByTagName("body").item(0).style.fontSize=(add*scale/100)+"%";
}
function refresh()
{
    var width = window.innerWidth;
    if (!width && document.body)
        width = document.body.offsetWidth;
    var height = window.innerHeight;
    if (!height && document.body)
        height = document.body.offsetHeight;
    if (width < 600)
        setSize(65);
    if (width > 600 && width < 800)
        setSize(70);
    if (width > 800 && width < 1000)
        setSize(75);
    if (width > 1000)
        setSize(80);
}
function load()
{
    window.onresize = refresh;
    var s = getCookie('pagescale');
    if (s)
        scale = s;
    refresh();
    window.onunload = function(){
        if (scale)
            document.cookie = 'pagescale='+scale+';path=/';
    }
    if (window.memory_load)
        window.memory_load();
}
window.onload = load;

function blank_list(list)
{
    var cdiv  = $(list+'_correct');
    var wdiv = $(list+'_wrong');
    cdiv.style.display = 'none';
    wdiv.style.display = 'none';
}

function check_list(list, values)
{
    var cdiv  = $(list+'_correct');
    var wdiv = $(list+'_wrong');
    cdiv.style.display = 'none';
    wdiv.style.display = 'none';
    var list = $(list);
    var items = list.getElementsByTagName('li');
    var correct = true;
    for (var i=0; i<items.length; i++)
    {
        //alert(items[i].innerHTML+' '+values[i]+' '+(items[i].innerHTML==values[i]));
        if (items[i].id != values[i])
            correct = false;
    }
    if (correct)
        Effect.Appear(cdiv);
    else
        Effect.Appear(wdiv);
}

function check_value(prefix, value)
{
    var entered = $(prefix+'_input').value;
    var cdiv  = $(prefix+'_correct');
    var wdiv = $(prefix+'_wrong');
    cdiv.style.display = 'none';
    wdiv.style.display = 'none';
    correct = (entered.toUpperCase()==value);
    if (correct)
        Effect.Appear(cdiv);
    else
        Effect.Appear(wdiv);
}

function check_definitions(values)
{
    var correct = true;
    for (var i=0;i<values.length;i++)
    {
        var cdiv  = $('definition'+(i+1)+'_correct');
        var wdiv = $('definition'+(i+1)+'_wrong');
        cdiv.style.display = 'none';
        wdiv.style.display = 'none';
      if ($('definition'+(i+1)).selectedIndex != values[i])
        Effect.Appear(wdiv);
    else
        Effect.Appear(cdiv);
        
     }
    setTimeout(function(){window_fix();}, 1000);
}

