
//
// Init popup windows for images
//
function popups_init()
{
    var ancs = document.getElementsByTagName("a");
    for (i=0; i<ancs.length; i++) {
        if ((ancs.item(i).className).indexOf("popup")!=-1) {
            // popup-width-height
            parts = ancs.item(i).className.split("-");
            addEvent(ancs.item(i), 'click', create_show_image_func(ancs.item(i).href, parts[1], parts[2]), false);
        }
    }
}

function create_show_image_func(href, width, height)
{
    return function(e) { 
        if (e.preventDefault) {
            e.preventDefault();
        }
        show_image(href, width, height); 
        return false;
    };
}

function show_image(href, width, height)
{
        var left = (screen.width-width)/2;
        var top  = (screen.height-height)/2;
        
        height = 30 + parseInt(height);
        features = 'width='+width+', height='+height+', location=no, menubar=no, personalbar=no, resizable=yes, scrollbars=no, status=no, titlebar=yes, toolbar=no, left='+left+', top='+top;
		openedWindow = window.open('/pic.php?p='+href, 'mywind', features);
		openedWindow.focus();
        return false;
}


//
// Tests
//
function test_check_answer()
{
    if (document.getElementById) {
        form = document.getElementById("test-form");
        answers = form.getElementsByTagName("input");
        for (i=0; i<answers.length; i++) {
            if ((answers[i].getAttribute("type")=='radio' || answers[i].getAttribute("type")=='checkbox') 
                && answers[i].checked) {
                return true;
            }
            else if (answers[i].getAttribute("type")=='radio') {
                type = 'radio';
            }
            else if (answers[i].getAttribute("type")=='checkbox') {
                type = 'checkbox';
            }
        }
        
        if (type=='radio') {
            alert("Выберите ответ");
        }
        else if (type=='checkbox') {
            alert("Выберите один или несколько ответов");
        }
        return false;
    }
    else {
        return true;
    }
}