// Generowanie listy
function TablewareProductsDetails( arr , cols )
{
	//alert( arr[1]['produkty'][0]['nazwa'] );
	//alert( arr[0]['nazwa'] );
	var res = "";
	for( var grupa_no = 0; grupa_no < arr.length; grupa_no++ )
	{
		res += TablewareProductsDetails_Grupa( arr[grupa_no], cols );
	}
	document.write( res );
	return;
}


// Wstawienie tytulu grupy
function TablewareProductsDetails_Grupa( arr , cols)
{
	var res = "";
	res += "<table border='0' cellspacing='0' cellpadding='0' width='100%'>";
		res += "<tr>";			
			res += "<td style='border-bottom:solid 0px #a0a0a0'><p class='title' style='margin-bottom: 10px; '>"+arr['nazwa']+"</p></td>";
		res += "</tr>";
	res += "</table>";
	res += TablewareProductsDetails_Produkty( arr['produkty'] , cols );
	return( res );
}


// Wstawienie listy produktow w danje grupie
function TablewareProductsDetails_Produkty( arr , cols)
{
	var res = "";
	var col = 0;
	var col_total = 4;
	var col_total = (cols == null) ? "4" : cols;
	
	if (cols == null)
		res += "<table border='0' cellspacing='0' cellpadding='0' style='margin-bottom:30px'>";
	else
		res += "<table border='0' cellspacing='0' cellpadding='0' style='margin-bottom:30px;' align='center'>";
	
		
	for( prod_no = 0; prod_no < arr.length; prod_no++ )
	{
		if( col == 0 ) { res += "<tr valign='bottom'>"; }
			res += "<td align='center'>";
				res += TablewareProductsDetails_Produkt( arr[prod_no] );
			res += "</td>";
			col++;
		if( col == col_total || prod_no == arr.length-1 ) { res += "</tr>"; col = 0; }
	}
	res += "</table>";
	return( res );
}



// Wstawienie pojedynczego produktu
function TablewareProductsDetails_Produkt( arr ){
	if( arr['symb'] == undefined ) arr['symb'] = "";
	var res = "";
	res += "<table border='0' cellspacing='0' cellpadding='0' style='margin:10px;margin-bottom:0px;width:100px;'>";
		res += "<tr valign='top'>";
			res += "<td style=\"text-align: center;\">";
				res += "<font style='color:#a0a0a0'><b>";
				res += arr['nazwa'];
				//if( arr['symb'].length ) res += "<br>"+arr['symb'];
				res += "</b></font><br>";

				if( typeof(arr['symb']) != "undefined" ){
					var symbol_index = false;
					var symbol = arr['symb'];
				}
				else if( typeof(arr['symb_index']) != "undefined" ){
					var symbol_index = true;
					var symbol = arr['symb_index'];
				}
				else{
					var symbol_index = false;
					var symbol = "";
				}
				var symbol = symbol.replace( /\'/g, "\\'" );

				if( typeof(arr['rozmiar']) != "undefined" ){
					var rozmiar_index = false;
					var rozmiar = arr['rozmiar'];
				}
				else if( typeof(arr['rozmiar_index']) != "undefined" ){
					var rozmiar_index = true;
					var rozmiar = arr['rozmiar_index'];
				}
				else{
					var rozmiar_index = false;
					var rozmiar = "";
				}
				var rozmiar = rozmiar.replace( /\'/g, "&rsquo;" );

				if( typeof(arr['pojemnosc']) != "undefined" ){
					var pojemnosc_index = false;
					var pojemnosc = arr['pojemnosc'];
				}
				else if( typeof(arr['poj']) != "undefined" ){
					var pojemnosc_index = false;
					var pojemnosc = arr['poj'];
					//alert(pojemnosc);
				}
				else if( typeof(arr['pojemnosc_index']) != "undefined" ){
					var pojemnosc_index = true;
					var pojemnosc = arr['pojemnosc_index'];
				}
				else if( typeof(arr['poj_index']) != "undefined" ){
					var pojemnosc_index = true;
					var pojemnosc = arr['poj_index'];
				}
				else{
					var pojemnosc_index = false;
					var pojemnosc = "";
				}
				var pojemnosc = pojemnosc.replace( /\'/g, "\\'" );

				var nazwa = arr['nazwa'].replace( /<br>/g, "" ).replace( /&nbsp;/g, "" );
				if( !arr['zoom_width'] ){ arr['zoom_width'] = 400; }
				
				var img_thumbnail = "i/products/100/"+arr['img'];
				//alert( rozmiar );
				//var rozmiar = addslashes(arr['rozmiar']);
				res += "<div style='cursor: pointer; border:solid 1px #c0c0c0; margin-top: 5px; width: 100px; height: 100px; padding: 5px; background: white url("+img_thumbnail+") no-repeat center center;' onClick=\"Zoom(";
				res += "'i/products/"+arr['zoom_width']+"/"+arr['img']+"',";
				res += "'"+nazwa+"',";
				res += "'";
				res += (typeof(symbol) == 'undefined' || symbol.length == 0 ? '' : symbol+ "<br>" );
				res += (typeof(pojemnosc) == 'undefined' || pojemnosc.length == 0 ? '' : pojemnosc+"<br>" );
				res += (typeof(rozmiar) == 'undefined' || rozmiar.length == 0 ? '' : rozmiar+"<br>" );
				res += (typeof(arr['dodatkowe_info']) == 'undefined' || arr['dodatkowe_info'].length == 0 ? '' : (arr['dodatkowe_info']+"<br>"));
				res += "' )\"></div>";

				res += "<font style='font-size:10px;color:#a0a0a0'>";
				if( symbol_index == true ) res += symbol+"<br>";
				if( rozmiar_index == true ) res += rozmiar+"<br>";
				if( pojemnosc_index == true ) res += pojemnosc+"<br>";
				if( arr['dodatkowe_info'] ) res += arr['dodatkowe_info'];
				res += "</font>";
			res += "</td>";
		res += "</tr>";
	res += "</table>";
	return( res );
}


