/*
 * Program - JS Joga-Khichuri
 * File Name - keys.js
 * Author - Mohammad Ahsanul Haque Shovon
 * Web site - http://www29.websamba.com/shovon
 * Email - ahsanul_haque_shovon@yahoo.com
 * (C) ShuvoRim Pvt. Ltd.
 * All rights reserved.
 */


//KEYBOARD EVENT - ADDING KEYBOARD SUPPORT TO THE GAME


          //////////////////////////////
         //   INTERNET EXPLORER      //
        //   OPERA WEB BROWSER*     //
       //   FIREFOX WEB BROWSER    //
      //   NETSCAPE NAVIGATOR     //
     //   EPIPHANY WEB BROWSER   //
    //   MOZILLA WEB BROWSER    //
   //   GALEON WEB BROWSER     //
  //////////////////////////////



/***************************************
 * FUNCTION: capture_ie() 
 * ARGUMENTS: None. 
 * PURPOSE: Capture events when the 
 * the player presses any keys. 
 * Works in Internet Explorer 5.0 or 
 * higher and Opera 7.0 or higher.
 * Sorry, Opera is not fully supported.
 * You may get some peculiar outputs 
 * while playing this game in Opera.
 ***************************************/
function capture_ie()
{
  if(event.keyCode == 13) //capturing the enter key
  {
    //should check that the check it button isn't disabled
    if(!document.js_joga_form.checkit.disabled)
    {
      //checks the current word
      check_it();
    }

    else
    {
      //the check it button is disabled 
      //so we should start the game first
      js_joga_main();
    }
  }

  if(event.keyCode == 32) //capturing the space bar
  {
    //starting a new game
    new_game();
  }

  if(event.keyCode == 48) //capturing the 0 key
  {
    //should check that the start game button isn't disabled
    if(!document.js_joga_form.start.disabled)
    {
      //showing how to file
      document.location.href = "./how_to.html";
    }

    else
    {
      var msg = "Are you sure you want to view the 'How to Play'";
      msg += "\nfile in middle of the game? You will lose your current";
      msg += "\ngame when you come back.";
      if(window.confirm(msg))
      {
        //showing how to file
        document.location.href = "./how_to.html";
      }
    }
  }

  if(event.keyCode == 49) //capturing the 1 key
  {
    //should check that the start game button isn't disabled
    if(!document.js_joga_form.start.disabled)
    {
      //setting difficulty level to easy
      document.js_joga_form.difficulty[0].checked = true;
      document.js_joga_form.time.value = "25";
    }
  }

  if(event.keyCode == 50) //capturing the 2 key
  {
    //should check that the start game button isn't disabled
    if(!document.js_joga_form.start.disabled)
    {
      //setting difficulty level to normal
      document.js_joga_form.difficulty[1].checked = true;
      document.js_joga_form.time.value = "35";
    }
  }

  if(event.keyCode == 51) //capturing the 3 key
  {
    //should check that the start game button isn't disabled
    if(!document.js_joga_form.start.disabled)
    {
      //setting difficulty level to hard
      document.js_joga_form.difficulty[2].checked = true;
      document.js_joga_form.time.value = "45";
    }
  }
}


/***********************************
 * FUNCTION: capture_gecko() 
 * ARGUMENTS: None. 
 * PURPOSE: Capture events when the 
 * the player presses any keys. 
 * Works in Gecko based browsers, 
 * such as Mozilla, Galeon, Firefox, 
 * Epiphany, Netscape etc.
 ***********************************/
function capture_gecko(e)
{
  if(e.which == 13) //capturing the enter key
  {
    //should check that the check it button isn't disabled
    if(!document.js_joga_form.checkit.disabled)
    {
      //checks the current word
      check_it();
    }

    else
    {
      //the check it button is disabled 
      //so we should start the game first
      js_joga_main();
    }
  }

  if(e.which == 32) //capturing the space bar
  {
    //starting a new game
    new_game();
  }

  if(e.which == 48) //capturing the 0 key
  {
    //should check that the start game button isn't disabled
    if(!document.js_joga_form.start.disabled)
    {
      //showing how to file
      document.location.href = "./how_to.html";
    }

    else
    {
      var msg = "Are you sure you want to view the 'How to Play'";
      msg += "\nfile in middle of the game? You will lose your current";
      msg += "\ngame when you come back.";
      if(window.confirm(msg))
      {
        //showing how to file
        document.location.href = "./how_to.html";
      }
    }
  }

  if(e.which == 49) //capturing the 1 key
  {
    //should check that the start game button isn't disabled
    if(!document.js_joga_form.start.disabled)
    {
      //setting difficulty level to easy
      document.js_joga_form.difficulty[0].checked = true;
      document.js_joga_form.time.value = "25";
    }
  }

  if(e.which == 50) //capturing the 2 key
  {
    //should check that the start game button isn't disabled
    if(!document.js_joga_form.start.disabled)
    {
      //setting difficulty level to normal
      document.js_joga_form.difficulty[1].checked = true;
      document.js_joga_form.time.value = "35";
    }
  }

  if(e.which == 51) //capturing the 3 key
  {
    //should check that the start game button isn't disabled
    if(!document.js_joga_form.start.disabled)
    {
      //setting difficulty level to hard
      document.js_joga_form.difficulty[2].checked = true;
      document.js_joga_form.time.value = "45";
    }
  }
}


/********************************
 * FUNCTION: st_bar() 
 * ARGUMENTS: None. 
 * PURPOSE: Shows texts in the 
 * status bar on mouse over.
 ********************************/
function st_bar(msg)
{
  //showing msg in the browser's status bar
  window.status = msg;
  return true;
}
