var browser_ver = "";
var browser = "";
var mouseoversupport = "";
var browsername = navigator.appName;
var browserversion = parseInt(navigator.appVersion);

if (browsername == "Netscape")
{
   browser = "ns";
   browser_ver = "ns" + browserversion;
}
else if (browsername == "Microsoft Internet Explorer")
{
   browser = "ie";
   if (browserversion >= 4)
   {
      browser_ver = "ie" + browserversion;
   }
   else
   {
      browser_ver = "ie3";
   }
}
else if (browsername == "Opera")
{
   browser = "op";
   browser_ver = "op" + browserversion;
}
else
{
      // If no browser is identified, assume Opera version 1.0
   browser_ver = "op1";
}

function Popup(url)
{
   if (browser_ver=="ns3" || browser_ver=="ns4")
   {
      window.open(url,'sml','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=500,height=510');
   mouseoversupport = "yes";
   }
   else if (browser_ver=="ie3" || browser_ver=="ie4" || browser_ver=="ie5")
   {
      window.open(url,'sml','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=500,height=510');
   mouseoversupport = "yes";
   }
   else if (browser_ver=="op5")
   {
      window.open(url,'sml','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=500,height=510');
   mouseoversupport = "yes";
   }
   else
   {
      window.open(url,'sml','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=500,height=510');
   mouseoversupport = "no";
   }
}

function MedPopup(url)
{
   if (browser_ver=="ns3" || browser_ver=="ns4")
   {
      window.open(url,'med','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=620,height=510');
   mouseoversupport = "yes";
   }
   else if (browser_ver=="ie3" || browser_ver=="ie4" || browser_ver=="ie5")
   {
      window.open(url,'med','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=620,height=510');
   mouseoversupport = "yes";
   }
   else if (browser_ver=="op5")
   {
      window.open(url,'med','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=620,height=510');
   mouseoversupport = "yes";
   }
   else
   {
      window.open(url,'med','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=620,height=510');
   mouseoversupport = "no";
   }
}

// Each "opts" array element corresponds to a second array that contains
// the values for the list box being populated.
var opts_1 = new Array();
opts_1[0] = new Array(
   // name, value
   "Print Sizes and Pricing...", "",
   "12x18 Print - $194.95", "print12x18",
   "12x18 Frame/No Mat - $369.95", "print12x18frm",
   "12x18 Framed/Matted - $399.95", "print12x18frmmat",
   "---------------------", "----",
   "16x24 Print - $344.95", "print16x24",
   "16x24 Frame/No Mat - $534.95", "print16x24frm",
   "16x24 Framed/Matted - $564.95", "print16x24frmmat",
   "---------------------", "----",
   "20x30 Print - $429.95", "print20x30",
   "20x30 Frame/No Mat - $659.95", "print20x30frm",
   "20x30 Framed/Matted - $689.95", "print20x30frmmat");

opts_1[1] = new Array(
   // name, value
   "Wall Tile Sizes and Pricing...", "",
   "3x4 (12 - 4 in. tiles) - $274.95", "4tilematrix3x4",
   "4x6 (24 - 4 in. tiles) - $479.95", "4tilematrix4x6",
   "5X7 (35 - 4 in. tiles) - $699.95", "4tilematrix5x7",
   "6X9 (54 - 4 in. tiles) - $1,099.95", "4tilematrix6x9",
   "---------------------", "----",
   "2x3 (6 - 6 in. tiles) - $299.95", "6tilematrix2x3",
   "3x4 (12 - 6 in. tiles) - $599.95", "6tilematrix3x4",
   "4x6 (24 - 6 in. tiles) - $1,099.95", "6tilematrix4x6");

var opts_2 = new Array();
opts_2[0] = new Array(
   // name, value
   "Print Sizes and Pricing...", "",
   "12x25 Print - $274.95", "print12x50",
   "12x25 Frame/No Mat - $405.95", "print12x50frm",
   "12x25 Framed 24x36 - $435.95", "print12x50frmmat",
   "---------------------", "----",
   "24x50 Print - $799.95", "print12x50",
   "24x50 Frame/No Mat - $949.95", "print12x50frm",
   "24x50 Framed 24x36 - $999.95", "print12x50frmmat");

opts_2[1] = new Array(
   // name, value
   "Wall Tile Sizes and Pricing...", "",
   "3x4 (12 - 4 tiles) - $274.95", "4tilematrix3x4",
   "4x6 (24 - 4 tiles) - $479.95", "4tilematrix4x6",
   "5X7 (35 - 4 tiles) - $699.95", "4tilematrix5x7",
   "6X9 (54 - 4 tiles) - $1,099.95", "4tilematrix6x9",
   "---------------", "----",
   "2x3 (6 - 6 tiles) - $299.95", "6tilematrix2x3",
   "3x4 (12 - 6 tiles) - $599.95", "6tilematrix3x4",
   "4x6 (24 - 6 tiles) - $1,099.95", "6tilematrix4x6");

// List the various framed picture options.  These get displayed ONLY if the
// user selects an option that contains the string "framed" in it.
var frameOpts = new Array(
   // name, value
   " -- Select Frame -- ", "Select A Frame",
   "Cherry Black", "-Cherry Black Frame",
   "Cherry Scallop", "-Cherry Scallop Frame",
   "Thin Cherry Burl", "-Thin Cherry Burl Frame",
   "Walnut Burl", "-Walnut Burl Frame",
   "Honey Burl", "- Honey Burl Frame",
   "Thin Gloss Black", "-Thin Gloss Black Frame",
   "Satin Black", "-Satin Black Frame",
   "Satin Black Gold", "-Satin Black Gold Frame",
   "Gold Reverse", "-Gold Reverse Frame",
   "Thin Gold Scallop", "-Thin Gold Scallop Frame",
   "Satin Gold", "-Satin Gold Frame",
   "Satin Silver", "-Satin Silver Frame",
   "Gray Fluted", "-Gray Fluted Frame",
   "Green Scallop", "-Green Scallop Frame");
var noFrameOpts = new Array(
   // name, value
   "No Frame", "-No Frame");

// List the various mat options.  These get displayed ONLY if the user
// selects an option that contains the string "mnt/mat"
var matOpts = new Array(
   // name, value
   " -- Select Mat -- ", "Select A Mat",
   "Teal Gray", "-Teal Gray Mat",
   "Dover Gray", "-Dover Gray Mat",
   "Gun Metal Gray", "-Gun Metal Gray Mat",
   "Ash", "-Ash Mat",
   "Balmy Blue", "-Balmy Blue Mat",
   "Tapestry", "-Tapestry Mat",
   "Frost", "-Frost Mat",
   "Sea Mist", "-Sea Mist Mat",
   "Lasso", "-Lasso Mat",
   "Dark Red", "-Dark Red Mat",
   "Pale Green", "-Pale Green Mat",
   "Forest Green", "-Forest Green Mat" );

var noMatOpts = new Array(
   // name, value
   "No Mat", "-No Mat");
   
// Since all forms contain the same name, simply loop over all forms on the document and
// initialize them all using "0" as the default.
function initAll(){
   for (j = 0; j < document.forms.length; j++){
      if (document.forms[j].type && document.forms[j].type.value == "opts_1"){
         changeList(document.forms[j], 0, opts_1);
         viewFrames(document.forms[j]);
      } else if (document.forms[j].type && document.forms[j].type.value == "opts_2"){
         changeList(document.forms[j], 0, opts_2);
         viewFrames(document.forms[j]);
      }
   }
}

// Change the drop-down list box content by passing in the corresponding array value
// to populate the list box.
function changeList(f, choice, opts){
   // Verify that the current form has the necessary fields
   if (choice < 0 || choice > opts.length || f.item1 == null){
      return;
   }
   
   f.item1.options.length = 0; // reset the list box
   var list = opts[choice];
   for (i = 0; i < list.length; i += 2){
      f.item1.options[i/2] = new Option(list[i], list[i+1]);
   }
   f.item1.selectedIndex = 0; // default selection

   // Set up the default frame options, based on the new selection
   viewFrames(f);
}

// Show/hide the framed print options.
function viewFrames(f){
   // Verify that the current form has the necessary fields
   if (f.item1 == null || f.descrc1 == null || f.descrb1 == null){
      return;
   }

   var choice = f.item1.options[f.item1.selectedIndex].text;
   choice = choice.toLowerCase(); // make lowercase
   
   // retain the mat choice, in case the user already selected one
   var choiceMat = f.descrb1.selectedIndex;
   
   f.descrc1.options.length = 0; // reset the frame box
   f.descrb1.options.length = 0; // reset the mat box
   var listFrames;
   var listMats;
   
   if (choice.indexOf('mnt/mat') >= 0){
      // User selected a picture with a mat
      f.descrb1.disabled = false;
      f.descrc1.disabled = true;
      listFrames = noFrameOpts;
      listMats = matOpts;
   } else if (choice.indexOf('no mat') >= 0){
      // User selected a picture with frame and no mat
      f.descrb1.disabled = true;
      f.descrc1.disabled = false;
      listFrames = frameOpts;
      listMats = noMatOpts;
   } else if (choice.indexOf('framed') >= 0){
      // User selected a picture with a frame and mat
      f.descrb1.disabled = false;
      f.descrc1.disabled = false;
      listFrames = frameOpts;
      listMats = matOpts;
   } else {
      // User chose no mat and no frame, default to the empty list
      f.descrb1.disabled = true;
      f.descrc1.disabled = true;
      listFrames = noFrameOpts;
      listMats = noMatOpts;
   }
   
   // Populate the frame choices, or lack of choices.
   for (i = 0; i < listFrames.length; i += 2){
      f.descrc1.options[i/2] = new Option(listFrames[i], listFrames[i+1]);
   }
   // Populate the mat choices, or lack of choices.
   for (i = 0; i < listMats.length; i += 2){
      f.descrb1.options[i/2] = new Option(listMats[i], listMats[i+1]);
   }
   
   // Restore the mat value, if previously selected
   if (choiceMat > 0 ){
      f.descrb1.selectedIndex = choiceMat;
   }
}

// Validate selection then submit the form.
function validateCart(f){

   var choice = f.item1.options[f.item1.selectedIndex].text;
   choice = choice.toLowerCase(); // make lowercase

   if (f.item1 == null || f.descrb1 == null || choice.indexOf('pricing') >= 0 || choice.indexOf('-----') >= 0){
      // Who knows, just submit the form
      alert("Select a product before clicking 'Add to Cart'.");
      return false;
   }
   
   // User MUST select a mat
   if (f.descrb1.disabled == false && f.descrb1.selectedIndex == 0){
      alert("Select a mat before clicking 'Add to Cart'.");
      return false;
   }

   // User MUST select a frame
   if (f.descrc1.disabled == false && f.descrc1.selectedIndex == 0){
      alert("Select a frame before clicking 'Add to Cart'.");

      return false;
   }

   return true;
}

function SwapImg(el,which){
  el.src=el.getAttribute(which || "origsrc");
}
