<?

    function _string($string) {
      
    $string = trim($string);
    
          $string = mysql_escape_string($string);
      
    $string = htmlspecialchars($string);

    return $string;
    
    }
    
    function _num($i) {
    
      $i = (int) abs($i);
    
    return $i;
    
    }
    
    function n_f($i) {

    if($i >= 10000 && $i < 1000000) {
    
      $i = number_format($i, 0, '', '.');
    
      $i = round($i,3).'K';
    
    }
elseif($i >= 1000000) {

      $i = number_format($i, 0, '', '.');
    
      $i = round($i,3).'M';

    }
    else
    {
      
      $i = number_format($i, 0, '', '\'');
     
    }
       
    return $i;
    
    }

    function pages($path) {
  
    global $page, $pages;
    
      if(($page - 2) > 0) {

        echo ' <a href="'.$path.'page=1">&lt;&lt;</a> ';

      }
      else
      {

        echo '&lt;&lt;';

      }
        
      if($page - 1 > 0) {

        echo ' <a href="'.$path.'page='.($page - 1).'">&lt;</a> ';
        
      }
      else
      {

        echo ' &lt; ';

      }
        
      if($page == $pages && $page - 4 > 0) {

        echo ' <a href="'.$path.'page='.($page - 4).'">'.($page - 4).'</a> ';
        
      }

        
      if($page == $pages && $page - 3 > 0) {

        echo ' <a href="'.$path.'page='.($page - 3).'">'.($page - 3).'</a> ';
        
      }
        
      if($page - 2 > 0) {

        echo ' <a href="'.$path.'page='.($page - 2).'">'.($page - 2).'</a> ';
        
      }

        
      if($page - 1 > 0) {

        echo ' <a href="'.$path.'page='.($page - 1).'">'.($page - 1).'</a> ';
        
      }


      echo $page;
        
       
      if($page + 1 <= $pages) {

        echo ' <a href="'.$path.'page='.($page + 1).'">'.($page + 1).'</a> ';
        
      }

        
      if($page + 2 <= $pages) {

        echo ' <a href="'.$path.'page='.($page + 2).'">'.($page + 2).'</a> ';
        
      }
        
      if($page == 1 && $page + 3 <= $pages) {

        echo ' <a href="'.$path.'page='.($page + 3).'">'.($page + 3).'</a> ';
        
      }
        
      if($page == 1 && $page + 4 <= $pages) {

        echo ' <a href="'.$path.'page='.($page + 4).'">'.($page + 4).'</a> ';
        
      }

        
      if($page + 1 <= $pages) {

        echo ' <a href="'.$path.'page='.($page + 1).'">&gt;</a> ';

      }
      else
      {

        echo ' &gt; ';

      }
        
      if(($page + 2) <= $pages) {

        echo ' <a href="'.$path.'page='.$pages.'">&gt;&gt;</a> ';
        
      }
      else
      {

        echo ' &gt;&gt; ';

      }
      
    }
    
    function smiles($string) {
    
      $string = str_replace(array(':@)',':ded'), '<img src="/images/smiles/mini_ded.gif" alt="*"/>',      $string);

      $string = str_replace(array('O:-)','o:-)'),'<img src="/images/smiles/mini_angel.gif" alt="*"/>',      $string);

      $string = str_replace(array(']:-)',']:-]'),'<img src="/images/smiles/mini_diablo.gif" alt="*"/>',     $string);

      $string = str_replace(array(':$',':-$',':-['),'<img src="/images/smiles/mini_blush.gif" alt="*"/>',        $string);

      $string = str_replace(array(':))',':-))','-))','=))'),'<img src="/images/smiles/mini_lol.gif" alt="*"/>',         $string);

      $string = str_replace(array(':)',':-)','=)'),'<img src="/images/smiles/mini_ulibka.gif" alt="*"/>',       $string);

      $string = str_replace(array(';)',';-)'),'<img src="/images/smiles/mini_podmigivanie.gif" alt="*"/>', $string);

      $string = str_replace(array(':-D',':-d',':D',')))'),'<img src="/images/smiles/mini_spin.gif" alt="*"/>',        $string);

      $string = str_replace(array(':-P',':-p',':-Р',':-р',':P',':p'),'<img src="/images/smiles/mini_yazyk.gif" alt="*"/>', $string);

      $string = str_replace(array(':(',':-('),'<img src="/images/smiles/mini_sad.gif" alt="*"/>',        $string);

      $string = str_replace(array(':\'(',':\'-('),'<img src="/images/smiles/mini_cry.gif" alt="*"/>',        $string);

      $string = str_replace(array(':]',':-]'),'<img src="/images/smiles/mini_dovolen.gif" alt="*"/>',        $string);

      $string = str_replace(array(':-/',':-\\'),'<img src="/images/smiles/mini_hm.gif" alt="*"/>',        $string);

      $string = str_replace(array('8-)','%-)'),'<img src="/images/smiles/mini_krut.gif" alt="*"/>',        $string);

      $string = str_replace(array(':*',':-*'),'<img src="/images/smiles/mini_kiss.gif" alt="*"/>',        $string);

      $string = str_replace(array('%)','%-)'),'<img src="/images/smiles/mini_crazy.gif" alt="*"/>',        $string);

      $string = str_replace(array(':-o',':-O',':-о',':-О','O.o','О.о','O_o','o_O'),'<img src="/images/smiles/mini_chok.gif" alt="*"/>',        $string);

      $string = str_replace(array('O^','o^'),'<img src="/images/smiles/mini_bye.gif" alt="*"/>',        $string);

      $string = str_replace(array(':Ob',':ob'),'<img src="/images/smiles/mini_good.gif" alt="*"/>',        $string);

      $string = str_replace(array('6-(','%-E',':gigi'),'<img src="/images/smiles/mini_fingal.gif" alt="*"/>',        $string);
      
      $string = str_replace(array(':bravo',':браво'),'<img src="/images/smiles/mini_bravo.gif" alt="*"/>',        $string);
      
      $string = str_replace(array(':heart',':сердце'),'<img src="/images/smiles/mini_heart.gif" alt="*"/>',        $string);
      
      $string = str_replace(array(':fig',':фиг'),'<img src="/images/smiles/mini_fig.gif" alt="*"/>',          $string);
      
      $string = str_replace(array(':rose',':роза','@--'),'<img src="/images/smiles/mini_rose.gif" alt="*"/>',        $string);
      
      $string = str_replace(array(':krut',':крут'),'<img src="/images/smiles/mini_krut.gif" alt="*"/>',        $string);

      $string = str_replace(array('dOOb','doob','d00b'),'<img src="/images/smiles/mini_friends.gif" alt="*"/>',        $string);

    return $string;
    
    }


    function _time($i) {

      $h  = floor(($i / 3600) - $d * 24); 
      
      $m  = floor(($i - $h * 3600 - $d * 86400) / 60); 
      
      $s  = $i - ($m * 60 + $h * 3600 + $d * 86400);
    
      
    return ($h > 0 ? ($h < 10 ? '0':'').$h.':':'').($m > 0 ? ($m < 10 ? '0':'').$m.':':'00:').($s > 0 ? ($s < 10 ? '0':'').$s:'00');
    
    }
    
    function bb($string) {
      
      $string = str_replace("\r\n","<br/>",$string);
    
    return $string;
    
    }
    
    function _times($i) {

      $d  = floor($i / 86400); 
      
      $h  = floor(($i / 3600) - $d * 24); 
      
      $m  = floor(($i - $h * 3600 - $d * 86400) / 60); 
      
      $s  = $i - ($m * 60 + $h * 3600 + $d * 86400);

    
      if($d > 0) {
      
        $result = $d.' д';
       
      }
      elseif($h > 0)
                 {
       
        $result = $h.' ч';
                
      }elseif($m > 0)
                 {
       
      $result = $m.' мин';
                
      }elseif($s >= 0)
                 {
       
      $result = $s.' сек';
                
      }

  return $result.' назад';
  
  }
function NameBot(){
$array = array('q','w','r','t','p','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m');
			$array2 = array('e','y','u','i','o','a');
			$strlen = rand(5,6);
			$name 	= '';			
for($i = 1; $i <= $strlen; $i ++) {
				if ($i == 1) {
					$key = array_rand($array);
					$name .= $array[$key];
				}
				elseif ($i == 2) {
					$key = array_rand($array2);
					$name .= $array2[$key];
				}
				elseif ($i <= 3) {
					$key = array_rand($array);
					$name .= $array[$key];
				}
				else
				{
				
					$key = array_rand($array);
					$name .= $array[$key];
				}
			}
			$name = mb_convert_case($name, MB_CASE_TITLE, "UTF-8");
			return $name;
		
		}

?>