// 20081218 AB Field Setup
function attr_onchange() {
  var obj;
  with (document) if ( getElementById && ((obj=getElementById('attrib-9'))!=null)) { 
    var en=(obj.selectedIndex>1);
    for(var e=0; e<(aids.length); e++) {
      attr_state(aids[e],en); 
    }
  }
}

function attr_formsubmit() {
  var obj,fld;
  
  // Robe Shipping Method
  with (document) if ( getElementById && ((obj=getElementById('attrib-9'))!=null)) { 
    // Nothing selected
    if(obj.selectedIndex==0) {
      alert('Please select a shipping method for your robe');
      var tclick = obj.parentNode.getAttribute( 'tabclick' );
      eval( tclick );
      obj.focus();
      return false;
    }
    // Walkin selected
    else if (obj.selectedIndex==1) {
      for(var e=0; e<(aids.length); e++) {
        with (document) if ( getElementById && ((fld=getElementById(aids[e]))!=null)) { fld.value = ''; }
      }
    }
    // Values are required
    else {
      var error_msg = '';
      var focus_first = false;
      for(var e=0; e<(aids.length); e++) {
        with (document) if ( getElementById && ((fld=getElementById(aids[e]))!=null)) { 
          fld.value = fld.value.replace(/^\s+|\s+$/g,""); 
          if(fld.value=='') { 
            error_msg = "Please enter shipping information for your robe.\n"; 
            if(!focus_first) { focus_first=fld; } 
          }
        }
      }
      if( error_msg != '' ) {
        alert( error_msg );
        var tid = focus_first.parentNode.getAttribute( 'tabclick' );
        eval( tid );
        // with (document) if ( getElementById && ((tab=getElementById(tid))!=null)) { tab.onclick(); }
        focus_first.focus();
        return false;
      }
    }
  }

  // Robe Size Field
  with (document) if ( getElementById && ((obj=getElementById('attrib-14'))!=null)) { 
    // Nothing selected
    if(obj.selectedIndex==0) {
      alert('Please select a robe size');
      var tclick = obj.parentNode.getAttribute( 'tabclick' );
      eval( tclick );
      obj.focus();
      return false;
    }
  }

  // Make all fields enabled otherwise blank disabled fields seem to get lost by Zen
  for(var e=0; e<(aids.length); e++) {
      attr_state(aids[e],true); 
    }
  return true;
}

function attr_validate( id ) {
  var obj;
  with (document) if ( getElementById && ((obj=getElementById(id))!=null)) { 
  }
}

// Initial setup on page load
function attr_onload() {
  var obj;
  aids = [ "attrib-10-0", "attrib-11-0", "attrib-13-0", "attrib-12-0" ];

  if ( document.getElementById && ((obj=document.getElementById('attrib-9'))!=null)) { 
    for(var e=0; e<(aids.length); e++) {
      attr_state(aids[e],false); 
    }
    obj.onchange=attr_onchange;
    attr_onchange();
  }
  // Prepare form validation
  var fm;
  for(f=0;f<(document.forms.length);f++) {
    if( document.forms[f].name == 'cart_quantity' ) {
      fm=document.forms[f];
      fm.onsubmit=attr_formsubmit;
    }
  }
  
  // Hide the "optional" label for email
  if ( document.getElementById && ((child=document.getElementById('optionalField'))!=null)) { 
      child.style.display='none';
      child.style.visibility='hidden';
      child.removeNode( true );
  }
  if ( document.getElementById && ((child=document.getElementById('optionalField'))!=null)) { 
      child.parentNode.removeChild( child );
  }

  // Nice Error Messages
/*  with (document) if ( getElementById && ((obj=getElementById('zenMessageStack'))!=null)) {
    // obj.style="color"
    var oc = "parobj=getElementById('zenMessageStack'); parobj.style.display='none'; parobj.style.visibility='hidden';"
    obj.innerHTML = obj.innerHTML + '<input type="button" value="OK" onclick="' + oc + '" />';
  } */
  
}

// Set individual attribute state
function attr_state( id, enstate ) {
  var obj;
  with (document) if ( getElementById && ((obj=getElementById(id))!=null)) { 
    if(enstate) {
      // obj.value='enabled';
      obj.removeAttribute('readonly'); 
      obj.removeAttribute('disabled'); 
    } else {
      // obj.value='disabled';
      obj.setAttribute('readonly','readonly'); 
      obj.setAttribute('disabled','disabled'); 
    }
  }
}

