var tp = "120px";
var clubs = 0;
var currarc = 0;
var currtape = 0;
var ext=".png";
    
var ahandle = ["spacer",
 "d_handle_white",
 "d_handle_Mgold",
 "d_handle_Msilver",
 "d_handle_Mblue",
 "d_handle_Mgreen",
 "d_handle_Mpurple",
 "d_handle_Mred",
 "d_handle_Vyellow",
 "d_handle_black",
 "d_handle_Vblue",
 "d_handle_Vgreen",
 "d_handle_Vpurple",
 "d_handle_Vred",
 "d_handle_glow"];
var abody = ["spacer", "d_body_blue", "d_body_pink"];
var atape = ["spacer", "d_tape_black", "d_tape_white"];
var ntape = ["spacer", "s_tape_black", "s_tape_white"];
var aarc = ["spacer",
 "spacer",
 "d_arc_Lgold",
 "d_arc_Lsilver",
 "d_arc_Laqua",
 "d_arc_Lgreen",
 "d_arc_Lpurple",
 "d_arc_Lred",
 "d_arc_Mgold",
 "d_arc_Msilver",
 "d_arc_Mblue",
 "d_arc_Mgreen",
 "d_arc_Mpurple",
 "d_arc_Mred",
 "d_arc_Vyellow",
 "d_arc_Vblue",
 "d_arc_Vgreen",
 "d_arc_Vpurple",
 "d_arc_Vred"];

var cf = 1;

function selHandle(i, p)
{ document.getElementById("ihandle").src = "../club/swatch/" + ahandle[i] + ext;
  if (p != 1)
  { document.fm.elements["pOption3[]"][cf].selectedIndex = i;}
  return false; }
function selBody(i, p)
{ document.getElementById("ibody").src = "../club/swatch/" + abody[i] + ext;
  if (p != 1)
  { document.fm.elements["pOption2[]"][cf].selectedIndex = i;}
  return false; }
function selTape(i, p)
{ if (currarc==1) {s=ntape[i];} else {s=atape[i];}
  document.getElementById("itape").src = "../club/swatch/" + s + ext;
  currtape = i;
  if (p != 1)
  { document.fm.elements["pOption4[]"][cf].selectedIndex = i; } return false; }
function selArc(i, p)
{ document.getElementById("iarc").src = "../club/swatch/" + aarc[i] + ext;
  currarc = i; selTape(currtape, 1);
  if (p != 1)
  { document.fm.elements["pOption[]"][cf].selectedIndex = i;}
  return false; }

function reArc(o)
{ f = getFline(o.value); cf = f;
  i = o.selectedIndex; selArc(i, 1); }

function reHandle(o)
{ f = getFline(o.value); cf = f;
  i = o.selectedIndex; selHandle(i, 1); }

function reBody(o)
{ f = getFline(o.value); cf = f;
  i = o.selectedIndex; selBody(i, 1); }

function reTape(o)
{ f = getFline(o.value); cf = f;
  i = o.selectedIndex; selTape(i, 1); }

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-1] + "."); 
	  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);
  ++fc; ns = "|" + fc;
  cf = fc;
  for (i=1; i<=4; i++)
  { 
if (i!=2) {
    if (i==1) {s = "pOption[]";} else {s = "pOption" + i + "[]";}
    var x = "var op = document.fm.elements[\"" + s + "\"][" + fc + "]";
    eval(x);
    for (c=1; c < op.length; c++) { op.options[c].value += ns; }
    op.selectedIndex = 0;
}
 }
  selHandle(0, 1); selTape(0, 1); selArc(0, 1);
//  selBody(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["pOption2[]"][n].selectedIndex;
	    h = 2;
	    var ig = '<img src="../club/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="../club/swatch/' + ahandle[h] + ext + '" width="150" height="400" />';
	    getDivs(ig, zid, lft, zind);
	    zind = (cnt*10) + 3; zid = "club" + zind;
	    h = document.fm.elements["pOption[]"][n].selectedIndex;
	    var ig = '<img src="../club/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="../club/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; }

