<?php if (isset($_GET['src'])) die(highlight_file(__FILE__, true));?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
  <title>Julia word comparision system</title>
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1257"/>
</head>

<body>
<?php

$name1 = isset($_GET['name1']) ? $_GET['name1'] : false;
$name2 = isset($_GET['name2']) ? $_GET['name2'] : false;

function lidzsk(&$nburts) {
  if (strlen($nburts)!=1) return false;
  return (strtr($nburts,'BCDFGHJKLMNPRSTVWXZ','') == '');
}


function nml_ch(&$burts) {
  $burts = strtoupper($burts);
  $burts = strtr($burts, 'âèçìîíïòôºðûþ','ÂÈÇÌÎÍÏÒÔªÐÛÞ'); // toUpper
  $burts = strtr($burts, "ÂÈÇÌÎÍÏÒÔªÐÛÞÄůÉÓÕÖ¨ÜÀÃËÆÁÙÑÚØÊÝ.'",'ACEGIKLNORSUZAAEEOOOOUACEEILNSUZZ'); // noAccent
  if (strtr($burts,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','') == '') $burts = '*';
  return $burts;
}

function julia($wd) {
  $rtwd = nml_wd($wd);
  while (nml_wd($rtwd) != $rtwd) 
    $rtwd = nml_wd($rtwd);
  return $rtwd;
}

function nml_wd(&$word) {
  for ($i=0; $i<strlen($word); $i++)
    $res .= nml_ch(substr($word, $i, 1));
  return nml_3(nml_2(nml_1($res)));
}

function alpha(&$burts) {
  return strtr($burts,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','');
}

function nml_1(&$nword) {
  for ($i=0; $i<strlen($nword); $i++) { // remove duplicate characters
    if ($cch != substr($nword, $i, 1)) $res .= substr($nword, $i, 1);
    $cch = substr($nword, $i, 1);
  }
  return $res;
}
  
function nml_2 (&$nwd) {
  $nwd = str_replace('DZ', 'J', $nwd);
  $nwd = str_replace('ZD', 'Z', $nwd);
  
  if (lastchars($nwd, 2) == 'TS') $nwd = nolastchars($nwd, 2).'T'; 
  if (lastchars($nwd, 2) == 'IS') $nwd = nolastchars($nwd, 2); 
  if (lastchars($nwd, 2) == 'IS') $nwd = nolastchars($nwd, 2); 
  if (lastchars($nwd, 2) == 'AS') $nwd = nolastchars($nwd, 2); 
  if (lastchars($nwd, 2) == 'ER') $nwd = nolastchars($nwd, 2).'R';
  if (lastchars($nwd, 1) == 'S')  $nwd = nolastchars($nwd, 1);
  return $nwd;
}
  
function nml_3(&$nword) {
  $nword = strtr($nword,'DGJBVWYZCFH','TKIPUUISSP');
  $nword = str_replace('KS','X',$nword);
  $nword = str_replace('KV','Q',$nword);
  $nword = str_replace('KU','Q',$nword);
  $nword = str_replace('QU','Q',$nword);
  $nword = str_replace('TS','S',$nword);
  $nword = str_replace('IU','U',$nword);
  $nword = str_replace('UI','U',$nword);
  $nword = str_replace('AI','A',$nword);
  $nword = str_replace('IA','A',$nword);
  $nword = str_replace('IE','I',$nword);
  $nword = str_replace('EI','E',$nword);
  $nword = str_replace('OI','O',$nword);
  $nword = str_replace('IO','O',$nword);
  $nword = str_replace('RS','R',$nword);
  $nword = str_replace('OU','U',$nword);
  $nword = str_replace('UO','O',$nword);
  $nword = str_replace('CS','S',$nword);
  
  $nword = str_replace('AH','A',$nword);
  $nword = str_replace('CH','C',$nword);
  $nword = str_replace('CJ','C',$nword);
  $nword = str_replace('GH','G',$nword);
  $nword = str_replace('GJ','G',$nword);
  $nword = str_replace('KJ','K',$nword);
  $nword = str_replace('KH','K',$nword);
  $nword = str_replace('LJ','L',$nword);
  $nword = str_replace('LH','L',$nword);
  $nword = str_replace('NJ','N',$nword);
  $nword = str_replace('NH','N',$nword);
  $nword = str_replace('SH','S',$nword);
  $nword = str_replace('ZH','Z',$nword);
  $nword = str_replace('ZJ','z',$nword);
  $nword = str_replace('PH','P',$nword);
  $nword = str_replace('TH','T',$nword);

  $nword = str_replace('KI','K',$nword);

  return $nword;
}

function lastchars($nwd, $cnt) {
  return substr($nwd, strlen($nwd) - $cnt, $cnt);
}
        
function nolastchars($nwd, $cnt) {
  return substr($nwd, 0, strlen($nwd) - $cnt);
}


?>

<form action=./>
<input type=text name=name1 value="<?=$name1?>"><!--<?php if($name1) echo julia($name1)?>--><br>
<input type=text name=name2 value="<?=$name2?>"><!--<?php if($name2) echo julia($name2)?>-->
<input type="submit" value="   Salidzinat   ">
</form>

<?php
if (trim($name1) != '' || trim($name2) != '') {
  if ((strlen($name1) > 2) && (strlen($name2) > 2)) {
    if (julia($name1)==julia($name2)) {
      echo "<h2>Vaardi<br>'$name1' un '$name2'<br>skan liidziigi</h2>";
    } else {
      echo '<h2>Ne mazaakaas liidziibas</h2>';
    }
  } else {
    echo 'Viens no vaardiem ir par iisu!';
  }
}
?>
<p><a href="?src">src</a></p>
</body>
</html>
<!--
* julia name comaprison system *prototype*
* (c) 2001 anger dei (programmed by eifelz/elfs)
* (t) 2001 PHP / optimization - laacz
* started: 18.07.2001
//-->