function intField()
{
  this.id = null;
  this.max = null;
  this.min = null;
  this.valid = function ()
  {
    if (tags[this.id].value<this.min)
    {
      tags[this.id].value = this.min;
      if (isIE) tags[this.id].attachEvent("onblur",function() {calculator.reset();});
      else tags[this.id].addEventListener("blur",function() {calculator.reset();},false);
      alert(tags[this.id].value+" is less than the minimum value for this field: " + this.min + ". Call us for a quote if your account is less than this employee number.");
      //attachevent to onblur
    }
    else if (tags[this.id].value>this.max)
    {
      tags[this.id].value = this.max;
      if (isIE) tags[this.id].attachEvent("onblur",function() {calculator.reset();});
      else tags[this.id].addEventListener("blur",function() {calculator.reset();},false);
      alert(tags[this.id].value+" is more than the maximum value for this field: " + this.max + ". Call us for a quote if your account exceeds this employee number.");
      //attachevent to onblur
    }
    doCalculate();
  }
  this.reset = function()
  {
    tags[this.id].removeEventListener("blur",function() {calculator.reset();},false);
    tags[this.id].focus();
    //remove listener
  }
}

var calculator = new intField();
function setCalculator()
{
  var eC = idIndex("employeeCount");
  var pF = idIndex("payFrequency");
  var iE = idIndex("includeESS");
  if (eC!=null)
  {
    calculator.max=employee[employee.length-1];
    calculator.min=1;
    calculator.id=eC;
    if (isIE)
    {
      tags[eC].attachEvent("onchange",function() {calculator.valid();});
      tags[pF].attachEvent("onchange",function() {calculator.valid();});
      tags[iE].attachEvent("onchange",function() {calculator.valid();});
    }
    else
    {
      tags[eC].addEventListener("change",function() {calculator.valid();},false);
	  tags[pF].addEventListener("change",function() {calculator.valid();},false);
	  tags[iE].addEventListener("change",function() {calculator.valid();},false);
	}
  }
  return null;
}

var employee = [5,10,15,20,25,30];
var monthly = [176,242,286,330,374,418];
var fortnightly = [220,330,396,462,528,594];
var weekly = [330,495,605,715,825,935];

/*function price(priceList)
{
  //var retval;
  for (i=0; i<(employee.length-1);i++)
  {

    if (tags[calculator.id].value==employee[i]) tags[idIndex("price")].value=priceList[i];
    else if (tags[calculator.id].value==employee[i+1]) tags[idIndex("price")].value=priceList[i+1];
    else if (tags[calculator.id].value<employee[i+1])
    {
      tags[idIndex("price")].value = parseFloat(priceList[employee[i]] + (priceList[employee[i+1]]-priceList[employee[i]])/(employee[i+1]-employee[i])*(tags[calculator.id].value-employee[i]));
    }
  } //for
}
*/

function price(priceList)
{
  var retval;
  for (i=0; i<(employee.length-1);i++)
  {
    if (tags[calculator.id].value==employee[i])
    {
      retval=priceList[i];
      i=employee.length;
    }
    else if (tags[calculator.id].value==employee[i+1])
	{
	  retval=priceList[i+1];
	  i=employee.length;
	}
    else if (tags[calculator.id].value<employee[i+1])
    {
      retval=(priceList[i] + ((priceList[i+1]-priceList[i])*(tags[calculator.id].value-employee[i])/5));
      i=employee.length;
    }
  } //for
  if (tags[idIndex("includeESS")].value=="y") retval = retval + (retval*0.2);
  retval = Math.ceil(retval);
  tags[idIndex("price")].value = "$" + retval;
}

function doCalculate()
{
  var freq;
  if (tags[idIndex("payFrequency")].value=='w') freq = weekly;
  else if (tags[idIndex("payFrequency")].value=='f') freq = fortnightly;
  else if (tags[idIndex("payFrequency")].value=='m') freq = monthly;
  price(freq);
}
