// Virtual Keyboard
// April 2005 - Emre TOPTANCI
// March 2007 - Hakan ÖZKELEMCÝ - Made Firefox compatible
//

    var isDown=false;
    var x;
    var y;
    
    //Is used to move the keyboard frame on the screen.
    function trackMouse(e){  
      if(!isDown) return;
      var frame = eval("parent.document.getElementById('" + document.getElementById('targetFrame').value + "')" );
      var framex;
      var framey;
      if(frame.style.left.indexOf("px")>0) {
        framex = frame.style.left.substring(0, frame.style.left.indexOf("px"));
        framey = frame.style.top.substring(0, frame.style.top.indexOf("px"));
      }else{
        framex = frame.style.left.substring(0, frame.style.left.indexOf("pt"));
        framey = frame.style.top.substring(0, frame.style.top.indexOf("pt"));
      }
      var parentx
      var parenty
      var IE = document.all ? true : false;
      if (IE){
        parentx = parseInt(framex) + event.clientX + document.body.scrollLeft;
        parenty = parseInt(framey) + event.clientY + document.body.scrollTop;
      }else {
        parentx = parseInt(framex) + e.clientX + document.body.scrollLeft;
        parenty = parseInt(framey) + e.clientY + document.body.scrollTop;
      }
      frame.style.left = (parentx - x ) + 'px';
      frame.style.top  = (parenty - y ) + 'px';
      
      if(IE) document.selection.clear();
      
      
    } 
    
    //Is used to mark the starting position of the frame for moving.
    function mouseDown(e){
      var IE = document.all ? true : false;
      if (IE) { // grab the x-y pos.s if browser is IE
        x = event.clientX + document.body.scrollLeft;
        y = event.clientY + document.body.scrollTop;
      } else {  // grab the x-y pos.s if browser is NS
        x = e.pageX
        y = e.pageY
      }
      isDown=true;
    }                   
    
    //Marks the end of the move of the frame on the form
    function mouseUp(e){
      isDown = false;
    }                 

    document.onmousemove = trackMouse; 
    document.onmousedown = mouseDown;
    document.onmouseup = mouseUp;

  //When a button is clicked, its value, which is a letter, is put to the activeElement
  // on the parent document
  function btClick(key){    
    var activeElementName = parent.document.getElementById("activeElement").value;
    if (activeElementName=="" || activeElementName=="undefined") return;
    activeElementName=activeElementName.replace(/\$/g, "_");
    var obj = eval("parent.document.getElementById('" + activeElementName + "')");
    if (obj==null) return;
    //var obj = eval("parent.document." + formName + "." + compName );
    obj.value = obj.value + key;
    obj.focus();
  } 
   
  //Change Case function for turkish keyboard
  function btCase_Click_TR(){
    if(document.all.CurrentCase.value=="lowerCase") {UpperCase_TR();}
    else if(document.all.CurrentCase.value=="upperCase") {LowerCase_TR();}
  }    
  
  //Change Case function for english keyboard
  function btCase_Click_EN(){
    if(document.all.CurrentCase.value=="lowerCase") {UpperCase_EN();}
    else if(document.all.CurrentCase.value=="upperCase") {LowerCase_EN();}
  }    

  //Closes keyboard frame
  function btClose_Click(){
    eval("parent.document.getElementById('" + document.getElementById('targetFrame').value + "').style").display = "none";
  }
  
  function UpperCase_TR(){
    document.all.bt_a.value = "A";
    document.all.bt_b.value = "B";
    document.all.bt_c.value = "C";
    document.all.bt_c_t.value = "Ç";
    document.all.bt_d.value = "D";
    document.all.bt_e.value = "E";
    document.all.bt_f.value = "F";
    document.all.bt_g.value = "G";
    document.all.bt_g_t.value = "Ð";
    document.all.bt_h.value = "H";
    document.all.bt_i_t.value = "I";
    document.all.bt_i.value = "Ý";
    document.all.bt_j.value = "J";
    document.all.bt_k.value = "K";
    document.all.bt_l.value = "L";
    document.all.bt_m.value = "M";
    document.all.bt_n.value = "N";
    document.all.bt_o.value = "O";
    document.all.bt_o_t.value = "Ö";
    document.all.bt_p.value = "P";
    document.all.bt_q.value = "Q";
    document.all.bt_r.value = "R";
    document.all.bt_s.value = "S";
    document.all.bt_s_t.value = "Þ";
    document.all.bt_t.value = "T";
    document.all.bt_u.value = "U";
    document.all.bt_u_t.value = "Ü";
    document.all.bt_v.value = "V";
    document.all.bt_w.value = "W";
    document.all.bt_x.value = "X";
    document.all.bt_y.value = "Y";
    document.all.bt_z.value = "Z";
    document.all.CurrentCase.value = "upperCase";
    document.all.btCase.value = "Küçük Harf";
  }
 
   function LowerCase_TR(){
    document.all.bt_a.value = "a";
    document.all.bt_b.value = "b";
    document.all.bt_c.value = "c";
    document.all.bt_c_t.value = "ç";
    document.all.bt_d.value = "d";
    document.all.bt_e.value = "e";
    document.all.bt_f.value = "f";
    document.all.bt_g.value = "g";
    document.all.bt_g_t.value = "ð";
    document.all.bt_h.value = "h";
    document.all.bt_i_t.value = "ý";
    document.all.bt_i.value = "i";
    document.all.bt_j.value = "j";
    document.all.bt_k.value = "k";
    document.all.bt_l.value = "l";
    document.all.bt_m.value = "m";
    document.all.bt_n.value = "n";
    document.all.bt_o.value = "o";
    document.all.bt_o_t.value = "ö";
    document.all.bt_p.value = "p";
    document.all.bt_q.value = "q";
    document.all.bt_r.value = "r";
    document.all.bt_s.value = "s";
    document.all.bt_s_t.value = "þ";
    document.all.bt_t.value = "t";
    document.all.bt_u.value = "u";
    document.all.bt_u_t.value = "ü";
    document.all.bt_v.value = "v";
    document.all.bt_w.value = "w";
    document.all.bt_x.value = "x";
    document.all.bt_y.value = "y";
    document.all.bt_z.value = "z";
    document.all.CurrentCase.value = "lowerCase";
    document.all.btCase.value = "Büyük Harf";
  }

  function UpperCase_EN(){
    document.all.bt_a.value = "A";
    document.all.bt_b.value = "B";
    document.all.bt_c.value = "C";
    document.all.bt_d.value = "D";
    document.all.bt_e.value = "E";
    document.all.bt_f.value = "F";
    document.all.bt_g.value = "G";
    document.all.bt_h.value = "H";
    document.all.bt_i.value = "I";
    document.all.bt_j.value = "J";
    document.all.bt_k.value = "K";
    document.all.bt_l.value = "L";
    document.all.bt_m.value = "M";
    document.all.bt_n.value = "N";
    document.all.bt_o.value = "O";
    document.all.bt_p.value = "P";
    document.all.bt_q.value = "Q";
    document.all.bt_r.value = "R";
    document.all.bt_s.value = "S";
    document.all.bt_t.value = "T";
    document.all.bt_u.value = "U";
    document.all.bt_v.value = "V";
    document.all.bt_w.value = "W";
    document.all.bt_x.value = "X";
    document.all.bt_y.value = "Y";
    document.all.bt_z.value = "Z";
    document.all.CurrentCase.value = "upperCase";
    document.all.btCase.value = "Lowercase";
  }

  function LowerCase_EN(){
    document.all.bt_a.value = "a";
    document.all.bt_b.value = "b";
    document.all.bt_c.value = "c";
    document.all.bt_d.value = "d";
    document.all.bt_e.value = "e";
    document.all.bt_f.value = "f";
    document.all.bt_g.value = "g";
    document.all.bt_h.value = "h";
    document.all.bt_i.value = "i";
    document.all.bt_j.value = "j";
    document.all.bt_k.value = "k";
    document.all.bt_l.value = "l";
    document.all.bt_m.value = "m";
    document.all.bt_n.value = "n";
    document.all.bt_o.value = "o";
    document.all.bt_p.value = "p";
    document.all.bt_q.value = "q";
    document.all.bt_r.value = "r";
    document.all.bt_s.value = "s";
    document.all.bt_t.value = "t";
    document.all.bt_u.value = "u";
    document.all.bt_v.value = "v";
    document.all.bt_w.value = "w";
    document.all.bt_x.value = "x";
    document.all.bt_y.value = "y";
    document.all.bt_z.value = "z";
    document.all.CurrentCase.value = "lowerCase";
    document.all.btCase.value = "Uppercase";
  }                           