// JavaScript Document

var arr_skeys  = new Array('1','2','3','4','5','6','7','8','9','0','`',',','.','/','-','=','\\','[',']',';');
var arr_ckeys  = new Array('!','@','#','$F','%','^','&','*','(',')','~','<','>','?','_','+','|','{','}',':');
var arr_dckeys = new Array('!','@','#','$F','%','^','&amp;','*','(',')','~','&lt;','&gt;','?','_','+','|','{','}',':');

function $F(o)
{
	return document.getElementById(o);
}

var rander = function(){return Math.random()-.5}

function inputkey(key)
{
	$F(inputbox).value += key;
}

function backkey()
{
	$F(inputbox).value = $F(inputbox).value.substr(0,$F(inputbox).value.length - 1);
}

function skeyevent(obj,type)
{
	if(type == 'down')obj.className = 'keydown';
	if(type == 'up')obj.className = 'key';
}

function bkeyevent(obj,type)
{
	if(type == 'down')obj.className = 'ckeydown';
	if(type == 'up')obj.className = 'ckey';
}

function ShowKeyBoard()
{
	bln_isLoaded = true;
	$F('keyboard').innerHTML = '<div id="mkeyboard"></div><div id="bkeyboard" style="display:none"></div><div class="backkey" onmousedown="this.className=\'backkey_down\'" onmouseup="this.className=\'backkey\'" onclick="backkey()">退格</div><div class="backkey" onclick="changStatus(this)" >Shift</div><div class="closekeyboard" onclick="closeKeyboard()" >关闭键盘</div>';
	var obj_list = obj_get_obj_position($F(inputbox), keyboard_x, keyboard_y);
	$F('keyboard').style.left = obj_list.y;
	$F('keyboard').style.top  = obj_list.x;
	var arr_index = new Array();
	for(i=0;i<20;i++)arr_index.push(i);
	arr_index = arr_index.sort(rander);  
	//document.write(arr_index);
	//其他字符
	for(var c = 0 ; c < arr_index.length ; c ++){
//		document.write(arr_index[c]);
		$F('mkeyboard').innerHTML += '<div class="key" onmousedown="skeyevent(this,\'down\');" onmouseup="skeyevent(this,\'up\')" onclick="inputkey(this.tags)" tags="'+ arr_skeys[arr_index[c]] +'"><div class="sc">' + arr_skeys[arr_index[c]] + '</div><div class="gc">' + arr_dckeys[arr_index[c]] + '</div></div>';
		$F('bkeyboard').innerHTML += "<div class='key' onmousedown='skeyevent(this,\"down\")' onmouseup='skeyevent(this,\"up\")' onclick='inputkey(this.tags)' tags='" + arr_ckeys[arr_index[c]] +"'><div class='sc2'>" + arr_skeys[arr_index[c]] + '</div><div class="gc2">' + arr_dckeys[arr_index[c]] + '</div></div>';
	}
	//alert($F('keyboard').innerHTML);
	//字母
	var arr_chars = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
	var arr_index2 = new Array();
	for(i=0;i<26;i++)arr_index2.push(i);
	arr_index2 = arr_index2.sort(rander);

	for(var s = 0; s < arr_index2.length ; s++){
		$F('mkeyboard').innerHTML += '<div class="ckey" onmousedown="bkeyevent(this,\'down\');" onmouseup="bkeyevent(this,\'up\')" onclick="inputkey(\'' + arr_chars[arr_index2[s]] + '\')"><div class="cc">' + arr_chars[arr_index2[s]] + '</div></div>' ;
		$F('bkeyboard').innerHTML += '<div class="ckey" onmousedown="bkeyevent(this,\'down\');" onmouseup="bkeyevent(this,\'up\')" onclick="inputkey(\'' + arr_chars[arr_index2[s]].toUpperCase() + '\')"><div class="cc">' + arr_chars[arr_index2[s]].toUpperCase() + '</div></div>';
	}
}

function closeKeyboard()
{
	$F('keyboard').style.display = 'none';
}

function changStatus(obj)
{
	
	if($F('bkeyboard').style.display == 'none'){
		obj.className = 'backkey_down';
		$F('bkeyboard').style.display = '';
		$F('mkeyboard').style.display = 'none';
	}
	else{
		obj.className = 'backkey';
		$F('bkeyboard').style.display = 'none';
		$F('mkeyboard').style.display = '';
	}
}

function softkeyboard()
{
	$F('keyboard').style.display = $F('keyboard').style.display == '' ? 'none' : '';
}

/* 获取控件的位置，并返回添加偏移相对位置(top,left)后的绝对位置
 * 输入：obj_ctl 相对的控件
 * 输入: int_cx  要偏移的top值
 * 输入: int_cy  要便移的left值
 * 输出: 返回对象x,偏移以后的坐标top
 * 输出: 返回对象y,偏移以后的坐标left
 */
function obj_get_obj_position(obj_ctl,int_ctop,int_cleft)
{
	//获取控件绝对位置
	var int_ctl_top  = parseInt(int_ctop) + obj_ctl.offsetTop;
	var int_ctl_left = parseInt(int_cleft) + obj_ctl.offsetLeft;
	return{x:int_ctl_top,y:int_ctl_left}
}


