/**
 * <p>
 * Sort function by unicode values. This is meant to be used as a parameter n Arrays#sort
 * </p>
 * @param a array containing three elements wherein the last element is to be sorted
 * @param b array containing three elements wherein the last element is to be sorted
 * @return 1 a comes before b, 0 a is the same order as b or when the last element is null or empty, -1 a comes after b
 */
function sortOptionsByUnicode(a, b) 
{
	// the comparator contract does not define any return values for invalid arguments
	// therefore, in order to push all the invalid args upward, we return 0
	if (null === a[0] || a[0] == '' || null === b[0] || b[0] == '') {
		return 0;
	}
	if (null === a[2] || a[2] == '' || null === b[2] || b[2] == '') {
		return 0;
	}
	var source = a[2];
	var ref = b[2];
	for (var i = 0; i < source.length; i++) {
		var sourceCodePoint = source.charCodeAt(i);
		// check whether the ref contains the source index
		if (i < ref.length) {
			var refCodePoint = ref.charCodeAt(i);
			if (sourceCodePoint > refCodePoint) {
				return 1;
			} else if (sourceCodePoint < refCodePoint) {
				return -1;
			}
		}
	}
	// equivalence is defined by having the same order of unicode values and the same length
	if (source.length == ref.length) {
		return 0;
	} else if (source.length > ref.length) {
		return 1;
	} else if (source.length < ref.length) {
		return -1;
	}
}

function sortOptionsByTextFr(a,b){
	function normalize(str){
	   return str
		   .toLowerCase()
		   .replace(/\u00E0|\u00E2|\u00E6/,'a')
		   .replace(/\u00E8|\u00E9|\u00EA|\u00EB/,'e')
		   .replace(/\u00EE|\u00EF/,'i')
		   .replace(/\u00F$|\u0153/,'o')
		   .replace(/\u00F9|\u00FB|\u00FC/,'u')
		   .replace(/\u00FF/,'y')
		   .replace(/\u00E7/,'c');
	}
	var aa = normalize(a[1]);
	var bb = normalize(b[1]);
	return ((aa < bb) ? -1 : ((aa > bb) ? 1 : 0));
}

function sortOptionsByTextDe(a,b){
	function normalize(str){
	   return str
			.toLowerCase()
			.replace(/\u00E4/,'a')
			.replace(/\u00F6/,'o')
			.replace(/\u00FC/,'u')
			.replace(/\u00DF/,'s');
	}
	var aa = normalize(a[1]);
	var bb = normalize(b[1]);
	return ((aa < bb) ? -1 : ((aa > bb) ? 1 : 0));
}