// fileuploadsupport V1.00
function updatefile(ref, filename){		// update product file info called from PHP upload script
  var ffield = 'file_' + ref;
  if ( document.getElementById(ffield) )
    {
    document.getElementById(ffield).value = filename;
    displayfilename(ref);
    }
  else
    {
    alert('Cannot locate main product page');
    }
}

function displayfilename(ref){		// update product file info
  var ffield = 'file_' + ref;
  if ( document.getElementById(ffield) )
    {
    var filename = document.getElementById(ffield).value;
    if ( filename != '' )
      {
      var infofield = 'finfo_' + ref;
      if ( document.getElementById(infofield) )
        {
        var basename = filename.replace(/file-\d+-/, '');
        document.getElementById(infofield).innerHTML = 'File:<b> ' + basename + ' </b> will be added to the Cart with this product';
        }
      }
    }
}

function updateallfilenames(){		// needed if page refreshed
  var ifields = document.getElementsByTagName('input');
  for (var i=0; i < ifields.length; i++)
    {
    var fileid = ifields[i].id;
    var bits = fileid.match(/^file_(.*)/);
    if ( bits != null )
      {
      displayfilename(bits[1]);
      }
    }
}

function popupfileuploadform(ref){		// display the Image Upload Form
if ( location.href.indexOf('PreviewHTML') > -1 )
  {
  alert('File can only be uploaded on live site');
  return;		// abandon if previewing
  }
  var popwin = window.open(basehref + 'file_upload_form.html?ref=_' + ref + '_', 'upform', 'height=250,width=500,toolbar=no');
  popwin.focus();
}

function checkuploadedfile(ref){
  var ffield = 'file_' + ref;
  if ( document.getElementById(ffield) )
    {
    if ( document.getElementById(ffield).value != '' ) return true;
    }
  alert('You must upload a file before adding this product to the Cart');
  return false;
}

