/*

String.toSafeChars() (version 1.2) by Riki "Fczbkk" Fridrich, 2004
http://www.fczbkk.com/, mailto:riki@fczbkk.com

Tento skript mozes volne pouzit a modifikovat bez povolenia.
Budem rad, ak mi o tom das vediet, pripadne mi posles URL stranky, kde
ho pouzivas. Ak sa ti podari ho nejako vylepsit, rozsirit alebo v nom
najdes a opravis nejaku chybu, budem ti vdacny, ak ma o tom budes informovat.

Aktualnu verziu tohto skriptu vzdy najdes na adrese:
http://www.fczbkk.com/js/tosafechars/

Dakujem Nailerovi (http://nailer.deejays.cz/) za cenne rady a pripomienky.

*/

if (!String.toSafeChars) {
	String.prototype.toSafeChars = function() {

		// zaciatok hacku pre IE50
		var ie50hack1 = ((typeof(RegExp.index) != "undefined") && (typeof(RegExp.input) == "undefined"));

		var badChars =		"áâäăąçćčďđéëęěíîĺľłńňóôöőŕřśşšţťúüůűýźżž";
		var goodChars =	"aaaaacccddeeeeiilllnnoooorrsssttuuuuyzzz";
		
		badChars = badChars + badChars.toUpperCase();
		goodChars = goodChars + goodChars.toUpperCase();
		
		var newString = this;
		
		// medzery a pomlcky nahradime podtrzitkami
		var re = new RegExp("[ \f\n\r\t]", "g");
		newString = newString.replace(re, "_");
		
		// nahradime diakritiku znakmi bez diakritiky
		var re = new RegExp("[^A-Za-z0-9_]", "g");
		
		var replaceChars = function(a, b, c) {
			
			// specialne znaky
			if (
				(a == "\\")	||
				(a == "\^")
			)
			{return "_";}

			var re = new RegExp("[" + a + "]");
			var charPosition = badChars.search(re);
			return (charPosition > -1) ? goodChars.charAt(charPosition) : "_";
		};
		
		// pokracovanie hacku pre IE50
		var ie50hack2 = ((typeof(RegExp.index) != "undefined") && (typeof(RegExp.input) == "undefined"));
		if (ie50hack1 != ie50hack2) {
			replaceChars = "_";
		}
		
		newString = newString.replace(re, replaceChars);
		
		// precistenie podtrzitiek (zaciatok, koniec a viacnasobne)
		var re = new RegExp("_{2,}", "g");
		newString = newString.replace(re, "_");

		var re = new RegExp("^_|_$", "g");
		newString = newString.replace(re, "");
		
		return newString;

	}
}

		

