<?php




function pl_sort($result){


	$diphthongs=array("cs", "dz", "gy", "ly", "ny", "sz", "ty", "zs");

	$i=0;
	while ($row=mysql_fetch_object($result)) {
		$name=$row->nev;
		$arr_forditok[$i][0]=$name;
		$arr_forditok[$i][2]=$row->id;
		$arr_forditok[$i][3]=$row->extra;

		switch (substr(strtolower($name), 0, 1)) {
			case "á": $arr_forditok[$i][1]="a"; break;
			case "é": $arr_forditok[$i][1]="e"; break;
			case "í": $arr_forditok[$i][1]="i"; break;
			case "ó": $arr_forditok[$i][1]="o"; break;
			case "õ": $arr_forditok[$i][1]="ö"; break;
			case "ú": $arr_forditok[$i][1]="u"; break;
			case "û": $arr_forditok[$i][1]="ü"; break;
			default: $arr_forditok[$i][1]=substr(strtolower($name), 0, 1);
		}
		for ($j=0; $j<count($diphthongs); $j++) {
			if (substr(strtolower($name), 0, 2)==$diphthongs[$j])
				$arr_forditok[$i][1]=substr(strtolower($name), 0, 2);
		}
		if (substr(strtolower($name), 0, 3)=="dzs")
			$arr_forditok[$i][1]=substr(strtolower($name), 0, 3);

		$i++;
	}

	usort($arr_forditok, "sort_multidimension_hungarian");
/*
print("<pre>");
	print_r($arr_forditok);
print("</pre>");
*/

return $arr_forditok;

}




function hungarian($string) {
	$string=strtolower($string);
	$string=str_replace("á", "a", $string);
	$string=str_replace("é", "e", $string);
	$string=str_replace("í", "i", $string);
	$string=str_replace("ó", "o", $string);
	$string=str_replace("õ", "ö", $string);
	$string=str_replace("ú", "u", $string);
	$string=str_replace("û", "ü", $string);
	$string=str_replace("ö", "ozzz", $string);
	$string=str_replace("ü", "uzzz", $string);
	$string=str_replace("cs", "czz", $string);
	$string=str_replace("zs", "zzz", $string);
	$string=str_replace("gy", "gzz", $string);
	$string=str_replace("ly", "lzz", $string);
	$string=str_replace("ny", "nzz", $string);
	$string=str_replace("ty", "tzz", $string);
	return $string;
}


function sort_multidimension_hungarian($a, $b) {
	if (hungarian($a[0]) == hungarian($b[0])) return 0;
	if (hungarian($a[0]) < hungarian($b[0])) return -1;
	return 1;
}



function letter_title($letter) {

	$letter_title=ucwords($letter);
	switch ($letter_title) {
		case "A": $letter_title="A, Á"; break;
		case "E": $letter_title="E, É"; break;
		case "I": $letter_title="I, Í"; break;
		case "O": $letter_title="O, Ó"; break;
		case "Ö": $letter_title="Ö, Õ"; break;
		case "U": $letter_title="U, Ú"; break;
		case "Ü": $letter_title="Ü, Û"; break;
		case "0": $letter_title="0&#150;9"; break;
	}
	return $letter_title;

} // end function



function all_letter() {

    $all_letter = array("0", "a", "b", "c", "cs", "d", "dz", "dzs", "e", "f", "g", "gy", "h", "i", "j", "k", "l", "ly", "m", "n", "ny", "o", "p", "q", "r", "s", "sz", "t", "ty", "u", "v", "w", "x", "y", "z", "zs");
    return $all_letter;

}




function pl_roman_sort($result) {

	$i=0;
	while ($row=mysql_fetch_object($result)) {
		$name=$row->nev;
		$arr_megye[$i][0]=$name;
        $arr_megye[$i][1]=substr(strtolower($name), 0, 1);
		$arr_megye[$i][2]=$row->id;

		$i++;
	}

	usort($arr_megye, "sort_multidimension_roman");
/*
print("<pre>");
	print_r($arr_megye);
print("</pre>");
*/

return $arr_megye;


}



function roman($string) {

	//$string=strtoupper($string);
	$string=str_replace("Budapest I.",      "1", $string);
	$string=str_replace("Budapest II.",     "2", $string);
	$string=str_replace("Budapest III.",    "3", $string);
	$string=str_replace("Budapest IV.",     "4", $string);
	$string=str_replace("Budapest V.",      "5", $string);
	$string=str_replace("Budapest VI.",     "6", $string);
	$string=str_replace("Budapest VII.",    "7", $string);
	$string=str_replace("Budapest VIII.",   "8", $string);
	$string=str_replace("Budapest IX.",     "9", $string);
	$string=str_replace("Budapest X.",      "10", $string);

	$string=str_replace("Budapest XI.",     "11", $string);
	$string=str_replace("Budapest XII.",    "12", $string);
	$string=str_replace("Budapest XIII.",   "13", $string);
	$string=str_replace("Budapest XIV.",    "14", $string);
	$string=str_replace("Budapest XV.",     "15", $string);
	$string=str_replace("Budapest XVI.",    "16", $string);
	$string=str_replace("Budapest XVII.",   "17", $string);
	$string=str_replace("Budapest XVIII.",  "18", $string);
	$string=str_replace("Budapest XIX.",    "19", $string);
	$string=str_replace("Budapest XX.",     "20", $string);

    $string=str_replace("Budapest XXI.",    "21", $string);
	$string=str_replace("Budapest XXII.",   "22", $string);
	$string=str_replace("Budapest XXIII.",  "23", $string);

	return $string;
}


function sort_multidimension_roman($a, $b) {
	if (roman($a[0]) == roman($b[0])) return 0;
	if (roman($a[0]) < roman($b[0])) return -1;
	return 1;
}








function pl_doc_sort($result) {

	$i=0;
	while ($row=mysql_fetch_object($result)) {
		$name=$row->cim;
		$arr_doc[$i][0]=$name;
        $arr_doc[$i][1]=substr(strtolower($name), 0, 1);
		$arr_doc[$i][2]=$row->id;

		$i++;
	}

	usort($arr_doc, "sort_multidimension_hungarian");
/*
print("<pre>");
	print_r($arr_doc);
print("</pre>");
*/

return $arr_doc;


}


?>
