// VARIOUS FORM MANIPULATION AND READING SCRIPTS
// HISTORY
// 22/09/2005 - PSB - Created (mostly for delivery instructions)

//safe function to hide an element with a specified id
function hideelement(elementid) {
  if (document.getElementById) { // DOM3 = IE5, NS6
    if (document.getElementById(elementid)) {
      dropdownval = document.getElementById(elementid).style.display = 'none';
    }
  }
  else {
    if (document.layers) { // Netscape 4
      if (document.elementid) {
        dropdownval = document.elementid.style.display = 'none';
      }
    }
    else { // IE 4
      if (document.all.elementid) {
        dropdownval = document.all.elementid.style.display = 'none';
      }
    }
  }
}
//safe function to show an element with a specified id
function showelement(elementid) {
  if (document.getElementById) { // DOM3 = IE5, NS6
    if (document.getElementById(elementid)) {
      dropdownval = document.getElementById(elementid).style.display = 'block';
    }
  }
  else {
    if (document.layers) { // Netscape 4
      if (document.elementid) {
        dropdownval = document.elementid.style.display = 'block';
      }
    }
    else { // IE 4
      if (document.all.elementid) {
        dropdownval = document.all.elementid.style.display = 'block';
      }
    }
  }
}
//safe function to get the value of an element
function getelementvalue(elementid) {
  if (document.getElementById) { // DOM3 = IE5, NS6
    if (document.getElementById(elementid)) {
      return document.getElementById(elementid).value;
    } else {
      return '';
    }
  }
  else {
    if (document.layers) { // Netscape 4
      if (document.elementid) {
        return document.elementid.value;
      } else {
        return '';
      }
    }
    else { // IE 4
      if (document.all.elementid) {
        return document.all.elementid.value;
      } else {
        return '';
      }
    }
  }
}

//safe function to set the value of an element
function setelementvalue(elementid,elemval) {
  if (document.getElementById) { // DOM3 = IE5, NS6
    if (document.getElementById(elementid)) {
      document.getElementById(elementid).value = elemval;
      return true;
    } else {
      return false;
    }
  }
  else {
    if (document.layers) { // Netscape 4
      if (document.elementid) {
        document.elementid.value = elemval;
        return true;
      } else {
        return false;
      }
    }
    else { // IE 4
      if (document.all.elementid) {
        document.all.elementid.value = elemval;
        return true;
      } else {
        return false;
      }
    }
  }
}


//safe function to hide an element with a specified id
function toggledeliveryfields() {
  //set up variables
  var dropdownval = '';
  dropdownval = getelementvalue('del_instr_dropdown');

  //trick to test if people have JavaScript enabled
  setelementvalue('supportsjavascript','true');

  //show dropdown list for JavaScript enabled users, always
  showelement('del_instr_dropdown_label');
  showelement('del_instr_dropdown');

  if (dropdownval == 'Brochure Request') {
    //We must be on "Other (please specify)...", so show free text delivery instructions and label
    showelement('BrochureAudioVisual');
    showelement('BrochureAudioVisual_label');
	showelement('BrochureWater');
    showelement('BrochureWater_label');
	showelement('BrochureCellar');
    showelement('BrochureCellar_label');
	showelement('BrochureSecurity');
    showelement('BrochureSecurity_label');
	showelement('BrochureSmoking');
    showelement('BrochureSmoking_label');
	showelement('BrochureFinance');
    showelement('BrochureFinance_label');
	showelement('BrochurePool');
    showelement('BrochurePool_label');
	showelement('ViaEmail');
    showelement('ViaEmail_label');
	showelement('ViaPost');
    showelement('ViaPost_label');
	showelement('BrochureAddress');
    showelement('BrochureAddress_label');
	Address_label
  }
  else {
    //hide instructions textbox and label
    hideelement('BrochureAudioVisual');
    hideelement('BrochureAudioVisual_label');
	hideelement('BrochureWater');
    hideelement('BrochureWater_label');
	hideelement('BrochureCellar');
    hideelement('BrochureCellar_label');
	hideelement('BrochureSecurity');
    hideelement('BrochureSecurity_label');
	hideelement('BrochureSmoking');
    hideelement('BrochureSmoking_label');
	hideelement('BrochureFinance');
    hideelement('BrochureFinance_label');
	hideelement('BrochurePool');
    hideelement('BrochurePool_label');
	hideelement('ViaEmail');
    hideelement('ViaEmail_label');
	hideelement('ViaPost');
    hideelement('ViaPost_label');
	hideelement('BrochureAddress');
    hideelement('BrochureAddress_label');
  }
}