function notDesc(val)
{
   if(val.length > (32*1024))
      return(true);
   return(false);
}

// formats: MM/DD/YYYY, MM/DD/YYYY, MM/YYYY, MM/YY, MM/DD
function notDate(val,day,year,year4)
{
   var ar;
   var vmonth;
   var vday;
   var vyear;
   if(day == null)
      day = true;
   if(year == null)
      year = true;
   if(year4 == null)
      year4 = false;
   ar = val.split('/');
   if(year && day)
      if(ar.length != 3)
         return(true);
   if(year && !day)
      if(ar.length != 2)
         return(true);
   if(!year && day)
      if(ar.length != 2)
         return(true);
   if(ar[0] == '')
      return(true);
   if(ar[1] == '')
      return(true);
   if(ar.length == 3)
      if(ar[2] == '')
         return(true);
   if(isNaN(ar[0]))
      return(true);
   if(isNaN(ar[1]))
      return(true);
   if(ar.length == 3)
      if(isNaN(ar[2]))
         return(true);
   if(ar.length == 3 && year)
   {
      vmonth = ar[0];
      vday = ar[1];
      vyear = ar[2];
   }
   if(ar.length == 2 && year && !day)
   {
      vmonth = ar[0];
      vday = 0;
      vyear = ar[1];
   }
   if(ar.length == 2 && !year && day)
   {
      vmonth = ar[0];
      vday = ar[1];
      vyear = 0;
   }
   if(vmonth < 1 || vmonth > 12)
      return(true);
   if(day)
   {
      if(vday < 1 || vday > 31)
         return(true);
      if((vmonth == 9 || vmonth == 4 || vmonth == 6 || vmonth == 11 ) && vday > 30)
         return(true);
      if(vmonth == 2 && vday > 29 && vyear % 4 == 0)
         return(true);
      if(vmonth == 2 && vday > 28 && vyear % 4 != 0)
         return(true);
   }
   if(year)
   {
      if(vyear.length != 2 && vyear.length != 4)
         return(true);
   }
   if(year4 && vyear.length != 4)
      return(true);
   return(false);
}

// formats: HH:MI:SS PM, HH:MI:SS, HH:MI PM, HH:MI, HH
function notTime(val,mins,secs,pm)
{
   var ar;
   var vhour;
   var vmin;
   var vsec;
   var vpm;
   val = val.toUpperCase();
   val = val.replace(/\:/g,' ');
   ar = val.split(' ');
   if(val.indexOf('AM') != -1 || val.indexOf('PM') != -1)
   {
      if(ar.length == 4)
      {
         vhour = ar[0];
         vmin = ar[1];
         vsec = ar[2];
         vpm = ar[3];
         format = 1;
      }
      else if(ar.length == 3)
      {
         vhour = ar[0];
         vmin = ar[1];
         vpm = ar[2];
      }
      else
      {
         return(true);
      }
   }
   else
   {
      if(ar.length == 3)
      {
         vhour = ar[0];
         vmin = ar[1];
         vsec = ar[2];
      }
      else if(ar.length == 2)
      {
         vhour = ar[0];
         vmin = ar[1];
      }
      else if(ar.length == 1)
      {
         vhour = ar[0];
      }
      else
      {
         return(true);
      }
   }
   if(isNaN(vhour))
      return(true);
   if(mins && isNaN(vmin))
      return(true);
   if(secs && isNaN(vsec))
      return(true);
   if(vhour < 1 || vhour > 12)
      return(true); 
   if(mins && vmin < 0 || vmin > 59)
      return(true); 
   if(secs && (vsec < 0 || vsec > 59))
      return(true); 
   if(pm && vpm != 'AM' && vpm != 'PM')
      return(true);
   if(mins && vmin.length != 2)
      return(true); 
   if(secs && String(vsec).length != 2)
      return(true); 
   return(false);
}

// isNaN does not trap spaces, so this is a work around
function notNumber(val)
{
   var idx;
   var valid = '0123456789-.';
   if(isNaN(val))
      return(true);
   for(idx = 0; idx < val.length; idx++)
   {
      if(valid.indexOf(val.substr(idx,1)) == -1)
         return(true);
   }
   return(false);
}

function notAlphaNumeric(val)
{
   var idx;
   var valids = '0123456789abcdefghijklmnopqrstuvwxyz';
   var tmp = val.toLowerCase();
   for(idx = 0; idx < tmp.length; idx++)
   {
      if(valids.indexOf(tmp.charAt(idx)) == -1)
         return(true);
   }
   return(false);
}

function notPosInteger(val)
{
   if(notNumber(val))
      return(true);
   if(val.indexOf('.') != -1)
      return(true);
   if(val.indexOf('-') != -1)
      return(true);
   return(false);
}

function notUsername(val)
{
   if(notAlphaNumeric(val))
      return(true);
   if(val.length > 8)
      return(true);
   return(false);
}

// formats: X@Y
function notEmail(val)
{
   if(val.indexOf('@') == -1)
      return(true);
   return(false);
}

// formats: 123-45-6789, 123456789
function notSSN(val)
{
   var ar;
   ar = val.split('-')
   if(ar.length != 1 && ar.length != 3)
      return(true);
   if(ar.length == 3 && val.indexOf('-') != 3)
      return(true);
   if(ar.length == 3 && val.indexOf('-',val.indexOf('-')+1) != 6)
      return(true);
   val = val.replace(/\-/g,'');
   if(val.length != 9)
      return(true);
   if(isNaN(val))
      return(true);
   return(false);
}

// formats: 1234567
function notStudentId(val)
{
   if(val.length != 7)
      return(true);
   if(isNaN(val))
      return(true);
   return(false);
}

// formats: accepts any combination of alphanumeric plus - characters
function notZip(val)
{
   var idx;
   var valids = '0123456789abcdefghijklmnopqrstuvwxyz-';
   var tmp = val.toLowerCase();
   for(idx = 0; idx < tmp.length; idx++)
   {
      if(valids.indexOf(tmp.charAt(idx)) == -1)
         return(true);
   }
   return(false);
}

// formats: (605)394-1295, 605-394-1295, 394-1295, 1295
function notPhone(val,area,prefix)
{
   var ar;
   val = val.replace(/\s/g,'');
   if(val.length != 13 && val.length != 12 && val.length != 8 && val.length != 4)
      return(true);
   if(area && val.length != 13 && val.length != 12)
      return(true);
   if(prefix && val.length != 13 && val.length != 12 && val.length != 8)
      return(true);
   if(val.length == 13 && (val.charAt(0) != '(' || val.charAt(4) != ')' || val.charAt(8) != '-'))
      return(true);
   if(val.length == 12 && (val.charAt(3) != '-' || val.charAt(7) != '-'))
      return(true);
   if(val.length == 8 && (val.charAt(3) != '-'))
      return(true);
   val = val.replace(/\(/,'');
   val = val.replace(/\)/,'-');
   ar = val.split('-')
   if(val.length == 13 && ar.length != 3)
      return(true);
   if(val.length == 12 && ar.length != 3)
      return(true);
   if(val.length == 8 && ar.length != 2)
      return(true);
   if(val.length == 4 && ar.length != 1)
      return(true);
   val = val.replace(/\-/g,'');
   if(isNaN(val))
      return(true);
   return(false);
}

