var tp = "120px";
var clubs = 0;
var ext=".png";

var ahandle = ["spacer",
 "d_handle_white",
 "d_handle_Mgold",
 "d_handle_Msilver",
 "d_handle_Mgreen",
 "d_handle_Mpurple",
 "d_handle_Mred"];
var abody = ["spacer",
 "s_body_Lgold",
 "s_body_Lsilver",
 "s_body_Laqua",
 "s_body_Lblue",
 "s_body_Lgreen",
 "s_body_Lred"];
var atape = ["spacer", "s_tape_black", "s_tape_white"];
var aarc = ["s_acc_blank",
 "s_acc_Lgold",
 "s_acc_Lsilver",
 "s_acc_Laqua",
 "s_acc_Lblue",
 "s_acc_Lgreen",
 "s_acc_Lred"];

var cf = 1;

function selHandle(i, p)
{ document.getElementById("ihandle").src = "swatch/" + ahandle[i] + ext;
  if (p != 1)
  { document.fm.elements["pOption3[]"][cf].selectedIndex = i;
    rePrice(); } return false; }
function selBody(i, p)
{ document.getElementById("ibody").src = "swatch/" + abody[i] + ext;
  if (p != 1)
  { document.fm.elements["pOption[]"][cf].selectedIndex = i;
    rePrice(); } return false; }
function selTape(i, p)
{ document.getElementById("itape").src = "swatch/" + atape[i] + ext;
  if (p != 1)
  { document.fm.elements["pOption4[]"][cf].selectedIndex = i; } return false; }
function selArc(i, p)
{ document.getElementById("iarc").src = "swatch/" + aarc[i] + ext;
  if (p != 1)
  { document.fm.elements["pOption2[]"][cf].selectedIndex = i;
    rePrice(); } return false; }

function rePrice()
{ m = document.fm.elements["pModel[]"][cf].selectedIndex;
    pr = pPrices[m];
    x = document.fm.elements["pOption3[]"][cf].selectedIndex;
    g = document.fm.elements["pOption3[]"][cf].length - 1;
    if (x > 1) {pr += pAdj[0];}
    pr = makeDec(pr * pWho[m]);
    document.fm.elements["pPrice[]"][cf].value = pr; }

function reArc(o)
{ f = getFline(o.value); cf = f;
  document.fm.pSel[f].checked = true; rePrice();
  i = o.selectedIndex; selArc(i, 1); }

function reHandle(o)
{ f = getFline(o.value); cf = f;
  document.fm.pSel[f].checked = true; rePrice();
  i = o.selectedIndex; selHandle(i, 1); }

function reBody(o)
{ f = getFline(o.value); cf = f;
  document.fm.pSel[f].checked = true; rePrice();
  i = o.selectedIndex; selBody(i, 1); }

function reTape(o)
{ f = getFline(o.value); cf = f;
  document.fm.pSel[f].checked = true;
  i = o.selectedIndex; selTape(i, 1); }

function reClubProduct(o)
{ i = o.selectedIndex;
  f = getFline(o.value); cf = f;
  document.fm.pSel[f].checked = true;
  document.mfm.swmodel[i].checked = true;
  if (i > -1)
  { document.fm.elements["pNum[]"][f].value = pNums[i]; rePrice();
    document.fm.elements["pName[]"][f].value = pNames[i]; } }

function setcf(o)
{ cf = o.value;
  h = document.fm.elements["pOption3[]"][cf].selectedIndex;
  b = document.fm.elements["pOption[]"][cf].selectedIndex;
  t = document.fm.elements["pOption4[]"][cf].selectedIndex;
  a = document.fm.elements["pOption2[]"][cf].selectedIndex;
  m = document.fm.elements["pModel[]"][cf].selectedIndex;
  document.mfm.swmodel[m].checked = true;
  selHandle(h, 1); selBody(b, 1); selTape(t, 1); selArc(a, 1); }

function setpMod(i)
{ document.fm.elements["pModel[]"][cf].selectedIndex = i; 
  document.fm.elements["pNum[]"][cf].value = pNums[i]; rePrice();
  document.fm.elements["pName[]"][cf].value = pNames[i]; }

function verifyClub()
{ var qt = document.fm.elements["pQty[]"];
  var op1 = document.fm.elements["pOption[]"];
  for (i=2; i<=4; i++)
  { var x = "var op" + i + " = document.fm.elements['pOption" + i + "[]']";
    eval(x); }
  var x = "var ops = [0, op1";
  for (i=2; i<=4; i++)
  { x += ",op" + i; }
  x += "]"; eval(x);
  var pTotal = 0;
  for (i=0; i<qt.length; i++)
  { if (qt[i].value > 0) { pTotal += qt[i].value; }
    for (c=4; c>0; c--)
    { if (ops[c][i].value == "no selection")
	{ x = popAlert("Please select " + earr[c] + "."); 
	  qt[i].focus(); qt[i].select(); return false; } }
    }
  if (pTotal == 0)
  { return popAlert("You must input a quantity."); }
  return true; }

function doClubs()
{ // f = verifyClub();
//  if (f) {return doMoreClubs();}
  return doMoreClubs(); }
//  return false; }

function doMoreClubs()
{ var newdiv = document.createElement("div");
  newdiv.innerHTML = document.getElementById("fline").innerHTML;
  var container = document.getElementById("flines");
  container.appendChild(newdiv);
  document.fm.pSel[fc].checked = false;
  ++fc; ns = "|" + fc;
  cf = fc;
  document.fm.elements["pSel"][fc].value = fc;
  var om = document.fm.elements["pModel[]"][fc];
  om.selectedIndex = document.fm.elements["pModel[]"][fc-1].selectedIndex;
  for (c=1; c < om.length; c++) { om.options[c].value += ns; }
  for (i=1; i<=4; i++)
  { if (i==1) {s = "pOption[]";} else {s = "pOption" + i + "[]";}
    var x = "var op = document.fm.elements[\"" + s + "\"][" + fc + "]";
    eval(x);
    if (om.selectedIndex == (i-1)) {chk=true;} else {chk=false;}    
    document.mfm.swmodel[i-1].checked = chk;
    for (c=1; c < op.length; c++) { op.options[c].value += ns; }
    op.selectedIndex = 0; }
  selHandle(0, 1); selBody(0, 1);  selTape(0, 1);
  selArc(0, 1);
  return false; }

function showAll()
{ f = verifyClub();
  if (!f) {return false; }
  else
  { clubs = 0;
    for (n=1; n<=fc; n++)
    { clubs += parseInt(document.fm.elements["pQty[]"][n].value); }

    var msg = '<div class="right"><a href="#" onclick="return hideall();">';
     msg += '<img src="../images/wclose_button.gif" alt="where am I?" /></a></div>';
     msg += '<table width="100%"><tr>';
    if (clubs<3)
    { msg += '<td class="bottom" height="420">';
      msg += '<a href="#" onclick="return hideall();">';
      msg += '<img src="../images/change_button.gif" alt="" /></a><p />';
      msg += '<a href="#" onclick="return submitall();">';
      msg += '<img src="../images/add_button.gif" alt="" /></a>'; }
    else
    { msg += '<td class="bottom" height="420">';
      msg += '<a href="#" onclick="return hideall();">';
      msg += '<img src="../images/change_button.gif" alt="" /></a></td>';
      msg += '<td class="bottom">';
      msg += '<a href="#" onclick="return submitall();">';
      msg += '<img src="../images/add_button.gif" alt="" /></a>'; }
     msg += '</td></tr></table>\n';

    var newdiv = document.createElement("div");
    document.getElementById("ashow").innerHTML = "";
    newdiv.innerHTML = msg;
    var container = document.getElementById("ashow");
    container.appendChild(newdiv);
    var w = 900 - (clubs * 76);
    var ind = (w/2);
    document.getElementById("ashow").style.left = ind - 10 + "px";
    document.getElementById("ashow").style.width = (clubs * 76) + 5 + "px";
    document.getElementById("ashow").style.display = "block";

    var cnt = 0;
    for (n=1; n<=fc; n++)
    { var c = document.fm.elements["pQty[]"][n].value;
	if (c > 0)
	{ for (i=1; i<=c; i++)
	  { ++cnt;
	    var lft = "" + (((cnt-1)*76) + ind - 37) + "px";
	    zind = (cnt*10) + 1; zid = "club" + zind;
	    h = document.fm.elements["pOption[]"][n].selectedIndex;
	    var ig = '<img src="swatch/' + abody[h] + ext + '" width="150" height="400" />';
	    getDivs(ig, zid, lft, zind);
	    zind = (cnt*10) + 2; zid = "club" + zind;
	    h = document.fm.elements["pOption3[]"][n].selectedIndex;
	    var ig = '<img src="swatch/' + ahandle[h] + ext + '" width="150" height="400" />';
	    getDivs(ig, zid, lft, zind);
	    zind = (cnt*10) + 3; zid = "club" + zind;
	    h = document.fm.elements["pOption2[]"][n].selectedIndex;
	    var ig = '<img src="swatch/' + aarc[h] + ext + '" width="150" height="400" />';
	    getDivs(ig, zid, lft, zind);
	    zind = (cnt*10) + 4; zid = "club" + zind;
	    h = document.fm.elements["pOption4[]"][n].selectedIndex;
	    var ig = '<img src="swatch/' + atape[h] + ext + '" width="150" height="400" />';
	    getDivs(ig, zid, lft, zind); } }
    } }
return false; }

function getDivs(ig, zid, lft, zind)
{ var newdiv = document.createElement("div");
  newdiv.innerHTML = ig;
  newdiv.setAttribute("id", zid);
  newdiv.style.position = "absolute";
  newdiv.style.top = tp;
  newdiv.style.left = lft;
  newdiv.style.zIndex = zind;
  newdiv.style.display = "block";
  document.getElementById("outer").appendChild(newdiv); }

function submitall()
{ document.fm.submit(); return false; }
function hideall()
{ document.getElementById("ashow").style.display = "none"; 
  var cnt = 0;
  for (n=1; n<=fc; n++)
  { var c = document.fm.elements["pQty[]"][n].value;
    if (c > 0)
    { for (z=1; z<=c; z++)
	{ ++cnt;

	for (i=1; i<5; i++)
	{ x = "club" + cnt + i;
	  var childnode=document.getElementById(x);
	  document.getElementById("outer").removeChild(childnode); }
 } } }
  return false; }
