<?php

	function fnCheckMail($address)
    {
        if (1 != preg_match("/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i", $address))
		{
			return false;
        }
        else 
        {
            return true;
        }
    }
    
    function fnShowStars($x, $hlasy = 0)
    {
    	$stars_path='images/stars/';
    	
    	$tmp = round($x);
    	
    	$y = round($x*100) % 100;
    	if($y>24 && $y < 50)
    	{
    		$tmp += 0.5;
    	}
    	if($y>=50 && $y<75)
    	{
    		$tmp -= 0.5;
    	}
    	
    	$tmp = $stars_path.str_replace('.', '', $tmp).'.jpg';
    	
    	echo "<img src='$tmp' alt='' width='74' height='14' title='$hlasy hlasov, priemer: ".$x."'/>";
    	return true;
    }

	function fnIsAdmin()
	{	
		global $admins;
		$result = (session_is_registered('my_id') && in_array($_SESSION['my_id'], $admins));
		return $result;	
	}

	function fnAdjustID()
	{
		$id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? intval($_GET['id']) : '';
		if($id == '')
		{
			$id = (isset($_GET['Id']) && is_numeric($_GET['Id'])) ? intval($_GET['Id']) : '';
			if($id == '')
			{
				$id = (isset($_GET['iD']) && is_numeric($_GET['iD'])) ? intval($_GET['iD']) : '';
				if($id == '')
				{
					$id = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? intval($_GET['ID']) : '';
				}
			}
		}
		return $id;
	}

	function fnCountNaviLimits($i , $stranok)
	{
		$pad = 4;
		if($i>$pad && $i<$stranok-$pad)
		{
			$low = $i - $pad;
			$high = $i + $pad;
			($i>$pad+1) ? $dots_left = true : $dots_left = false;
			$dots_right = true;
			$result = array($low, $high, $dots_left, $dots_right);
			return $result;
		}
		elseif($i<$pad+1)
		{
			$low = 1;
			($stranok>$pad*2) ? $high = $pad*2+1 : $high = $stranok;
			$dots_left = false;
			($stranok>$pad*2+1) ? $dots_right = true : $dots_right = false;
			$result = array($low, $high, $dots_left, $dots_right);
			return $result;
		}
		else 
		{
			($stranok>$pad*2) ? $low = $stranok - $pad*2 : $low = 1;
			$high = $stranok;
			($i>$pad+1) ? $dots_left = true : $dots_left = false;
			$dots_right = false;
			$result = array($low, $high, $dots_left, $dots_right);
			return $result;	
		}
	}
	
	function fnNavi($i, $stranok, $link)
	{
		if($stranok>1)
		{
			echo "
			<div id=\"navigation\">\n
			<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n
			  <tr>\n
			    <td width=\"100\" align=\"left\">";
			if($i>1) echo "<a href=\"index.php?$link&amp;i=".($i-1)."\" id=\"navi\"><<</a>";
			echo "</td>\n";
			echo "<td align=\"center\">";
			
			$chunk = fnCountNaviLimits($i, $stranok);
			$low = $chunk[0];
			$high = $chunk[1];
			$dots_left = $chunk[2];
			$dots_right = $chunk[3];
			
			if($dots_left) echo ".. ";
			for($j=$low; $j<=$high; $j++)
			{
				if($j!=$i)
				{
					echo "<a href=\"index.php?$link&amp;i=$j\" id=\"navi\">$j</a> ";
				}
				else echo "<span id=\"red\">$j</span> ";
			}
			if($dots_right) echo " ..";
			
			echo 
			"</td>\n
			    <td width=\"100\" align=\"right\">";
			if($i<$stranok) echo "<a href=\"index.php?$link&amp;i=".($i+1)."\" id=\"navi\">>></a>";
			echo
			"</td>\n
			  </tr>\n
			</table>\n
			</div>\n
			";
		}
	}
	
	//funkcie na nastavenie sirky a vysky bunky tabulky
	function fnResWidth($res)
	{
		global $resolution;
		if(array_key_exists($res, $resolution)) return $resolution[$res]['width'];
		else return $resolution[0]['width'];
	}
	
	function fnResHeight($res)
	{
		global $resolution;
		if(array_key_exists($res, $resolution)) return $resolution[$res]['height'];
		else return $resolution[0]['height'];
	}
	
	function InitialzeReklama()
	{
		srand(microtime()*12346);
		if(!isset($_SESSION['rmu']))
		{
			$_SESSION['rmu'] = -1;
		}
		$_SESSION['rmu']++;
		if($_SESSION['rmu'] == 2)
		{
			$_SESSION['rmu'] = 0;
		}
	}
	
	function ShowReklama()
	{
		$ads = array
		(
			"<div class=\"melodia_div\">
				<a href='http://sk.iq-test.eu/?d=318' class='reklama_link' target='_blank'><span class='question'>Viete aké máte IQ? Patríte medzi elitu?</span><br/> 
				<span class='reklama_popis'>Otestujte sa v IQ teste vytvorenom predsedom Menzy ČR a porovnajte svoje výsledky s občanmi iných európskych krajín!</a><br/><strong><a href='http://sk.iq-test.eu/?d=318' class='reklama_link' target='_blank'><span class='reklama_popis'>IQ test nájdete TU!</span></a></strong></span>
			 </div>
			",
			"<div class=\"melodia_div\">
				<a href='http://sk.iq-test.eu/?d=318' class='reklama_link' target='_blank'><span class='question'>Mám IQ 137! A ty?</span><br/> 
				<span class='reklama_popis'>Otestuj sa v IQ teste vytvorenom predsedom Menzy ČR a zisti ako si na tom!</a><br/><strong><a href='http://sk.iq-test.eu/?d=318' class='reklama_link' target='_blank'><span class='reklama_popis'>IQ test nájdeš TU!</span></a></strong></span>
			 </div>
			",
			"<div class=\"melodia_div\">
				<a href='http://sk.iq-test.eu/?d=318' class='reklama_link' target='_blank'><span class='question'>Zistite o sebe PRAVDU!</span><br/> 
				<span class='reklama_popis'>Otestujte sa v IQ teste vytvorenom predsedom Menzy ČR a zistite ako ste na tom!</a><br/><strong><a href='http://sk.iq-test.eu/?d=318' class='reklama_link' target='_blank'><span class='reklama_popis'>IQ test nájdeš TU!</span></a></strong></span>
			 </div>
			"
		);
//		if(fnIsAdmin())
//		{
			if($_SESSION['rmu'] == 0)
			{
				if(rand(0, 3) == 1)
				{
					if(rand(0, 2) == 1)
					{
						echo $ads[rand(0, sizeof($ads)-1)];
					}
					else
					{
						echo '<div class="reklama_div">
						<script type="text/javascript"><!--
						google_ad_client = "pub-4917301309934013";
						//468x60, bola vytvorené 14.1.2008
						google_ad_slot = "2353614394";
						google_ad_width = 468;
						google_ad_height = 60;
						//--></script>
						<script type="text/javascript"
						src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
						</script></div>
						';
					}
					$_SESSION['rmu']++;
				}
			}
//		}
	}
	
	function  fnVypisMelodieNew($result)
	{
		global $blocked_dloads, $melody_genres;
		if($result)
		{
			echo "
			<script language='javascript' type='text/javascript'>\n
			function play(id)\n
			{\n
				window.open('player.php?id=' + id, 'player', 'width=220, height=250, menubar=no, directories=no, toolbar=no, top=100, left=100, location=no, scrollbars=no, resizable=no');\n
			}\n
			</script>\n
			";
			if(fnIsAdmin() && session_is_registered('melody_edit'))
			{
				echo "<form name='frm' action='index.php?module_top=melody_sort&action=sort' method='POST'>";
			}
			(key_exists('nazov', $_GET) && $_GET['nazov']<>'') ? $nazov = $_GET['nazov'] : $nazov = '';
			
			InitialzeReklama();
			
			while($row = mysql_fetch_array($result))
			{
				ShowReklama();
				
				$size=round(filesize('melody/'.$row["file"])/1024,2);		
				echo "<div class=\"melody_div_new\">";
				echo "	<div class='typ'>";
				$hlasy = '';
				if(ord($row["hlasy"][0])>='48' && ord($row["hlasy"][0]<='57'))
				{
					echo "MID";
					$hlasy = $row["hlasy"];
				}
				else 
				{
					echo strtoupper($row["hlasy"]);
				}
				echo "</div>";
				echo "	<div class='nazov'>";
				if($row['interpret'] != '')
				{
					echo $row['interpret']." - ";
				}
				echo $row['nazov']." &nbsp;<span>(";
				if($hlasy != '')
				{
					echo "".$hlasy." hlasné, ";
				}
				echo "$size kB)</span></div>";
				echo "	<div class='buttons'>";
				if (strtoupper($row['hlasy']) != 'AMR' && session_is_registered('mobile_logged_in')) 
				{
					echo "	<a href='javascript:play(".$row['ID'].");'><img src='images/melodky_vypocuj.png' alt='Vypočuj' title='Vypočuj' /></a> ";
				}
				if(!$blocked_dloads[1] && session_is_registered('mobile_logged_in'))
				{
					echo "	<a href='http://4mobile.sk/melodia/".$row["ID"]."/'><img src='images/melodky_stiahni.png' alt='Stiahni' title='Stiahni' /></a>";
				}
				echo "
						</div>";
				echo "	<div class='content'>
							http://4mobile.sk/melodia/".$row["ID"]."/<br/>
							<span class='popis'>".$row["poznamka"]."&nbsp;</span>
							<div>";
				$priemer=round($row["priemer"],2);
				fnShowStars($priemer, $row['hlasov']);
				echo " &nbsp;&nbsp;<span id=\"red_b\">Hlasuj!</span> <img src=\"images/smile/17.gif\" alt=\"\" /> ";
				
				for($k=1;$k<=5;$k++) {echo"<a href='hlasuj.php?action=melody&amp;id=".$row['ID']."&amp;hlas=".$k."' id=\"hlasuj\">".$k."</a> ";}
				echo"<img src=\"images/smile/5.gif\" alt=\"\" />\n";
				echo "		</div>
						</div>";
				if(fnIsAdmin())
				{
					echo "<div class='stiahnuti'>Stiahnutí: ".$row['dload']."</div>";
				}
				
				echo "</div>";
			}
			if(fnIsAdmin() && session_is_registered('melody_edit'))
			{
				echo '<div style="width:100%: text-align: center;"><input type="submit" name="submit" value="Utrieď" class="field" /></div>';
				echo '</form>';
			}
		}
	}
	
	
	function fnExec_TIme(){
	  return 0;
	}
	
	function fnVypisMelodySearch($result)
	{
		global $search, $blocked_dloads;
		
		echo "
			<script language='javascript' type='text/javascript'>\n
			function play(id)\n
			{\n
				window.open('player.php?id=' + id, 'player', 'width=200, height=80, menubar=no, directories=no, toolbar=no, top=100, left=100, location=no, scrollbars=no, resizable=no');\n
			}\n
			</script>\n
			";
		$match = 0;
		while($row = mysql_fetch_array($result))
		{
		    $row["interpret"] = eregi_replace($search, "<span id=\"red_b\">".strtoupper($search)."</span>", $row["interpret"]);
			$row["nazov"] = eregi_replace($search, "<span id=\"red_b\">".strtoupper($search)."</span>", $row["nazov"]);
			echo "<div id=\"melodia_div\">";
			$match += 1;
			$size=round(filesize('melody/'.$row["file"])/1024,2);
			if($row["interpret"]<>'') 
			{
				echo"<b>".ucwords($row["interpret"]).": "; 
			} 
			else 
			{
				echo"<b>";
			} 
			echo ucwords($row["nazov"])." - <span id=\"red\">ID: ".$row["ID"]."</span></b> (";
			if($row["hlasy"]=='0')
			{
				echo"?";
			} 
			else
			{
				echo $row["hlasy"];
			}
			if(ord($row["hlasy"][0])>='48' && ord($row["hlasy"][0]<='57'))
			{
				echo " hlasné - polyfonické";
			}
			echo ", ".$size." kB)<br />";
			echo "http://4mobile.sk/melodia.php?id=".$row["ID"]."<br />";
			if($row["poznamka"]<>'') echo $row["poznamka"]."<br />";
			$priemer=round($row["priemer"],2);
			fnShowStars($priemer);
			echo '<br/>'.$row["hlasov"]." hlasov, priemer: ".$priemer.", ".$row["dload"]." stiahnuti";
//			echo " | <span id=\"red_b\">Hlasuj!</span> <img src=\"images/smile/17.gif\" alt=\"\" /> ";
//			for($k=1;$k<=5;$k++) {echo"<a href='hlasuj.php?action=video&amp;id=".$row['ID']."&amp;hlas=".$k."' id=\"hlasuj\">".$k."</a> ";}
//			echo"<img src=\"images/smile/5.gif\" alt=\"\" />\n";
			if (strtoupper($row['hlasy']) != 'AMR' && session_is_registered('mobile_logged_in') ) 
			{
				echo " | <a href='javascript:play(".$row['ID'].");' class='tahaj'>VYPOČUŤ</a>";
			}
			if(!$blocked_dloads[1] && session_is_registered('mobile_logged_in'))
			{
				echo " | <a href='melodia.php?id=".$row["ID"]."' class='tahaj'>STIAHNI</a><br />";
			}
			echo "</div>";
		}
	}
	
	function fnShowMobile($id)
	{
		global $rozlisenie;
		global $farby;
		global $wap;
		global $gprs; 
		global $edge;
		global $zvonenie;
		global $mp3_play;
		global $java;
		global $dba;
		
		$row = $dba->GetRow('mobile_moj_mobil', $id, '*');
		echo "
		<table border='0' cellspacing='10'>\n
			<tr>\n
				<td><img src='images/moj_mobil/".$row['image']."' alt=''></td>\n
				<td valign='top'><span class='red'><b>".$row['mobil']."</b></span><br /><br />\n
				Pozadia: ".$rozlisenie[$row['rozlisenie']]." px<br />\n
				Počet farieb displeja: ".$farby[$row['farby']]." farieb<br />\n
				Wap: ".$wap[$row['wap']]."<br />\n
				GPRS: ".$gprs[$row['gprs']]."<br />\n
				EDGE: ".$edge[$row['edge']]."<br />\n
				Polyfonické zvonenia: ".$zvonenie[$row['zvonenie']]."<br />\n
				MP3 prehrávač: ".$mp3_play[$row['mp3_play']]."<br />\n
				Java: ".$java[$row['java']]."\n
				</td>\n
			</tr>\n
		</table>\n";
	}
	
	function fnSmile($text)
	{
		for($j=1;$j<=20;$j++)
		{
			$original = " s".$j." "; 
			$novy = "<img src=\"images/smile/".$j.".gif\" border=\"0\" align=\"middle\" alt=\"\"/> "; 
			$text = str_replace($original, $novy, $text);
		}
		return $text;
	}
	
	function fnSmileys($text)
	{
		$smls = array
		(
			':)' => ' s5 ',
			':-)' => ' s5 ',
			':o) ' => ' s5 ',
			':(' => ' s17 ',
			':-(' => ' s17 ',
			':o(' => ' s17 ',
			':/' => ' s6 ',
			':-/' => ' s6 ',
			':o/' => ' s6 ',
			';)' => ' s4 ',
			';-)' => ' s4 ',
			';o)' => ' s4 ',
			':-D' => ' s1 ',
			':oD' => ' s1 ',
			':D' => ' s1 ',
			':|' => ' s7 ',
			':-|' => ' s7 ',
			':o|' => ' s7 ',
			':O' => ' s10 ',
			':-O' => ' s10 ',
			':oO' => ' s10 ',
			':p' => ' s2 ',
			':-p' => ' s2 ',
			':op' => ' s2 ',
			':P' => ' s2 ',
			':-P' => ' s2 ',
			':oP' => ' s2 '
		);
		foreach($smls as $k => $v)
		{
			$text = str_replace($k, $v, $text);
		}
		return $text;
	}
	
	function fnWriteGbook($result)
	{
		echo "<div id='gbook_div'>";
		global $admins, $i;
		while($row = mysql_fetch_array($result))
		{
			if($row['admin'] == 'a')
			{
				echo "<div class=\"admin_div\">";
			}
			else 
			{
				echo "<div id=\"melodia_div\">";
			}
			echo "<span id=\"red\"><b>".$row['meno']."</b></span> | ";
			if($row['mail']!='') echo $row['mail']." | ";
			echo "odoslané: ".$row['datum']."<br />";
			echo fnSmile(fnSmileys(fnCutLong(stripslashes($row['text']))));
			if(session_is_registered('my_id') && in_array($_SESSION['my_id'], $admins))
			{
				echo " | <a href=\"javascript:DeleteConfirm('index.php?module=gbook&i=$i&action=delete&id=".$row['id']."')\" class='anketa_link'>zmazať</a>";
			}
			echo "</div>";
		}
		echo "</div>";
	}
	
	function fnWriteGbook2($result)
	{
		global $admins, $i;
		echo "<div id='gbook_div'>";
		while($row = mysql_fetch_array($result))
		{
			$pad = (isset($_SESSION['threads']) && $_SESSION['threads']) ? (94 - (substr_count($row['vector'], '#') - 2) * 2) : 96;
			$pad = ($pad < 50) ? 50 : $pad;
			$margin = ($pad < 94) ? ' margin-top: 4px;' : '';
			if($row['admin'] == 'a')
			{
				echo "<div class=\"admin_gbook_div\" style='width:$pad%;$margin'>";
			}
			else 
			{
				echo "<div class=\"noadmin_gbook_div\" style='width:$pad%;$margin'>";
			}
			echo "<span id=\"red\"><b>".$row['meno']."</b></span> | ";
			if($row['mail']!='') echo $row['mail']." | ";
			echo "odoslané: ".$row['datum']." z IP: ".$row['ip']."<br />";
			echo fnSmile(fnSmileys(fnCutLong(stripslashes($row['text']))));
			echo " | <a href='index.php?module=gbook&amp;reply=".$row['id']."' class='anketa_link'>odpovedať</a>";
			if(session_is_registered('my_id') && in_array($_SESSION['my_id'], $admins))
			{
				echo " | <a href=\"javascript:DeleteConfirm('index.php?module=gbook&i=$i&action=delete&id=".$row['id']."')\" class='anketa_link'>zmazať</a>";
			}
			echo "</div>";
		}
		echo "</div>";
	}
	
	function fnWriteForum($result)
	{
		global $admins;
		while($row = mysql_fetch_array($result))
		{
			$pad = (isset($_SESSION['threads']) && $_SESSION['threads']) ? (96 - (substr_count($row['vector'], '#') - 2) * 2) : 96;
			$pad = ($pad < 50) ? 50 : $pad;
			echo "<div class=\"forum_posts_div\" style='width:$pad%;'><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
			if($row['avatar']!='') echo "<td rowspan=\"2\" width=\"80\" valign=\"top\" align=\"center\"><img src=\"images/users/".$row['avatar']."\" alt=\"\"/></td>";
			echo "<td valign=\"top\"";
			if($row['avatar']!='') echo " style=\"padding-left:8px;\"";
			echo "><span id=\"red\"><b>".$row['pridal_login']."</b></span> | ";
			echo "pridané: ".$row['cas']."<br />";
			echo fnSmile(fnSmileys(stripslashes(fnCutLong($row['text']))));
			echo "</td></tr><tr><td ";
			if($row['avatar']!='') echo "style=\"padding-left:8px;\" ";
			echo "valign=\"bottom\">";
			if($row['mail']!='') echo $row['mail'];
			if($row['icq']!='') echo ' | ICQ: '.$row['icq'];
			if($row['msn']!='') echo ' | MSN: '.$row['msn'];
			echo " | <a href='index.php?module=forum&amp;action=topic&amp;topic_id=".$row['parent_topic']."&amp;reply=".$row['ID']."' class='anketa_link'>odpovedať</a>";
			if(session_is_registered('my_id') && in_array($_SESSION['my_id'], $admins))
			{
				echo " | <a href=\"javascript: fnConfirm2('index.php?module=forum&action=delete_post&id=".$row['ID']."')\" class=\"refresh\">zmaž</a>";
			}
			echo "</td></tr></table></div>";
		}
	}
	
	function fnWriteBazar($result)
	{
		$types = array
		(
			1 => 'Kúpim',
			2 => 'Predám',
			3 => 'Vymením',
		);
		InitialzeReklama();
		
		while($row = mysql_fetch_array($result))
		{
			ShowReklama();
			echo "<div id=\"melodia_div\">";
			echo "<table id=\"inz_edit_table\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>";
			echo "<b>".$types[$row['kat']]."</b>";
			echo " <span id=\"red\">".$row['typ']."</span> | pridal ".$row['pridal_user']." | ".$row['datum'];
			echo "</td><td align=\"right\">";
			if(session_is_registered('my_id') && $row['pridal']==$_SESSION['my_id'])
			echo "<a href=\"index.php?module=bazar&amp;action=edit&amp;id=".$row['ID']."\" id=\"index_link_01\">edit</a> | <a href=\"javascript: fnConfirm01('index.php?module=bazar&amp;action=delete&amp;id=".$row['ID']."')\" id=\"index_link_01\">zmaž</a>";
			echo "</td></tr></table>";
			echo fnCutLong($row['popis'])."<br />";
			echo "Cena: ".$row['cena']."<br />";
			echo "Kontakt: ".$row['kontakt']."<br />";
			echo "Mesto: ".$row['mesto'];
			echo "</div>";
		}
	}
	
	function fnCutLong($text, $lng = 40)
	{
		$result = '';
		$dlzka = 0;
		for($i=0;$i<=strlen($text)-1; $i++)
		{
			if($text[$i] == ' ')
			{	
				$dlzka = 0;
			}
			else $dlzka++;
			$result .= $text[$i];
			if($dlzka==$lng) 
			{
				$result .= ' ';
				$dlzka = 0;
			}
		}
		return $result;
	}
	
	function fnAnketa($stripes)
	{	
		global $dba;
		if(!session_is_registered("hlasoval_v_ankete"))
		{
			$query = "SELECT * FROM mobile_anketa WHERE visible=1 ORDER by selector ASC limit 0, 1";
			$result = $dba->GetResult($query);
			if($result) 
			{
				$row = mysql_fetch_array($result);
				$anketa = $row["id"];
				$zob = $row["zobrazeni"];
				$zob += 1;
				$query = "UPDATE mobile_anketa SET zobrazeni = zobrazeni + 1, selector = selector + 1 WHERE ID = '$anketa' limit 1";
				$dba->ExecuteQuery($query);
//				$dba->Increment('mobile_anketa', 'zobrazeni', $anketa, 1);
//				$dba->Increment('mobile_anketa', 'selector', $anketa, 1);
				$_SESSION["anketa_id"] = $anketa;
				$mobile_anketa_string = "mobile_anketa_".$anketa;
				$anketa_cookie = "mobile_hlas_anketa".$anketa;
				if(!isset($_COOKIE[$anketa_cookie]) && !session_is_registered($mobile_anketa_string))
				{	
					$query = "SELECT * FROM mobile_anketa WHERE id=$anketa";
					$result = $dba->GetResult($query);
					if($result) 
					{
						$row = mysql_fetch_array($result);
						$spolu = 0;
						for($i=1;$i<=10;$i++)
						{
							$spolu += $row["poc".$i];
						}	
						echo "<b>".$row["otazka"]."</b><br/><br/>";
						$perc=array();
						for($i=1; $i<=10; $i++)
						{
							if($row["odp".$i]<>'')
							{
								echo "<a href='index.php?module_top=aw&amp;odpoved=poc".$i."' class='anketa_link'>".$row["odp".$i]."</a> (".$row["poc".$i].")<br />";
								if($stripes)
								{
									if($spolu==0) $perc[$i] = 0;
									else
									{
										$perc[$i] = round($row["poc".$i]*100/$spolu);
									}
									if($perc[$i] == 0) $perc[$i] = 1;
									echo "<img src='images/pas_ank.gif' height='10' width='".$perc[$i]."' alt='' /><br />";
								}
								echo '<br />';
							}
						}
						echo "Spolu: ".$spolu."<br />Od ".$row["od"];
					}
				}
			}
		}
		else 
		{	
			if(session_is_registered('hlasoval_v_ankete'))
			{
				$query="SELECT * FROM mobile_anketa WHERE id='".$_SESSION['hlasoval_v_ankete']."' limit 0, 1";
			}
			else $query="SELECT * FROM mobile_anketa WHERE visible='1' ORDER by selector ASC";
			$result = $dba->GetResult($query);
			if($result)
			{
				$row = mysql_fetch_array($result);
				$anketa = $row["id"];
				$spolu = 0;
				for($i=1;$i<=10;$i++)
				{
					$spolu += $row["poc".$i];
				}
				echo "<b>".$row["otazka"]."</b><br/><br/>";
				$perc=array();
				for($i=1; $i<=10; $i++)
				{
					if($row["odp".$i]<>'')
					{
						echo "<span class=menu2>".$row["odp".$i]."</span> (".$row["poc".$i].")<br/>";
						if($stripes)
						{
							if($spolu==0) $perc[$i]=0; 
							else
							{
								$perc[$i]=round($row["poc".$i]*100/$spolu);
							}
							if($perc[$i] == 0) $perc[$i] = 1;
							echo "<img src='images/pas_ank.gif' height='10' width='".$perc[$i]."' alt=''/><br/>";
						}
						echo '<br />';
					}
				}
				echo "Spolu:".$spolu."<br />Od ".$row["od"];
			}	
			else 
			{
				dump($query);
			}
		}
		session_register("anketa_id");
		$_SESSION["anketa_id"] = $anketa;
		if(session_is_registered("mobile_voted"))
		{
			echo"<br /><b>Už si hlasoval!</b>";
//			session_unregister("mobile_voted");
		}
	}
	
	function fnTextPreview($text, $znakov)
	{
		if(strlen($text) > $znakov)
		{
			$uvod = substr($text, 0, $znakov-1);
			$l = 0;
			for($jz=0;$jz<$znakov-1;$jz++)
			{
				if($uvod[$jz]==' ') $l = $jz;
			}
			if($l==0) $l = $znakov;
			$uvod = substr($uvod, 0, $l);
			$uvod .= '...';
		}
		else
		{ 
			$uvod = $text;
		}
		return $uvod;
	}
	
	function fnWriteAgent($param)
	{
		$filename = 'lib/log/'.date('j-m-y').'-agents.log';
		if(!file_exists($filename))
		{
			$fp = fopen($filename, 'w');
		}
		else 
		{
			$fp = fopen($filename, 'a');
		}
		$llg = (isset($_SESSION['log'])) ? $_SESSION['log'] : '';
		if($param)
		{
			fputs($fp, $_SERVER['HTTP_USER_AGENT']." | ".$llg."\n");
		}
		else 
		{
			fputs($fp, "*** BLOCKED *** ".$_SERVER['HTTP_USER_AGENT']." | ".$llg."\n");
		}
		fclose($fp);
	}

	function fnDetectAgent($part)
	{
		global $blocked_dloads;
		
		if(!$blocked_dloads[$part])
		{
			$result = true;
		}
		else 
		{
			if(eregi('Mozilla', $_SERVER['HTTP_USER_AGENT']) || 
			   eregi('FDM', $_SERVER['HTTP_USER_AGENT']) || 
			   eregi('FlashGet', $_SERVER['HTTP_USER_AGENT']) || 
				 eregi('opera', $_SERVER['HTTP_USER_AGENT']))
			{
				$result = false;
			}
			else 
			{
				$result = true;
			}
		}
		fnWriteAgent($result);
		return $result;
	}
	
	function fnIsComputer()
	{
		if(eregi('Mozilla', $_SERVER['HTTP_USER_AGENT']) || 
		   eregi('FDM', $_SERVER['HTTP_USER_AGENT']) || 
		   eregi('FlashGet', $_SERVER['HTTP_USER_AGENT']) || 
		   eregi('Kobyrk', $_SERVER['HTTP_USER_AGENT']) || 
//		   eregi('Configuration', $_SERVER['HTTP_USER_AGENT']) || 
			 eregi('opera', $_SERVER['HTTP_USER_AGENT']))
		{
			$result = true;
		}
		else 
		{
			$result = false;
		}
		return $result;
	}
	
	function fnWriteLog($type, $message)
	{
		global $dba;
		
		$filename = "lib/log/".$type;
		if(!file_exists($filename))
		{
			$fp = fOpen($filename, "w");
			$time = date("d.m.Y H:i:s");
			fPuts($fp, $time.": ".$message."\n");
			fClose($fp);
			chmod($filename, 0204);
		}
		else 
		{
			$fp = fOpen($filename, "a");
			$time = date("d.m.Y H:i:s");
			fPuts($fp, $time.": ".$message."\n");
			fClose($fp);
		}
		$message = addslashes($message);
		$query = "INSERT INTO mobile_logs (type, time, message) VALUES ('".$type."', '".$time."', '".$message."')";
		$dba->ExecuteQuery($query);
	}
	
	function Dump($var)
	{
		global $admins;
		
		if(@in_array($_SESSION['my_id'], $admins))
		{
			echo "<div style='width:100%; text-align: left; border-style: solid: border-color: #333333; border-width:1px; background-color: red; color: #ffffff;'><pre>";
			print_r($var, false);
			echo "</pre></div>";
		}
	}
	
	function Dump2($var)
	{
		global $admins;
		
//		if(@in_array($_SESSION['my_id'], $admins))
		{
			echo "<div style='width:100%; text-align: left; border-style: solid: border-color: #333333; border-width:1px; background-color: red; color: #ffffff;'><pre>";
			print_r($var, false);
			echo "</pre></div>";
		}
	}
	
	function fnPridajKred($id, $kredits)
	{
		global $dba;
		
		if($_SESSION['mobile_active'] == 'a' || $kredits < 0)
		{
			$dba->Increment('mobile_users', 'kredits', $id, $kredits);
			if($kredits > 0)
			{
				$dba->Increment('mobile_users', 'kredits_earned', $id, $kredits);
			}
		}
	}
?>