<!--
var SelColorNdx		// index into Color SELECT list
var SelShadeNdx		// index into Shade SELECT list
var prmColor			// Color ID delivered in command line query string
var prmColorNdx		// Color index within the selColor SELECT object
var prmShade			// Shade ID delivered in command line query string
var prmShadeNdx		// Shade index within the selShade SELECT object
var xmlHttp				// Object for xmlHttp communication with host
var hostShadeRtn	// URL which delivers shades for the current color
hostShadeRtn = "XtrctShadesAJAX"

function StartUp()
{
	var MatchDetailSender = RegExp(".*details.php.*");
	var FromDetail = document.referrer.match(MatchDetailSender);
	loadParams();
	loadShadeList(prmColorNdx,prmShadeNdx);
	document.frmColorShade.selColor.options[prmColorNdx].selected = true;
	document.frmColorShade.selShade.options[prmShadeNdx].selected = true;
//	if (FromDetail == null)
//	  alert("We will close Friday, December 28th and re-open Monday, January 7th.  Orders placed while we are closed will be shipped on January 7th.  Thank you for your understanding.");
}

//
//  SetBtnOn & SetBtnOff are not currently used, but they could be handy.
//  Pass the row & column for a button and they accomplish MouseOver and MouseOut functionality.
//
function SetBtnOn(RC)
{
  document.images["btn" + RC].src = ButtonsPath + "btn" + ProdCodes[RC] + "Over.jpg" ;
}

function SetBtnOff(RC)
{
  document.images["btn" + RC].src = ButtonsPath + "btn" + ProdCodes[RC] + ".jpg" ;
}

function gotoDetails(RC, Desc, Name, Code, Type, WM, HM, WL, HL)
{
  lvlProdDesc = Desc.replace(/,/g,"%2C")	// commas to ASCII code
  lvlProdDesc = Desc.replace(/&/g,"%26")	// ampersands to ASCII code
//	alert("SelColorNdx / SelShadeNdx / Colors[SelColorNdx][1][SelShadeNdx][1]: " +SelColorNdx + " / " + SelShadeNdx + " / " + Colors[SelColorNdx][1][SelShadeNdx][1])
  var QueryString = "name=" + Name + 
          "&id=" + Code + 
          "&pt=" + Type + 
	        "&c=" + Colors[SelColorNdx][0][1] +
	        "&ci=" + document.frmColorShade.selColor.value +
	        "&s=" + Colors[SelColorNdx][1][SelShadeNdx][1] +
					"&si=" + document.frmColorShade.selShade.selectedIndex +
		  "&w=" + WM +	 		// width of medium sized pic
		  "&h=" + HM + 		// height of medium sized pic
		  "&wl=" + WL + 		// width of large sized pic 
		  "&hl=" + HL + 		// height of large sized pic
		  "&desc=" + lvlProdDesc;
  var URL="details.php?" + QueryString;
  window.location.href = URL;
}

function loadParams()
{
  var args = getArgs();

  if (args["c"] != null)
	  prmColor = args["c"];
	else
	  prmColor = 0;

  if (args["ci"] != null)
	  prmColorNdx = args["ci"];
	else
	  prmColorNdx = 0;

  if (args["s"] != null)
	  prmShade = args["s"];
	else
	  prmShade = 0;

  if (args["si"] != null)
	  prmShadeNdx = args["si"];
	else
	  prmShadeNdx = 0;
		
	if (SelColorNdx==null)
	  SelColorNdx=0
	if (SelShadeNdx==null)
	  SelShadeNdx=0
}

// Load the Shades selection list for color currently selected in Colors list
function loadShadeList(parmColorNdx, parmShadeNdx) {
    SelColorNdx = parmColorNdx;
    var Shades = Colors[SelColorNdx][1];
    document.frmColorShade.selShade.options.length = Shades.length;
//    document.frmColorShade.selShade.options[0] = new Option("All", 0);
    for (i=0; i<Shades.length; i++) { 
        document.frmColorShade.selShade.options[i] = new Option(Shades[i][0], i);
    }
		UpdateSelectedShade(parmShadeNdx);
}

function UpdateSelectedShade(parmShadeNdx) {
//  alert ("SelShadeNdx / parmShadeNdx: " + SelShadeNdx + " / " + parmShadeNdx)
  SelShadeNdx = parmShadeNdx
	var ActionBefore;
	var ActionAfter;
	var qrystrpos;
	ActionBefore = document.frmColorShade.action;
	qrystrpos = ActionBefore.search(/\?.*&/);	// if ampersand is present, there are params already in place
	if (qrystrpos==-1)														// -1 says there was no ampersand
	{
		qrystrpos = ActionBefore.search(/\?.*$/);
	}

	ActionAfter = ActionBefore.substring(0,qrystrpos) + 
	              "?c=" + Colors[SelColorNdx][0][1] +
	              "&ci=" + document.frmColorShade.selColor.value +
	              "&s=" + Colors[SelColorNdx][1][SelShadeNdx][1] +
								"&si=" + document.frmColorShade.selShade.selectedIndex;
  document.frmColorShade.action=ActionAfter;
}

function resetLists() { 
    loadShadeList(0, 0);
    document.frmColorShade.selColor.options[0].selected = true;
}
