<!--

function Validate(formNode, validControlClass, invalidControlClass, validErrorClass, invalidErrorClass) {
  
  var valid = true;
  var regExps = new Array();
  regExps['text'] = new RegExp(/[^\w\d\s]/);
  regExps['number'] = new RegExp(/[^\d]/);
  regExps['decimal'] = new RegExp(/[^\d\.]/);
  regExps['money'] = new RegExp(/[^\d\.\$]/);
  regExps['boolean'] = new RegExp(/[^(0|1){1}]/);
  regExps['email'] = new RegExp(/[^\w\d\s\@\.\-]/);
  regExps['url'] = new RegExp(/[^\w\d\s\@\.\-\/\:]/);
  
  for (var i = 0; i < formNode.elements.length; i++) {
    var element = formNode.elements[i];
    var value = '';
    var type = '';
    var errorId = ''
    var check = false;
    
    if (element.nodeName == 'INPUT') check = true;
    if (element.nodeName == 'SELECT') check = true;
    if (element.nodeName == 'TEXTAREA') check = true;
    
    if (check == false) continue;
    
    errorId = element.getAttribute('errorId');
    var errorNode = document.getElementById(errorId);
    value = element.value;
    
    if ((element.getAttribute('required')) && (value.length == 0)) {
      element.className = invalidControlClass;
      if (errorNode) errorNode.className = invalidErrorClass;
      valid = false;
    } else {
      type = element.getAttribute('datatype');
      if ((regExps[type]) && (regExps[type].exec(value) != null)) {
        element.className = invalidControlClass;
        if (errorNode) errorNode.className = invalidErrorClass;
        valid = false;
      } else {
        element.className = validControlClass;
        if (errorNode) errorNode.className = validErrorClass;
      };
    };
  };
  
  return valid;
};


function addLightBox(ImageName) {
  winLB = window.open("lightBox.asp?mode=add&Image=" +ImageName, "LightBox", "width=650,height=420,resizable,scrollbars,toolbar");
  if (document.focus) winLB.focus();

  return false;
}

function partialSelect(node, start, end) {
  if (document.selection) {
    var sel = node.createTextRange();
    sel.select();
    sel.moveStart("character", start);
    sel.select();
  } else if (node.selectionStart) {
    node.selectionStart = start;
    node.selectionEnd = end;
  };
};

function autoComplete(event, input, values) {
  var key;
  if (window.event) var event = window.event;
  if (event.keyCode) {
    key = event.keyCode;
  } else if (event.which) {
    key = event.which;
  };

  key = String.fromCharCode(key);
  if (((key < 'A') || (key > 'Z')) && (key != ' ')) return;

  for (var i = 0; i < values.length; i++) {
    if (values[i].search(input.value) > -1) {
      var start = input.value.length;
      input.value = values[i];
      partialSelect(input, start, input.value.length);
      return;
    }
  }  
}


function setAllSelects(index) {
  var list = document.getElementsByTagName('select');

  for (var i = 0; i < list.length; i++) {
    list.item(i).selectedIndex = index;
  };
  return false;
};  

function MailFriend(imageNumber) {
  winMail = window.open('mailFriend.asp?image=' + imageNumber,'MailFriend','toolbar=no,status=no,width=400,height=500');
  if (window.focus) winMail.focus();

  return false;
}

function AddTerm(form) {
  index = form.selectedIndex;
  value = form[index].value;

  if (value.length > 0) 
  {
    termLength = document.searchform.Term.value.length;
    if (termLength > 0) 
    {
      if (document.searchform.Term.value.charAt(termLength - 1) != " ") 
      {
        document.searchform.Term.value += " ^ ";
      }
    }
    document.searchform.Term.value += value;
    form.selectedIndex = 0;
  }
  termLength = document.searchform.withinField.value.length
  if (termLength > 0) 
  {
     document.searchform.Term.value += document.searchform.withinField.value;
  }
}

function AddTermWithin(form, within, reset) {
  index = form.selectedIndex;
  value = form[index].value;

  if (value.length > 0) {
    termLength = document.searchform.Term.value.length;

    if (termLength > 0) {
      if (document.searchform.Term.value.charAt(termLength - 1) != " ") {
        document.searchform.Term.value += " ^ ";
      }
    }
    document.searchform.Term.value += value + ":" + within;
    if (reset) form.selectedIndex = 0;
  }
}

function AddTermWithinForSQL(form, within, reset) {
  index = form.selectedIndex;
  value = form[index].value;

  if (value.length > 0) {
    termLength = document.searchform.Term.value.length;

    if (termLength > 0) {
      if (document.searchform.Term.value.charAt(termLength - 1) != " ") {
        document.searchform.Term.value += " ";
      }
    }
    document.searchform.Term.value += value + ":" + within;
    if (reset) form.selectedIndex = 0;
  }
}

function AddTermForSQL(form) {
  index = form.selectedIndex;
  value = form[index].value;

  if (value.length > 0) {
    termLength = document.searchform.Term.value.length;

    if (termLength > 0) {
      if (document.searchform.Term.value.charAt(termLength - 1) != " ") {
        document.searchform.Term.value += " ";
      }
    }
    document.searchform.Term.value += value;
    if (reset) form.selectedIndex = 0;
  }
}

function AddToSearchTerm(form) 
{
  index = form.selectedIndex;
  value = form[index].value;
  termLength = document.searchform.Term.value.length

  if(termLength > 0 )
  {
    document.searchform.Term.value += " ";
  }
  document.searchform.Term.value += value;
}

function AddIdentifier(form) {
  index = form.selectedIndex;
  value = form[index].value;

  append = value + " ";
  document.searchform.Term.value += append;

  form.selectedIndex = 0;
}

function ChangeSelection(form)
{
  index = form.selectedIndex;
  value = form[index].value;
}

function AddStorWithin(form)
{
  index = form.selectedIndex;
  value = form[index].value;

  if (value.length > 0) 
  {
    termLength = document.searchform.Term.value.length;

    if (termLength > 0) 
    {
      document.searchform.Term.value += value;
      document.searchform.withinField.value = "";
    }
    else
    {
      document.searchform.withinField.value = value;
    }
  }
}

function setWithin(form) 
{
  if (form.withinField.value.length > 0) 
    form.Term.value = form.Term.value + form.withinField.value;
  return true;
}

function popDownloads() {
  winVD = window.open("viewDownloads.asp","checkDownloads", "width=500,height=300,resizable,scrollbars,toolbar");
  if (window.focus) winVD.focus();
  return false;
}

function verifyData(){
  if (emailCheck() == false) return false;
  if (passwordMatch() == false) return false;

  var len = document.frmUser.length;

  for (var i = 0; i < len; i++) {
    var item = document.frmUser.elements[i];
    if ((item == null) || (item.name == undefined)) continue;

    if (item.name.indexOf("db_nc_") == -1 && item.name.indexOf("db_") > -1) {
      if (item.value.length == 0) {
        var niceName = item.name.replace("db_", "");

        niceName = niceName.substring(0, 1).toUpperCase() + niceName.substring(1);

        if (niceName.indexOf("2") > -1) {
          niceName = niceName.replace("2", "");
          niceName = "Billing " + niceName;
        }

        if (niceName.indexOf("1") > -1) {
          niceName = niceName.replace("1", "");
          niceName = "Shipping " + niceName;
        };

        alert(niceName + ' is a required field');
        if (window.focus) item.focus();
        return false;
      }
    }
  }

  return true;
}

function emailCheck(){
  var a = document.frmUser.db_email.value;
  if(a.indexOf("@") == -1){
    alert('Invalid Email address - please enter again');
    document.frmUser.db_email.select();
    return false;
  }
  return true;
}


function passwordMatch() {
  if (document.frmUser.db_password.value.length < 6) {
    alert('Passwords must be at least 6 characters long');
    document.frmUser.db_password.focus();
    return false
  }

  if (document.frmUser.db_password.value != document.frmUser.verifyPassword.value) {
    alert ("Your passwords do not match - please enter again");
    document.frmUser.db_password.select();
    return false;
  }
  return true;
}

function goDefault() {
  document.location = "default.asp?member=yes"
}

function getFocus() {
  window.focus()
}

function continueBrowse() {
  window.blur()
}

function closeWindow() {
  window.close()
}

function checkUsageNotes() {
  var a = document.frm.usageNotes.value;
  if(a == ""){
    alert('The Usage Notes should not be empty.');
    document.frm.usageNotes.select();
    return false;
  }
  return true;
}


function goBasket() {
  document.location = "basket.asp"
}

function goCheckOutLast() {
  window.location="checkOutLast.asp"
}

function StartMess() {
  CopyWin = window.open('copyrght.asp','Copyright','toolbar=no,status=no,width=400,height=220');
  WarnWin = window.open('warning.asp','Warning','toolbar=no,status=no,width=400,height=200');
}

function CopyMess() {
  winCopy = window.open('copyrght.asp','Copyright','toolbar=no,status=no,width=400,height=220');
  if (document.focus) winCopy.focus();

  return false;
}

function WarnMess() {
  winWarn = window.open('warning.asp','Warning','toolbar=no,status=no,width=400,height=200');
  if (document.focus) winWarn.focus();

  return false;
}

function openDownload(image,title) {
  winHR = window.open("download.asp?image=" + image + "&title=" + title, "download", "width=580,height=320,resizable,scrollbars,toolbar");
  if (document.focus) winHR.focus();

  return false;
}

function addBasket(direct,showFormat,showQuantity) {
  if (direct > 0) {
    addString = ""
    if (showQuantity > 0) {
      quantity = document.frm.quantity.value
      addString = addString + "&quantity=" + quantity
    }
    if (showFormat > 0) {
      kind = document.frm.format.selectedIndex
      addString = addString + "&format=" + kind
    }
    winCC = window.open("checkCookie.asp?preview=no&mode=add" + addString + "&kind=" + kind, "basket", "width=650,height=420,resizable,scrollbars,toolbar")
  } else {
    winCC = window.open("checkCookie.asp?mode=add&alwaysUsage=no&preview=no", "basket", "width=650,height=420,resizable,scrollbars,toolbar")
  }

  if (document.focus) winCC.focus();
  return false;
}

function showBasket() {
  winCC = window.open("checkCookie.asp?preview=no","basket", "width=600,height=420,resizable,scrollbars,toolbar")
  if (document.focus) winCC.focus();

  return false;
}

function goCheckout() {
  winCC = window.open("checkCookie.asp?mode=checkout","basket", "width=600,height=420,resizable,scrollbars,toolbar")
  if (document.focus) winCC.focus();

  return false;
}


function addThumbBasket(direct,showFormat,showQuantity,image,title) {
  if (direct > 0) {
    addString = ""
    if (showQuantity > 0) {
      quantity = document.frm.quantity.value
      addString = addString + "&quantity=" + quantity
    }

    if (showFormat>0) {
      kind = document.frm.format.selectedIndex
      addString = addString + "&format=" + kind
    }
    addString = addString + "&image=" + image
    addString = addString + "&title=" + title

    winCC = window.open("checkCookie.asp?from=thumb&preview=no&mode=add" + addString, "basket", "width=600,height=420,resizable,scrollbars,toolbar")

  } else {
    addString = ""
    addString = addString + "&image=" + image
    addString = addString + "&title=" + title

    winCC = window.open("checkCookie.asp?from=thumb&mode=add&alwaysUsage=no&preview=no" + addString, "basket", "width=600,height=420,resizable,scrollbars,toolbar")
  }

  if (document.focus) winCC.focus();
  return false;

}

function collectionWindow() {
  winCol = window.open('collection.asp','winCol','scrollbars=yes,resizable=yes,width=400,height=300');
  if (document.focus) winCol.focus();

  return false;
}

function copyrightWindow() {
  winCopy = window.open('copyright.asp','winCopy','scrollbars=yes,resizable=yes,width=400,height=220');
  if (document.focus) winCopy.focus();

  return false;
}

function warningWindow() {
  winWarn = window.open('warning.asp','winWarn','scrollbars=yes,resizable=yes,width=400,height=200');
  if (document.focus) winWarn.focus();

  return false;
}

function helpWindow() {
  winHelp = window.open('help.asp','winHelp','scrollbars=yes,resizable=yes,width=600,height=400');
  if (document.focus) winHelp.focus();

  return false;
}

function pricesWindow() {
  winPrices = window.open('prices.asp','winPrices','scrollbars=yes,resizable=yes,width=600,height=400');
  if (document.focus) winPrices.focus();

  return false;
}
function OrderWindow() {
  winOrder = window.open('order.asp','basket','scrollbars=yes,resizable=yes,width=600,height=420');
  if (document.focus) winOrder.focus();

  return false;
}

function DownloadWindow() {
  winDownload = window.open('viewDownloads.asp','winDownload','scrollbars=yes,resizable=yes,width=600,height=420');
  if (document.focus) winDownload.focus();

  return false;
}

function contactWindow() {
  winContact = window.open('contactUs.asp', 'winContact', 'scrollbars=yes,resizable=yes,width=600,height=420');
  if (document.focus) winContact.focus();

  return false;
}

function confirmClear() {
  return confirm('ALL contents in the basket will be CLEARED if you click OK')
}

function imageOver(image, name) {
  imageSwitch(image, "../images/" + name + "mo.gif");
}

function imageOut(image, name) {
  imageSwitch(image, "../images/" + name + ".gif");
}

function imageClick(image, name) {
  imageSwitch(image, "../images/" + name + "cl.gif");
}

function imageSwitch(image, name) {
  image.src = name;
}

function newUserPassCheck(pass1, pass2, newUser){
  if (newUser.checked == true) {
    return true;
  }

  var passLength = pass1.value.length;

  if (passLength < 6) {
    alert('Passwords should be at least 6 characters long, please enter a new password');
    pass1.select();
    return false;
  }

  if (pass1.value != pass2.value) {
    alert('Your passwords do not match, please retype your passwords');
    pass1.select();
    return false;
  }

  return true;
}

function openURL(url, width, height) {
  winOpener = window.open(url,'STURLOpener','scrollbars=yes,resizable=yes,width=' + width +',height=' + height);
  if (document.focus) winOpener.focus();

  return false;
}

//-->