function StringUtil() {
}

StringUtil.getRecordTextWithoutUnit = function(value) {
	var number = Math.floor(value);
	return NumberUtil.numberWithCommas(number);
}

StringUtil.getRecordTextWithUnit = function(value) {
	var number = Math.floor(value);
	var numberWithCommas = NumberUtil.numberWithCommas(number);

	if(isTypingGame())
		return numberWithCommas + " 타";
	else
		return numberWithCommas + " 점";
}

StringUtil.getNumberStartWithZero = function(number, digitCount) {
	var n = number + '';
	return n.length >= digitCount ? n : new Array(digitCount - n.length + 1).join('0') + n;
}

StringUtil.toKoreanAlphabets = function(text) {
	var cCho = [ 'ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ' ];
	var cJung = [ 'ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ', 'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ' ];
	var cJong = [ '', 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ' ];

	var cho, jung, jong;
	var str = text;
	var cnt = str.length;
	var chars = [], cCode;

	for (var i = 0; i < cnt; i++) {
		cCode = str.charCodeAt(i);
		// if (cCode == 32) { continue; } // 한글이 아닌 경우
		if (cCode < 0xAC00 || cCode > 0xD7A3) {
			chars.push(str.charAt(i));
			continue;
		}
		cCode = str.charCodeAt(i) - 0xAC00;
		jong = cCode % 28; // 종성
		jung = ((cCode - jong) / 28 ) % 21; // 중성
		cho = (((cCode - jong) / 28 ) - jung ) / 21; // 초성

		chars.push(cCho[cho], cJung[jung]);
		if (cJong[jong] !== '') {
			chars.push(cJong[jong]);
		}
	}
	return chars;
};

StringUtil.getUnicodeKoreanAlphabetCount = function(text) {
	var chars = StringUtil.toKoreanAlphabets(text);
	// console.log('char : ' + chars);

	var doubleJaum = [
		'ㄲ', 'ㅉ', 'ㄸ', 'ㄲ', 'ㅆ',
		'ㄳ', 'ㄵ', 'ㄶ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅄ'
	];
	var doubleMoum = [
		'ㅒ', 'ㅖ',
		'ㅘ', 'ㅙ', 'ㅚ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅢ'
	];

	var alphabetCount = 0;
	var alphabet;
	for(var i = 0; i < chars.length; i++) {
		alphabet = chars[i];
		if(doubleJaum.indexOf(alphabet) > -1 || doubleMoum.indexOf(alphabet) > -1) {
			// console.log('double alphabet : ' + alphabet);
			alphabetCount += 2;
		}
		else
			alphabetCount++;
	}

	// return chars;
	return alphabetCount;
};

StringUtil.chosung = function(letter) {
	var alphabets = StringUtil.toKoreanAlphabets(letter);
	return alphabets[0];
}

StringUtil.jungsung = function(letter) {
	var alphabets = StringUtil.toKoreanAlphabets(letter);
	return alphabets[1];
}

StringUtil.hasJongsung = function(letter) {
	var alphabets = StringUtil.toKoreanAlphabets(letter);
	if(alphabets.length == 3)
		return true;

	return false;
};

StringUtil.jongsung = function(letter) {
	if(!StringUtil.hasJongsung(letter))
		return "";

	var alphabets = StringUtil.toKoreanAlphabets(letter);
	return alphabets[2];
}

StringUtil.isSameKoreanAlphabet = function(firstAlphabet, secondAlphabet) {
	if(firstAlphabet == secondAlphabet)
		return true;
	return false;
};

StringUtil.isMultiAlphabetJungsung = function(alphabet) {
	var cMultiJung = [ 'ㅘ', 'ㅙ', 'ㅚ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅢ' ];
	for(var i = 0; i < cMultiJung.length; i++) {
		if(cMultiJung[i] == alphabet)
			return true;
	}

	return false;
};

StringUtil.getMultiAlphabetFromJungsung = function(alphabet) {
	if(!StringUtil.isMultiAlphabetJungsung(alphabet))
		return alphabet;

	var multiJungsungList = new Object();
	multiJungsungList['ㅘ'] = ['ㅗ', 'ㅏ'];
	multiJungsungList['ㅙ'] = ['ㅗ', 'ㅐ'];
	multiJungsungList['ㅚ'] = ['ㅗ', 'ㅣ'];
	multiJungsungList['ㅝ'] = ['ㅜ', 'ㅓ'];
	multiJungsungList['ㅞ'] = ['ㅜ', 'ㅔ'];
	multiJungsungList['ㅟ'] = ['ㅜ', 'ㅣ'];
	multiJungsungList['ㅢ'] = ['ㅡ', 'ㅣ'];

	return multiJungsungList[alphabet];
};

StringUtil.isMultiAlphabetJongsung = function(alphabet) {
	var cMultiJong = [ 'ㄲ', 'ㄳ', 'ㄵ', 'ㄶ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅄ', 'ㅆ' ];
	for(var i = 0; i < cMultiJong.length; i++) {
		if(cMultiJong[i] == alphabet)
			return true;
	}

	return false;
};

StringUtil.getMultiAlphabetFromJongsung = function(alphabet) {
	if(!StringUtil.isMultiAlphabetJongsung(alphabet))
		return alphabet;

	var multiJongsungList = new Object();
	multiJongsungList['ㄲ'] = ['ㄱ', 'ㄱ'];
	multiJongsungList['ㄳ'] = ['ㄱ', 'ㅅ'];
	multiJongsungList['ㄵ'] = ['ㄴ', 'ㅈ'];
	multiJongsungList['ㄶ'] = ['ㄴ', 'ㅎ'];
	multiJongsungList['ㄺ'] = ['ㄹ', 'ㄱ'];
	multiJongsungList['ㄻ'] = ['ㄹ', 'ㅁ'];
	multiJongsungList['ㄼ'] = ['ㄹ', 'ㅂ'];
	multiJongsungList['ㄽ'] = ['ㄹ', 'ㅅ'];
	multiJongsungList['ㄾ'] = ['ㄹ', 'ㅌ'];
	multiJongsungList['ㄿ'] = ['ㄹ', 'ㅍ'];
	multiJongsungList['ㅀ'] = ['ㄹ', 'ㅎ'];
	multiJongsungList['ㅄ'] = ['ㅂ', 'ㅅ'];
	multiJongsungList['ㅆ'] = ['ㅅ', 'ㅅ'];

	return multiJongsungList[alphabet];
}

StringUtil.isSameKoreanAlphabet = function(firstAlphabet, secondAlphabet) {
	if(firstAlphabet == secondAlphabet)
		return true;

	return false;
};

StringUtil.isKoreanAlphabet = function(char) {
	c = char.charCodeAt(0);
	if(0x1100 <= c && c <= 0x11FF)
		return true;
	if(0x3130 <= c && c <= 0x318F)
		return true;
	if(0xAC00 <= c && c <= 0xD7A3)
		return true;

	return false;
};

StringUtil.getSyllableCount = function(text) {
	var count = 0;
	var textLen = text.length
	for(var i = 0; i < textLen; i++) {
		var unicodeLetter = text[i];
		if(StringUtil.isKoreanAlphabet(unicodeLetter))
			count += StringUtil.getUnicodeKoreanAlphabetCount(unicodeLetter);
		else
			count++;
	}

	// console.log(unicodeLetter + " count : " + count);
	return count;
};

StringUtil.getUnicodeAlphabetCount = function(text) {
	var count = 0;
	var textLen = text.length
	for(var i = 0; i < textLen; i++) {
		var unicodeLetter = text[i];
		if(StringUtil.isKoreanAlphabet(unicodeLetter))
			count += 2;
		else
			count++;
	}

	// console.log(unicodeLetter + " count : " + count);
	return count;
};

StringUtil.getMultibyteIndex = function(multibyteText, unicodeCharIndex) {
	var multibyteTextIndex = 0;
	var index = 0;
	while(index < unicodeCharIndex) {
		var unicodeChar = multibyteText[multibyteTextIndex];
		if(typeof unicodeChar == "undefined")
			break;

		if(StringUtil.isKoreanAlphabet(unicodeChar)) {
			if(index + 2 <= unicodeCharIndex)
				index += 2;
			else
				break;
		} else
			index += 1;

		multibyteTextIndex++;
	}

	return multibyteTextIndex;
};


StringUtil.getScoreUnit = function(playingAppID) {
	if(playingAppID == 104)
		return " 초";
	else if(playingAppID < 100)
		return " 타";
	else
		return " 점";
}