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

PhotoButtonForm.init = function(thisObj, name)
{
  OIRDesignForm.init(thisObj, name);
  /* grpEl keys
  button_size_id
  button_qty_id
  text_message
  photo_file_name
  photo_file_id

  button_unit
  extra_price
  button_subtotal

  color_id_fg
  color_num_display_fg

  reorder_row_id
  */
}


PhotoButtonForm.prototype.chooseColor = function(elColor, elNum)
{
  if (elColor.name.indexOf("_fg") > -1)
  {
    obj = this.grpEls['color_num_display_fg']
  }
  else
  {
    obj = this.grpEls['color_num_display_bg']
  }
  
  if (obj != null)
  {
    obj.cacheVal = this.getElVal(elNum);
  }
}

PhotoButtonForm.prototype.onchange = function()
{
}

PhotoButtonForm.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(PhotoButtonForm.priceGroup, size_id, parseInt(qty));
}

PhotoButtonForm.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(PhotoButtonForm.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(PhotoButtonForm.priceGroup, size_id, parseInt(qty));
}

PhotoButtonForm.prototype.updateSubtotal = function()
{
  var button_size_id, unit_price, ext_price, extra_price, reorder;

  qty = OIRDesignForms.getQty(this.getElVal(this.grpEls['button_qty_id'].el));
  button_size_id = this.getElVal(this.grpEls['button_size_id'].el);
  
  sched = PhotoButtonForm.sched[button_size_id];
  
  unit_price = this.pricer.getUnitPrice(PhotoButtonForm.priceGroup, button_size_id, sched);
  ext_price = unit_price * qty;
  
  reorder = false;
  if (this.grpEls['reorder_row_id'])
  {
    reorder = 
     this.getElVal(this.grpEls['reorder_row_id'].el) ? 
     true :
     false;
  }
  
  if ((qty >= PhotoButtonForm.setupWaive) ||
      reorder)
  {
    extra_price = 0
  }
  else
  {
    extra_price = PhotoButtonForm.setup;
  }

  this.setElVal(this.grpEls['button_unit'].el, "$"+this.fmtMoney(unit_price));
  this.setElVal(this.grpEls['extra_price'].el, "$"+this.fmtMoney(extra_price));
  this.setElVal(this.grpEls['button_subtotal'].el, "$"+this.fmtMoney(ext_price + extra_price));

  return ext_price + extra_price;
}

PhotoButtonForm.prototype.onsubmit = function()
{
  var str, obj;
  /* Check design name*/

  if (this.grpEls['photo_file_name'])
  {
    str = this.getElVal(this.grpEls['photo_file_name'].el);
    if (this.formOK && (!str.match(/^.+$/)))
    {
      //alert("You must choose photograph to upload");    
      //this.formOK = false;
    }

    if (this.formOK && (!str.toLowerCase().match(/\.(jpeg|jpg)$/)))
    {
      //alert("The file must be a jpeg:"+str);    
      //this.formOK = false;
    }
  }

  return this.formOK;
}

