/*
AjaxExplorer Copyright (C) 2007-2008 Syed Mohammad Sidque Tahir Al-Habshi

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 3 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. Head to
GNU site http://www.gnu.org/licenses/ for license copy.
*/

function formPopulate1(data)
{
  var a=data.split('');

  for(var i=6; i<9; i++)
  {
    get('S'+i+'1').checked=a[(i-6)] & 0x0004? 'checked':'';
    get('S'+i+'2').checked=a[(i-6)] & 0x0002? 'checked':'';
    get('S'+i+'3').checked=a[(i-6)] & 0x0001? 'checked':'';
  }

  get('S58').value=data;
}

function formPopulate2()
{
  var data='', sum=0;

  for(var i=6; i<9; i++)
  {
    for(var j=1; j<4; j++)
    {
      sum-=get('S'+i+j).checked? -(j==1? 4:(j==2? 2:1)):0;
    }

    data+=sum;
    sum=0;
  }

  get('S58').value=data;
}

function formRemember1(data)
{
  edit=4;
  fld1=data;
}

function formValidate1(data)
{
  edit=0;
  var a=data.split(''), flag=0;

  for(var i=0; i<3; i++)
  {
    if(a[i]>7 || isNaN(a[i])) flag=1;
  }

  if(flag) formPopulate1(fld1);
}