
function isWhitespace (c) {
    var whitespace = " \t\r\n\f";
    return (whitespace.indexOf (c) != -1);
    }

function trim (str) {
    if (str != null) {
        var front = 0;
        var back = str.length;
        while ((front != back) && isWhitespace (str.charAt (front))) {
            front++;
            }
        while ((front != back) && isWhitespace (str.charAt (back - 1))) {
            back--;
            }
        str = str.substring (front, back);
        }
    return (str);
    }

function isBlank (str) {
    if (str == null) {
        return (true);
        }
    for (var i = 0; i < str.length; i++) {        
        var c = str.charAt (i);
        if (!isWhitespace (c)) {
           return (false);
           }
        }
    return (true);
    }

function isValidEmail (str) {
    if (str == null) {
        return (false);
        }
    str = trim (str);                        // Start by trimming off whitespace at both ends
    for (var i = 0; i < str.length; i++) {   // Check that the address does not contain whitespace
        var c = str.charAt (i);
        if (isWhitespace (c)) {
           return (false);
           }
        }
    if (window.RegExp) {
        var tempStr = "a";  // First check that regular expression support is present
        var tempReg = new RegExp (tempStr);
        if (tempReg.test (tempStr)) {
            var r1 = new RegExp ("(@.*@)|(@\\.)|(^\\.)");
            var r2 = new RegExp ("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
            return (!r1.test(str) && r2.test(str));
            }
        }
    return (str.indexOf (".") > 2) && (str.indexOf ("@") > 0);
    }
	
// checkdaterange.js
function isDigit (c) {
    var digits = "0123456789";
    return (digits.indexOf (c) != -1);
    }
function make2digits (num) {
   return (num >= 10 ? num : ("0" + num));
   }

function formatDate (year, month, day) {
   return (year + "-" + make2digits (month) + "-" + make2digits (day));
   }

function getDate (date) {
   var part = date.split ("-");
   return (new Date (parseInt (part[0], 10), parseInt (part[1], 10) - 1, parseInt (part[2], 10)));
   }

function firstOfMonthDate () {
   var date = new Date ();
   return (formatDate (date.getFullYear (), date.getMonth () + 1, 1));
   }

function makeDate () {
   var date = new Date ();
   return (formatDate (date.getFullYear (), date.getMonth () + 1, date.getDate ()));
   }

   
function checkDate (entryfield) {
   var date = entryfield.value;
   if (date.search (/^\d+-\d\d-\d\d$/) != 0) {
      alert ("Bad date format. Dates must be in ISO8601 (YYYY-MM-DD) format");
      }
   else {
      var part  = date.split ("-");
      var year  = parseInt (part[0], 10);
      var month = parseInt (part[1], 10);
      var day   = parseInt (part[2], 10);
      if ((year < 1990) || (year > 2100)) {        
         alert ("Year out of range");
         }
      else if ((month < 1) || (month > 12)) {        
         alert ("Month out of range");
         }
      else if ((day < 1) || (day > 31)) {        
         alert ("Day out of range");
         }
      else {
         var monthDays = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
         if (((year % 4) == 0) == ((year % 100) == 0) == ((year % 400) == 0)) {
            monthDays[1]++;
            }
         if (day <= monthDays[month - 1]) {
            return (true);
            }
         var newDate = formatDate (year, month, monthDays[month - 1]);
         if (confirm ("\"" + date + "\" is not a valid date.\n\nWould you like to use \"" + newDate + "\" instead?")) {
            entryfield.value = newDate;
            return (true);
            }
         }
      }
   entryfield.focus ();
   return (false);
   }

function CheckDateRange (form) {
   if (checkDate (form.DATEFROM) && checkDate (form.DATETO)) {
      if (getDate (form.DATEFROM.value) <= getDate (form.DATETO.value)) {
         return (true);
         }
      alert ("\"To\" date is before \"From\" date");
      form.DATEFROM.focus ();
      }
   return (false);
   }

// location.js   
function getLocationValue (name) { 
   var loc = unescape (location.href);
   var begin = loc.indexOf ('?'); 
   if (begin != -1) {
      begin = loc.indexOf (name + "=", begin); 
      if (begin != -1) { 
         begin += name.length + 1; 
         var end = loc.indexOf ('&', begin);
         if (end == -1) {
            end = loc.length;
            }
         return (unescape (loc.substring (begin, end)));
         } 
      }
   return (null); 
   }

// cookie.js   
function getCookieValue (name) { 
   if (document.cookie.length != 0) { 
      var begin = document.cookie.indexOf (name + '='); 
      if (begin != -1) { 
         begin += name.length + 1; 
         var end = document.cookie.indexOf (';', begin);
         if (end == -1) {
            end = document.cookie.length;
            }
         return (unescape (document.cookie.substring (begin, end)));
         } 
      }
   return (null); 
   }

function setCookieValue (name, value, expiredays) { 
   var ExpireDate = new Date ();
   ExpireDate.setTime (ExpireDate.getTime () + (expiredays * 24 * 3600 * 1000));
   document.cookie = name + "=" + escape (value) + ((expiredays == null) ? "" : "; expires = " + ExpireDate.toGMTString ());
   }

function deleteCookie (name) { 
   if (getCookieValue (name) != null) {
      document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
      }
   } 
 
// affiliate.js
function getAffiliateID (form) {
   var affiliateID = getCookieValue ("BMTMicro.AID");
   if (affiliateID == null) {
      affiliateID = getLocationValue ("AID");
      if (affiliateID != null) {
         setCookieValue ("BMTMicro.AID", affiliateID, 90);
         }
      }
   form.AFFILIATEID.value = affiliateID;
   }
  
   