///////////////////////////////////////////////////////////////////////////////
//
// Class isoStringUtils
//
function isoStringUtils()
{
	// Constructor of the isoStringUtils class
	this.normalizeTable1 = new Array(
		new Array(0x0041, 0x005a, 0x0061, 0x007a),
		new Array(0x00c0, 0x00c5, 0x0061, 0x0061),
		new Array(0x00c7, 0x00c7, 0x0063, 0x0063),
		new Array(0x00c8, 0x00cb, 0x0065, 0x0065),
		new Array(0x00cc, 0x00cf, 0x0069, 0x0069),
		new Array(0x00d0, 0x00d0, 0x0064, 0x0064),
		new Array(0x00d1, 0x00d1, 0x006e, 0x006e),
		new Array(0x00d2, 0x00d6, 0x006f, 0x006f),
		new Array(0x00d8, 0x00d8, 0x006f, 0x006f),
		new Array(0x00d9, 0x00dc, 0x0075, 0x0075),
		new Array(0x00dd, 0x00dd, 0x0079, 0x0079),
		new Array(0x00e0, 0x00e5, 0x0061, 0x0061),
		new Array(0x00e7, 0x00e7, 0x0063, 0x0063),
		new Array(0x00e8, 0x00eb, 0x0065, 0x0065),
		new Array(0x00ec, 0x00ef, 0x0069, 0x0069),
		new Array(0x00f0, 0x00f0, 0x0064, 0x0064),
		new Array(0x00f1, 0x00f1, 0x006e, 0x006e),
		new Array(0x00f2, 0x00f6, 0x006f, 0x006f),
		new Array(0x00f8, 0x00f8, 0x006f, 0x006f),
		new Array(0x00f9, 0x00fc, 0x0075, 0x0075),
		new Array(0x00fd, 0x00fd, 0x0079, 0x0079),
		new Array(0x00ff, 0x00ff, 0x0079, 0x0079)
	);
	
	this.normalizeTable2 = new Array(
		new Array(0x0100, 0x0105, 0x0061, 0x0061),
		new Array(0x0106, 0x010d, 0x0063, 0x0063),
		new Array(0x010e, 0x0111, 0x0064, 0x0064),
		new Array(0x0112, 0x011b, 0x0065, 0x0065),
		new Array(0x011c, 0x0123, 0x0067, 0x0067),
		new Array(0x0124, 0x0127, 0x0068, 0x0068),
		new Array(0x0128, 0x0131, 0x0069, 0x0069),
		new Array(0x0134, 0x0135, 0x006a, 0x006a),
		new Array(0x0136, 0x0138, 0x006b, 0x006b),
		new Array(0x0139, 0x0142, 0x006c, 0x006c),
		new Array(0x0143, 0x014b, 0x006e, 0x006e),
		new Array(0x014c, 0x0151, 0x006f, 0x006f),
		new Array(0x0154, 0x0159, 0x0072, 0x0072),
		new Array(0x015a, 0x0161, 0x0073, 0x0073),
		new Array(0x0162, 0x0167, 0x0074, 0x0074),
		new Array(0x0168, 0x0173, 0x0075, 0x0075),
		new Array(0x0174, 0x0175, 0x0077, 0x0077),
		new Array(0x0176, 0x0178, 0x0079, 0x0079),
		new Array(0x0179, 0x017e, 0x007a, 0x007a)
	);

	this.normalizeTable3 = new Array(
		new Array(0x0386, 0x0386, 0x03b1, 0x03b1),
		new Array(0x0388, 0x0388, 0x03b5, 0x03b5),
		new Array(0x0389, 0x0389, 0x03b7, 0x03b7),
		new Array(0x038a, 0x038a, 0x03b9, 0x03b9),
		new Array(0x038c, 0x038c, 0x03bf, 0x03bf),
		new Array(0x038e, 0x038e, 0x03c5, 0x03c5),
		new Array(0x038f, 0x038f, 0x03c9, 0x03c9),
		new Array(0x0390, 0x0390, 0x03b9, 0x03b9),
		new Array(0x0391, 0x03a1, 0x03b1, 0x03c1),
		new Array(0x03a3, 0x03a9, 0x03c3, 0x03c9),
		new Array(0x03aa, 0x03aa, 0x03b9, 0x03b9),
		new Array(0x03ab, 0x03ab, 0x03c5, 0x03c5),
		new Array(0x03ac, 0x03ac, 0x03b1, 0x03b1),
		new Array(0x03ad, 0x03ad, 0x03b5, 0x03b5),
		new Array(0x03ae, 0x03ae, 0x03b7, 0x03b7),
		new Array(0x03af, 0x03af, 0x03b9, 0x03b9),
		new Array(0x03b0, 0x03b0, 0x03c5, 0x03c5),
		new Array(0x03c2, 0x03c2, 0x03c3, 0x03c3),
		new Array(0x03ca, 0x03ca, 0x03b9, 0x03b9),
		new Array(0x03cb, 0x03cb, 0x03c5, 0x03c5),
		new Array(0x03cc, 0x03cc, 0x03bf, 0x03bf),
		new Array(0x03cd, 0x03cd, 0x03c5, 0x03c5),
		new Array(0x03ce, 0x03ce, 0x03c9, 0x03c9),
		new Array(0x03d0, 0x03d0, 0x03b2, 0x03b2),
		new Array(0x03d1, 0x03d1, 0x03b8, 0x03b8),
		new Array(0x03d2, 0x03d2, 0x03c5, 0x03c5),
		new Array(0x03d3, 0x03d3, 0x03c5, 0x03c5),
		new Array(0x03d4, 0x03d4, 0x03c5, 0x03c5),
		new Array(0x03d5, 0x03d5, 0x03c6, 0x03c6),
		new Array(0x03d6, 0x03d6, 0x03c0, 0x03c0),
		new Array(0x03e2, 0x03e2, 0x03e3, 0x03e3),
		new Array(0x03e4, 0x03e4, 0x03e5, 0x03e5),
		new Array(0x03e6, 0x03e6, 0x03e7, 0x03e7),
		new Array(0x03e8, 0x03e8, 0x03e9, 0x03e9),
		new Array(0x03ea, 0x03ea, 0x03eb, 0x03eb),
		new Array(0x03ec, 0x03ec, 0x03ed, 0x03ed),
		new Array(0x03ee, 0x03ee, 0x03ef, 0x03ef)
	);
}

isoStringUtils.prototype.normalizeCode = function(code, table)
{
	for(var i=0; i < table.length; i++) {
		var row = table[ i ];
		if(code >= row[0] && code <= row[1]) {
			if(row[2] == row[3]) return row[2];
			return row[2] + code - row[0];
		}
	}
	return code;
}

isoStringUtils.prototype.normalizeString = function( str )
{
	var res = "";
	for(var i=0; i < str.length; i++) {
		var code = str.charCodeAt(i);
		if(code >= 0x41 && code <= 0xff) {
			code = this.normalizeCode(code, this.normalizeTable1) ;
		} else if(code >= 0x100 && code <= 0x017e) {
			code = this.normalizeCode(code, this.normalizeTable2) ;
		} else if(code >= 0x386 && code < 0x3ef) {
			code = this.normalizeCode(code, this.normalizeTable3);
		}
		res += String.fromCharCode(code);
	}
	return res ;
}

isoStringUtils.prototype.htmlEntities = function( str, preserve )
{
	if ( preserve == null ) preserve = "'" ;
	if ( preserve != "\"" ) preserve = "'" ;
	str = str.replace(/&/g, "&amp;" ) ;
	str = str.replace(/</g, "&lt;" ) ;
	str = str.replace(/>/g, "&gt;" ) ;
	if ( preserve == "'" ) str = str.replace(/\"/g, "&quot;" ) ;
	else str = str.replace(/'/g, "&apos;" ) ;
	return str ;
}

//	-------------------------------------------------------------------------
//	Escaping of string
//	Parameters :
//      	- s1: the string to escape
//      	- s2: escaped characters
//	Returns : Escaped string
//	-------------------------------------------------------------------------
isoStringUtils.prototype.hexagit = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
isoStringUtils.prototype.escape = function(s1, s2)
{
	if((s2 == null) || (s2 == "")) return escape(s1);
	s2 += "%";
	var codes = new Object();
	var search = "[";
	var done = new Object();
	for(var i=0;i<s2.length;i++) {
		var l = s2.substr(i, 1);
		if(done[l]) continue;
		done[l] = 1;
		var c = l.charCodeAt(0);
		var h;
		if(c < 256) {
			h = this.hexagit[(c >> 4) & 0xf] + this.hexagit[c & 0xf];
			search += "\\x" + h;
			codes[l] = "%" + h;
		} else {
			h = this.hexagit[(c >> 12) & 0xf] + this.hexagit[(c >> 8) & 0xf] + this.hexagit[(c >> 4) & 0xf] + this.hexagit[c & 0xf];
			search += "\\u" + h;
			codes[l] = "%u" + h;
		}
		var letter = String.fromCharCode(c);
		if("\\$^*+?.[(".indexOf(letter) >=0) letter = "\\" + letter;
	}
	search += "]";
	var regexp = new RegExp(search);
	var text = s1;
	var array = regexp.exec(text);
	var res = "";
	var lastPos = 0;
	while(array != null && array.index >= 0) {
		if(array.index > 0) res += text.substr(0, array.index);
		var l = array[0];
		text = text.substr(array.index + l.length);
		var value = codes[l];
		if(value != null) {
			res += value;
		} else {
			res += l;
		}
		array = regexp.exec(text);
		//break;
	}
	res += text;
	return res;
}

var objStringUtils = new isoStringUtils();

///////////////////////////////////////////////////////////////////////////////

