  function previewCanvas(whichID,previewOnly) {
    if (previewOnly == undefined) previewOnly = false;
    if (!previewOnly) {
      document.getElementById('addToCartButton').disabled = false;
      for (i=0;i<3;i++) if (canvasChoice[i] == whichID) {
        document.getElementById('addToCartButton').disabled = true;
        break;
      }
    }
    document.getElementById('previewImage').src           = (whichID == selectedID) ? '/images/products/canvases/__holder.jpg'  : id2img[whichID];
    document.getElementById('previewName').innerHTML      = (whichID == selectedID) ? '&nbsp;'                                  : id2name[whichID];
    document.getElementById('previewText').innerHTML      = (whichID == selectedID) ? '&nbsp;'                                  : id2desc[whichID];
    if (!previewOnly)  document.getElementById('addToCartRow').style.display = (whichID == selectedID) ? 'none'                                    : 'inline';
    document.getElementById('canvasText').style.display   = (whichID == selectedID) ? 'none'                                    : 'inline';
    selectedID                                            = (whichID == selectedID) ? false                                     : whichID;
  }

  var selectButtonDisabled;
  function selectCanvas(whichID,whichPosition) {
    if (whichID == undefined) {
      if (!selectedID)  return false;
      whichID = selectedID;
    }
    if (whichPosition == undefined) {
      for (i=0;i<idLoop.length;i++) if (!canvasChoice[i]) {
        whichPosition = i;
        break;
      }
      if (whichPosition == undefined) return false;
    }
    canvasChoice[whichPosition] = whichID;
    document.getElementById('selectedstyle'+whichPosition+'_img').src = id2thumb[whichID];
    document.getElementById('canvasHidden_'+whichPosition).value      = whichID;
    document.getElementById('addToCartButton').disabled = true;
    toggleUploadForm();
    return false;
  }

  var origDet,newDet;
  function moveLeft(whichPosition) {
    if (whichPosition < 1)            return false;
    if (!canvasChoice[whichPosition]) return false;
    origDet = canvasChoice[whichPosition];
    newDet  = canvasChoice[(whichPosition-1)];
    selectCanvas (origDet,(whichPosition-1));
    selectCanvas (newDet,whichPosition);
    return true;
  }
  function moveRight (whichPosition) {
    if (whichPosition > 1)                return false;
    if (!canvasChoice[whichPosition] || !canvasChoice[(whichPosition+1)]) return false;
    origDet = canvasChoice[whichPosition];
    newDet  = canvasChoice[(whichPosition+1)];
    selectCanvas (origDet,(whichPosition+1));
    selectCanvas (newDet,whichPosition);
    return true;
  }
  var enableButton;
  function removeSelection (whichPosition) {
    if (!canvasChoice[whichPosition]) return false;
    enableButton = (selectedID == canvasChoice[whichPosition]);
    for (i=0;i<idLoop.length;i++) {
      if (whichPosition == i) {
        if (whichPosition == 0 && canvasChoice[1]) {
          moveLeft(1);
          whichPosition++;
        }
        if (whichPosition == 1 && canvasChoice[2]) {
          moveLeft(2);
          whichPosition++;
        }
        document.getElementById('selectedstyle'+whichPosition+'_img').src = '/images/products/canvases/__holder.jpg';
        document.getElementById('canvasHidden_'+whichPosition).value      = '';
        canvasChoice[whichPosition]                                       = false;

        break;
      }
    }
    document.getElementById('addToCartButton').disabled = !enableButton;
    return false;
  }

  function toggleUploadForm () {
    if (!canvasChoice[0]) {
      document.getElementById('upload_image_row').style.display = 'inline';
      document.getElementById('no_upload_image_row').style.display = 'none';
      return true;
    }
    document.getElementById('upload_image_row').style.display = (id2ui[canvasChoice[0]])    ? 'inline'  : 'none';
    document.getElementById('no_upload_image_row').style.display = (id2ui[canvasChoice[0]]) ? 'none'    : 'inline';
    return true;
  }
  function toggleUploadField(val) {
    document.getElementById('upload_image').disabled = (document.getElementById('sendbypost').checked);
    return true;
  }

  function loadTimer() {
    document.getElementById('submit').disabled  = true;
    document.getElementById('pageLoadTimer').style.display  = 'inline';
    appendToTimer();
    return true;
  }
  function appendToTimer () {
    document.getElementById('pageLoadTimer').innerHTML += '.';
    setTimeout('appendToTimer()',1000);
    return true;
  }

  function unlockCustomerDetails() {
    document.getElementById('val_name').disabled = false;
    document.getElementById('val_email').disabled = false;
    document.getElementById('val_address_0').disabled = false;
    document.getElementById('val_address_1').disabled = false;
    document.getElementById('val_address_2').disabled = false;
    document.getElementById('val_address_3').disabled = false;
    document.getElementById('val_postcode').disabled = false;
    document.getElementById('val_telephone').disabled = false;

    document.getElementById('editmydetails').value = '1';
    return false;
  }