// Esker.js
// English-to-Esker translation utility

/*
YUOR do AKS =

""May I assume that you hold 2.9 Billion of the 20.99 Million outstanding shares of SCOX then?""

YUOR am TRY for TRIKC ESKER in to REVEALE hes ULTRA SECRET METHODE and
CONSEPTS of MEGA STOCKES INFVESTEING for FREEE?????? ??????????

HAR!!!!!  HAR!!!!!  HAR!!!!!  ITS SO NICE TRY!!!!!!

IF yuor WANA LEAERN SO = yuo MSUT GO to ""EXSCLUSIFE ESKERS MEGA SEMINNAR
of ESKERS STOKC MAGICS TRUETH"" its COMEING TO YUOR CITEY MUCH SOON NOW
dont MISSS IT!!!!!
*/

/*
Each word has a 50% of becoming capitalized.
CK has 50% chance of becoming KC
Double consonants become triple consonants.
Each S-form plural has a 50% chance of becoming ES.
YOU becomes YUO, YOUR becomes YUORS.
C (unaccompanied by K) has a 50% chance of becoming S.
*/

function En2Esk() {
	var sText1 = document.text.original.value.toLowerCase();
	var sText2 = "";
		
	bCapitalize = Math.floor(Math.random()*2);
	for (var i=0; i < sText1.length; i++) {
		var cur_char = sText1.charAt(i);
		var next_char = sText1.charAt(i+1);
		var new_text = "";
		
		if ((sText1.substr(i, 5) == " was " || sText1.substr(i, 5) == " are ") && Math.floor(Math.random()*5) == 0) {
			new_text = " = "
			i += 4;
		} else if ((sText1.substr(i, 4) == " is " || sText1.substr(i, 4) == " am " || sText1.substr(i, 4) == " be ") && Math.floor(Math.random()*5) == 0) {
			new_text = " = "
			i += 3;
		} else if (cur_char == " " || cur_char == "\n" || cur_char == "\t") {
			bCapitalize = Math.floor(Math.random()*2);
			new_text = cur_char;
		} else if (cur_char == "c" && next_char == "k" && Math.floor(Math.random()*2) == 0) {
			new_text = "kc";
			i++;
		} else if (sText1.substr(i, 4) == "scox") {
			new_text = "SCOXES";
			i += 3;
		} else if (sText1.substr(i, 5) == "linux") {
			new_text = "LIE-NUX";
			i += 4;
		} else if (sText1.substr(i, 4) == "the ") {
			new_text = "teh ";
			i += 3;
		} else if (sText1.substr(i, 3) == "you") {
			new_text = "yuo";
			if (sText1.substr(i+3, 1) == " ") {
				if (Math.floor(Math.random()*2) == 0)
					new_text += "r";
				if (Math.floor(Math.random()*2) == 0)
					new_text += " am";
			}
			i += 2;
		} else if (cur_char == next_char && Math.floor(Math.random()*2) == 0) {
			new_text = cur_char + cur_char;
		} else if (cur_char == "x" && next_char == "c" && Math.floor(Math.random()*2) == 0) {
			new_text = cur_char + "s";
			i++;
		} else if (cur_char == "t" && next_char == "h" && Math.floor(Math.random()*2) == 0) {
			new_text = "ht";
			i++;
		} else if (cur_char == "e" && next_char == " " && Math.floor(Math.random()*5) == 0) {
			new_text = cur_char + "s";
		} else if (cur_char == "y" && Math.floor(Math.random()*2) == 0) {
			if (Math.floor(Math.random()*2) == 0)
				new_text = "ie";
			else
				new_text = "ee";
		} else if ((cur_char == "a" || cur_char == "e" || cur_char == "i" || cur_char == "o" || cur_char == "u") && Math.floor(Math.random()*20) == 0) {
			// Drop the a few vowels here and there.
		} else if ((cur_char == "a" || cur_char == "e" || cur_char == "i" || cur_char == "o" || cur_char == "u") && next_char == "r" && Math.floor(Math.random()*2) == 0) {
			new_text = "a";
		} else if (cur_char == "?") {
			var k = Math.floor(Math.random()*10)+1;
			for (var j = 0; j < k; j++)
				new_text += "?";
		} else if (cur_char == "." || cur_char == "!") {
			var k = Math.floor(Math.random()*10)+1;
			for (var j = 0; j < k; j++)
				new_text += "!";
				
			if (Math.floor(Math.random()*5) == 0) {
				//k = Math.floor(Math.random()*5)+1;
				//for (var j = 0; j < k; j++)
				//	new_text += " HAR";
					
				//k = Math.floor(Math.random()*10)+1;
				//for (var j = 0; j < k; j++)
				//	new_text += "!";
				new_text += " HAR!!!! HAR!!!! HAR!!!!";
			}
		} else if (cur_char == "," || cur_char == ";" || cur_char == "'" || cur_char == ":") {
			// Needless punctuation. Get rid of it!
		} else if (next_char > "a" && next_char < "b" && Math.floor(Math.random()*10) == 0) {
			new_text = next_char + cur_char;
			i++;
		} else {
			new_text = cur_char;
		}
		
		if (bCapitalize)
			sText2 += new_text.toUpperCase();
		else
			sText2 += new_text;
	}
	
	document.text.translated.value = sText2;
}
 

