function obliterate ( inselect ) {
 if ( inselect.options.length > 1 ) {
  while ( inselect.length > 1 ) { inselect.options[1] = null; }
  inselect.selectedIndex = 0;
} }
function showColor( inselect ) {
	var color = inselect.options[inselect.selectedIndex].value;
	if (color == 'Gray') {
		changeBeauty(2);
	}else if (color == 'Fuchsia') {
		changeBeauty(3);
	}else if (color == 'Indigo') {
		changeBeauty(4);
	}else if (color == 'Green') {
		changeBeauty(5);
	}else if (color == 'Grape') {
		changeBeauty(6);
	}else if (color == 'Black') {
		changeBeauty(7);
	}
}
function buildlist ( inselect, optionlist ) {
 var cloc, cloc2 = 0;
 var portion     = '';
 while ( optionlist.length > 0 ) {
  cloc = optionlist.indexOf( '|' );
  if ( cloc == -1 ) { cloc = optionlist.length; }
  portion = optionlist.substring( 0, cloc );
  cloc2   = portion.indexOf( ':' );
  var foo = new Option( portion.substring( (cloc2 + 1), portion.length ), portion.substring( 0, cloc2 ) );
  inselect.options[inselect.options.length] = foo;
  if ( optionlist.indexOf ( '|' ) != -1 ) { optionlist = optionlist.substring( ( cloc + 1 ), optionlist.length ); }
  else { optionlist = ''; }
} }

function handlesize ( inselect ) {
	obliterate( document.whatamess.colorpick );
	var thissize = inselect.options[inselect.selectedIndex].value;
	var choices = '';
	if ( thissize == '10' ) {
		choices = '1:Black';
	}
	else if (thissize == '4' ) {
		choices = '1:Black|6:Sage|7:Mushroom|3:Magenta';
	}
	else if ( thissize == '2') {
		choices = '1:Black|6:Sage|7:Mushroom';
	}
	else if ( thissize == '1' ) {
		choices = '';
	}
	else if ( thissize == '11' ) {
		choices = '1:Black|6:Sage|7:Mushroom';
	}
	else {
		choices = '1:Black';
	}
	buildlist( document.whatamess.colorpick,choices);
}


function resetfields (  ) {
  document.whatamess.sizepick.selectedIndex = 0;
  document.whatamess.colorpick.selectedIndex = 0;
}

function generate_fields ( inform ) {
  var thiscolor = inform.colorpick.options[inform.colorpick.selectedIndex].value;
  var thissize  = inform.sizepick.options[inform.sizepick.selectedIndex].value;
  var sku = '';
  
// a conditional H*A*C*K - array not worth the effort


  if ( thiscolor == '1' ) // BLACK
  {
  	if (thissize == '11') { inform.ProdId.value = '14019'; }
  	if (thissize == '2') { inform.ProdId.value = '13918'; }
	if (thissize == '3') { inform.ProdId.value = '14004'; }
	if (thissize == '4') { inform.ProdId.value = '13943'; }
	if (thissize == '5') { inform.ProdId.value = '13944'; }
	if (thissize == '6') { inform.ProdId.value = '13940'; }
	if (thissize == '7') { inform.ProdId.value = '13942'; }
	if (thissize == '8') { inform.ProdId.value = '13943'; }
	if (thissize == '9') { inform.ProdId.value = '13944'; }
	if (thissize == '10') { inform.ProdId.value = '14065'; }
  }
  
   if ( thiscolor == '2' ) // BURGUNDY
  {
  	if (thissize == '1') { inform.ProdId.value = '14043'; }
  	if (thissize == '2') { inform.ProdId.value = '14047'; }
  	if (thissize == '4') { inform.ProdId.value = '14051'; }
  	
}
  
  if ( thiscolor == '3' ) // MAGENTA
  {
  	if (thissize == '1') { inform.ProdId.value = '14044'; }
	if (thissize == '2') { inform.ProdId.value = '14048'; }
  	if (thissize == '4') { inform.ProdId.value = '14052'; }
  	if (thissize == '10') { inform.ProdId.value = '14066'; }
  }
   if ( thiscolor == '4' ) // TEAL
  {
  	if (thissize == '1') { inform.ProdId.value = '14045'; }
  	if (thissize == '2') { inform.ProdId.value = '14049'; }
  	if (thissize == '4') { inform.ProdId.value = '14053'; }
  	if (thissize == '10') { inform.ProdId.value = '14067'; }
  }
  if ( thiscolor == '5' ) // ORANGE
  {
  	if (thissize == '1') { inform.ProdId.value = '14046'; }
	if (thissize == '2') { inform.ProdId.value = '14050'; }
  	if (thissize == '4') { inform.ProdId.value = '14054'; }
  	
  }
    if ( thiscolor == '6' ) // SAGE
  {
  	if (thissize == '11') { inform.ProdId.value = '14100'; }
	if (thissize == '2') { inform.ProdId.value = '14102'; }
  	if (thissize == '4') { inform.ProdId.value = '14104'; }
  	
  }
    if ( thiscolor == '7' ) // MUSHROOM
  {
  	if (thissize == '11') { inform.ProdId.value = '14101'; }
	if (thissize == '2') { inform.ProdId.value = '14103'; }
  	if (thissize == '4') { inform.ProdId.value = '14105'; }
  	
  }
}

function handleform ( inform ) {
 var errmsg = '';
  if ( inform.sizepick.selectedIndex < 1 ) { errmsg += '\n   - Size'; }
 if ( inform.colorpick.selectedIndex < 1 ) { errmsg += '\n   - Color'; }

// NB: secondary conditional statements below are due to NN 4.x hack

 if ( errmsg ) { alert ('Please choose the following before purchasing:' + errmsg); return false; }
 else { generate_fields( inform ); return true; }
}


