//funkcja wyświetlająca wyniki obliczeń
function createResultField(wyniki) {
	
	if (IPOLISA_NOWY_LAYOUT) {
		var pole = $('wyniki');
		
		for(w in wyniki['taryfikatory']) {
			var kwota = $('kwota'+wyniki['taryfikatory'][w]['tu']);
			//jeśli nie ma wiersza dla tu to go tworzę
			if (kwota == undefined) {
				kwota = document.createElement('table'); 
				kwota.id = 'kwota'+wyniki['taryfikatory'][w]['tu'];
				kwota.setAttribute('class', 'pole');
				kwota.setAttribute('className', 'pole');
				var row = kwota.insertRow(0);
				var lewa = row.insertCell(0);
				lewa.id = 'kwota_tytul_'+wyniki['taryfikatory'][w]['tu'];
				lewa.setAttribute('class', 'tytul');
				lewa.setAttribute('className', 'tytul');
				var prawa = row.insertCell(1);
				prawa.id = 'kwota_tresc_'+wyniki['taryfikatory'][w]['tu'];
				prawa.setAttribute('class', 'tresc');
				prawa.setAttribute('className', 'tresc');
			} else {
				var lewa = $('kwota_tytul_'+wyniki['taryfikatory'][w]['tu']);
				var prawa = $('kwota_tresc_'+wyniki['taryfikatory'][w]['tu']);
				if (lewa == undefined || prawa == undefined) return;
				while (lewa.childNodes.length > 0)
					lewa.removeChild(lewa.childNodes[0]);
				while (prawa.childNodes.length > 0)
					prawa.removeChild(prawa.childNodes[0]);
			}
			lewa.appendChild(document.createTextNode(wyniki['taryfikatory'][w]['tu']));
			if (wyniki['taryfikatory'][w]['skladka'] == 'Brak składki' && wyniki['taryfikatory'][w]['hint'] != null) {
				prawa.appendChild(document.createTextNode(wyniki['taryfikatory'][w]['hint']));
			} else {
				prawa.appendChild(document.createTextNode(wyniki['taryfikatory'][w]['skladka']));
			}
			pole.appendChild(kwota);
		}
		//wyszaża przycisk do przejścia na stronę z wynikami
		if (wyniki['ok'] != null && !wyniki['ok']) {
			var t = document.getElementById('pokaz_true');
			if (t != undefined) t.style.display = 'none'
			var f = document.getElementById('pokaz_false');
			if (f != undefined) f.style.display = '';
		} else {
			var t = document.getElementById('pokaz_true');
			if (t != undefined) t.style.display = ''
			var f = document.getElementById('pokaz_false');
			if (f != undefined) f.style.display = 'none';
		}
		
		return;
	}
	
	
	
	
	/**	Wyciągam div'a w którym pokazuje wyniki.
	*
	*/
	var pole = document.getElementById('divwyniki');
	if(pole == null) {
		prm = document.getElementById('wyniki');
		pole = document.createElement('div');
		pole.id = 'divwyniki';
		pole.style.marginTop = "20px";
		prm.appendChild(pole);
	}
	
	var h = document.getElementById('podglad_header');
	if (h == undefined) {
		var header = (document.createElement('div'));
		header.id = 'podglad_header';
		header.setAttribute('class', 'naglowekgrupyparametrow');
		header.setAttribute('className', 'naglowekgrupyparametrow');
		header.appendChild(document.createTextNode('Składka Twojego ubezpieczenia:'));
		pole.appendChild(header);
	}
	
	for(w in wyniki['taryfikatory']) {
		var kwota = document.getElementById('kwota'+wyniki['taryfikatory'][w]['tu']);
		if (kwota == null) {
			kwota = createField('kwota'+wyniki['taryfikatory'][w]['tu'], 'skrotwyniku', pole.id);
		} else {
			removeAll(kwota);
		}
		kwota.appendChild(document.createTextNode(wyniki['taryfikatory'][w]['tu']+' - '+wyniki['taryfikatory'][w]['skladka']));
		if (wyniki['taryfikatory'][w]['hint'] != null) {
			//rysuje dymek w wynikach
			var qm = document.createElement('img');
			qm.id = 'dymek'+wyniki['taryfikatory'][w]['tu'];
			qm.setAttribute('src', '/button.php?tekst='+encodeURIComponent("?")+'&rodzaj=blue_1');
			qm.style.verticalAlign = 'middle';
			qm.style.marginLeft = '5px';
			kwota.appendChild(qm);
			dymek('dymek'+wyniki['taryfikatory'][w]['tu'], wyniki['taryfikatory'][w]['hint']);
		}
	}

	if (wyniki['ok'] != null && !wyniki['ok']) {
		var t = document.getElementById('pokaz_true');
		if (t != undefined) t.style.display = 'none'
		var f = document.getElementById('pokaz_false');
		if (f != undefined) f.style.display = '';
	} else {
		var t = document.getElementById('pokaz_true');
		if (t != undefined) t.style.display = ''
		var f = document.getElementById('pokaz_false');
		if (f != undefined) f.style.display = 'none';
	}
}