var VK_CONTROL= 0x100;
var VK_ALT	= 0x400;
var KEY_UP 	= 0x26;
var KEY_DOWN 	= 0x28;
var KEY_LEFT	= 0x25;
var KEY_RIGHT	= 0x27;
var KEY_BACK 	= 0x79;
var KEY_HOME 	= 0x78;
var KEY_MENU	= 0x7b;
var KEY_WWW	= 0x73;
var KEY_TV	= 0x72;
var KEY_HELP	= 0x70;
var KEY_OK    = 0x7a;
var KEY_TEXT  = 0x71;
var KEY_LIST	= KEY_HOME | VK_CONTROL;

var KEY_CHUP	= KEY_UP   | VK_ALT;
var KEY_CHDN	= KEY_DOWN | VK_ALT;

var KEY_PGUP	= KEY_UP   | VK_CONTROL;
var KEY_PGDN	= KEY_DOWN | VK_CONTROL;

var KEY_RED	= 0x74;
var KEY_GREEN	= 0x75;
var KEY_YELLOW= 0x76;
var KEY_BLUE	= 0x77;

var KEY_PLAY	= 0x74 | VK_ALT;
var KEY_PAUSE	= 0x77 | VK_ALT;
var KEY_PLAYPAUSE=0x74 | VK_CONTROL;
var KEY_STOP	= 0x77 | VK_CONTROL;
var KEY_FWD	= 0x76 | VK_CONTROL;
var KEY_RWD	= 0x75 | VK_CONTROL;

//var KEY_FRWD= KEY_LEFT  | VK_ALT;
//var KEY_FFWD= KEY_RIGHT | VK_ALT;
var KEY_FRWD	= -10;
var KEY_FFWD	= -20;

var KEY_VOLUP	= 0x72 | VK_CONTROL;
var KEY_VOLDN	= 0x71 | VK_CONTROL;
var KEY_MUTE	= 0x73 | VK_CONTROL;

var KEY_0	= 0x30;
var KEY_1	= 0x31;
var KEY_2	= 0x32;
var KEY_3	= 0x33;
var KEY_4	= 0x34;
var KEY_5	= 0x35;
var KEY_6	= 0x36;
var KEY_7	= 0x37;
var KEY_8	= 0x38;
var KEY_9	= 0x39;

var cCursor = "|&nbsp;&nbsp;&nbsp;";

var arrKeys = [
	["0"," ",".",",",":",";","(",")","_","=","-",""],
	["1","/","!","*","@","#","$","%","\\",""],
	["a","b","c","2","A","B","C",""],
	["d","e","f","3","D","E","F",""], 
	["g","h","i","4","G","H","I",""],
	["j","k","l","5","J","K","L",""],
	["m","n","o","6","M","N","O",""],
	["p","q","r","s","7","P","Q","R","S",""],
	["t","u","v","8","T","U","V",""],
	["w","x","y","z","9","W","X","Y","Z",""]
];

function CharInput_ClearLastKey(cItem) {
	iLastKeyChar = -1;
	document.getElementById(cItem + "_Info").innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}

function CharInput_KeyDown(cItem, keyChar) {
	var cTemp;
	var cTemp2;
	switch (keyChar) {
	case KEY_UP:
	case KEY_DOWN:
	case KEY_RIGHT:
		return 0;
	case KEY_0: case KEY_1:
	case KEY_2: case KEY_3:
	case KEY_4: case KEY_5:
	case KEY_6: case KEY_7:
	case KEY_8: case KEY_9:
		if (lTimerKeyChar != null) {
			clearTimeout(lTimerKeyChar);
			lTimerKeyChar = null;
		}
		cTemp = document.getElementById(cItem + "_Valor").innerHTML;
		if (keyChar != iLastKeyChar) {
			iLastKeyChar = keyChar;
			cTemp = cTemp.slice(0,-cCursor.length);
			cTemp2 = "";
			for (iPosKeyChar = 0; arrKeys[iLastKeyChar - KEY_0][iPosKeyChar] != ""; iPosKeyChar++) {
				cTemp2 = cTemp2 + arrKeys[iLastKeyChar - KEY_0][iPosKeyChar] + "&nbsp;&nbsp;"
			}
			document.getElementById(cItem + "_Info").innerHTML = cTemp2 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			iPosKeyChar = 0;
		} else {
			cTemp = cTemp.slice(0,-cCursor.length-1);
			iPosKeyChar = iPosKeyChar + 1;
			if (arrKeys[iLastKeyChar - KEY_0][iPosKeyChar] == "") {
				iPosKeyChar = 0;
			}
		}
		cTemp = cTemp + arrKeys[iLastKeyChar - KEY_0][iPosKeyChar] + cCursor;
		lTimerKeyChar = setTimeout("CharInput_ClearLastKey('" + cItem + "')",1000);
		document.getElementById(cItem + "_Valor").innerHTML = cTemp;
		return 0;
	case KEY_RED:
		cTemp = document.getElementById(cItem + "_Valor").innerHTML;
		cTemp = cTemp.slice(0,-cCursor.length-1);
		document.getElementById(cItem + "_Valor").innerHTML = cTemp + cCursor;
		return 0;
	}
	return 1;
}

function NumberInput_KeyDown(cItem, keyChar) {
	var cTemp;
	var cTemp2;
	switch (keyChar) {
	case KEY_UP:
	case KEY_DOWN:
	case KEY_RIGHT:
		return 0;
	case KEY_0: case KEY_1:
	case KEY_2: case KEY_3:
	case KEY_4: case KEY_5:
	case KEY_6: case KEY_7:
	case KEY_8: case KEY_9:
		cTemp = document.getElementById(cItem + "_Valor").innerHTML;
		cTemp = cTemp.slice(0,-cCursor.length);
		cTemp = cTemp + (keyChar - KEY_0) + cCursor;
		document.getElementById(cItem + "_Valor").innerHTML = cTemp;
		return 0;
	case KEY_RED:
		cTemp = document.getElementById(cItem + "_Valor").innerHTML;
		cTemp = cTemp.slice(0,-cCursor.length-1);
		document.getElementById(cItem + "_Valor").innerHTML = cTemp + cCursor;
		return 0;
	}
	return 1;
}
