/* THE SEWING MACHINE MAN */
function mailadd (which) {
   if (which==2) {
      var one = "t.gresswell@";
      var two = "ntlworl";
      var three = "d.com";
   } else {
     var one = "enquiries@";
     var two = "the-sewing-machine-man.c";
     var three = "om";
   }
   return one+two+three;
}
function mailtag () {
   return '<a href=\"mailto:' + mailadd() + '?subject=Email from web site' + '\">';
}
function maillink () {
   return mailtag() + mailadd() + "</a>";
}
/* Date format routines */

/* Thanks to:  http://www.javascript-page.com & http://www.irt.org */

function makeArray0() {
     for (i = 0; i<makeArray0.arguments.length; i++)
          this[i] = makeArray0.arguments[i];
}

var months = new makeArray0('January','February','March',
    'April','May','June','July','August','September',
    'October','November','December');

function nths(day) {
     if (day == 1 || day == 21 || day == 31) return 'st';
     if (day == 2 || day == 22) return 'nd';
     if (day == 3 || day == 23) return 'rd';
     return 'th';
}

function correctedYear(year) {
// required for Netscape
    year = year - 0;
    if (year < 70) return (2000 + year);
    if (year < 1900) return (1900 + year);
    return year;
}

function formatDate(date) {
    var newYear = correctedYear(date.getYear());
    var newDate = new Date(newYear,date.getMonth(),date.getDate());
    return newDate.getDate() /* +  nths(newDate.getDate()) */ + " " + months[newDate.getMonth()] + " " + newYear;
}

function thisYear() {
    date = new Date();
    return correctedYear(date.getYear());
}

/* roll over routines for menu */

on = new Image; on.src = 'graphics/menuon.gif';
off = new Image; off.src = 'graphics/menuoff.gif';
function imgOn(page) {
  if (document.images && document[page]) {
    document[page].src = on.src;
  }
}
function imgOff(page) {
  if (document.images && page != mypage) {
    document[page].src = off.src;
  }
}

/* Checks for forms */

function checkFields() {
   missinginfo = "";
   if(document.form.NAME.value == "") {
      missinginfo += "\n     -  Your name";
   }
   if (document.form.TELEPHONE.value == "") {
      missinginfo += "\n     -  Your telephone number";
   }
   if ((document.form.email.value == "") || (document.form.email.value.indexOf('@') == -1) || (document.form.email.value.indexOf('.') == -1)) {
      missinginfo += "\n     -  A valid email address";
   }
   if (missinginfo != "") {
      missinginfo ="You did not fill in:\n" +
      missinginfo + "\n\nPlease re-enter and submit again.";
      alert(missinginfo);
      return false;
   }
   else return true;
}

function checkOrderFields() {
   missinginfo = "";
   if(document.form.NAME.value == "") {
      missinginfo += "\n     -  Your name";
   }
   if (document.form.TELEPHONE.value == "") {
      missinginfo += "\n     -  Your telephone number";
   }
   if (document.form.ADDRESS1.value == "") {
      missinginfo += "\n     -  The first line of your address";
   }
   if (document.form.ADDRESS_TOWN.value == "") {
      missinginfo += "\n     -  Your post town";
   }
   if (document.form.ADDRESS_POSTCODE.value == "") {
      missinginfo += "\n     -  Your postcode \n           (enter 'none' if you do not have one)";
   }
   if ((document.form.email.value == "") || (document.form.email.value.indexOf('@') == -1) || (document.form.email.value.indexOf('.') == -1)) {
      missinginfo += "\n     -  A valid email address";
   }
   if (missinginfo != "") {
      missinginfo ="You failed to correctly fill in:\n" +
      missinginfo + "\n\nPlease re-enter and submit again.";
      alert(missinginfo);
      return false;
   }
   else return true;
}

