/*

 ' Program - Discover The Word
 ' File Name - main_func.js
 ' Author - Shovon
 ' Email - shuvorim@yahoo.com
 ' Web site - http://www29.websamba.com/shovon
 ' (C) ShuvoRim Pvt. Ltd.
 ' All rights reserved.

 ' Mailing Address-
 ' North Palace (8th Floor), Flat-9A
 ' 75, North Road, Dhanmondi
 ' Dhaka-1205, Bangladesh.


 ' This program is free software; you can redistribute it and/or modify
 ' it under the terms of the GNU General Public License as published by
 ' the Free Software Foundation; either version 2 of the License, or
 ' (at your option) any later version.

 ' This program is distributed in the hope that it will be useful,
 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ' GNU General Public License for more details.

 ' You should have received a copy of the GNU General Public License
 ' along with this program; if not, write to the Free Software
 ' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/



/********************************************
 * The main function of 'Discover The Word'.
 ********************************************/
function callMe(letter, prev, imgName)
{
  if(tries < 5)
  {
    if(prev > 1) {}

    else
    {
      document.images[imgName].src = used.src;
      tries++;
      document.form1.trd.value = tries;

      for(counter = 0; counter < wordsLength; counter++)
      {
        if(holdWords.charAt(counter) == letter)
        {
          document.images[counter+1].src = eval(letter + ".src");
          correct++;
          --tries;
          tries = ((tries < 0) ? 0 : tries);
          document.form1.trd.value = tries;

          if(correct == wordsLength)
          {
            if(window.confirm("Congratulations! You have successfully"
            + " discovered the word:\n\n" + holdWords.toUpperCase()
            + "\n\nDo you want to play again?"))
            {
              tries = 0;
              location.reload();
              document.form1.trd.value = tries;
            }
          }
        }
      }
    }
  }

  if(tries >= 5)
  {
    if(!track)
    {
      document.images[imgName].src = used.src;
      track++;
    }

    document.form1.trd.value = 5;

    if(window.confirm("Sorry, your chances over. The word was:\n\n"
    + holdWords.toUpperCase() + "\n\nDo you want to play again?"))
    {
      tries = 0;
      location.reload();
      document.form1.trd.value = tries;
    }
  }
}
