
var AgatOnScreenKeyboard={shifton:false,keyboardType:"hidden",capsLockOn:false,handleKeyboardSwitch:function(){if(AgatEngine.getGeneralAttribute("tfsOnScreenKeyboard").toLowerCase()!="yes"){return;}
if(AgatEngine.getWindowProperty("glbFocusedInput")==""){this.keyboardType="hidden";this.changeKeyboard("hidden");}
else{if(this.keyboardType=="hidden"){this.showKeyboard();}
var elem=$('#'+AgatEngine.getWindowProperty("glbFocusedInput"));if($(elem).hasAttribute("tfsdatatype")&&($(elem).attr("tfsdatatype").toLowerCase()=="idnum"||$(elem).attr("tfsdatatype").toLowerCase()=="decimal"||$(elem).attr("tfsdatatype").toLowerCase()=="numeric")){if(this.keyboardType!="numeric"){this.keyboardType="numeric";this.changeKeyboard("numeric");}}
else if($(elem).hasAttribute("tfsdatatype")&&$(elem).attr("tfsdatatype").toLowerCase()=="english"){if(this.keyboardType!="english"){this.keyboardType="english";this.changeKeyboard("english");}}
else{if(this.keyboardType!="standard"){this.keyboardType="standard";this.changeKeyboard("standard");}}}},hideKeyboard:function(){$('#keyboard').tfsHide();},showKeyboard:function(){$('#keyboard').tfsShow();},onShift:function(e){var i;var showedRowSuffix="";var hiddenRowSuffix="";if(this.keyboardType=="english"){showedRowSuffix="_eng";}
else{hiddenRowSuffix="_eng";}
if(e==1){for(i=0;i<4;i++){var rowid="#row"+i;$(rowid+showedRowSuffix).hide();$(rowid+hiddenRowSuffix).hide();$(rowid+"_shift").show();}}
else{for(i=0;i<4;i++){var rowid="#row"+i;$(rowid+showedRowSuffix).show();$(rowid+hiddenRowSuffix).hide();$(rowid+"_shift").hide();}
$("#row0_numeric").hide();$("#row0").show();$("#row4").show();}},changeKeyboard:function(type){if(type=="hidden"){this.hideKeyboard();}
var i;if(type=="numeric"){$("#row0_numeric").show();$("#row4").hide();for(i=0;i<4;i++){var rowid="#row"+i;$(rowid).hide();$(rowid+"_shift").hide();$(rowid+"_eng").hide();}}
else{this.onShift(0);}},handleKeyboardChar:function(KeyboardElem){if(AgatEngine.getWindowProperty("glbFocusedInput")!=""){var elem=$('#'+AgatEngine.getWindowProperty("glbFocusedInput"));}
else{return;}
if($(KeyboardElem).attr("name")=='keyboardChangeLang'){if(this.keyboardType=="english"){this.keyboardType="standard";this.changeKeyboard("standard");}
else{this.keyboardType="english";this.changeKeyboard("english");}}
else if($(KeyboardElem).val()=='Backspace'){this.replaceSelection("",true,elem);}
else if($(KeyboardElem).val()=="Shift"){if(this.shifton==false){this.onShift(1);this.shifton=true;}
else{this.onShift(0);this.shifton=false;}}
else if($(KeyboardElem).val()=="Capslock"){if(this.capLockOn==false){this.onShift(1);this.capLockOn=true;}
else{this.onShift(0);this.capLockOn=false;}}
else{this.replaceSelection($(KeyboardElem).val(),true,elem);if(this.shifton==true&&this.capsLockOn==false){this.onShift(0);this.shifton=false;}}
$(elem).trigger('keyup');},handleInputChange:function(id){if(AgatEngine.getGeneralAttribute("tfsOnScreenKeyboard").toLowerCase()!="yes"){return;}
var currentInputID=AgatEngine.getWindowProperty("glbFocusedInput");AgatEngine.setWindowProperty("glbFocusedInput",id);if(currentInputID!="initialValue"&&currentInputID!=id){if(currentInputID!=""){$("#"+currentInputID).trigger('change');}
AgatOnScreenKeyboard.handleKeyboardSwitch();}
if(currentInputID=="initialValue"&&id!=""){AgatOnScreenKeyboard.handleKeyboardSwitch();}},replaceSelection:function(value,bool,elem){var e=elem.jquery?elem[0]:elem;var text=arguments[0]||'';return(('selectionStart'in e&&function(){var x=e.selectionStart;if(text=="")
{if(e.selectionStart==e.selectionEnd)
{e.value=e.value.substr(0,e.selectionStart-1)+text+e.value.substr(e.selectionEnd,e.value.length);e.selectionStart=x-1;e.selectionEnd=x-1;}
else{e.value=e.value.substr(0,e.selectionStart)+text+e.value.substr(e.selectionEnd,e.value.length);e.selectionStart=x;e.selectionEnd=x;}}
else{e.value=e.value.substr(0,e.selectionStart)+text+e.value.substr(e.selectionEnd,e.value.length);e.selectionStart=x+1;e.selectionEnd=x+1;}
return elem;})||(document.selection&&function(){e.focus();var range=document.selection.createRange();if(text=="")
{if(range.text=="")
range.moveStart("character",-1);range.text=text;}
else
{range.text=text;range.moveEnd("character",text.length-1);range.select();}
return elem;})||function(){if(text=="")
{var str=e.val();e.val(str.substring(0,str.length-1));}
else
e.value+=text;return elem;})();}}