

function setTextFields(txt,form,disList) {
  var i=0;
  for (i=2; i < setTextFields.arguments.length; i++) {
    if (form[setTextFields.arguments[i]]) {
      box = form[setTextFields.arguments[i]];
      if (box.type == 'text' || box.type == 'textarea' ) {
		  box.value = txt;
	  }
	}
  }
}

function disable(form,dis,disList) {
  var i=0;
  //alert(dis);
  for (i=2; i < disable.arguments.length; i++) {
    if (form[disable.arguments[i]]) {
      box = form[disable.arguments[i]];
      box.disabled = dis;
	  //alert(box.disabled);
    }
  }
}

function urlCheck(form,str,reqList) {
    for (i=2; i < urlCheck.arguments.length; i+=2) {
      if (form[urlCheck.arguments[i]]) {
        box = form[urlCheck.arguments[i]];
        if ((  (box.type == 'text' && box.value == '') 
             ||(box.type == 'select-one' && box.options[box.selectedIndex].value == 'nil'))
            && ! box.disabled )
        {
          alert(urlCheck.arguments[i+1]); // + urlCheck.arguments[i] + "\n Dis = " + box.disabled );
          return false;
        }
      }
    }
  return true;    
}

function getCost(str) {
  num = parseFloat(str.substring(str.indexOf(",")+1));
  if (isNaN(num)) num = "0";
  return num;
}

// Pass first the box to do, then any it clashes with.
// ie (Box, Clash1, Clash2, ....).
function checkChoice(whichbox) {
  var form = whichbox.form;
  var total = parseFloat(form.hiddentotal.value.toString().replace(/\$|,/,''));
  var boxCost = getCost(whichbox.value);
  // alert(total+' -- '+boxCost);

  // Uncheck any clashes and remove.
  for (i = 1; i < checkChoice.arguments.length; i++) {
    clash = checkChoice.arguments[i];
    if (clash.checked) {
      clash.checked = false; 
      form.hiddenCountChosen.value--;
      total -= getCost(clash.value);
    }
  }
 
  if (whichbox.checked) {
    form.hiddenCountChosen.value++;
    total += boxCost;
  } else {
    form.hiddenCountChosen.value--;
    total -= boxCost;
  }
  form.hiddentotal.value = formatCurrency(total);
  return form.hiddentotal.value;
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|,/g,'');
    if(isNaN(num)) 
        num = "0";
    cents = Math.floor((num*100+0.5)%100);
    num = Math.floor((num*100+0.5)/100).toString();
    if(cents < 10) 
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));

    val = num + "." + cents;
    val = val.substr(0,val.indexOf(".")+3);
    return (val);
	  }

