<?php
			unset($totalCondition);
			
			//echo "multi";
			foreach ($colTypesStructure[$key] as $key_code => $keyVar) {
				
				$sql = "SELECT count(*) as n  FROM ".$proj."_structure WHERE ".$keyVar." > 0 ";
					if ($filter) $sql .=" AND ( ".$filter." )";	
				
				//echo $sql;
				$res = $db->SQLexecute($sql);
				$zad = $db->fetchAssoc($res);
				$freq[$keyVar] = $zad['n'];	
				$totalCondition[] = $keyVar." > 0 ";						
			}
				$sql = "SELECT count(*) as n  FROM ".$proj."_structure WHERE ( ";
					$sql .= implode(" OR ",$totalCondition);
				$sql .= " ) ";
					if ($filter) $sql .=" AND ( ".$filter." )";	
				
				//echo $sql;
				$res = $db->SQLexecute($sql);
				$zad = $db->fetchAssoc($res);
				$total = $zad['n'];	
			
				foreach ($colAns[$key] as $labVal) {
					$Graph['labels'][] = $labVal[1];
					$Graph['values'][] =  round( ($freq[$key."_".$labVal[0]]/$total) * 100,2);	
				}
				
				
				if ($_GET['showTable']) {
				
					echo "<table class=\"reportTable\" cellpadding=\"5\" cellspacing=\"0\" width=\"600\" align=\"center\">";
						echo "<tr>
									<td class=\"TableHeader\">".$val."</td>
							 		<td class=\"TableHeader\" width=20>N</td>
							 		<td class=\"TableHeader\" width=20>%</td>
							 </tr>";
						foreach ($colAns[$key] as $labVal) {
							echo "<tr>";
								echo "<td>".$labVal[1]."</td>";
								echo "<td align=\"center\">";
									if (!$freq[$key."_".$labVal[0]]) echo "0";
										else echo $freq[$key."_".$labVal[0]];
								echo "</td>";
								echo "<td align=\"center\">";
									if (!$freq[$key."_".$labVal[0]]) echo "0";
										else {
											//$Graph['labels'][] = $labVal[1];
											//$Graph['values'][] =  round( ($freq[$key."_".$labVal[0]]/$total) * 100,2);							
											echo number_format(( round( ($freq[$key."_".$labVal[0]]/$total) * 100,2)),1);
										}
									
								echo "</td>";
							echo "</tr>";
						}
						echo "<tr>";
							echo "<td class=\"TableHeader\" style=\"text-align:right\">TOTAL</td>";
							echo "<td class=\"TableHeader\">".$total."</td>";
							echo "<td class=\"TableHeader\" >100%</td>";
						echo "</tr>";
					echo "</table>";
				}
				
				if ($_GET['showGraph']) {
					echo  "<script type=\"text/javascript\">
					$(function () {
					    
					    $(document).ready(function() {
					         new Highcharts.Chart({
					            chart: {
					                renderTo: 'container".$key."',
					                type: 'bar'
					            },
					            title: {
					                text: '".controlGraphString(wordwrap($val,70,"<br />"))."'
					            },
					            tooltip: {
					                formatter: function() {
					                    return ''+
					                        this.x +': '+ this.y + '%';
					                }
				            	},
					            credits: {
								    enabled: false
								},
					            xAxis: {
				                	categories: ['".implode("','",$Graph['labels'])."']
					            },
					            yAxis: {
				              		min: 0,
					          	    max: 100,
					                title: {
					                	text: '%'
					           		}
				            	},
				            	 legend: {
						           	enabled: false
						         },
				            	  plotOptions: {
						                bar: {
						                    dataLabels: {
						                        enabled: true,
						                         formatter: function(a,val) {
							                    	//console.log(a);
							                       return  this.y + ' %';
							               		 }
						                    }
						                }
						            },
	
						         series: [{
					               
					                name: ' ',
					                data: [
					                	
					         ";
				       
					                 	unset($tmp);
										foreach ($Graph['labels'] as $key1=>$val) {
												
												$tmp[] = "['".$val."',".round($Graph['values'][$key1],1)."]";
									        
											} 
										echo implode(",",$tmp);
									
					echo "             
					                ]
					            }]
					        });
					    });
					    
					});
					</script>	
			
						<div id=\"container".$key."\" style=\"width: 600px;  height: 400px; padding-top:20px; margin: 0 auto\"></div>";
				} // end if  ($_GET['showGraph']) 
				else echo "<div  style=\"width: 600px;  height: 50px; \"></div>";
?>