/************************************************************************
**                                                                     **
** PerfectCar Option Related Scripts                                   **
** Copyright (c) 2003 Xprima Corporation, All Rights Reserved          **
**                                                                     **
** Francis Caporuscio                                                  **
** December 2003 - January 2004                                        **
**                                                                     **
************************************************************************/

// #######################################################################
function setV()
{
  var i;
  var opname="";
  var VChange = curV;

  for(i = 0; i < V.length; i++) {
    opname = "OP" + i.toString();
    if(document.forms.pcOptionSelection[opname].checked == true)
      VChange += getPrice(i);
  }

  if(_regTaxes) {
    calcTaxes(frmt(VChange), curTPDI);
  }
}

// #######################################################################
function getPrice(idx)
{
  var curPrice = V[idx][0];
  var i = 0;
  var set = false;

  for(i = 0; i < V.length; i++) {
    if(PT.length > i && PT[i].length > idx && isNaN(PT[i][idx]) == false && PT[i][idx] != null && ch[i] == 1) {
      if(set == false) {
        curPrice = PT[i][idx];
        set = true;
      }
      else {
        if(PT[i][idx] < curPrice) {
          curPrice = PT[i][idx];
        }
      }
    }
  }

  return curPrice;
}

// #######################################################################
function itemSelect(idx,r) {
  var opname="OP" + idx.toString();
  var state = document.forms.pcOptionSelection[opname].checked;
  var ret = true;

  if(state == true)
    document.forms.pcOptionSelection[opname].checked = false;
  else
    document.forms.pcOptionSelection[opname].checked = true;

  ret = itemAllowed(idx,r);
  if(ret == false) {
    document.forms.pcOptionSelection[opname].checked = state;
  }

  self.focus();
  return false;
}

// #######################################################################
function setImages()
{
  for(i = 0; i < V.length; i++)
    if(document.forms.pcOptionSelection["IM"+i.toString()].src != iOK.src) document.forms.pcOptionSelection["IM"+i.toString()].src = iOK.src;

  for(i = 0; i < V.length; i++) {
    if(ch[i] == 1) {
      for(j = 0; j < E[i].length; j++) {
        if(E[i][j] == 1) if(document.forms.pcOptionSelection["IM"+j.toString()].src != iExc.src) document.forms.pcOptionSelection["IM"+j.toString()].src = iExc.src;
      }

      for(j = 0; j < D[i].length; j++) {
        if(D[i][j] == 1) if(document.forms.pcOptionSelection["IM"+j.toString()].src != iDep.src) document.forms.pcOptionSelection["IM"+j.toString()].src = iDep.src;
      }
    }
  }
}


