var _currentFill = "fill:#d4213d";
var p_red = 'fill:#d4213d';
var p_yellow = 'fill:#ffe131';
var p_green = 'fill:#80ce1b';
var p_violet = 'fill:#990066';
var p_blue = 'fill:#3300ff';
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 = $('#Warstwa_5_kopia').children().children();
	var elements_2 = $('#Warstwa_6_kopia').children().children();
	var elements_3 = $('#Warstwa_7_kopia').children().children();
	var elements_4 = $('#Warstwa_8_kopia').children().children();
	var wariant_1 = false, wariant_2 = false, wariant_3 = false, wariant_4 = false, wariant_5 = false, wariant_6 = false, wariant_7 = false, wariant_8 = false, wariant_9 = false, wariant_10 = false, wariant_11 = false, wariant_12 = false, wariant_13 = false, wariant_14 = false, wariant_15 = false, wariant_16 = false, wariant_17 = false, wariant_18 = false, wariant_19 = false, wariant_20 = false, wariant_21 = false, wariant_22 = false, wariant_23 = false, wariant_24 = false;
	var red_1 = false, red_2 = false, red_3 = false, red_4 = false, red_5 = false, red_6 = false, red_7 = false, red_8 = false, red_8 = false, red_9 = false, red_10 = false, red_11 = false, red_12 = false, red_13 = false, red_14 = false, red_15 = false, red_16 = false;
	var yellow_1 = false, yellow_2 = false, yellow_3 = false, yellow_4 = false, yellow_5 = false, yellow_6 = false, yellow_7 = false, yellow_8 = false, yellow_9 = false, yellow_10 = false, yellow_11 = false, yellow_12 = false, yellow_13 = false, yellow_14 = false, yellow_15 = false, yellow_16 = false;
	var blue_1 = false, blue_2 = false, blue_3 = false, blue_4 = false, blue_5 = false, blue_6 = false, blue_7 = false, blue_8 = false, blue_9 = false, blue_10 = false, blue_11 = false, blue_12 = false, blue_13 = false, blue_14 = false, blue_15 = false, blue_16 = false;
	var green_1 = false, green_2 = false, green_3 = false, green_4 = false, green_5 = false, green_6 = false, green_7 = false, green_8 = false, green_9 = false, green_10 = false, green_11 = false, green_12 = false, green_13 = false, green_14 = false, green_15 = false, green_16 = false;
    var allred_1 = false, allred_2 = false, allred_3 = false, allred_4 = false;
	var allyellow_1 = false, allyellow_2 = false, allyellow_3 = false, allyellow_4 = false;
	var allblue_1 = false, allblue_2 = false, allblue_3 = false, allblue_4 = false;
	var allgreen_1 = false, allgreen_2 = false, allgreen_3 = false, allgreen_4 = 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') == 'path43' && fill == p_red){
			red_1 = true;
		}
		if ($(elements[i]).attr('id') == 'path45' && fill == p_red){
			red_2 = true;
		}
		if ($(elements[i]).attr('id') == 'path53' && fill == p_red){
			red_3 = true;
		}
		if ($(elements[i]).attr('id') == 'path55' && fill == p_red){
			red_4 = true;
		}
		if ($(elements[i]).attr('id') == 'path43' && fill == p_yellow){
			yellow_1 = true;
		}
		if ($(elements[i]).attr('id') == 'path45' && fill == p_yellow){
			yellow_2 = true;
		}
		if ($(elements[i]).attr('id') == 'path53' && fill == p_yellow){
			yellow_3 = true;
		}
		if ($(elements[i]).attr('id') == 'path55' && fill == p_yellow){
			yellow_4 = true;
		}
		if ($(elements[i]).attr('id') == 'path43' && fill == p_blue){
			blue_1 = true;
		}
		if ($(elements[i]).attr('id') == 'path45' && fill == p_blue){
			blue_2 = true;
		}
		if ($(elements[i]).attr('id') == 'path53' && fill == p_blue){
			blue_3 = true;
		}
		if ($(elements[i]).attr('id') == 'path55' && fill == p_blue){
			blue_4 = true;
		}
		if ($(elements[i]).attr('id') == 'path43' && fill == p_green){
			green_1 = true;
		}
		if ($(elements[i]).attr('id') == 'path45' && fill == p_green){
			green_2 = true;
		}
		if ($(elements[i]).attr('id') == 'path53' && fill == p_green){
			green_3 = true;
		}
		if ($(elements[i]).attr('id') == 'path55' && fill == p_green){
			green_4 = true;
		}
		if (red_1 == true && red_2 == true && red_3 == true && red_4 == true){
			allred_1 = true;
		}
		if (yellow_1 == true && yellow_2 == true && yellow_3 == true && yellow_4 == true){
			allyellow_1 = true;
		}
		if (blue_1 == true && blue_2 == true && blue_3 == true && blue_4 == true){
			allblue_1 = true;
		}
		if (green_1 == true && green_2 == true && green_3 == true && green_4 == true){
			allgreen_1 = true;
		}
    }
	
	for (var i = 0; i < elements_2.length; i++) {

        if ($(elements_2[i]).attr('style') !== undefined){
			fill = $(elements_2[i]).attr('style').replace(" ", "").replace(";", "");
		}// IE hack
        else{
			fill = '';
		}
		
		if ($(elements_2[i]).attr('id') == 'path430' && fill == p_red){
			red_5 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path450' && fill == p_red){
			red_6 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path530' && fill == p_red){
			red_7 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path550' && fill == p_red){
			red_8 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path430' && fill == p_yellow){
			yellow_5 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path450' && fill == p_yellow){
			yellow_6 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path530' && fill == p_yellow){
			yellow_7 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path550' && fill == p_yellow){
			yellow_8 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path430' && fill == p_blue){
			blue_5 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path450' && fill == p_blue){
			blue_6 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path530' && fill == p_blue){
			blue_7 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path550' && fill == p_blue){
			blue_8 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path430' && fill == p_green){
			green_5 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path450' && fill == p_green){
			green_6 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path530' && fill == p_green){
			green_7 = true;
		}
		if ($(elements_2[i]).attr('id') == 'path550' && fill == p_green){
			green_8 = true;
		}
		if (red_5 == true && red_6 == true && red_7 == true && red_8 == true){
			allred_2 = true;
		}
		if (yellow_5 == true && yellow_6 == true && yellow_7 == true && yellow_8 == true){
			allyellow_2= true;
		}
		if (blue_5 == true && blue_6 == true && blue_7 == true && blue_8 == true){
			allblue_2 = true;
		}
		if (green_5 == true && green_6 == true && green_7 == true && green_8 == true){
			allgreen_2 = true;
		}
    }
	
	for (var i = 0; i < elements_3.length; i++) {

        if ($(elements_3[i]).attr('style') !== undefined){
			fill = $(elements_3[i]).attr('style').replace(" ", "").replace(";", "");
		}// IE hack
        else{
			fill = '';
		}
		
		if ($(elements_3[i]).attr('id') == 'path4300' && fill == p_red){
			red_9 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path4500' && fill == p_red){
			red_10 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path5300' && fill == p_red){
			red_11 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path5500' && fill == p_red){
			red_12 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path4300' && fill == p_yellow){
			yellow_9 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path4500' && fill == p_yellow){
			yellow_10 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path5300' && fill == p_yellow){
			yellow_11 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path5500' && fill == p_yellow){
			yellow_12 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path4300' && fill == p_blue){
			blue_9 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path4500' && fill == p_blue){
			blue_10 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path5300' && fill == p_blue){
			blue_11 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path5500' && fill == p_blue){
			blue_12 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path4300' && fill == p_green){
			green_9 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path4500' && fill == p_green){
			green_10 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path5300' && fill == p_green){
			green_11 = true;
		}
		if ($(elements_3[i]).attr('id') == 'path5500' && fill == p_green){
			green_12 = true;
		}
		if (red_9 == true && red_10 == true && red_11 == true && red_12 == true){
			allred_3 = true;
		}
		if (yellow_9 == true && yellow_10 == true && yellow_11 == true && yellow_12 == true){
			allyellow_3 = true;
		}
		if (blue_9 == true && blue_10 == true && blue_11 == true && blue_12 == true){
			allblue_3 = true;
		}
		if (green_9 == true && green_10 == true && green_11 == true && green_12 == true){
			allgreen_3 = true;
		}
    }
	
	for (var i = 0; i < elements_4.length; i++) {

        if ($(elements_4[i]).attr('style') !== undefined){
			fill = $(elements_4[i]).attr('style').replace(" ", "").replace(";", "");
		}// IE hack
        else{
			fill = '';
		}
		
		if ($(elements_4[i]).attr('id') == 'path43000' && fill == p_red){
			red_13 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path45000' && fill == p_red){
			red_14 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path53000' && fill == p_red){
			red_15 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path55000' && fill == p_red){
			red_16 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path43000' && fill == p_yellow){
			yellow_13 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path45000' && fill == p_yellow){
			yellow_14 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path53000' && fill == p_yellow){
			yellow_15 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path55000' && fill == p_yellow){
			yellow_16 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path43000' && fill == p_blue){
			blue_13 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path45000' && fill == p_blue){
			blue_14 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path53000' && fill == p_blue){
			blue_15 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path55000' && fill == p_blue){
			blue_16 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path43000' && fill == p_green){
			green_13 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path45000' && fill == p_green){
			green_14 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path53000' && fill == p_green){
			green_15 = true;
		}
		if ($(elements_4[i]).attr('id') == 'path55000' && fill == p_green){
			green_16 = true;
		}
		if (red_13 == true && red_14 == true && red_15 == true && red_16 == true){
			allred_4 = true;
		}
		if (yellow_13 == true && yellow_14 == true && yellow_15 == true && yellow_16 == true){
			allyellow_4 = true;
		}
		if (blue_13 == true && blue_14 == true && blue_15 == true && blue_16 == true){
			allblue_4 = true;
		}
		if (green_13 == true && green_14 == true && green_15 == true && green_16 == true){
			allgreen_4 = true;
		}
    }
	
	if (allred_1 == true && allyellow_2 == true && allblue_3 == true && allgreen_4 == true){
		wariant_1 = true;
		console.log("wariant 1 = "+wariant_1);
	}
	if (allred_1 == true && allyellow_2 == true && allblue_4 == true && allgreen_3 == true){
		wariant_2 = true;
		console.log("wariant 2 = "+wariant_2);
	}
	if (allred_1 == true && allyellow_3 == true && allblue_2 == true && allgreen_4 == true){
		wariant_3 = true;
		console.log("wariant 3 = "+wariant_3);
	}
	if (allred_1 == true && allyellow_4 == true && allblue_2 == true && allgreen_3 == true){
		wariant_4 = true;
		console.log("wariant 4 = "+wariant_4);
	}
	if (allred_1 == true && allyellow_4 == true && allblue_3 == true && allgreen_2 == true){
		wariant_5 = true;
		console.log("wariant 5 = "+wariant_5);
	}
	if (allred_1 == true && allyellow_3 == true && allblue_4 == true && allgreen_2 == true){
		wariant_6 = true;
		console.log("wariant 6 = "+wariant_6);
	}
	if (allred_2 == true && allyellow_1 == true && allblue_3 == true && allgreen_4 == true){
		wariant_7 = true;
		console.log("wariant 7 = "+wariant_7);
	}
	if (allred_2 == true && allyellow_1 == true && allblue_4 == true && allgreen_3 == true){
		wariant_8 = true;
		console.log("wariant 8 = "+wariant_8);
	}
	if (allred_3 == true && allyellow_1 == true && allblue_2 == true && allgreen_4 == true){
		wariant_9 = true;
		console.log("wariant 9 = "+wariant_9);
	}
	if (allred_4 == true && allyellow_1 == true && allblue_2 == true && allgreen_3 == true){
		wariant_10 = true;
		console.log("wariant 10 = "+wariant_10);
	}
	if (allred_4 == true && allyellow_1 == true && allblue_3 == true && allgreen_2 == true){
		wariant_11 = true;
		console.log("wariant 11 = "+wariant_11);
	}
	if (allred_3 == true && allyellow_1 == true && allblue_4 == true && allgreen_2 == true){
		wariant_12 = true;
		console.log("wariant 12 = "+wariant_12);
	}
	if (allred_3 == true && allyellow_2 == true && allblue_1 == true && allgreen_4 == true){
		wariant_13 = true;
		console.log("wariant 13 = "+wariant_13);
	}
	if (allred_4 == true && allyellow_2 == true && allblue_1 == true && allgreen_3 == true){
		wariant_14 = true;
		console.log("wariant 14 = "+wariant_14);
	}
	if (allred_2 == true && allyellow_4 == true && allblue_1 == true && allgreen_3 == true){
		wariant_15 = true;
		console.log("wariant 15 = "+wariant_15);
	}
	if (allred_2 == true && allyellow_3 == true && allblue_1 == true && allgreen_4 == true){
		wariant_16 = true;
		console.log("wariant 16 = "+wariant_16);
	}
	if (allred_4 == true && allyellow_3 == true && allblue_1 == true && allgreen_2 == true){
		wariant_17 = true;
		console.log("wariant 17 = "+wariant_17);
	}
	if (allred_3 == true && allyellow_4 == true && allblue_1 == true && allgreen_2 == true){
		wariant_18 = true;
		console.log("wariant 18 = "+wariant_18);
	}
	if (allred_2 == true && allyellow_4 == true && allblue_3 == true && allgreen_1 == true){
		wariant_19 = true;
		console.log("wariant 19 = "+wariant_19);
	}
	if (allred_2 == true && allyellow_3 == true && allblue_4 == true && allgreen_1 == true){
		wariant_20 = true;
		console.log("wariant 20 = "+wariant_20);
	}
	if (allred_4 == true && allyellow_3 == true && allblue_2 == true && allgreen_1 == true){
		wariant_21 = true;
		console.log("wariant 21 = "+wariant_21);
	}
	if (allred_3 == true && allyellow_4 == true && allblue_2 == true && allgreen_1 == true){
		wariant_22 = true;
		console.log("wariant 22 = "+wariant_22);
	}
	if (allred_4 == true && allyellow_2 == true && allblue_3 == true && allgreen_1 == true){
		wariant_23 = true;
		console.log("wariant 23 = "+wariant_23);
	}
	if (allred_3 == true && allyellow_2 == true && allblue_4 == true && allgreen_1 == true){
		wariant_24 = true;
		console.log("wariant 24 = "+wariant_24);
	}

    if (wariant_1 == true || wariant_2 == true || wariant_3 == true || wariant_4 == true || wariant_5 == true || wariant_6 == true || wariant_7 == true || wariant_8 || wariant_9 == true || wariant_10 == true || wariant_11 == true || wariant_12 == true || wariant_13 == true || wariant_14 == true || wariant_15 == true || wariant_16 == true || wariant_17 == true || wariant_18 == true || wariant_19 == true || wariant_20 == true || wariant_21 == true || wariant_22 == true || wariant_23 == true || wariant_24 == true){
        document.getElementById('vs_' + task).innerHTML = "1";
    } else{
		document.getElementById('vs_' + task).innerHTML = "0";
	}
})

$("#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 = $(event.target).parent();

    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 ($(event.target).parent().attr('id') == 'europe' && _currentFill == p_red) europe = true;
        if ($(event.target).parent().attr('id') == 'europe' && _currentFill != p_red) europe = false;

        if ($(event.target).parent().attr('id') == 'asia' && _currentFill == p_yellow) asia = true;
        if ($(event.target).parent().attr('id') == 'asia' && _currentFill != p_yellow) asia = false;

        if ($(event.target).parent().attr('id') == 'africa' && _currentFill == p_green) africa = true;
        if ($(event.target).parent().attr('id') == 'africa' && _currentFill != p_green) africa = false;

        if ($(event.target).parent().attr('id') == 'australia' && _currentFill == p_brown) australia = true;
        if ($(event.target).parent().attr('id') == 'australia' && _currentFill != p_brown) australia = false;

        if ($(event.target).parent().attr('id') == 'north_america' && _currentFill == p_orange) north_america = true;
        if ($(event.target).parent().attr('id') == 'north_america' && _currentFill != p_orange) north_america = false;

        if ($(event.target).parent().attr('id') == 'south_america' && _currentFill == p_pink) south_america = true;
        if ($(event.target).parent().attr('id') == 'south_america' && _currentFill != p_pink) south_america = false;

        if ($(event.target).parent().attr('id') == 'antarctica' && _currentFill == p_white) antarctica = true;
        if ($(event.target).parent().attr('id') == 'antarctica' && _currentFill != 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);
        }
       
    }

    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";
    }


})