/*
 * Name:        concordance.js
 * 
 * Description: Common Javascript functions for the concordance search screen. 
 *  
 * Created:     May 21, 2006
 * Developer:   shadfield - for Blue's Arthouse
 *              www.bluesarthouse.com
 */
/*------------------------------------------------------------
 * function set_Radio() - sets the radio button foem value.
 *------------------------------------------------------------
 */
function set_Radio(f,val)
{
   f.radioval.value = val;
   //alert("radioval="+f.radioval.value);

} /*--- end function: set_Radio() ---*/ 

/*------------------------------------------------------------
 * function whatIsIt() - determines from the first character 
 * entered whether a word or a number was entered.
 *------------------------------------------------------------
 */
function whatIsIt(f)
{
   var val;
   var num = f.value;
   anum=/\d/;
   if (anum.test(num.charAt(0))) {
      //alert("its a number");
	  val="NUMBER";
   }
   else {
      //alert("its a char");
	  val="WORD";
   }
   return val;

} /*--- end function: whatIsIt() ---*/ 

/*------------------------------------------------------------
 * function chkStrongs() - checks the radio btns and strongs
 * input value.
 * NOTE: This function will not prevent stupid entries like:
 *       123abc, or abc123
 *------------------------------------------------------------
 */
function chkStrongs(f)
{
   //alert("radioval="+f.radioval.value);
   if ((f.strongsword.value == "") && (f.strongsnumber.value == "")) {
   	  f.action.value="stop";
   	  alert("You must enter either AR Word or Strongs Number.");
   }
   else if ((f.strongsword.value != "") && (f.strongsnumber.value != "")) {
   	  f.action.value="stop";
   	  alert("You must enter one or the other, but not both (AR Word or Strongs Number).");
   }
   else {
      if (f.strongsword.value != "") {
         var rtntype = whatIsIt(f.strongsword);
         if (rtntype == "NUMBER") {
            alert("You have entered a Number in the AR Word Search field!");
            f.action.value="stop";
         }
         else {
            f.radioval.value = rtntype;
            f.action.value="dsplyWord";
            //alert("action="+f.action.value+"; radioval="+f.radioval.value);
         }
      }
      else {
         var rtntype = whatIsIt(f.strongsnumber);
         //alert("strongnumber is:"+rtntype);
         if (rtntype == "WORD") {
            alert("You have selected Word in the Strongs Number Search field!");
            //f.action.value="stop";
         }
         else {
            f.radioval.value = rtntype;
            f.action.value="dsplyWord";
            //alert("action="+f.action.value+"; radioval="+f.radioval.value);
         }
      }
      //alert("radioval="+f.radioval.value);
   }

} /*-- end function chkStrongs() --*/

/*------------------------------------------------------------
 * function chkStrongsRadios() - checks the radio btns and strongs
 * input value.
 * NOTE: This function will not prevent stupid entries like:
 *       123abc, or abc123
 *------------------------------------------------------------
 */
function chkStrongsRadios(f)
{
   //alert("radioval="+f.radioval.value);
   if (f.radioval.value == "") {
   	  f.action.value="stop";
   	  alert("You must select either Strongs Word or Number.");
   }
   else if ((f.strongsword.value == "") && (f.strongsnumber.value == "")) {
   	  f.action.value="stop";
   	  alert("You must enter either Strongs Word or Number.");
   	  //f.strongs.select()
   }
   else {
      if (f.radioval.value == "WORD") {
         var rtntype = whatIsIt(f.strongsword);
         //alert("strongword is:"+rtntype);
         if (rtntype == "NUMBER") {
            alert("You have selected Word Search and entered a Number!");
            f.action.value="stop";
         }
         else {
            f.action.value="dsplyWord";
         }
      }
	  else {
         var rtntype = whatIsIt(f.strongsnumber);
         //alert("strongnumber is:"+rtntype);
         if (rtntype == "WORD") {
            alert("You have selected Number Search and entered a Word!");
            f.action.value="stop";
         }
         else {
            f.action.value="dsplyWord";
         }
      }
   }

} /*-- end function chkStrongsRadios() --*/

/*------------------------------------------------------------
 * function resetPage() - Resets the display_concordance page.
 *------------------------------------------------------------
 */
function resetPage (f)
{
	f.radioval.value = 0;
	f.strongs.value = 0;
	f.action.value = 'nothing';
	//alert('test='+f.book_id.value+'; action='+f.action.value);
	f.submit();

} /*--- end function: resetPage() ---*/ 
