var RegionSites = {}; var FeatureSites = {}; siteCitiesSorted = []; $.each(siteCities, function(k, v) { siteCitiesSorted.push(k); }); function UTF8polishSort(a, b){ if( !(typeof a === "string") || !(typeof b === "string") ){ throw new Error("provide strings as arguments"); } var polZnaki = ["ą","ć","ę","ł","ń","ó","ś","ź","ż"]; var polZnakiLen = polZnaki.length; var pol = {"a":1,"ą":2,"b":3,"c":4,"ć":5,"d":6,"e":7,"ę":8,"f":9,"g":10,"h":11,"i":12,"j":13,"k":14,"l":15,"ł":16,"m":17,"n":18,"ń":19,"o":20,"ó":21,"p":22,"q":23,"r":24,"s":25,"ś":26,"t":27,"u":28,"v":29,"w":30,"x":31,"y":32,"z":33,"ź":34,"ż":35} var a = a.toLocaleLowerCase(); var b = b.toLocaleLowerCase(); var aLen = a.length; var bLen = b.length; var minLen = Math.min( aLen, bLen ); var shorterWins = aLen < bLen ? -1 : 1; var hasPolZnaki = false; var normalSort = []; for(var i = 0; i < polZnakiLen; i++){ if(a.indexOf( polZnaki[i] ) !== -1 || b.indexOf( polZnaki[i] ) !== -1){ hasPolZnaki = true; break; } } if( !hasPolZnaki ){ normalSort = [a,b].sort(); //FIX this with localecompare if( normalSort[0] === a ){ return -1; } else { return 1; } } for( var i = 0; i < minLen; i++ ){ if ( pol[a.charAt(i)] < pol[b.charAt(i)] ){ return -1; } else if ( pol[a.charAt(i)] > pol[b.charAt(i)] ){ return 1; } else if ( (a.charAt(i) === b.charAt(i)) ){ continue; } else if ( pol[a.charAt(i)] === undefined || pol[b.charAt(i)] === undefined ){ if ( a.charAt(i).localeCompare( b.charAt(i) ) < 0 ){ return -1; } else if( a.charAt(i).localeCompare( b.charAt(i) ) > 0 ){ return 1; } else { continue; } } } return shorterWins; } var sortUTF = function(a, b) { if (typeof a === 'string' && typeof b === 'string') { return a.localeCompare(b); } }; if (navigator.userAgent.indexOf('Chrome') > -1){ siteCitiesSorted.sort(UTF8polishSort); } else { siteCitiesSorted.sort(sortUTF); } //for (i=0; i' + siteCitiesSorted[i] + ''); //}