﻿var ilosc = 1;
var ilosc2 = 1;

var miasta = 4;
var kluby = 4;

function sprawdzMiastaKluby()
{
	for(i=2;i<miasta+1;i++){
		if(document.getElementById('div_miasto'+i).style.display == 'block')
		{
			ilosc++;
		}
	}
	if(ilosc == miasta) {
		document.getElementById('przycisk_dodaj_miasto').style.display = "none";
	}
	for(i=2;i<kluby+1;i++){
		if(document.getElementById('div_klub'+i).style.display == 'block')
		{
			ilosc2++;
		}
	}
	if(ilosc2 == kluby) {
		document.getElementById('przycisk_dodaj_klub').style.display = "none";
	}
}

function dodajMiasto()
{
	for(i=2;i<miasta+1;i++){
		if(document.getElementById('div_miasto'+i).style.display == 'none')
		{
			ilosc++;
			document.getElementById('div_miasto'+i).style.display = "block";
			if(ilosc == miasta)
				document.getElementById('przycisk_dodaj_miasto').style.display = "none";
			return;
		}
	}
}

function dodajKlub()
{
	for(i=2;i<kluby+1;i++){
		if(document.getElementById('div_klub'+i).style.display == 'none')
		{
			ilosc2++;
			document.getElementById('div_klub'+i).style.display = "block";
			if(ilosc2 == kluby)
				document.getElementById('przycisk_dodaj_klub').style.display = "none";
			return;
		}
	}
}

function miastoUsun(miasto)
{
	document.getElementById("przycisk_dodaj_miasto").style.display = "block";
	ilosc--;
	document.getElementById("div_"+miasto).style.display = "none";
	document.getElementById(miasto).options[0].selected = true;
}

function klubUsun(klub)
{
	document.getElementById("przycisk_dodaj_klub").style.display = "block";
	ilosc2--;
	document.getElementById("div_"+klub).style.display = "none";
	document.getElementById(klub).options[0].selected = true;
}

function zmienSelect(select, co) {
	var zaznaczony = 0;
	for (var i = 0; i < document.getElementById(select).length; i++) {
		if (document.getElementById(select).options[i].selected) {
			zaznaczony = i;
			break;
		}
	}
	if (zaznaczony == 0) {
		return;
	}
	for (var i = 1; i < 5; i++) {
		if (select == co+i) {
			for (var k = 1; k < 5; k++) {
				if (i != k) {
					var tmp = document.getElementById(co + "" + k);
					if (tmp && tmp.options[zaznaczony]) {
						if (tmp.options[zaznaczony].selected) {
							tmp.options[zaznaczony].selected = false;
							tmp.options[0].selected = true;
						}
					}
				}
			}
			return;
		}
	}
}

