function CustomArtForm(name)
{
  if (name != null)
  {
    CustomArtForm.init(this, name);
  }
}
new CustomArtForm(null);
CustomArtForm.prototype = new OIRDesignForm(null);
CustomArtForm.prototype.superOnchange = OIRDesignForm.prototype.onchange;
CustomArtForm.priceGroup = 'custom_art';

CustomArtForm.init = function(thisObj, name)
{
  OIRDesignForm.init(thisObj, name);
  this.colorPreviewImg = null;
  /* grpEl keys
  button_size_id
  button_qty_id
  art_type_id
  paper_color_id
  text_message
  design_name
  
  paper_color_src
  paper_color
  swatch_label_display

  button_unit
  extra_price
  button_subtotal
  */
}


CustomArtForm.prototype.onchange = function()
{
  var paper_color_id, art_type_id;

  /* Check paper vs. color*/
  paper_color_id = this.getElVal(this.grpEls['paper_color_id'].el);
  art_type_id = this.getElVal(this.grpEls['art_type_id'].el);
  if (this.formOK && (paper_color_id != 1) && (art_type_id == 2))
  {
    alert("You must choose black and white art to use colored paper");
    
    obj = this.grpEls['art_type_id'];
    this.setElVal(obj.el, obj.cacheVal);

    obj = this.grpEls['paper_color_id'];
    this.setElVal(obj.el, obj.cacheVal);

    obj = this.grpEls['paper_color_src'];
    this.setElVal(obj.el, obj.cacheVal);

    obj = this.grpEls['paper_color'];
    this.setElVal(obj.el, obj.cacheVal);
    
    obj = this.grpEls['swatch_label_display'];
    this.setElVal(obj.el, obj.cacheVal);
    
    if (this.colorPreviewImg != null)
    {
      this.colorPreviewImg.src = this.getElVal(this.grpEls['paper_color_src'].el);
    }
  }  
}

CustomArtForm.prototype.initQty = function()
{
  var qty, size_id;
  qty = OIRDesignForms.getQty(this.getElVal(this.grpEls['button_qty_id'].el));
  size_id = this.getElVal(this.grpEls['button_size_id'].el);
  this.pricer.addCount(CustomArtForm.priceGroup, size_id, parseInt(qty));
}

CustomArtForm.prototype.updateQty = function()
{
  var old_qty, qty, old_size_id, size_id;
  
  old_qty = OIRDesignForms.getQty(this.grpEls['button_qty_id'].cacheVal);
  old_size_id = this.grpEls['button_size_id'].cacheVal;
  this.pricer.addCount(CustomArtForm.priceGroup, old_size_id, parseInt(old_qty) * -1);
  
  qty = OIRDesignForms.getQty(this.getElVal(this.grpEls['button_qty_id'].el));
  size_id = this.getElVal(this.grpEls['button_size_id'].el);
  this.pricer.addCount(CustomArtForm.priceGroup, size_id, parseInt(qty));
}


CustomArtForm.prototype.updateSubtotal = function()
{
  var art_type_id, button_size_id, 
   unit_price, ext_price;

  qty = OIRDesignForms.getQty(this.getElVal(this.grpEls['button_qty_id'].el));
  art_type_id = this.getElVal(this.grpEls['art_type_id'].el);
  button_size_id = this.getElVal(this.grpEls['button_size_id'].el);
  
  sched = CustomArtForm.sched[button_size_id][art_type_id];
  
  unit_price = this.pricer.getUnitPrice(CustomArtForm.priceGroup, button_size_id, sched);
  ext_price = unit_price * qty;
  
  this.setElVal(this.grpEls['button_unit'].el, "$"+this.fmtMoney(unit_price));
  this.setElVal(this.grpEls['button_subtotal'].el, "$"+this.fmtMoney(ext_price));
  return ext_price;
}

CustomArtForm.prototype.onsubmit = function()
{
  var str, obj;
  /* Check design name*/
  if (this.grpEls['design_name'])
  {
    str = this.getElVal(this.grpEls['design_name'].el);
    if (this.formOK && (!str.match(/[^ \r\t\n]/)))
    {
      alert("You must enter a design name");
      
      obj = this.grpEls['design_name'];
      this.setElVal(obj.el, obj.cacheVal);
  
      this.formOK = false;
    }
  }
  return this.formOK;
}
