CD.VirtualKeyboard=new Class({textFieldId:null,currentCASh:0,keyboardWrap:null,focused:false,focusedEl:null,flashWrapEl:null,wrapTop:null,defaultWrapTop:"125px",initialize:function(A,B){this.keyboardWrap=A;this.isHidden=B;if(new CD.FlashDetect().isInstalled()){this.enableVKIntall()}else{this.disableVkIntall()}},enableVKIntall:function(){this.flashStart();var A=new Swiff(CD.Conf.path+"keyboard/"+CD.Conf.keyboardName+"Sound.swf?lang="+CD.Conf.keyboardDialect+"&keyboardname=CD.VKS&path="+CD.Conf.path+"keyboard/&current="+CD.Conf.currentLayout+"&soundMode="+CD.Conf.searchSound+"&time="+$time(),{id:"keyboardIE",width:CD.Conf.keyboardWidth,height:CD.Conf.keyboardHeight,allowScriptAccess:"sameDomain",wmode:"transparent",bgcolor:CD.Conf.keyboardBackground});$("divkeyboard").appendChild(A);this.swiff=A;this.keyboardWrapHandlers()},disableVkIntall:function(){CD.Conf.VKLoad=false;this.keyboardWrap.setStyle("display","none");CD.Conf.currentLayout="latin";new CD.Setting("searchPlace",0).save();new CD.Setting("searchInputType","SRO").save();var A=$("FontError");if($defined(A)){A.innerHTML="<div style='line-height:3em;'>Some features of the website such as sound and Syllabics Keyboard require Adobe Flash Plugin which can be downloaded using the link below.<br /><a href=\"http://www.adobe.com/go/getflashplayer/\">Get the latest Flash player</a>.</div>"}},getObject:function(){CD.Conf.VKLoad=true;this.sendValue=function(A,B,C){if(CD.Conf.VKLoad){Swiff.remote(this.swiff,"getValue",A,B)}};this.switchLanguage=function(){if(CD.Conf.VKLoad){Swiff.remote(this.swiff,"switchLanguage")}};this.setupHashes();this.flashFinish();window.fireEvent("onVKLoad")},flashStart:function(){this.wrapTop=this.keyboardWrap.getStyle("top");this.keyboardWrap.setStyles({top:"0",opacity:"0.01",visibility:"visible"})},flashFinish:function(){var A=this.isHidden?"hidden":"visible";var B=this.wrapTop.toInt()==0?this.defaultWrapTop:this.wrapTop;this.keyboardWrap.setStyles({top:B,opacity:"1",visibility:A})},switchLanguage:function(){},sendValue:function(A,B){},keyboardWrapHandlers:function(){var D=this.keyboardWrap.getElement(".popupBoxClose");if($defined(D)){D.addEvent("click",function(){this.switchBinder()}.bind(this))}var B=this.keyboardWrap.getElement("#virtual-keyboard-header");if($defined(B)){B.setStyles({cursor:"move"});new Drag.Move(this.keyboardWrap,{handle:B})}var A=this.keyboardWrap.getElement("#select_dialect");if($defined(A)){var C=A.getFirst().getNext().getChildren();if(C.length>0){$each(C,function(E){E.addEvent("click",function(){this.switchDialect(A.obj.state,A.obj.value)}.bind(this))}.bind(this))}}},switchBinder:function(){if("visible"==this.keyboardWrap.getStyle("visibility")){this.keyboardWrap.setStyle("visibility","hidden");if(null!=this.focusedEl){this.focusedEl.focus()}}else{if(null!=this.focusedEl){var A=this.focusedEl.getCoordinates();var B=$("canvas").getCoordinates();this.keyboardWrap.setStyle("top",A.top-B.top+40+"px")}this.keyboardWrap.setStyle("visibility","visible");this.swiff.focus()}},handleFields:function(A){this.removeKeyListeners();this.textFieldId=A?A:{syllabic:[],roman:[]};this.addKeListeners()},setupHashes:function(){if($defined(CD.overKeyLayout)&&$defined(CD.overKeyLayout[CD.Conf.keyboardDialect])&&CD.overKeyLayout[CD.Conf.keyboardDialect].length>0){for(var A=0;A<CD.overKeyLayout[CD.Conf.keyboardDialect].length;A++){if($defined(CD.overKeyLayout[CD.Conf.keyboardDialect][A])){CD.keyLayout.latin[1][A]=CD.overKeyLayout[CD.Conf.keyboardDialect][A]}}}if($defined(CD.basicKeyLayout)&&$defined(CD.basicKeyLayout[CD.Conf.keyboardDialect])&&CD.basicKeyLayout[CD.Conf.keyboardDialect].length>0){for(var A=0;A<CD.basicKeyLayout[CD.Conf.keyboardDialect].length;A++){if($defined(CD.basicKeyLayout[CD.Conf.keyboardDialect][A])){CD.keyLayout.latin[0][A]=CD.basicKeyLayout[CD.Conf.keyboardDialect][A]}}}},switchDialect:function(A,C){var B=["mask_cree","sask_cree","woodland_cree"];dialect=B[$chk(A)&&A<3&&A>=0?A:0];if(dialect!=CD.Conf.keyboardDialect){this.changeDialect(dialect,CD.Conf.currentLayout);CD.Conf.keyboardDialect=dialect;CD.Conf.currentLayout=("latin"==CD.Conf.currentLayout)?CD.Conf.currentLayout:CD.Conf.keyboardDialect;this.setupHashes();$("dialectTitle").innerHTML=C;new CD.Setting("searchInputDialect",dialect).save()}},sendLanguage:function(B){if(CD.Conf.currentLayout!=B){var A=B&&"latin"==B?CD.Conf.keyboardDialect:"latin";this.sendValue("CFG.currentLayout",A,"");this.switchLanguage()}},sendCode:function(A,B){if(CD.Conf.VKLoad){Swiff.remote(this.swiff,"getCode",A,B)}},changeDialect:function(A,B){if(CD.Conf.VKLoad){Swiff.remote(this.swiff,"changeDialect",A,B)}},getLanguage:function(B){if(CD.Conf.currentLayout!=B){CD.Conf.currentLayout=B;var A=B=="latin"?0:2;new CD.Setting("searchPlace",A).save();if(2==A&&"Syllabic"!=CD.Conf.searchInputType){new CD.Setting("searchInputType","Syllabic").save()}else{if(2!=A&&"SRO"!=CD.Conf.searchInputType){new CD.Setting("searchInputType","SRO").save()}}}},getSound:function(A){if(1==A&&"Click"!=CD.Conf.searchSound){new CD.Setting("searchVKSound","Click").save()}else{if(2==A&&"On"!=CD.Conf.searchSound){new CD.Setting("searchVKSound","On").save()}else{if(0==A&&"Off"!=CD.Conf.searchSound){new CD.Setting("searchVKSound","Off").save()}}}},insertAtCursor:function(E,A){var D=false;if(document.selection&&!CD.Conf.isOpera){var F;if(!this.focused){D=true}E.focus();if(D||CD.Conf.isOpera){this.setCursorPosition(E,CD.Conf.isIE8?E.innerHTML.length:E.value.length,CD.Conf.isIE8?E.innerHTML.length:E.value.length)}F=document.selection.createRange();F.text=A;F.collapse(false);F.select()}else{if(E.selectionStart||E.selectionStart=="0"){var C=E.selectionStart;var B=E.selectionEnd;E.value=E.value.substring(0,C)+A+E.value.substring(B,E.value.length);E.selectionEnd=E.selectionStart=C+A.length}else{E.value+=A}}},setCursorPosition:function(B,E,A){if(B.setSelectionRange){B.setSelectionRange(E,A)}else{if(B.createTextRange){C=B.createTextRange();C.collapse(true);C.moveEnd("character",A);C.moveStart("character",E);C.select()}else{if((CD.Conf.isIE8&&B.tagName=="DIV")||CD.Conf.isOpera){var C=document.body.createTextRange();C.moveToElementText(B);var D=C.duplicate();C.collapse(false);C.move("character",-D.text.length+B.innerHTML.length);C.select()}}}},deleteAtCursor:function(A){if(A.selectionStart||A.selectionStart=="0"){if(!this.focused){A.focus()}var E=A.selectionStart;var D=A.selectionEnd;if(E==D){E--}A.value=A.value.substring(0,E)+A.value.substring(D,A.value.length);A.selectionEnd=A.selectionStart=E}else{if(document.selection){var C=false;if(!this.focused){C=true;A.focus()}if(C){var B=A.createTextRange();B.moveStart("character",A.value.length-1);B.moveEnd("character",A.value.length-1);B.select()}else{B.collapse(true);var F=B.moveEnd("character",1)}var G=document.selection.createRange();G.text="";G.collapse(false);G.select()}else{A.value=A.value.substring(0,A.value.length-1)}}},addKeListeners:function(){if($chk(this.textFieldId)){$each(this.textFieldId.syllabic,function(A){var B=$(A);if($defined(B)){this.addHandlers(B)}}.bind(this));$each(this.textFieldId.roman,function(A){var B=$(A);if($defined(B)){this.addHandlers(B)}}.bind(this))}},removeKeyListeners:function(){if($chk(this.textFieldId)){$each(this.textFieldId.syllabic,function(A){var B=$(A);if($defined(B)){this.removeHandlers(B)}}.bind(this));$each(this.textFieldId.roman,function(A){var B=$(A);if($defined(B)){this.removeHandlers(B)}}.bind(this))}},handleNewField:function(A){this.unhandleField(A);var B=$(A);if($defined(B)){this.addHandlers(B);this.textFieldId.roman.push(A);if("latin"!=CD.Conf.currentLayout){this.switchLanguage()}}},unhandleField:function(A){var B=$(A);if($defined(B)){this.removeHandlers(B)}},addHandlers:function(A){var B=A;if(CD.Conf.isIE8){B=this.makeEditableDiv(A)}B.addEvents({keyup:this.onKeyUp.bind(this),keydown:this.onKeyDown.bind(this),keypress:this.onKeyPress.bind(this),blur:this.onBlur.bind(this),focus:this.onFocus.bind(this)})},removeHandlers:function(A){A.removeEvents(["keyup","keydown","keypress","blur","focus"])},makeEditableDiv:function(B){var D=B.getProperty("id");var C=B.getCoordinates();B.setStyle("display","none");var A=new Element("div").addClass(B.getProperty("class")).setProperty("contenteditable",true).setProperty("id",D).inject(B,"before");if(B.tagName=="TEXTAREA"){A.setStyles({width:C.width>0?C.width:270,height:C.height>0?C.height:102})}A.innerHTML=B.value;B.setProperty("id",B.id+"Input");return A},onKeyUp:function(C){var B=new Event(C);var A=B.target;if(CD.Conf.isIE8&&$defined(A.getNext())&&(A.getNext().tagName=="INPUT"||A.getNext().tagName=="TEXTAREA")){A.getNext().value=A.innerHTML}return this.keyUpVK(B)},keyUpVK:function(B){var A=B.code;if(B.control||(CD.Conf.isMac&&B.meta)){return true}if(!B.shift&&this.currentCASh&1){this.currentCASh--;this.sendValue("CFG.currentCASh",this.currentCASh,"up");return true}if(!B.alt&&this.currentCASh&4){this.currentCASh-=4;this.sendValue("CFG.currentCASh",this.currentCASh,"up");return true}this.sendCode(A,1);if((A>47&&(undefined!=CD.keyLayout[CD.Conf.currentLayout][this.currentCASh][A]||0==this.currentCASh))||undefined!=CD.Conf.specSymbol[A]){return false}else{return true}},onKeyDown:function(B){var A=new Event(B);return this.keyDownVK(A)},keyDownVK:function(C){var B=C.code;if(C.shift&&C.control){this.switchLanguage();return false}if(C.control||(CD.Conf.isMac&&C.meta)){return true}if(C.shift&&B!=16){if(!(this.currentCASh&1)){this.currentCASh++;this.sendValue("CFG.currentCASh",this.currentCASh,"down")}}if(C.alt&&B!=18){if(!(this.currentCASh&4)){this.currentCASh+=4;this.sendValue("CFG.currentCASh",this.currentCASh,"down")}}this.sendCode(B,3);var A=this.typeSymbol("js",B,this.currentCASh);if(false===A&&!CD.Conf.isIE){C.preventDefault()}return A},onKeyPress:function(B){var A=new Event(B);return this.keyPressVK(A)},keyPressVK:function(B){var A=B.code;if(B.shift&&B.control){return false}if(B.control||(CD.Conf.isMac&&B.meta)){return true}if(A>96&&A<123){A-=32}if(9==A){if(!CD.Conf.isIE){this.focusedEl.getParent().blur()}this.focusedEl.getParent().focus();if(!CD.Conf.isIE){B.preventDefault()}return false}else{if((A>47&&($defined(CD.keyLayout[CD.Conf.currentLayout][this.currentCASh][A])||0==this.currentCASh)&&!(CD.Conf.isSafari&&A<63236&&A>63231))||$defined(CD.Conf.specSymbol[A])){if(!CD.Conf.isIE){B.preventDefault()}return false}else{if(A<256||(CD.Conf.isSafari&&A<63236&&A>63231)){return true}else{if(!CD.Conf.isIE){B.preventDefault()}return false}}}},onBlur:function(C){var B=new Event(C).stop();B.preventDefault();var A=B.target;if($defined(A)){this.focused=false}},onFocus:function(C){var B=new Event(C);var A=B.target;if($defined(A)){this.focusedEl=A;this.focused=true;if(CD.Conf.isIE&&!CD.Conf.isIE8){this.setCursorPosition(A,A.value.length,A.value.length)}else{if(CD.Conf.isIE8){this.setCursorPosition(A,A.innerHTML.length,A.innerHTML.length)}}}},typeSymbol:function(B,A,C){return this.typeSymbolVK(B,A,C)},typeSymbolVK:function(C,B,D){if(B<48&&!$defined(CD.Conf.specSymbol[B])){return true}if((D&1&&B==17&&!(D&4))||(D&2&&B==16&&!(D&4))){this.currentCASh=0;this.sendValue("CFG.currentCASh",0,C+"_typeSymbol");this.switchLanguage();return false}var A=false;switch(B){case 8:if(this.focusedEl){if(CD.Conf.isIE&&C=="js"){return true}else{if(CD.Conf.isIE){this.focusedEl.focus();this.deleteAtCursor(this.focusedEl);return false}else{this.deleteAtCursor(this.focusedEl);return false}}}return true;break;case 9:return true;break;case 13:if($defined(this.focusedEl)){this.insertAtCursor(this.focusedEl,"\n")}return false;break;case 1:case 2:case 3:case 4:case 16:if(!(D&1)){this.currentCASh=D+1;this.sendValue("CFG.currentCASh",this.currentCASh,C+"_typeSymbol")}return true;break;case 17:if(!(D&2)){this.currentCASh=D+2;this.sendValue("CFG.currentCASh",this.currentCASh,C+"_typeSymbol")}return true;break;case 18:if(!(D&4)){this.currentCASh=D+4;this.sendValue("CFG.currentCASh",this.currentCASh,C+"_typeSymbol")}return true;break;case 116:location.href=document.URL;return false;break;default:if($defined(this.focusedEl)&&$defined(CD.keyLayout[CD.Conf.currentLayout][this.currentCASh][B])){this.insertAtCursor(this.focusedEl,CD.keyLayout[CD.Conf.currentLayout][this.currentCASh][B]);if(CD.Conf.isGecko){this.focusedEl.blur()}this.focusedEl.focus();return false}else{return true}}return false},copyToClipboard:function(A){if(CD.Conf.VKLoad){Swiff.remote(this.swiff,"setClipboard",A)}}});