
// COMMON

function required(s)
{
   if (s.value.length == 0)
   {
      return false;
   }
   return true;
}

function checknumber(s)
{
    for(var n=0;n<s.value.length;n++)
    {
       c = s.value.charAt(n);
       if ( c != "0" &&  c != "1" &&  c != "2" &&  c != "3" &&  c != "4" &&  c != "5" &&  c != "6" &&  c != "7" &&  c != "8" &&  c != "9" && c != "-"  && c != "." )
       {
          return false;
       }          
    }
    
    return true;
    
}



// ATS

function verifyats()
{        

    // EDIT SECTION
    
    if (!required(document.ATS.section))
    {
       alert("Section number is blank. Please enter a Section from 1 to 36.");
       document.ATS.section.focus();
       return false;
    }    
    
    if (!checknumber(document.ATS.section))
    {
       alert("Section is not a valid number. Please enter a Section from 1 to 36.");
       document.ATS.section.focus();
       return false;
    }
    
    ret = parseInt(document.ATS.section.value);
    
    if (ret<1 || ret > 36)
    {
       message = "Section "+ret+" is out of range. Please enter a Section from 1 to 36."
       alert(message);
       document.ATS.section.focus();
       return false;
    }  
    
    // EDIT TOWNSHIP
    
    if (!required(document.ATS.township))
    {
       alert("Please enter a Township from 1 to 137.");
       document.ATS.township.focus();
       return false;
    }  
    
    if (!checknumber(document.ATS.township))
    {
       alert("Township is not a valid number. Please enter a Township from 1 to 137.");
       document.ATS.township.focus();
       return false;
    }
    
    ret = parseInt(document.ATS.township.value);
    
    if (ret<1 || ret > 137)
    {
       message = "Township "+ret+" is out of range. Please enter a Township from 1 to 137."
       alert(message);
       document.ATS.township.focus();
       return false;
    }  
    
    
    // EDIT RANGE
    
    if (!required(document.ATS.range))
    {
       alert("Please enter a range from 1 to 140.");
       document.ATS.range.focus();
       return false;
    }  
    
    if (!checknumber(document.ATS.range))
    {
       alert("Range is not a valid number. Please enter a Range from 1 to 140.");
       document.ATS.range.focus();
       return false;
    }
    
    ret = parseInt(document.ATS.range.value);
    
    if (ret<1 || ret > 140)
    {
       message = "Range "+ret+" is out of range. Please enter a Range from 1 to 140."
       alert(message);
       document.ATS.range.focus();
       return false;
    }  
        
      
    // EDIT MERIDIAN
        
        
    if (!required(document.ATS.meridian))
    {
       alert("Please select a Meridian");
       document.ATS.meridian.focus();
       return false;
    }
    
    return true;
}



function resetats()
{
   document.ATS.quarter.value  = "";
   document.ATS.section.value  = "";
   document.ATS.township.value = "";
   document.ATS.range.value    = "";
   document.ATS.meridian.value = "";
   document.ATS.quarter.focus();
}

// REVERSE

function verifyreverse()
{
    if (!required(document.REVERSE.latitude))
    {
       alert("Please enter a Latitude");
       document.REVERSE.latitude.focus();
       return false;
    }  
    
    if (!required(document.REVERSE.longitude))
    {
       alert("Please enter a Longitude");
       document.REVERSE.longitude.focus();
       return false;
    }
    
    return true;
}


function verifyreverse2()
{
    if (!required(document.REVERSE2.latdeg))
    {
       alert("Please enter a Latitude Degree");
       document.REVERSE2.latdeg.focus();
       return false;
    }  
    
    if (!required(document.REVERSE2.longdeg))
    {
       alert("Please enter a Longitude Degree");
       document.REVERSE2.longdeg.focus();
       return false;
    }  
    
    
    return true;
}

function resetreverse()
{
   document.REVERSE.latitude.value  ="";
   document.REVERSE.longitude.value ="";
   document.REVERSE.latitude.focus();
}


function resetreverse2()
{
   document.REVERSE2.latdeg.value  ="";
   document.REVERSE2.latmin.value  ="";
   document.REVERSE2.latsec.value  ="";
   document.REVERSE2.longdeg.value ="";
   document.REVERSE2.longmin.value ="";
   document.REVERSE2.longsec.value ="";
   document.REVERSE2.latdeg.focus();
}



