var _currentFill = "fill:#d4213d";
var p_red = 'fill:#d4213d';
var p_yellow = 'fill:#ffe131';
var p_green = 'fill:#80ce1b';
var p_violet = 'fill:#6d2bed';
var p_blue = 'fill:#339eff';
var p_orange = 'fill:#f28d20';
var p_brown = 'fill:#843617';
var p_pink = 'fill:#ff5cae';
var p_white = 'fill:#e9e8e7';

var $swatches = $(".swatches");
$swatches.click(function (event) {
    $swatch = $(event.target);
    loc = [parseInt($swatch.attr('x'), 10), parseInt($swatch.attr('y'), 10)]
    if (loc[0] > -1) $("#selection", $swatches).attr('x', loc[0]);
    if (loc[1] > -1) $("#selection", $swatches).attr('y', loc[1]);
    _currentFill = $swatch.attr('style');
})

// svg_MODUL_nrZadania
$("#svg_MW_I_1_3").click(function (event) {
    var task = 'MW_I_1_3'; // MODUL_nrZadania

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('style') != 'fill:#000000') $(event.target).attr('style', _currentFill);

    //var elements = $("svg_" + task).children;
    var elements = $(event.target).parent().children();

    var yellow = false;
    var green = false;
    var violet = false;
    var other = true;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if (fill == p_yellow) yellow = true;
        else if (fill == p_green) green = true;
        else if (fill == p_violet) violet = true;
    }

    if (yellow && green && violet) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
})


$("#svg_MW_I_5_2").click(function (event) {
    var task = 'MW_I_5_2';

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('style') != 'fill:#000000') $(event.target).attr('style', _currentFill);

    var elements = $(event.target).parent().children();

    var red = false;
    var blue = false;
    var yellow = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if (fill == p_red) red = true;
        else if (fill == p_blue) blue = true;
        else if (fill == p_yellow) yellow = true;
    }

    if (red && blue && yellow) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
})

$("#svg_MW_I_9_4").click(function (event) {
    var task = 'MW_I_9_4';

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var elements = $(event.target).parent().children();

    var red = false;
    var orange = false;
    var brown = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'dab' && fill == p_red) red = true;
        if ($(elements[i]).attr('id') == 'kasztanowiec' && fill == p_brown) brown = true;
        if ($(elements[i]).attr('id') == 'klon' && fill == p_orange) orange = true;
    }

    if (red && orange && brown) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }

})

// OK
$("#svg_MW_I_10_2").click(function (event) {
    var task = 'MW_I_10_2';

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var elements = $(event.target).parent().children();
    
    var tak = 0;
    var nie = 0;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'tak' && fill != "fill:#ffffff") tak++;

        if ($(elements[i]).attr('id') == 'nie' && fill == "fill:#ffffff") nie++;   /// poprawka #ffffff ?

    }


    if (tak == 5 && nie == 1) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }

})





// OK
$("#svg_OS_I_1_8").click(function (event) { 
    var task = 'OS_I_1_8';

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var elements = $(event.target).parent().children();

    var rect = 0;
    var circle = 0;
    var triangle = 0;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'trojkat' && fill == p_red) triangle++;
        if ($(elements[i]).attr('id') == 'trojkat' && fill != p_red) triangle--;

        if ($(elements[i]).attr('id') == 'kwadrat' && fill == p_blue) rect++;
        if ($(elements[i]).attr('id') == 'kwadrat' && fill != p_blue) rect--;

        if ($(elements[i]).attr('id') == 'kolo' && fill == p_yellow) circle++;
        if ($(elements[i]).attr('id') == 'kolo' && fill != p_yellow) circle--;

    }


    if (rect == 4 && circle == 6 && triangle == 5) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }


})

// OK
$("#svg_OS_I_3_1").click(function (event) { 
    var task = 'OS_I_3_1';

    var elements = $(event.target).parent().children();

    for (var i = 0; i < elements.length; i++) $(elements[i]).removeAttr("style");

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }


    var polska = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'polska' && fill != '') polska = true;
        if ($(elements[i]).attr('id') == 'polska' && fill == '') polska = false;
    }


    if (polska) document.getElementById('vs_' + task).innerHTML = "1";
    else document.getElementById('vs_' + task).innerHTML = "0";

})


// OK
$("#svg_MW_I_3_1").click(function (event) {
    var task = 'MW_I_3_1';

    var elements = $(event.target).parent().children();

    for (var i = 0; i < elements.length; i++) $(elements[i]).removeAttr("style");

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var polska = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'polska' && fill != '') polska = true;
        if ($(elements[i]).attr('id') == 'polska' && fill == '') polska = false;
    }

    if (polska) document.getElementById('vs_' + task).innerHTML = "1";
    else document.getElementById('vs_' + task).innerHTML = "0";

})

// OK
$("#svg_OS_I_3_2").click(function (event) {
    var task = 'OS_I_3_2';

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var elements = $(event.target).parent().children();

    var yellow = 0;
    var red = 0;
    var fill = '';

    

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';
        
        if ($(elements[i]).attr('id') == 'path7' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path9' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path11' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path13' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path15' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path17' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path19' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path21' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path23' && fill == p_yellow) yellow++;
        if ($(elements[i]).attr('id') == 'path25' && fill == p_yellow) yellow++;

        if ($(elements[i]).attr('id') == 'rect36' && fill == p_red) red++;
        if ($(elements[i]).attr('id') == 'path5' && fill == p_red) red++;

    }

    if (yellow >= 10 && red >= 2) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }

})


// OK
var europe = false, asia = false, africa = false, australia = false, north_america = false, south_america = false, antarctica = false;
$("#svg_OS_I_3_7").click(function (event) {
    var task = 'OS_I_3_7';

    var elements = $('#svg_OS_I_3_7').children();

    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';
        
        if ($(elements[i]).attr('id') == 'europe' && fill == p_red) europe = true;
        if ($(elements[i]).attr('id') == 'europe' && fill != p_red) europe = false;

        if ($(elements[i]).attr('id') == 'asia' && fill == p_yellow) asia = true;
        if ($(elements[i]).attr('id') == 'asia' && fill != p_yellow) asia = false;

        if ($(elements[i]).attr('id') == 'africa' && fill == p_green) africa = true;
        if ($(elements[i]).attr('id') == 'africa' && fill != p_green) africa = false;

        if ($(elements[i]).attr('id') == 'australia' && fill == p_brown) australia = true;
        if ($(elements[i]).attr('id') == 'australia' && fill != p_brown) australia = false;

        if ($(elements[i]).attr('id') == 'north_america' && fill == p_orange) north_america = true;
        if ($(elements[i]).attr('id') == 'north_america' && fill != p_orange) north_america = false;

        if ($(elements[i]).attr('id') == 'south_america' && fill == p_pink) south_america = true;
        if ($(elements[i]).attr('id') == 'south_america' && fill != p_pink) south_america = false;

        if ($(elements[i]).attr('id') == 'antarctica' && fill == p_white) antarctica = true;
        if ($(elements[i]).attr('id') == 'antarctica' && fill != p_white) antarctica = false;


        // Coloring Group Hack
        var inner = $(event.target).parent().children(); 
        for (var j = 0; j < inner.length; j++) {
            $(inner[j]).attr('style', _currentFill); // dla wyglądu
        }
        $(event.target).parent().attr('style', _currentFill); // dla logiki
       
    }

    if (europe && asia && africa && australia && north_america && south_america && antarctica) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
    else document.getElementById('vs_' + task).innerHTML = "0";


})

// OK
$("#svg_OS_I_4_2").click(function (event) {
    var task = 'OS_I_4_2';

    var elements = $(event.target).parent().children();

    for (var i = 0; i < elements.length; i++) $(elements[i]).removeAttr("style");

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var wielka_brytania = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'wielka_brytania' && fill != '') wielka_brytania = true;
        if ($(elements[i]).attr('id') == 'wielka_brytania' && fill == '') wielka_brytania = false;
    }

    if (wielka_brytania) document.getElementById('vs_' + task).innerHTML = "1";
    else document.getElementById('vs_' + task).innerHTML = "0";

})

// OK
$("#svg_OS_I_5_1").click(function (event) {
    var task = 'OS_I_5_1';

    var elements = $(event.target).parent().children();

    for (var i = 0; i < elements.length; i++) $(elements[i]).removeAttr("style");

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var hiszpania = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'hiszpania' && fill != '') hiszpania = true;
        if ($(elements[i]).attr('id') == 'hiszpania' && fill == '') hiszpania = false;
    }

    if (hiszpania) document.getElementById('vs_' + task).innerHTML = "1";
    else document.getElementById('vs_' + task).innerHTML = "0";

})


// OK
$("#svg_OS_I_6_3").click(function (event) {
    var task = 'OS_I_6_3';

    var elements = $(event.target).parent().children();

    for (var i = 0; i < elements.length; i++) $(elements[i]).removeAttr("style");

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var grecja = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'grecja' && fill != '') grecja = true;
        if ($(elements[i]).attr('id') == 'grecja' && fill == '') grecja = false;
    }

    if (grecja) document.getElementById('vs_' + task).innerHTML = "1";
    else document.getElementById('vs_' + task).innerHTML = "0";

})


// OK
$("#svg_OS_I_8_7").click(function (event) {
    var task = 'OS_I_8_7';

    var elements = $(event.target).parent().children();

    for (var i = 0; i < elements.length; i++) $(elements[i]).removeAttr("style");

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var rumunia = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'rumunia' && fill != '') rumunia = true;
        if ($(elements[i]).attr('id') == 'rumunia' && fill == '') rumunia = false;
    }

    if (rumunia) document.getElementById('vs_' + task).innerHTML = "1";
    else document.getElementById('vs_' + task).innerHTML = "0";

})


// OK
$("#svg_OS_I_9_3").click(function (event) {
    var task = 'OS_I_9_3'; 

    var elements = $(event.target).parent().children();

    for (var i = 0; i < elements.length; i++) $(elements[i]).removeAttr("style");

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }

    var francja = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'francja' && fill != '') francja = true;
        if ($(elements[i]).attr('id') == 'francja' && fill == '') francja = false;
    }

    if (francja) document.getElementById('vs_' + task).innerHTML = "1";
    else document.getElementById('vs_' + task).innerHTML = "0";

})

$("#svg_ZIP_I_9_8").click(function (event) {
    var task = 'ZIP_I_9_8';

    var elements = $(event.target).parent().children();

    for (var i = 0; i < elements.length; i++) $(elements[i]).removeAttr("style");

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('id') != undefined) {
        $(event.target).attr('style', _currentFill);
    }


    var polska = false;
    var fill = '';

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'polska' && fill != '') polska = true;
        if ($(elements[i]).attr('id') == 'polska' && fill == '') polska = false;
    }


    if (polska) document.getElementById('vs_' + task).innerHTML = "1";
    else document.getElementById('vs_' + task).innerHTML = "0";

})





// *************************** II klasa ***********************************



$("#svg_OS_II_1_8").click(function (event) {
    var task = 'OS_II_1_8';

    if ($(event.target).parent().attr('id') != 'svgContainer') {

        var elements = $("#svg_OS_II_1_8").children();
        
        for (var i = 0; i < elements.length; i++) $(elements[i]).children().attr("style", "fill:#b3b3b3");
        
        var fill = '';
        var australia_2 = false;

        for (var i = 0; i < elements.length; i++) {

            if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
            else fill = '';

            if ($(event.target).parent().attr('id') == 'australia') australia_2 = true;

            // Coloring Group Hack
            var inner = $(event.target).parent().children();
            for (var j = 0; j < inner.length; j++) {
                $(inner[j]).attr('style', _currentFill);
            }

        }

    }

    if (australia_2) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
    else document.getElementById('vs_' + task).innerHTML = "0";


})


$("#svg_OS_II_2_7").click(function (event) {
    var task = 'OS_II_2_7';

    if ($(event.target).parent().attr('id') != 'svgContainer') {

        var elements = $('#svg_OS_II_2_7').children().children();

        for (var i = 0; i < elements.length; i++) if ($(elements[i]).children().attr('style') != "fill:#b3b3b3") $(elements[i]).children().removeAttr("style");

        var fill = '';
        var usa = false;

        for (var i = 0; i < elements.length; i++) {

            if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
            else fill = '';

            if ($(event.target).parent().attr('id') == 'us') usa = true;

            // Coloring Group Hack
            var inner = $(event.target).parent().children();
            for (var j = 0; j < inner.length; j++) {
                $(inner[j]).attr('style', _currentFill);
            }

        }

    }

    if (usa) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
    else {
        document.getElementById('vs_' + task).innerHTML = "0";
    }


})




$("#svg_OS_II_3_9").click(function (event) {
    var task = 'OS_II_3_9';

    if ($(event.target).parent().attr('id') != 'svgContainer') {

        var elements = $('#svg_OS_II_3_9').children().children();

        for (var i = 0; i < elements.length; i++) if ($(elements[i]).children().attr('style') != "fill:#b3b3b3") $(elements[i]).children().removeAttr("style");

        var fill = '';
        var kanada = false;

        for (var i = 0; i < elements.length; i++) {

            if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
            else fill = '';

            if ($(event.target).parent().attr('id') == 'ca') kanada = true;

            // Coloring Group Hack
            var inner = $(event.target).parent().children();
            for (var j = 0; j < inner.length; j++) {
                $(inner[j]).attr('style', _currentFill);
            }

        }

    }

    if (kanada) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
    else {
        document.getElementById('vs_' + task).innerHTML = "0";
    }


})



$("#svg_OS_II_6_10").click(function (event) {
    var task = 'OS_II_6_10';

    if ($(event.target).parent().attr('id') != 'svgContainer') {

        var elements = $('#svg_OS_II_6_10').children().children();

        for (var i = 0; i < elements.length; i++) $(elements[i]).children().removeAttr("style");

        var fill = '';
        var wyspywielkanocne = false;

        for (var i = 0; i < elements.length; i++) {

            if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
            else fill = '';

            if ($(event.target).parent().attr('id') == 'wyspywielkanocne') wyspywielkanocne = true;

            // Coloring Group Hack
            var inner = $(event.target).parent().children();
            for (var j = 0; j < inner.length; j++) {
                $(inner[j]).attr('style', _currentFill);
            }

        }

    }

    if (wyspywielkanocne) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
    else {
        document.getElementById('vs_' + task).innerHTML = "0";
    }


})



$("#svg_OS_II_4_9").click(function (event) {
    var task = 'OS_II_4_9';

    if ($(event.target).parent().attr('id') != 'svgContainer') {

        var elements = $('#g2972').children();

        for (var i = 0; i < elements.length; i++) $(elements[i]).children().removeAttr("style");

        var fill = '';
        var brazylia = false;

        for (var i = 0; i < elements.length; i++) {

            if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
            else fill = '';

            if ($(event.target).parent().attr('id') == 'Brazil') brazylia = true;

            // Coloring Group Hack
            var inner = $(event.target).parent().children();
            for (var j = 0; j < inner.length; j++) {
                $(inner[j]).attr('style', _currentFill);
            }

        }

    }

    if (brazylia) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
    else {
        document.getElementById('vs_' + task).innerHTML = "0";
    }


})



$("#svg_OS_II_5_11").click(function (event) {
    var task = 'OS_II_5_11';

    if ($(event.target).parent().attr('id') != 'svgContainer') {

        var elements = $('#g3248').children();
        console.log($(event.target).attr("id"));
        for (var i = 0; i < elements.length; i++) $(elements[i]).attr("style", "fill:#cccccc");

        var fill = '';
        var maroko = false;

        for (var i = 0; i < elements.length; i++) {

            if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
            else fill = '';

            if ($(event.target).attr('id') == 'Marokko') maroko = true;

            // Coloring Group Hack
            var inner = $(event.target);
            for (var j = 0; j < inner.length; j++) {
                $(inner[j]).attr('style', _currentFill);
            }

        }

    }

    if (maroko) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
    else {
        document.getElementById('vs_' + task).innerHTML = "0";
    }


})



$("#svg_ZIP_II_2_1").click(function (event) {
    var task = 'ZIP_II_2_1'; 

    if ($(event.target).attr('id') != 'svg_' + task && $(event.target).attr('style') != 'fill:#000000') $(event.target).attr('style', _currentFill);

    var elements = $("#layer1").children()[0].children;

    var polwhite = false;
    var polred = false;

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'polwhite' && fill == p_white) polwhite = true;
        if ($(elements[i]).attr('id') == 'polwhite' && fill != p_white) polwhite = false;

        if ($(elements[i]).attr('id') == 'polred' && fill == p_red) polred = true;
        if ($(elements[i]).attr('id') == 'polred' && fill != p_red) polred = false;

        
    }

    // rus

    var elements = $("#layer1").children()[1].children;

    var ruswhite = false;
    var rusblue = false;
    var rusred = false;

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'ruswhite' && fill == p_white) ruswhite = true;
        if ($(elements[i]).attr('id') == 'ruswhite' && fill != p_white) ruswhite = false;

        if ($(elements[i]).attr('id') == 'rusblue' && fill == p_blue) rusblue = true;
        if ($(elements[i]).attr('id') == 'rusblue' && fill != p_blue) rusblue = false;

        if ($(elements[i]).attr('id') == 'rusred' && fill == p_red) rusred = true;
        if ($(elements[i]).attr('id') == 'rusred' && fill != p_red) rusred = false;

    }


    // cz

    var elements = $("#layer1").children()[2].children;

    var czwhite = false;
    var czblue = false;
    var czred = false

    for (var i = 0; i < elements.length; i++) {

        if ($(elements[i]).attr('style') !== undefined) fill = $(elements[i]).attr('style').replace(" ", "").replace(";", ""); // IE hack
        else fill = '';

        if ($(elements[i]).attr('id') == 'czwhite' && fill == p_white) czwhite = true;
        if ($(elements[i]).attr('id') == 'czwhite' && fill != p_white) czwhite = false;

        if ($(elements[i]).attr('id') == 'czred' && fill == p_red) czred = true;
        if ($(elements[i]).attr('id') == 'czred' && fill != p_red) czred = false;

        if ($(elements[i]).attr('id') == 'czblue' && fill == p_blue) czblue = true;
        if ($(elements[i]).attr('id') == 'czblue' && fill != p_blue) czblue = false;

    }

    if (polwhite && polred && ruswhite && rusblue && rusred && czwhite && czblue && czred) {
        document.getElementById('vs_' + task).innerHTML = "1";
    }
})