var vkb = null;
var flag=0;

function HideKeyboardOnTab(){
	var intKBStatus = document.getElementById('kb_status');
	if(intKBStatus.value == '2')
	{
		intKBStatus.value = "1";
		vkb.Show(false);
		vkb = null;
	}
}

function ToggleKeyboard()
{
	var intKBStatus = document.getElementById('kb_status');//wheather keyboard.gif clicked
	switch(intKBStatus.value)
	{
		case "1":
			intKBStatus.value = "2";
			ShowKB();
			break;
		case "2":
			intKBStatus.value = "1";
			vkb.Show(false);
			vkb = null;
			break;
	}
}

function ShowKB()
{
var lang = document.getElementById('langCode').value;
if (vkb)
{
	vkb.Show(false);
}
//var keyBoardDiv = $(".tab_content:last");
$('#keyboardPlaceHolder').html('');
vkb =
    new VKeyboard("keyboardPlaceHolder",   // container's id, mandatory
                  keyb_callback,// reference to callback function, mandatory
                                // (this & following parameters are optional)
                  false,         // create the arrow keys or not?
                  false,         // create up and down arrow keys?
                  false,        // reserved
                  false,         // create the numpad or not?
                  "",           // font name ("" == system default)
                  "14px",       // font size in px
                  "#000",       // font color
                  "#F00",       // font color for the dead keys
                  "#FFF",       // keyboard base background color
                  "#FFF",       // keys' background color
                  "#DDD",       // background color of switched/selected item
                  "#777",       // border color
                  "#CCC",       // border/font color of "inactive" key
                                // (key with no value/disabled)
                  "#FFF",       // background color of "inactive" key
                                // (key with no value/disabled)
                  "#F77",       // border color of language selector's cell
                  true,         // show key flash on click? (false by default)
                  "#CC3300",    // font color during flash
                  "#FF9966",    // key background color during flash
                  "#CC3300",    // key border color during flash
                  false,        // embed VKeyboard into the page?
                  true,         // use 1-pixel gap between the keys?
                  lang);
				  
	vkb.Show(true);
}
//ba harbar zadane har key een faal mishe
function keyb_callback(ch)
{
	// Let's bind vkeyboard to the <TEXTAREA>

	// with id="textfield":
	var active_input_id = $("div.tab_content.active form input.keyword").attr('id');
	if(flag==0){
		$(active_input_id).css("color","#000");
	}
	var name_1 = active_input_id;
    var text = document.getElementById(name_1 ), val = text.value;
	if(text.value == 'نام استاد مورد نظر خود را تایپ کنید ...' || text.value== 'نام دانشگاه مورد نظر خود را تایپ کنید ...') text.value = ''	;
    switch(ch)
    {
        case "BackSpace":
			var min=(val.charCodeAt(val.length - 1) == 10) ? 2 : 1;
			text.value = val.substr(0, val.length - min);
			ajaxSuggestions(text.value);
        break;

       case "Enter":
	   		$(".tab_content.active form").submit();
			//document.getElementById('sendForm').submit();
            break;

       default:
           text.value += ch;		switch(active_input_id){			case "search_uni_kw":				ajaxSuggestions(text.value);				break;							case "search_ostad_kw":				ajaxSuggestions2(text.value);		}
		   
    }
	
}