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

IHeartForm.init = function(thisObj, name)
{
  OIRDesignForm.init(thisObj, name);
  thisObj.previewFrame = null;
  /* grpEl keys
  button_size_id
  button_qty_id
  text_type_id
  text_message

  button_unit
  extra_price
  button_subtotal

  reorder_row_id
  */
}


IHeartForm.prototype.preview = function()
{
  var bcolor, fcolor, obj;
  this.formOK = true;
  if (this.previewFrame && this.onsubmit())
  {
    obj = this.grpEls['text_type_id'];
    if (this.getElVal(obj.el) == 1)
    {
      bcolor = "FFFFFF";
      fcolor = "000000";
    }
    else
    {
      bcolor = "000000";
      fcolor = "FFFFFF";
    }
     
     
    this.previewFrame.location = 
     "preview-i_heart.php"+
     "?string="+URLCoder.encode(this.getElVal(this.grpEls['text_message'].el))+
     "&fcolor="+fcolor+
     "&bcolor="+bcolor;
  }
}

IHeartForm.prototype.onchange = function()
{
}

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

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


IHeartForm.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 = IHeartForm.sched[button_size_id];
  
  unit_price = this.pricer.getUnitPrice(IHeartForm.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 >= IHeartForm.setupWaive) ||
      reorder)
  {
    extra_price = 0
  }
  else
  {
    extra_price = IHeartForm.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;
}

IHeartForm.prototype.onsubmit = function()
{
  var str, obj;
  /* Check design name*/
  if (this.grpEls['text_message'])
  {
    str = this.getElVal(this.grpEls['text_message'].el);
    if (this.formOK && (!str.match(/[^ \r\t\n]/)))
    {
      alert("You must enter a text message");
      this.formOK = false;
    }
  }
  
  if (this.grpEls['text_type_id'])
  {
    str = this.getElVal(this.grpEls['text_type_id'].el);
    if (this.formOK && (!str.match(/^[0-9]$/)))
    {
      alert("You must choose a text color");    
      this.formOK = false;
    }
  }

  return this.formOK;
}

