// Product Selects- Copyright ©2006-2008 Glen A. Reece, Ph.D. (www.thesilkenthread.com)
// Last updated: July 20th, 2006  This notice MUST stay intact for legal use.

function multiDimArray(iRows,iCols) {
   var i;
   var j;
   var a = new Array(iRows);
   for (var i=0; i < iRows; i++)
   {
       a[i] = new Array(iCols);
       for (j=0; j < iCols; j++)
       {
           a[i][j] = "";
       }
   }
   return(a);
}

// Adds options to existing SELECT elements on product pages. Check to see if the previous length
// of the select box was longer and would leave "dangling" options behind if not removed.

function createSelectboxOptions(fname, sname, valueArray) {
   var I = 0;
   var minI = 0;
   var maxI = valueArray.length - 1;
   var s = "";
   var tmp = eval("document.forms['" + fname + "']." + sname + ".options.length");

   if (tmp > maxI) eval("document.forms['" + fname + "']." + sname + ".options.length =" + maxI);
   for (var I = minI; I <= maxI; I++ ) {
    s = valueArray[ I ][0];
    eval( "document.forms['" + fname + "']." + sname + ".options[" +
    I  + "] = new Option('" + s + "','" + s + "');" );
   }
}

// Fills in the boxes of the Thread Tab on product pages with available colors (see makeThreadColorArray below)

function fillColorBoxes(colorarray) {
  for (var i=1; i <= colorarray.length-1; i++) {
    eval( "document.getElementById('cb" + i + "').style.backgroundColor='" + colorarray[i][1] + "';");
  }
}

// Sets the click functionality of the color boxes on the Thread Tab of product pages
// sname = name of selection box, cbox = colorbox to display to, colorarray is all avail thread colors.

function setupColorSelection(sname, cbox, colorarray) {
   for (var i=1; i <= colorarray.length-1; i++) {
    document.write("<a href='#' onClick=\"changeColors('" + sname + "','" + cbox + "','" + i + "','" + colorarray[i][1] +
       "'); hidetrail();\" onMouseover=showtrail(1,'" + colorarray[i][1] + "','" + colorarray[i][0] +
       "',150); onMouseout=hidetrail()><span id='cb" + i + "' class='cb'>&nbsp&nbsp&nbsp&nbsp</span></a>");
    if(i==13||i==26) document.write('<br />');
   }
}

// Sets the tooltip and click functionality of the ribbon choices on the Ribbon Tab of product pages
// sname = name of selection box, cbox = imgbox to display to, ribarray is all avail ribbon colors.

function setupRibbonSelection(sname, cbox, ribarray) {
   var x = "";
   for (var i=1; i <= ribarray.length-1; i++) {
     x = ribarray[i][1];
     document.write("<img src='" + x + "' height='30' width='30' onClick=\"changeImg('" +
        sname + "','" + cbox + "','" + i + "','" + x + "'); hidetrail();\" onMouseover=\"showtrail(0,'" + x + "','" + ribarray[i][0] + "',215);\" onMouseout=\"hidetrail();\">&nbsp");
     if(i==10||i==20) document.write('<br />');
   }
}

function makeElementVis(formname, ele) {
  eval("document.forms['" + formname + "']." + ele + ".style.visibility='visible'");
}

function swapImg(imgbox, value, thearray) {
  eval("document.getElementById('" + imgbox + "').src = '" + thearray[value][1] + "';");
}

function getOnlySelectFonts(ftype, fontarray) {
  var zarray = multiDimArray(fontarray.length,'1');
  var c = 1;
  zarray[0][0] = "Not Selected";
  zarray[0][1] = fontarray[0][1];

  for (var i=1; i<=fontarray.length-1; i++) {
   if (fontarray[i][ftype] == '1') {
     zarray[c][0] = fontarray[i][0];
     zarray[c][1] = fontarray[i][1];
     c = c + 1;
   }
  }
  zarray.length = c;
  return zarray;
}

function setupMotifs(mloc, sname, Marray, imgbox, container) {
  setupEmbFont(mloc, sname, imgbox, container, Marray);
  swapImg("IMGF", '0', Marray);
}

// doFontActions performs several functions when the user selects what they want to embroider. It makes the
// input visible, changes the text on the font tab, displays the fonts for the embroidery type, and makes the
// select list visible for the form.

function doFontActions(inputnum, form, sname, fontarray, ele1, style, imgbox, container, ele2, info) {
  makeInputVis(inputnum);
  showInfo(container, ele2, info);
  fonts = getOnlySelectFonts(style, allfonts);
  setupEmbFont(ele1, sname, imgbox, container, fonts);
  createSelectboxOptions(form, sname, fonts);
  makeElementVis(form, sname);
  swapImg("IMGF", '0', fonts);
}

function setupFonts(form, sname, fontarray, ele1, style, imgbox, container) {
  fonts = getOnlySelectFonts(style, allfonts);
  setupEmbFont(ele1, sname, imgbox, container, fonts);
  createSelectboxOptions(form, sname, fonts);
  swapImg("IMGF", '0', fonts);
}

function setupEmbFont(fontloc, sname, cbox, container, fontarray) {
 var newHTML = "<br />";
 var tab = document.getElementById(container);
 var loc = document.getElementById(fontloc);
 var size = fontarray.length - 1;

 for (var i=1; i<=size; i++) {
     newHTML = newHTML + "<img src='" + fontarray[i][1] + "' height='30' width='30' onClick=\"changeImg('" +
      sname + "','" + cbox + "','" + i + "','" + fontarray[i][1] + "'); hidetrail();\" onMouseover=\"showtrail(0,'" +
      fontarray[i][1] + "','" + fontarray[i][0] + "',100);\" onMouseout=\"hidetrail();\">&nbsp";
  }
  tab.appendChild(loc);
  loc.innerHTML = newHTML;
}

function showInfo(container, infoloc, txt) {
	var loc = document.getElementById(infoloc);
	loc.innerHTML = txt;
}


function getInput(dname) {
  var sx=document.getElementById(dname);
  sx.style.visibility='visible';
}

function hideInput(dname) {
  var sx=document.getElementById(dname);
  sx.style.visibility='hidden';
}

function showDetails(content) {
 var details = document.getElementById("productdetails");
 var txt = content.split('^');
 var newHTML = "<b>Product Details</b><br /><br />";
 for (var d=0; d<txt.length; d++) {
   newHTML+="<strong>" + txt[d] + "</strong><br />" + txt[d+1] + "<br /><br />";
   d++;
 }
 details.innerHTML = newHTML;
}

// Two-Dimensional Array of Motifs (Name / IMG filename) "literal notation"

function makeMotifArray() {
   var Marray = [
    ["Not Selected","/images/blank.gif"],["NONE","/images/blank.gif"],["Alligator","/images/MS/alligator.JPG"],["Bee","/images/MS/bee.JPG"],["Crab","/images/MS/crab.JPG"],["Crown","/images/MS/crown.JPG"],["Dog","/images/MS/dog.JPG"],["Golf","/images/MS/golf.JPG"],[ "Horse","/images/MS/horse.JPG"],["Lobster","/images/MS/lobster.JPG"],["Lure","/images/MS/lure.JPG"],[ "Palm Tree","/images/MS/palmtree.JPG"],[ "Pineapple","/images/MS/pineapple.JPG"],["Sailboat","/images/MS/sailboat.JPG"],["Shell","/images/MS/shell.JPG"],["Ship","/images/MS/ship.JPG"],[ "Tennis1","/images/MS/tennis1.JPG"],[ "Tennis2","/images/MS/tennis2.JPG"],[ "Turtle","/images/MS/turtle.JPG"]
   ];

   return ( Marray );
}


// Two-Dimensional Array of Thread Colors (Name / HEX color / Tooltip length) "literal notation"

function makeThreadColorArray() {
  var Tarray = [
   ["Not Selected","FFFFFF","0"],["Aqua","7DC7CA","33"],["Azalea","DF3E9E","45"],["Azure","009AB0","40"],["Bone","FFFFCC","35"],["Carrot","ED7222","45"],["Celadon","8D9A65","55"],["Coral","DC5961","40"],["DeepCoral","D75C57","75"],["Espresso","4E403D","60"],["Honeysuckle","FCC659","85"],["Laurel","48753E","45"],["Lilac","CCAED4","45"],["Maize","F8C37F","45"],["Marine","233855","45"],["Milk","FFFFFF","35"],["Nori","000000","35"],["Olive","978C4A","40"],["PeaShoot","578D1B","65"],["Peony","F698BC","45"],["Periwinkle","6076B2","70"],["Quicksilver","A7B0B7","70"],["Rose","DC5F99","35"],["Ruby","B92233","35"],["Sky","74AED6","35"],["Thistle","50347E","45"],["Tomato","9D1718","30"],["Vermeil","AB773D","50"],["Wedgewood","597CB2","85"],["Wisteria","9E93FC","60"]];
  return( Tarray );
}

// Two-Dimensional Array of Ribbon Colors (Name / IMG filename) "literal notation"

function makeRibbonColorArray() {
   var Rarray = [
    ["Not Selected","/images/blank.gif"],["Aqua Brown Dot","/images/RibbonColors/Ribbon_ABD.JPG"],["Brown Polka Dot","/images/RibbonColors/Ribbon_BPPD.JPG"],["Cupcake Stripe","/images/RibbonColors/Ribbon_CS.jpg"],["Green Blue Stripe","/images/RibbonColors/Ribbon_GB.JPG"],["Green Pink Dot","/images/RibbonColors/Ribbon_GPD.JPG"],["Holiday Stripe","/images/RibbonColors/Ribbon_HOLS.JPG"],[ "London Stripe","/images/RibbonColors/Ribbon_LS.JPG"],["Neapolitan","/images/RibbonColors/Ribbon_NS.JPG"],["Pink Lime Stripe","/images/RibbonColors/Ribbon_PLS.jpg"],["Red Navy","/images/RibbonColors/Ribbon_RNS.JPG"],["Truly Stripe","/images/RibbonColors/Ribbon_TS.JPG"],[ "Yellow Orange Stripe","/images/RibbonColors/Ribbon_YOS.JPG"]
   ];

   return ( Rarray );
}
//                                                       2  3 4  5  6  7     8      9   10 11     12     13  14    15      16     17    18    19       20        21     22      23
// Two-Dimensional Array of Fonts (Name / IMG filename / SL/T/M/SLT/M4/T2/SL-scroll/M2/a13/T3/SLT-scroll/M3/Soap/Soap-SL/Soap-M/flute/HSall/PLgirl-M/PL-girl-N/PLboy-M/PLboy-N/lbits) "literal notation"

function makeFontArray() {
  var Farray = [
   [ "Not Selected", "/images/blank.gif",               "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Architect", "/images/Fonts/Architect.png",        "0", "1", "0", "1", "0", "1", "0", "0", "0", "0", "1", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0"],
   [ "Bamboo","/images/Fonts/Bamboo.png",               "1", "1", "0", "1", "0", "1", "1", "0", "1", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Candlewyck","/images/Fonts/Candlewyck.png",       "1", "0", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Century Block","/images/Fonts/Century.png",       "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0"],
   [ "Circle","/images/Fonts/Circle.JPG",               "0", "0", "1", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Circle Flower","/images/Fonts/CircleFlower.png",  "1", "0", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Classic Script","/images/Fonts/Classic.png",      "0", "0", "1", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Script w Flourish","/images/Fonts/ClassicF.png",  "0", "0", "1", "0", "1", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Crisp Block","/images/Fonts/Crisp.png",           "1", "1", "1", "1", "1", "1", "1", "1", "1", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Decorative","/images/Fonts/Decorative.png",       "1", "0", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Diamond","/images/Fonts/Diamond.png",             "0", "0", "1", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Edwardian","/images/Fonts/Edwardian.png",         "1", "0", "1", "1", "1", "0", "1", "1", "0", "0", "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Empire","/images/Fonts/Empire.JPG",               "0", "0", "1", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "English Script","/images/Fonts/English.png",      "1", "1", "0", "1", "0", "1", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Fairy Script","/images/Fonts/FairyS.png",         "1", "1", "1", "1", "1", "1", "1", "1", "0", "1", "1", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0"],
   [ "Fairy Tale","/images/Fonts/FairyT.png",           "0", "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Feather","/images/Fonts/Feather.png",             "1", "0", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Filigree","/images/Fonts/Filigree.png",           "1", "1", "1", "1", "1", "0", "1", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Kids Style","/images/Fonts/Kids.png",             "0", "1", "0", "0", "0", "1", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Ophelia","/images/Fonts/Ophelia.png",             "1", "0", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Plume Script","/images/Fonts/Plume.png",          "1", "1", "0", "1", "0", "1", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Scroll (+ 5.00)","/images/Fonts/Scroll.png",      "1", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Sparkle","/images/Fonts/Sparkle.png",             "1", "0", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Square","/images/Fonts/Square.png",               "1", "0", "0", "1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Victorian","/images/Fonts/Victorian.png",         "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
   [ "Circle Monogram","/images/Fonts/CircleMono.JPG",  "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "1", "0", "0", "0", "0", "0"],
   [ "Curlz","/images/Fonts/Curlz.JPG",                 "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "1", "0", "1", "0", "0", "0", "0", "0"],
   [ "Cursive","/images/Fonts/Cursive.JPG",             "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0"],
   [ "Doodle","/images/Fonts/Doodle.JPG",               "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0"],
   [ "Interlocking","/images/Fonts/Interlocking.JPG",   "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "1", "0", "1", "0", "0", "0", "0", "0"],
   [ "Times Block","/images/Fonts/TimesBlock.JPG",      "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "1", "1", "0", "1", "0", "0", "0", "0", "0"],
   [ "Jack","/images/Fonts/Jack.JPG",                   "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0"],
   [ "Ethan","/images/Fonts/Ethan.JPG",                 "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0"],
   [ "Alex","/images/Fonts/Alex.JPG",                   "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0"],
   [ "Olivia","/images/Fonts/Olivia.JPG",               "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0"],
   [ "Emily","/images/Fonts/Emily.JPG",                 "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0"],
   [ "Hannah","/images/Fonts/Hannah.JPG",               "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0"],
   [ "Emma","/images/Fonts/Emma.JPG",                   "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0"],
   [ "Andrew","/images/Fonts/Andrew.JPG",               "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0"],
   [ "Style 1","/images/Fonts/lb-s1.JPG",               "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1"],
   [ "Style 8","/images/Fonts/lb-s8.JPG",               "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1"],
   [ "Style 40","/images/Fonts/lb-s40.JPG",             "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1"],
   [ "Style 56","/images/Fonts/lb-s56.JPG",             "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1"],
   [ "Style 107","/images/Fonts/lb-s107.JPG",            "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1"]
  ];

   return ( Farray );
}