// ASP Web Database Interface Builder (http://www.awdib.com)
// © Handy Productions, 2002 - All Rights Reserved
// You may use all/part of this script in your own, non-competing
// projects on the condition that you leave this message in tact.

function enterField(f1)
{
   f1.style.background='FEFDE0';   
}

function exitField(f1)
{
   f1.style.background='FFFFFF'
}

function ValidateKey(f1,f2,f3,f4,f5) 
{   
   var key=window.event.keyCode;
   if (f3=='a')
   {
     var allowed='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ :;,.?!£$%^&*()_+-*{}@~<>&"\'';
   }
   else if (f3=='n')
   {
     var allowed='0123456789.-';
   }
   else if (f3=='i')
   {
     var allowed='0123456789-';
   }
   else if (f3=='s')
   {
     var allowed=f4;
   }
   if (f3!='')
   {
      if (key!=13)
      {
         if (allowed.indexOf(String.fromCharCode(key))==-1) 
         {
            key=0;  
         }
      }
   }

   if (f3=='n'||f3=='i')
   {    
      if (key==46)
      {
         if (f1.value.indexOf('.')>-1)
         {
            key=0;
         }
      }
   }

   
   if (f5=='u')
   {
      var newkey=String.fromCharCode(key).toUpperCase();
      key=newkey.charCodeAt(0);
   }
   else if (f5=='l')
   {
      var newkey=String.fromCharCode(key).toLowerCase();
      key=newkey.charCodeAt(0);
   }

   window.event.keyCode=key;
}


function ValidateField(f1,f2) 
{   
   if (document.frmMain.currentError.value!='') 
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;  
      }
   }

   if (f1.value.length<f2)
   {
      alert('This field must be at least '+f2+' characters long');
      document.frmMain.currentError.value=f1.name;      
      f1.focus();
      f1.select();      
      return false;
   }
   else
   {
      exitField(f1);
      document.frmMain.currentError.value='';
      return true;
   }
}

function ValidateNumber(f1,f2,f3,f4)
{
   if (document.frmMain.currentError.value!='')
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;
      }
   }

   if (f1.value=='')
   {
      alert('This value must be specified.');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }


   if ((f3!=0||f4!=0))
   {
      if (f1.value<f3)
      {
         alert('Minimum value allowed is: '+f3);
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
      else if (f1.value>f4)
      {
         alert('This value must be less than or equal to '+f4);
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
   }

   var decimalpos=f1.value.indexOf('.');
   var fieldlen=f1.value.length;
   if (decimalpos>0)
   {
      if ((f2+1)<(fieldlen-decimalpos))
      {
        alert('Only '+f2+' decimal places allowed!');
        document.frmMain.currentError.value=f1.name;
        f1.focus();
        f1.select();
        return false;
      }
   }
   exitField(f1);
   document.frmMain.currentError.value='';
   return true;
}

function ValidateSearchNumber(f1,f2,f3,f4) 
{
   if (f1.value=='')
   {
      exitField(f1);  
      return true;
   }
   else
   {
      return ValidateNumber(f1,f2,f3,f4);
   }

}


function ValidateDateTime(f1,f2,f3)
{
   if ((f3==0) & (f1.value.length==0))
   {
     exitField(f1);
     return true;
   }
   if (document.frmMain.currentError.value!='')
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;
      }
   }

   if (f1.value.length<12)
   {
      alert('Please enter date/time in format');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }

   if (f2==1)
   {
      var dd=f1.value.substring(0,2);
      var mm=f1.value.substring(2,4);
      var yy=f1.value.substring(4,8);
   }
   else if (f2==0)
   {
      var mm=f1.value.substring(0,2);
      var dd=f1.value.substring(2,4);
      var yy=f1.value.substring(4,8);
   }
   else if (f2==2)
   {
      var yy=f1.value.substring(0,2);
      var mm=f1.value.substring(2,4);
      var dd=f1.value.substring(4,8);
   }

   if (dd>31)
   {
      alert('Day value must not be larger than 31!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (mm>12)
   {
      alert('Month must not be larger than 12!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (dd==30)
   {
      if (mm==4||mm==6||mm==9||mm==11)
      {
         alert('There is no 30th in Month '+mm);
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
   }
   if (mm==2)
   {
      if (dd>29)
      {
         alert('There are not '+dd+' days in February!');
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
      if (dd==29)
      {
         if (yy%4!=0)
         {
            alert('There are not 29 days in February of that year!');
            document.frmMain.currentError.value=f1.name;
            f1.focus();
            f1.select();
            return false;
         }
      }
   }

   var hh=f1.value.substring(8,10);
   var mm=f1.value.substring(10,12);
   if (hh>23)
   {
      alert('Hours can not be larger than 23!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (mm>59)
   {
      alert('[M13]!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   exitField(f1);
   document.frmMain.currentError.value='';
   return true;
}




function ValidateDate(f1,f2,f3)
{
   if ((f3==0) & (f1.value.length==0))
   {
     exitField(f1);
     return true;
   }
   if (document.frmMain.currentError.value!='')
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;
      }
   }

   if (f1.value.length<8)
   {
      alert('Please enter date/time in format');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }

   if (f2==1)
   {
      var dd=f1.value.substring(0,2);
      var mm=f1.value.substring(2,4);
      var yy=f1.value.substring(4,8);
   }
   else if (f2==0)
   {
      var mm=f1.value.substring(0,2);
      var dd=f1.value.substring(2,4);
      var yy=f1.value.substring(4,8);
   }
   else if (f2==2)
   {
      var yy=f1.value.substring(0,2);
      var mm=f1.value.substring(2,4);
      var dd=f1.value.substring(4,8);
   }

   if (dd>31)
   {
      alert('Day value must not be larger than 31!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (mm>12)
   {
      alert('Month must not be larger than 12!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (dd==30)
   {
      if (mm==4||mm==6||mm==9||mm==11)
      {
         alert('There is no 30th in Month '+mm);
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
   }
   if (mm==2)
   {
      if (dd>29)
      {
         alert('There are not '+dd+' days in February!');
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
      if (dd==29)
      {
         if (yy%4!=0)
         {
            alert('There are not 29 days in February of that year!!');
            document.frmMain.currentError.value=f1.name;
            f1.focus();
            f1.select();
            return false;
         }
      }
   }
   exitField(f1);
   document.frmMain.currentError.value='';
   return true;
}

function ValidateTime(f1,f2,f3)
{
   if ((f3==0) & (f1.value.length==0))
   {
     exitField(f1);
     return true;
   }
   if (document.frmMain.currentError.value!='')
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;
      }
   }

   if (f1.value.length<4)
   {
      alert('Please enter time in format HHMM');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }

   var hh=f1.value.substring(0,2);
   var mm=f1.value.substring(2,4);
   if (hh>23)
   {
      alert('Hours can not be larger than 23!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (mm>59)
   {
      alert('Minutes can not be larger than 59');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   exitField(f1);
   document.frmMain.currentError.value='';
   return true;
}

function processClick(f1,f2,f3,f4)
{
   if (f1.checked)
   {
     f2.value=f3;
   }
   else
   {
     f2.value=f4;
   }
   return true;
}

function processRange(f1,f2)
{
   if (f1.value=='3')
   {
      f2.className='fieldSettings'
   }
   else
   {
      f2.className='fieldSettingsHidden'
   }
   return true;
}

function lineOn(f1) 
{
  f1.className="lineOn"
}

function lineOff(f1) 
{
  f1.className="lineOff"
}

function highlightRow(f1) 
{
  if (eval(frmRow.selRow.value)==f1)
  {
     return false;
  }
  f1.className="gridHighlight"
}

function revertRow(f1) 
{  
  if (eval(frmRow.selRow.value)==f1)
  {
     return false;
  }
  if (f1.id.charAt(0)=='A')
  {
     f1.className="gridRowA"
  }
  else
  {
     f1.className="gridRowB"
  }
}

function revertRowNC(f1) 
{  
  if (f1.id.charAt(0)=='A')
  {
     f1.className="gridRowA";
  }
  else
  {
     f1.className="gridRowB";
  }
}

function selectRow(f1)
{
   if (frmRow.selRow.value!='')
   {
      revertRowNC(eval(frmRow.selRow.value));
   }

   frmRow.selRow.value=f1.id; 

   f1.className="gridSelected";
   if (btnEdit)
   {
      btnEdit.className="buttonColor";
   }
   btnDelete.className="buttonColor";
}

function showRow()
{
   if (document.all("frmRow"))
   {    
   
      if (frmRow.selRow.value=='')
      {
         return false;
      }
      if (eval(frmRow.selRow.value))
      {
         selectRow(eval(frmRow.selRow.value));
      }
   }
}

function editDeleteRecord(F1)
{
   if (F1=='a')
   {
      frmMain.mode.value='add';
      frmMain.submit();  
      return true;
   } 

   if (frmRow.selRow.value=='')
   {
      alert('Please select record!');
      return false;
   }
   
   frmMain.f105where.value=eval('frm'+frmRow.selRow.value).f105where.value;
   
   if (F1=='e')
   {
      frmMain.mode.value='edit';
      frmMain.submit();
      return true;
   }
   else
   {
      var result
      result = confirm("Are you sure that you wish to delete this record?");
      if (result) 
      {
         frmMain.mode.value='delete';
         frmMain.submit();
         return true;
      }
   }
   return true;
}

function showOutline(f1)
{
   f1.className="menubuttonGreyRaised"
}

function removeOutline(f1)
{
   f1.className="menubuttonGrey"
}

function doStatus(f1)
{
   window.status=f1;
}

function checkCombo(f1,f2)
{
   if (f1.value=='') 
   {
      f2.value=0;
      return false;
   }
   if (f2.value==0)
   {
      f2.value=1
   }
}
 
 
 
 
 
 
 
 
 
