  var jqzoom = null;
  bSwitchBack = false;
  dPid = '';
  bDefSwatch = '';
  bCloseBox = false;
  bOpenBox = false;
  bSelectBox = false;
  pcontents = "";
  popbox = '';

  function callBack(data) {
    pcontents = data;
    popbox = document.getElementById('PopBox');
    var div = document.createElement('div');
    div.innerHTML = pcontents;
    popbox.appendChild(div);
    initSwatches();
    var drop = document.forms["cart_quantity_popup"].elements["id[2]"]
      if (drop)
      {
      	AttachEvent(drop, 'focus', focusSelect);
      	AttachEvent(drop, 'blur', blurSelect);
      }
  }

  function loadData(pid) {
    return jx.load('/popfiller.php?p_id='+pid,function(data){callBack(data)},'text','get');
    // console.log("Ajaxy goodness requested");
  }
  
  
  function hoverAbsoluteImage(pid,top,left) {
    if (pid != dPid) {
        try {
          clearTimeout(t);
        } catch (e) {}
        t=setTimeout('showInWindow('+pid+','+top+','+left+');',750);
        // console.log("New Box open Request");
      } else {
        StopTimeOut();
        // console.log("Same box hover request");
      }
  }
  function hoverImage(pid,pcol,prow) {
    if (pid != dPid) {
      try {
        clearTimeout(t);
      } catch (e) {}      
      t=setTimeout('openBoxByPosition('+pid+','+pcol+','+prow+');',750);
      // console.log("New Box open Request");
    } else {
      StopTimeOut();
      // console.log("Same box hover request");
    }
  }
  function openBoxByPosition(pid,pcol,prow) {

	    leftOffSet = 0;
	    if (pcol == 0) {
	      leftOffSet =  5;
	    } else if (pcol == 1) {
	      leftOffSet = 195;
	    } else {
	      leftOffSet =  -240;
	    }

	    // set the top offset based on the row and the scroll offset of the page
	    var top = 300;
	    top += (prow*160);
	    
	    showInWindow(pid,top,leftOffSet);
  }
  function showInWindow(pid,top,pleft){
	  if (!bOpenBox) {
	  	var left = (document.body.clientWidth / 2) + pleft;
	  	popbox = document.getElementById('PopBox');
  	
	    if (document.body.scrollTop > top) {
	        top = document.body.scrollTop + 10;
	    }
	    else if (top+popbox.clientHeight > document.body.scrollTop+document.body.clientHeight) {
	    	top = document.body.scrollTop + document.body.clientHeight - popbox.clientHeight;
	    }
	    pOpenBox(pid,top,left);
	  }
  }
  function pOpenBox(pid,top,leftOffSet) {
	dPid = pid;
	popbox = document.getElementById('PopBox');
	popbox.innerHTML = ' ';
	loadData(pid);
    
	
	popbox.style.top = top + "px";
    popbox.style.left = leftOffSet+"px";
    // popbox.innerHTML = pcontents;
    popbox.style.visibility = 'visible';
    // console.log("Box Popped Open");
  }
  
  function focusSelect() {
	  bSelectBox = true;
  }
  
  function blurSelect() {
	  bSelectBox = false;
  }
  
  function closeHover() {
    bCloseBox = true;
    bOpenBox = true;
    setTimeout('closeBox();',750);
  }
  function StopTimeOut() {
    bCloseBox = false;
    bOpenBox = false;
  }
  function fCloseBox () {
    bCloseBox = true;
    closeBox();
  }
  function closeBox() {
    if (bCloseBox && !bSelectBox) {
      popbox = document.getElementById('PopBox');
      popbox.style.visibility = 'hidden';
      bDefSwatch = '';
      // console.log("Box Closed");
      bCloseBox = false;
    }
    
    dPid = '';
  }
  function revertSwap () {
    if (bSwitchBack == true) {
      document.getElementById('feature').src = bDefSwatch;
    }
  }
  function swapFeature (swapfor, imageId) {
    s = document.getElementById(swapfor);
    f = document.getElementById(imageId);
    f.src = s.src;

    jqzoom = document.getElementById('jqzoom');
	if (jqzoom) {
	   	jqzoom.href = f.src.replace("_S_", "_B_");
		var options = {
			zoomWidth: 243,
			zoomHeight: 300,
			title: false,
			showPreload: false,
			imageOpacity: 0.4
		}
		$("#jqzoom").jqzoom(options);
	}
    bSwitchBack = true;
    // console.log("Feature Swapped");
  }
  
  function resetBoxes() {
    var els = document.getElementsByTagName('div');
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)swatches-selected(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
      if ( pattern.test(els[i].className) ) {
    	  els[i].className = "swatches";
      }
    }
  }
  
  function sizeChart() {
	  window.open("/sizechart.html","mywindow","menubar=0,location=0,statusbar=0,resizable=1,width=435,height=593");
  }
  
  function initProductInfoSwatches(product) {
	  if (document.getElementsByName('id[1]').length > 1) {
      	bSwatches = document.getElementsByName('id[1]')[1];
      } else {
      	bSwatches = document.getElementsByName('id[1]')[0];
      }
      bSwatchesLen = bSwatches.options.length;

      var sendColours = '';
	  for (i=0;i<bSwatchesLen;i++) {
	    sendColours += ":" + bSwatches.options[i].text;
	  }
	    
	  getSwatchBoxes(product, sendColours.substring(1,sendColours.length), 'm');
	  initDefaultSwatch(product);
	  
	  if (document.getElementsByName('id[2]')[0] && document.getElementsByName('id[2]')[0].options[0].text == 'Small'  && dPid != 96) {
	      document.getElementById('mi2').innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;<a style="font-size:12px" href="javascript:sizeChart()">Size Chart &gt;</a>';
      }
  }
  
  function initDefaultSwatch(product) {
	    m1 = document.getElementById('m1');
	    m2 = document.getElementById('m2');
	    if (m1 && m2) {
		    m1.src = "/images/"+product+dSwatch+"S_2.jpg";
		    m2.src = "/images/"+product+dSwatch+"S_3.jpg";
	    }
  }
  
  // called by the product popup
  function initSwatches () {
	try {
    	bModels = document.getElementById('feature').src.split('/');
       	bSwatches = document.getElementsByName('id[1]')[0];
        bSwatchesLen = bSwatches.options.length;
        var sendColours = '';
	    for (i=0;i<bSwatchesLen;i++) {
	    	sendColours += ":" + bSwatches.options[i].text;
	    }
      
	    getSwatchBoxes(bModels[4].substring(0,bModels[4].length-6),sendColours.substring(1,sendColours.length),'f');
	    bDefSwatch = document.getElementById('feature').src;
	    if (document.getElementsByName('id[2]')[0] && document.getElementsByName('id[2]')[0].options[0].text == 'Small'  && dPid != 96) {
			document.getElementById('si2').innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:sizeChart()">Size Chart &gt;</a>';
//			document.getElementById('si2').style.width='90% !important';
	    }
      //document.getElementById('si2').style.paddingLeft='15px';
      // console.log("Swatch Init Ran");
    } catch (err) {
      // alert(err.message);
      // setTimeout('initSwatches();',50);
      // console.log("Recalling Swatch Init");
    }
  }

  function changeFeature (swatch, fm, product, swatchBox) {
    // console.log("Feature Image Change Requested");
    bSwitchBack = false;
   
   	mainPic = document.getElementById('mainImage');
   	jqzoom = document.getElementById('jqzoom');

    if (!fm) {
    	fm = 'f'
    }
    
    f1 = document.getElementById(fm + '1');
    f2 = document.getElementById(fm + '2');
    
    resetBoxes();
    if (!product) {
    	product = cProduct;
    }
    
    if (f1 && f2) {
	    f1.src = "/images/"+product+swatch+"S_2.jpg";
	    f2.src = "/images/"+product+swatch+"S_3.jpg";
    }
    
    if (!swatchBox) {
	    selBox = document.getElementById('d'+swatch);
	    selBox.className = "swatches-selected";
    } else {
    	swatchBox.className = "swatches-selected";
    }
    colorBox = document.getElementsByName('id[1]')[0];
    bDefSwatch = mainPic.src;
    mainPic.src = "/images/"+product+swatch+"S.jpg";
	if (jqzoom) {
	    jqzoom.href = "/images/"+product+swatch+"B.jpg";
		var options = {
			zoomWidth: 243,
			zoomHeight: 300,
			title: false,
			showPreload: false,
			imageOpacity: 0.4
		}
		$("#jqzoom").jqzoom(options);
	}
	
    switch (swatch) {
      case "_EVGRN_":
        colorBox.options[colorBox.selectedIndex].value = '37';
        document.getElementById('cdisp').innerHTML = "Evergreen";
        break;
      case "_MOSS_":
        colorBox.options[colorBox.selectedIndex].value = '38';
        document.getElementById('cdisp').innerHTML = "Moss";
        break;
      case "_MAUV_":
        colorBox.options[colorBox.selectedIndex].value = '39';
        document.getElementById('cdisp').innerHTML = "Mauve";
        break;
      case "_TOUP_":
        colorBox.options[colorBox.selectedIndex].value = '40';
        document.getElementById('cdisp').innerHTML = "Taupe";
        break;
      case "_DEAN_":
        colorBox.options[colorBox.selectedIndex].value = '41';
        document.getElementById('cdisp').innerHTML = "Dean";
        break;
      case "_NATR_":
        colorBox.options[colorBox.selectedIndex].value = '42';
        document.getElementById('cdisp').innerHTML = "Natural";
        break;a 
      case "_STON_":
        colorBox.options[colorBox.selectedIndex].value = '43';
        document.getElementById('cdisp').innerHTML = "Stone";
        break;
      case "_LEAF_":
        colorBox.options[colorBox.selectedIndex].value = '44';
        document.getElementById('cdisp').innerHTML = "Leaf";
        break;
      case "_KHAK_":
        colorBox.options[colorBox.selectedIndex].value = '45';
        document.getElementById('cdisp').innerHTML = "Khaki";
        break;
      case "_INDI_":
        colorBox.options[colorBox.selectedIndex].value = '46';
        document.getElementById('cdisp').innerHTML = "Indigo";
        break;
      case "_SERE_":
        colorBox.options[colorBox.selectedIndex].value = '47';
        document.getElementById('cdisp').innerHTML = "Serenity";
        break;
      case "_PEBB_":
        colorBox.options[colorBox.selectedIndex].value = '48';
        document.getElementById('cdisp').innerHTML = "Pebble";
        break;
      case "_CUNB_":
        colorBox.options[colorBox.selectedIndex].value = '49';
        document.getElementById('cdisp').innerHTML = "Country Blue";
        break;
      case "_PCH_":
        colorBox.options[colorBox.selectedIndex].value = '50';
        document.getElementById('cdisp').innerHTML = "Peach";
        break;
	  case "_BLK_":
		colorBox.options[colorBox.selectedIndex].value = '51';
		document.getElementById('cdisp').innerHTML = "Black";
		break;
      case "_SHAD010_":
        colorBox.options[colorBox.selectedIndex].value = '52';
        document.getElementById('cdisp').innerHTML = "Shadow 010";
        break;
      case "_PAPY_":
        colorBox.options[colorBox.selectedIndex].value = '53';
        document.getElementById('cdisp').innerHTML = "Papaya";
        break;
      case "_CBLT_":
        colorBox.options[colorBox.selectedIndex].value = '54';
        document.getElementById('cdisp').innerHTML = "Cobalt";
        break;
      case "_GHST_":
        colorBox.options[colorBox.selectedIndex].value = '56';
        document.getElementById('cdisp').innerHTML = "Ghost";
        break;
      case "_SKY_":
        colorBox.options[colorBox.selectedIndex].value = '57';
        document.getElementById('cdisp').innerHTML = "Sky";
        break;
      case "_WAX_":
        colorBox.options[colorBox.selectedIndex].value = '58';
        document.getElementById('cdisp').innerHTML = "Wax";
        break;
      case "_SLTN_":
        colorBox.options[colorBox.selectedIndex].value = '59';
        document.getElementById('cdisp').innerHTML = "Saltine";
        break;
      case "_DUST_":
        colorBox.options[colorBox.selectedIndex].value = '60';
        document.getElementById('cdisp').innerHTML = "Dust";
        break;
      case "_SGRS_":
        colorBox.options[colorBox.selectedIndex].value = '61';
        document.getElementById('cdisp').innerHTML = "Sea Grass";
        break;
      case "_SAGE_":
        colorBox.options[colorBox.selectedIndex].value = '62';
        document.getElementById('cdisp').innerHTML = "Sage";
        break;
      case "_SPLH_":
        colorBox.options[colorBox.selectedIndex].value = '63';
        document.getElementById('cdisp').innerHTML = "Splash";
        break;
      case "_HUND_":
        colorBox.options[colorBox.selectedIndex].value = '64';
        document.getElementById('cdisp').innerHTML = "Hound";
        break;
      case "_DWSH_":
        colorBox.options[colorBox.selectedIndex].value = '65';
        document.getElementById('cdisp').innerHTML = "Dark Wash";
        break;
      case "_LBST_":
        colorBox.options[colorBox.selectedIndex].value = '66';
        document.getElementById('cdisp').innerHTML = "Light Blue Stone";
        break;
      case "_VWSH_":
        colorBox.options[colorBox.selectedIndex].value = '67';
        document.getElementById('cdisp').innerHTML = "Vintage Wash";
        break;
      case "_TWSH_":
        colorBox.options[colorBox.selectedIndex].value = '68';
        document.getElementById('cdisp').innerHTML = "Timber Wash";
        break;
      case "_MBLU_":
        colorBox.options[colorBox.selectedIndex].value = '69';
        document.getElementById('cdisp').innerHTML = "Medium Blue";
        break;
      case "_OLIV_":
        colorBox.options[colorBox.selectedIndex].value = '89';
        document.getElementById('cdisp').innerHTML = "Olive";
        break;
      case "_CRMS_":
        colorBox.options[colorBox.selectedIndex].value = '90';
        document.getElementById('cdisp').innerHTML = "Crimson";
        break;
      case "_SFOM_":
        colorBox.options[colorBox.selectedIndex].value = '91';
        document.getElementById('cdisp').innerHTML = "Sea Foam";
        break;
      case "_SMOK_":
        colorBox.options[colorBox.selectedIndex].value = '92';
        document.getElementById('cdisp').innerHTML = "Smoke";
        break;
      case "_RAFF_":
        colorBox.options[colorBox.selectedIndex].value = '93';
        document.getElementById('cdisp').innerHTML = "Raffia";
        break;
      case "_SPMT_":
        colorBox.options[colorBox.selectedIndex].value = '94';
        document.getElementById('cdisp').innerHTML = "Spearmint";
        break;
      case "_WLLO_":
        colorBox.options[colorBox.selectedIndex].value = '95';
        document.getElementById('cdisp').innerHTML = "Willow";
        break;
      case "_BDST_":
        colorBox.options[colorBox.selectedIndex].value = '96';
        document.getElementById('cdisp').innerHTML = "Blue Dust";
        break;
      case "_FFLY_":
        colorBox.options[colorBox.selectedIndex].value = '97';
        document.getElementById('cdisp').innerHTML = "Fire Fly";
        break;
      case "_BRBL_":
        colorBox.options[colorBox.selectedIndex].value = '98';
        document.getElementById('cdisp').innerHTML = "Bright Blue";
        break;
      case "_IPNK_":
        colorBox.options[colorBox.selectedIndex].value = '99';
        document.getElementById('cdisp').innerHTML = "Ice Pink";
        break;
      case "_VBRN_":
        colorBox.options[colorBox.selectedIndex].value = '100';
        document.getElementById('cdisp').innerHTML = "Venetian Brown";
        break;
      case "_VBLK_":
        colorBox.options[colorBox.selectedIndex].value = '101';
        document.getElementById('cdisp').innerHTML = "Venetian Black";
        break;
      case "_VCGN_":
        colorBox.options[colorBox.selectedIndex].value = '102';
        document.getElementById('cdisp').innerHTML = "Venetian Cognac";
        break;
      case "_BRWN_":
        colorBox.options[colorBox.selectedIndex].value = '103';
        document.getElementById('cdisp').innerHTML = "Brown";
        break;
      case "_TAN_":
        colorBox.options[colorBox.selectedIndex].value = '104';
        document.getElementById('cdisp').innerHTML = "Tan";
        break;
      case "_GSMK_":
        colorBox.options[colorBox.selectedIndex].value = '105';
        document.getElementById('cdisp').innerHTML = "Gunsmoke";
        break;
      case "_OTML_":
        colorBox.options[colorBox.selectedIndex].value = '106';
        document.getElementById('cdisp').innerHTML = "Oatmeal";
        break;
      case "_CNUT_":
        colorBox.options[colorBox.selectedIndex].value = '107';
        document.getElementById('cdisp').innerHTML = "Chestnut";
        break;
      case "_RED_":
        colorBox.options[colorBox.selectedIndex].value = '108';
        document.getElementById('cdisp').innerHTML = "Red";
        break;
      case "_PCFC_":
        colorBox.options[colorBox.selectedIndex].value = '109';
        document.getElementById('cdisp').innerHTML = "Pacific";
        break;
      case "_OWSH_":
        colorBox.options[colorBox.selectedIndex].value = '110';
        document.getElementById('cdisp').innerHTML = "Oil Wash";
        break;
      case "_NAVY_":
        colorBox.options[colorBox.selectedIndex].value = '111';
        document.getElementById('cdisp').innerHTML = "Navy";
        break;
      case "_EUCA_":
        colorBox.options[colorBox.selectedIndex].value = '112';
        document.getElementById('cdisp').innerHTML = "Eucalyptus";
        break;
      case "_SHBT_":
        colorBox.options[colorBox.selectedIndex].value = '113';
        document.getElementById('cdisp').innerHTML = "Sherbet";
        break;	
      case "_CBRY_":
        colorBox.options[colorBox.selectedIndex].value = '114';
        document.getElementById('cdisp').innerHTML = "Chambray";
        break;
      case "_ROYL_":
        colorBox.options[colorBox.selectedIndex].value = '115';
        document.getElementById('cdisp').innerHTML = "Royal";
        break;
      case "_TRWD_":
        colorBox.options[colorBox.selectedIndex].value = '116';
        document.getElementById('cdisp').innerHTML = "Torchwood";
        break;
      case "_DEWK_":
          colorBox.options[colorBox.selectedIndex].value = '125';
          document.getElementById('cdisp').innerHTML = "Dewkist";
          break;   
      case "_RDBR_":
          colorBox.options[colorBox.selectedIndex].value = '126';
          document.getElementById('cdisp').innerHTML = "Red Brown";
          break; 
      case "_ARMY_":
        colorBox.options[colorBox.selectedIndex].value = '127';
        document.getElementById('cdisp').innerHTML = "Army";
        break;
      case "_CARD_":
        colorBox.options[colorBox.selectedIndex].value = '128';
        document.getElementById('cdisp').innerHTML = "Cardiff";
        break;		  
      case "_CLR_":
          colorBox.options[colorBox.selectedIndex].value = '129';
          document.getElementById('cdisp').innerHTML = "Clear";
          break;
		case "_ERTH_":
			colorBox.options[colorBox.selectedIndex].value = '130';
			document.getElementById('cdisp').innerHTML = "Earth";
			break;
		case "_LNEN_":
			colorBox.options[colorBox.selectedIndex].value = '131';
			document.getElementById('cdisp').innerHTML = "Linen";
			break;
		case "_CHRL_":
			colorBox.options[colorBox.selectedIndex].value = '132';
			document.getElementById('cdisp').innerHTML = "Charcoal";
			break;
		case "_DKBL_":
			colorBox.options[colorBox.selectedIndex].value = '133';
			document.getElementById('cdisp').innerHTML = "Dark Blue";
			break;
		case "_CHRM_":
			colorBox.options[colorBox.selectedIndex].value = '134';
			document.getElementById('cdisp').innerHTML = "Chrome";
			break;
		case "_SHAD_":
			colorBox.options[colorBox.selectedIndex].value = '135';
			document.getElementById('cdisp').innerHTML = "Shadow";
			break;
		case "_STEL_":
			colorBox.options[colorBox.selectedIndex].value = '136';
			document.getElementById('cdisp').innerHTML = "Steel";
			break;
		case "_SEPI_":
			colorBox.options[colorBox.selectedIndex].value = '137';
			document.getElementById('cdisp').innerHTML = "Sepia";
			break;
		case "_FAWK_":
			colorBox.options[colorBox.selectedIndex].value = '138';
			document.getElementById('cdisp').innerHTML = "Fawkes";
			break;
		case "_TRIB_":
			colorBox.options[colorBox.selectedIndex].value = '139';
			document.getElementById('cdisp').innerHTML = "Tribal";
			break;
		case "_MONT_":
			colorBox.options[colorBox.selectedIndex].value = '140';
			document.getElementById('cdisp').innerHTML = "Mountain";
			break;
		case "_ANTQ_":
			colorBox.options[colorBox.selectedIndex].value = '141';
			document.getElementById('cdisp').innerHTML = "Antique Medium Wash";
			break;
		case "_LTBL_":
			colorBox.options[colorBox.selectedIndex].value = '142';
			document.getElementById('cdisp').innerHTML = "Light Blue";
			break;
		case "_KTBL_":
			colorBox.options[colorBox.selectedIndex].value = '143';
			document.getElementById('cdisp').innerHTML = "Kent Blue";
			break;
		case "_VLTG_":
			colorBox.options[colorBox.selectedIndex].value = '144';
			document.getElementById('cdisp').innerHTML = "Voltage";
			break;
		case "_ASH_":
			colorBox.options[colorBox.selectedIndex].value = '145';
			document.getElementById('cdisp').innerHTML = "Ash";
			break;
		case "_EWSH_":
			colorBox.options[colorBox.selectedIndex].value = '146';
			document.getElementById('cdisp').innerHTML = "Earthwash";
			break;
		case "_BRCH_":
			colorBox.options[colorBox.selectedIndex].value = '147';
			document.getElementById('cdisp').innerHTML = "Birch";
			break;
		case "_PEWT_":
			colorBox.options[colorBox.selectedIndex].value = '148';
			document.getElementById('cdisp').innerHTML = "Pewter";
			break;
		case "_PHAN_":
			colorBox.options[colorBox.selectedIndex].value = '149';
			document.getElementById('cdisp').innerHTML = "Phantom";
			break;
		case "_ADOB_":
			colorBox.options[colorBox.selectedIndex].value = '150';
			document.getElementById('cdisp').innerHTML = "Adobe";
			break;
		case "_LOG_":
			colorBox.options[colorBox.selectedIndex].value = '151';
			document.getElementById('cdisp').innerHTML = "Log";
			break;
		case "_MINK_":
			colorBox.options[colorBox.selectedIndex].value = '152';
			document.getElementById('cdisp').innerHTML = "Mink";
			break;
		case "_CGNC_":
			colorBox.options[colorBox.selectedIndex].value = '153';
			document.getElementById('cdisp').innerHTML = "Cognac";
			break;
		case "_ZOBL_":
			colorBox.options[colorBox.selectedIndex].value = '154';
			document.getElementById('cdisp').innerHTML = "Zobel";
			break;
		case "_COUV_":
			colorBox.options[colorBox.selectedIndex].value = '155';
			document.getElementById('cdisp').innerHTML = "Couverture";
			break;
		case "_IDBL_":
			colorBox.options[colorBox.selectedIndex].value = '156';
			document.getElementById('cdisp').innerHTML = "Indigo Black";
			break;
		case "_TRCT_":
			colorBox.options[colorBox.selectedIndex].value = '157';
			document.getElementById('cdisp').innerHTML = "Terracotta";
			break;
		case "_EGSL_":
			colorBox.options[colorBox.selectedIndex].value = '158';
			document.getElementById('cdisp').innerHTML = "Eggshell";
			break;
		case "_CCBR_":
			colorBox.options[colorBox.selectedIndex].value = '159';
			document.getElementById('cdisp').innerHTML = "Cocoa Brown";
			break;
		case "_PLUM_":
			colorBox.options[colorBox.selectedIndex].value = '160';
			document.getElementById('cdisp').innerHTML = "Plum";
			break;
		case "_DKBR_":
			colorBox.options[colorBox.selectedIndex].value = '161';
			document.getElementById('cdisp').innerHTML = "Dark Brown";
			break;
		case "_RBTN_":
			colorBox.options[colorBox.selectedIndex].value = '162';
			document.getElementById('cdisp').innerHTML = "Rootbeer Tan";
			break;
		case "_DKTN_":
			colorBox.options[colorBox.selectedIndex].value = '163';
			document.getElementById('cdisp').innerHTML = "Dark Tan";
			break;
		case "_BEIG_":
			colorBox.options[colorBox.selectedIndex].value = '164';
			document.getElementById('cdisp').innerHTML = "Beige";
			break;
		case "_SLUS_":
			colorBox.options[colorBox.selectedIndex].value = '165';
			document.getElementById('cdisp').innerHTML = "Slush";
			break;
		case "_CRME_":
			colorBox.options[colorBox.selectedIndex].value = '166';
			document.getElementById('cdisp').innerHTML = "Cream";
			break;
		case "_CORA_":
			colorBox.options[colorBox.selectedIndex].value = '167';
			document.getElementById('cdisp').innerHTML = "Crystal Orange";
			break;
		case "_SLVR_":
			colorBox.options[colorBox.selectedIndex].value = '168';
			document.getElementById('cdisp').innerHTML = "Silver";
			break;
		case "_AMBR_":
			colorBox.options[colorBox.selectedIndex].value = '169';
			document.getElementById('cdisp').innerHTML = "Amber";
			break;
		case "_TRTS_":
			colorBox.options[colorBox.selectedIndex].value = '170';
			document.getElementById('cdisp').innerHTML = "Tortoise";
			break;
		case "_BKTT_":
			colorBox.options[colorBox.selectedIndex].value = '171';
			document.getElementById('cdisp').innerHTML = "Black Tortoise";
			break;
		case "_BRTT_":
			colorBox.options[colorBox.selectedIndex].value = '172';
			document.getElementById('cdisp').innerHTML = "Brown Tortoise";
			break;
		case "_BLTT_":
			colorBox.options[colorBox.selectedIndex].value = '173';
			document.getElementById('cdisp').innerHTML = "Blond Tortoise";
			break;
		case "_BRNZ_":
			colorBox.options[colorBox.selectedIndex].value = '174';
			document.getElementById('cdisp').innerHTML = "Bronze";
			break;
		case "_GLXY_":
			colorBox.options[colorBox.selectedIndex].value = '178';
			document.getElementById('cdisp').innerHTML = "Galaxy";
			break;
		case "_ROSE_":
			colorBox.options[colorBox.selectedIndex].value = '179';
			document.getElementById('cdisp').innerHTML = "Rose";
			break;
		case "_MIST_":
			colorBox.options[colorBox.selectedIndex].value = '180';
			document.getElementById('cdisp').innerHTML = "Mist";
			break;
		case "_BLUE31A_":
			colorBox.options[colorBox.selectedIndex].value = '181';
			document.getElementById('cdisp').innerHTML = "Blue 031A";
			break;
		case "_CHMB_":
			colorBox.options[colorBox.selectedIndex].value = '182';
			document.getElementById('cdisp').innerHTML = "Bleached Chambray";
			break;
		case "_RUBY_":
			colorBox.options[colorBox.selectedIndex].value = '183';
			document.getElementById('cdisp').innerHTML = "Ruby";
			break;
		case "_PRL_":
			colorBox.options[colorBox.selectedIndex].value = '184';
			document.getElementById('cdisp').innerHTML = "Pearl";
			break;
		case "_WHIT_":
			colorBox.options[colorBox.selectedIndex].value = '185';
			document.getElementById('cdisp').innerHTML = "White";
			break;
		case "_BLUE69B_":
			colorBox.options[colorBox.selectedIndex].value = '186';
			document.getElementById('cdisp').innerHTML = "Blue 069B";
			break;
		case "_WHIT67A_":
			colorBox.options[colorBox.selectedIndex].value = '187';
			document.getElementById('cdisp').innerHTML = "White 067A";
			break;
		case "_WHIT65A_":
			colorBox.options[colorBox.selectedIndex].value = '188';
			document.getElementById('cdisp').innerHTML = "White 065A";
			break;
		case "_WHIT69A_":
			colorBox.options[colorBox.selectedIndex].value = '189';
			document.getElementById('cdisp').innerHTML = "White 069A";
			break;
         case "_PCFC19B_":
			colorBox.options[colorBox.selectedIndex].value = '190';
			document.getElementById('cdisp').innerHTML = "Pacific 019B";
			break;
		case "_BLK001_":
			colorBox.options[colorBox.selectedIndex].value = '191';
			document.getElementById('cdisp').innerHTML = "Black 001";
			break;
		case "_IBLU_":
			colorBox.options[colorBox.selectedIndex].value = '192';
			document.getElementById('cdisp').innerHTML = "Ice Blue";
			break; 
		case "_COPE_":
			colorBox.options[colorBox.selectedIndex].value = '193';
			document.getElementById('cdisp').innerHTML = "Copen Blue";
			break;
		case "_BLUE_":
			colorBox.options[colorBox.selectedIndex].value = '194';
			document.getElementById('cdisp').innerHTML = "Blue";
			break;
		case "_KYOT_":
			colorBox.options[colorBox.selectedIndex].value = '196';
			document.getElementById('cdisp').innerHTML = "Kyoto";
			break;
		case "_ZBLU_":
			colorBox.options[colorBox.selectedIndex].value = '197';
			document.getElementById('cdisp').innerHTML = "Zen Blue";
			break;
		case "_YACL_":
			colorBox.options[colorBox.selectedIndex].value = '198';
			document.getElementById('cdisp').innerHTML = "Yacht Club";
			break;
		case "_STRU_":
			colorBox.options[colorBox.selectedIndex].value = '199';
			document.getElementById('cdisp').innerHTML = "Structure";
			break;
		case "_CALL_":
			colorBox.options[colorBox.selectedIndex].value = '200';
			document.getElementById('cdisp').innerHTML = "Calligraphy";
			break;
		case "_STAR_":
			colorBox.options[colorBox.selectedIndex].value = '201';
			document.getElementById('cdisp').innerHTML = "Starflower";
			break;
		case "_CISQ_":
			colorBox.options[colorBox.selectedIndex].value = '202';
			document.getElementById('cdisp').innerHTML = "City Square";
			break;
		case "_HAND_":
			colorBox.options[colorBox.selectedIndex].value = '203';
			document.getElementById('cdisp').innerHTML = "Handblock";
			break;
		case "_STUC_":
			colorBox.options[colorBox.selectedIndex].value = '204';
			document.getElementById('cdisp').innerHTML = "Stucco";
			break;
		case "_TAKE_":
			colorBox.options[colorBox.selectedIndex].value = '205';
			document.getElementById('cdisp').innerHTML = "Take";
			break;
		case "_SKY453_":
			colorBox.options[colorBox.selectedIndex].value = '206';
			document.getElementById('cdisp').innerHTML = "Sky 453";
			break;
      case "_BWSH_":
        colorBox.options[colorBox.selectedIndex].value = '207';
        document.getElementById('cdisp').innerHTML = "Black Wash";
        break;
      case "_SFOM332_":
        colorBox.options[colorBox.selectedIndex].value = '212';
        document.getElementById('cdisp').innerHTML = "Sea Foam 332";
        break;
      case "_YELL_":
        colorBox.options[colorBox.selectedIndex].value = '213';
        document.getElementById('cdisp').innerHTML = "Yellow";
        break;
      case "_ROYL425_":
        colorBox.options[colorBox.selectedIndex].value = '214';
        document.getElementById('cdisp').innerHTML = "Royal 425";
        break;
      case "_SHBT823_":
        colorBox.options[colorBox.selectedIndex].value = '215';
        document.getElementById('cdisp').innerHTML = "Sherbet 823";
        break;	
      case "_GREEN_":
        colorBox.options[colorBox.selectedIndex].value = '216';
        document.getElementById('cdisp').innerHTML = "Green";
        break;
      case "_TAN217_":
        colorBox.options[colorBox.selectedIndex].value = '217';
        document.getElementById('cdisp').innerHTML = "Tan 217";
        break;	
      case "_CREAM012_":
        colorBox.options[colorBox.selectedIndex].value = '218';
        document.getElementById('cdisp').innerHTML = "Cream 012";
        break;	
      case "_RUST_":
        colorBox.options[colorBox.selectedIndex].value = '219';
        document.getElementById('cdisp').innerHTML = "Rust";
        break;	
		case "_MIST047A_":
			colorBox.options[colorBox.selectedIndex].value = '224';
			document.getElementById('cdisp').innerHTML = "Mist 047A";
			break;	
      case "_PEBB017A_":
        colorBox.options[colorBox.selectedIndex].value = '225';
        document.getElementById('cdisp').innerHTML = "Pebble 017A";
        break;
      case "_SAGE300_":
        colorBox.options[colorBox.selectedIndex].value = '226';
        document.getElementById('cdisp').innerHTML = "Sage 300";
        break;	
      case "_STON008B_":
        colorBox.options[colorBox.selectedIndex].value = '227';
        document.getElementById('cdisp').innerHTML = "Stone 008B";
        break;	
      case "_RED003_":
        colorBox.options[colorBox.selectedIndex].value = '228';
        document.getElementById('cdisp').innerHTML = "Red 003";
        break;		
      case "_PCH831_":
        colorBox.options[colorBox.selectedIndex].value = '229';
        document.getElementById('cdisp').innerHTML = "Peach 831";
        break;
		case "_SHAD001_":
			colorBox.options[colorBox.selectedIndex].value = '230';
			document.getElementById('cdisp').innerHTML = "Shadow 001";
			break;
      case "_DEAN249_":
        colorBox.options[colorBox.selectedIndex].value = '231';
        document.getElementById('cdisp').innerHTML = "Dean 249";
        break;
      case "_INDI406_":
        colorBox.options[colorBox.selectedIndex].value = '232';
        document.getElementById('cdisp').innerHTML = "Indigo 406";
        break;
      case "_DKGREY_":
        colorBox.options[colorBox.selectedIndex].value = '233';
        document.getElementById('cdisp').innerHTML = "Dark Grey";
        break;
      case "_PURP_":
        colorBox.options[colorBox.selectedIndex].value = '234';
        document.getElementById('cdisp').innerHTML = "Purple";
        break;
      case "_LEAF346_":
        colorBox.options[colorBox.selectedIndex].value = '235';
        document.getElementById('cdisp').innerHTML = "Leaf 346";
        break;
      case "_SMOK10_":
        colorBox.options[colorBox.selectedIndex].value = '236';
        document.getElementById('cdisp').innerHTML = "Smoke 10";
        break;
	  case "_WHIT100_":
			colorBox.options[colorBox.selectedIndex].value = '237';
			document.getElementById('cdisp').innerHTML = "White 100";
			break;
      case "_NAVY012_":
        colorBox.options[colorBox.selectedIndex].value = '238';
        document.getElementById('cdisp').innerHTML = "Navy 012";
        break;
      case "_CRYS_":
        colorBox.options[colorBox.selectedIndex].value = '239';
        document.getElementById('cdisp').innerHTML = "Crystal";
        break;
	  case "_ADOB010_":
		colorBox.options[colorBox.selectedIndex].value = '240';
		document.getElementById('cdisp').innerHTML = "Adobe 010";
		break;
	  case "_SEPI808_":
		colorBox.options[colorBox.selectedIndex].value = '241';
		document.getElementById('cdisp').innerHTML = "Sepia 808";
		break;
      case "_KHAK211_":
        colorBox.options[colorBox.selectedIndex].value = '242';
        document.getElementById('cdisp').innerHTML = "Khaki 211";
        break;
      case "_BUTTR_":
        colorBox.options[colorBox.selectedIndex].value = '243';
        document.getElementById('cdisp').innerHTML = "Butter";
        break;




		
      default:
      /*
       SHOULD NEVER HIT THIS BRANCH, MEANS COLOUR NOT ACCOUNTED FOR, AND NOT GENERATED BY SwatchBoxes FUNCTION
      */
    }
    bDefSwatch = mainPic.src;
  }

  function getSwatchBoxes (product,colours,fm) {
    // For testing - remove the value of the product
    // console.log("Writing Swatch Boxes");
    cProduct = product;
    dSwatch = '';
    // Change the drop-down into a hidden field
    if (document.getElementById('si1')) {
    	var dVal = document.getElementById('si1').style.display='none';
    }
    else {
    	var dVal = document.getElementsByName('id[1]')[0];     		
	    dVal.style.display='none';
    	var parent = dVal.parentNode;
    	var newS1 = document.createElement('div');
    	newS1.id = 'localS1';
    	parent.appendChild(newS1);
    }
    
    if (!fm) {
    	fm = 'f'
    }
    var strReturnVal = '';
    var aryColours = colours.split(':');
    strReturnVal = "<div style='color:#000000; font-size:14px;text-align:left;margin-top:0px;'>Color: <span id='cdisp'>&nbsp;</span></div><div style='height:28px;width:90%;margin-top:5px;margin-left:8px;'>";
    for (i=0;i<aryColours.length;i++) {
      switch (aryColours[i]) {
        case "Evergreen":
		  color = '#339966';
          swatch = '_EVGRN_';
          break;
        case "Moss":
		  color = '#999999';
          swatch = '_MOSS_';
          break;
        case "Mauve":
		  color = '#D3A1AD';
          swatch = '_MAUV_';
          break;
        case "Taupe":
		  color = '#D0CEBB';
          swatch = '_TOUP_';
          break;
        case "Dean":
		  color = '#996633';
          swatch = '_DEAN_';
          break;
        case "Natural":
		  color = '#D4D4C7';
          swatch = '_NATR_';
          break;
        case "Stone":
		  color = '#E6DABA';
          swatch = '_STON_';
          break;
        case "Leaf":
		  color = '#86A486';
          swatch = '_LEAF_';
          break;
        case "Khaki":
		  color = '#BEA082';
          swatch = '_KHAK_';
          break;
        case "Indigo":
		  color = '#01018F';
          swatch = '_INDI_';
          break;
        case "Serenity":
		  color = '#CCCCFF';
          swatch = '_SERE_';
          break;
        case "Pebble":
		  color = '#ACAC96';
          swatch = '_PEBB_';
          break;
        case "Country Blue":
		  color = '#6699CC';
          swatch = '_CUNB_';
          break;
        case "Peach":
		  color = '#FF9966';
          swatch = '_PCH_';
          break;
        case "Black":
		  color = '#000000';
          swatch = '_BLK_';
          break;
        case "Shadow 010":
		  color = '#56555A';
          swatch = '_SHAD010_';
          break;
        case "Papaya":
		  color = '#E7A972';
          swatch = '_PAPY_';
          break;
        case "Cobalt":
		  color = '#1D5EB4';
          swatch = '_CBLT_';
          break;
        case "Ghost":
		  color = '#E8E8E8';
          swatch = '_GHST_';
          break;
        case "Sky":
		  color = '#A1D5D7';
          swatch = '_SKY_';
          break;
        case "Wax":
		  color = '#EAEACE';
          swatch = '_WAX_';
          break;
        case "Saltine":
		  color = '#E7E7DF';
          swatch = '_SLTN_';
          break;
        case "Dust":
		  color = '#907e74';
          swatch = '_DUST_';
          break;
        case "Seagrass":
		  color = '#68B859';
          swatch = '_SGRS_';
          break;
        case "Sage":
		  color = '#A1B79D';
          swatch = '_SAGE_';
          break;
        case "Splash":
		  color = '#93ADD8';
          swatch = '_SPLH_';
          break;
        case "Hound":
		  color = '#BFB5A5';
          swatch = '_HUND_';
          break;
        case "Dark Wash":
		  color = '#292a2e';
          swatch = '_DWSH_';
          break;
        case "Light Blue Stone":
		  color = '#8596B2';
          swatch = '_LBST_';
          break;
        case "Vintage Wash":
		  color = '#454F5E';
          swatch = '_VWSH_';
          break;
        case "Timber Wash":
		  color = '#383C43';
          swatch = '_TWSH_';
          break;
        case "Medium Blue":
		  color = '#405E90';
          swatch = '_MBLU_';
          break;
        case "Olive":
		  color = '#595F28';
          swatch = '_OLIV_';
          break;
        case "Crimson":
		  color = '#C92466';
          swatch = '_CRMS_';
          break;
        case "Seafoam":
		  color = '#8ACFC4';
          swatch = '_SFOM_';
          break;
        case "Smoke":
		  color = '#515050';
          swatch = '_SMOK_';
          break;
        case "Raffia":
		  color = '#B2B2B2';
          swatch = '_RAFF_';
          break;
        case "Spearmint":
		  color = '#A9DED5';
          swatch = '_SPMT_';
          break;
        case "Willow":
		  color = '#7EAC85';
          swatch = '_WLLO_';
          break;
        case "Blue Dust":
		  color = '#8896c3';
          swatch = '_BDST_';
          break;
        case "Firefly":
		  color = '#DFE0A9';
          swatch = '_FFLY_';
          break;
        case "Bright Blue":
		  color = '#408AFA';
          swatch = '_BRBL_';
          break;
        case "Ice Pink":
		  color = '#E6C5E9';
          swatch = '_IPNK_';
          break;
        case "Venetian Brown":
		  color = '#732f0c';
          swatch = '_VBRN_';
          break;
        case "Venetian Black":
		  color = '#000000';
          swatch = '_VBLK_';
          break;
        case "Venetian Cognac":
		  color = '#9c3922';
          swatch = '_VCGN_';
          break;
        case "Brown":
		  color = '#6d2d23';
          swatch = '_BRWN_';
          break;
        case "Tan":
		  color = '#B3A590';
          swatch = '_TAN_';
          break;
        case "Gunsmoke":
		  color = '#665f59';
          swatch = '_GSMK_';
          break;
        case "Oatmeal":
		  color = '#D1D1C2';
          swatch = '_OTML_';
          break;
        case "Chestnut":
		  color = '#9d6041';
          swatch = '_CNUT_';
          break;
        case "Red":
		  color = '#FA2020';
          swatch = '_RED_';
          break;
        case "Pacific":
		  color = '#2a4065';
          swatch = '_PCFC_';
          break;
        case "Navy":
		  color = '#3C365E';
          swatch = '_NAVY_';
          break;
        case "Sherbet":
		  color = '#FFE291';
          swatch = '_SHBT_';
          break;
        case "Royal":
		  color = '#073CA8';
          swatch = '_ROYL_';
          break;
        case "Army":
		  color = '#a4ac97';
          swatch = '_ARMY_';
          break;
        case "Cardiff":
		  color = '#788ab8';
          swatch = '_CARD_';
          break;
        case "Chambray":
		  color = '#7F82A3';
          swatch = '_CBRY_';
          break;
        case "Eucalyptus":
		  color = '#808D87';
          swatch = '_EUCA_';
          break;
        case "Oil Wash":
		  color = '#33394B';
          swatch = '_OWSH_';
          break;
        case "Torchwood":
		  color = '#D2C4A4';
          swatch = '_TRWD_';
          break;
        case "Black Wash":
		  color = '#393838';
          swatch = '_BWSH_';
          break;
        case "Dewkist":
		  color = '#A599B7';
          swatch = '_DEWK_';
          break;
        case "Red Brown":
		  color = '#4c1a11';
          swatch = '_RDBR_';
          break;
        case "Clear":
		  color = '#666';
          swatch = '_CLR_';
          break;
        case "Ice Blue":
		  color = '#7197a4';
          swatch = '_IBLU_';
		case "Earth":
		  color = '#4B4A46';
		  swatch = '_ERTH_';
		  break;
		case "Linen":
		  color = '#CDBAAB';
		  swatch = '_LNEN_';
		  break;
		case "Charcoal":
		  color = '#39373A';
		  swatch = '_CHRL_';
		  break;
		case "Dark Blue":
		  color = '#393A3F';
		  swatch = '_DKBL_';
		  break;
		case "Chrome":
		  color = '#A3A2A7';
		  swatch = '_CHRM_';
		  break;
		case "Shadow":
		  color = '#56555A';
		  swatch = '_SHAD_';
		  break;
		case "Steel":
		  color = '#74717C';
		  swatch = '_STEL_';
		  break;
		case "Sepia":
		  color = '#A27F6B';
		  swatch = '_SEPI_';
		  break;
		case "Fawkes":
		  color = '#F4EFEC';
		  swatch = '_FAWK_';
		  break;
		case "Tribal":
		  color = '#9B7058';
		  swatch = '_TRIB_';
		  break;
		case "Mountain":
		  color = '#85746D';
		  swatch = '_MONT_';
		  break;
		case "Antique Medium Wash":
		  color = '#41414D';
		  swatch = '_ANTQ_';
		  break;
		case "Light Blue":
		  color = '#666';
		  swatch = '_LTBL_';
		  break;
		case "Kent Blue":
		  color = '#3E3D45';
		  swatch = '_KTBL_';
		  break;
		case "Voltage":
		  color = '#484649';
		  swatch = '_VLTG_';
		  break;
		case "Ash":
		  color = '#C2BDBB';
		  swatch = '_ASH_';
		  break;
		case "Earthwash":
		  color = '#414046';
		  swatch = '_EWSH_';
		  break;
		case "Birch":
		  color = '#8C6345';
		  swatch = '_BRCH_';
		  break;
		case "Pewter":
		  color = '#5F6162';
		  swatch = '_PEWT_';
		  break;
		case "Phantom":
		  color = '#57514E';
		  swatch = '_PHAN_';
		  break;
		case "Adobe":
		  color = '#C06B4E';
		  swatch = '_ADOB_';
		  break;
		case "Log":
		  color = '#3D3B3E';
		  swatch = '_LOG_';
		  break;
		case "Mink":
		  color = '#666';
		  swatch = '_MINK_';
		  break;
		case "Cognac":
		  color = '#7F534A';
		  swatch = '_CGNC_';
		  break;
		case "Zobel":
		  color = '#706458';
		  swatch = '_ZOBL_';
		  break;
		case "Couverture":
		  color = '#725F5A';
		  swatch = '_COUV_';
		  break;
		case "Bronze":
			color = '#908066';
			swatch = '_BRNZ_';
			break;
		case "Blond Tortoise":
			color = '#666';
			swatch = '_BLTT_';
			break;
		case "Brown Tortoise":
			color = '#666';
			swatch = '_BRTT_';
			break;
		case "Black Tortoise":
			color = '#666';
			swatch = '_BKTT_';
			break;
		case "Tortoise":
			color = '#666';
			swatch = '_TRTS_';
			break;
		case "Amber":
			color = '#CC6600';
			swatch = '_AMBR_';
			break;
		case "Silver":
			color = '#666';
			swatch = '_SLVR_';
			break;
		case "Crystal Orange":
			color = '#FF9933';
			swatch = '_CORA_';
			break;
		case "Cream":
			color = '#A6501C';
			swatch = '_CRME_';
			break;
		case "Slush":
			color = '#D8D8D0';
			swatch = '_SLUS_';
			break;
		case "Beige":
			color = '#666';
			swatch = '_BEIG_';
			break;
		case "Dark Tan":
			color = '#666';
			swatch = '_DKTN_';
			break;
		case "Rootbeer Tan":
			color = '#A67F52';
			swatch = '_RBTN_';
			break;
		case "Dark Brown":
			color = '#917E6F';
			swatch = '_DKBR_';
			break;
		case "Plum":
			color = '#3C2834';
			swatch = '_PLUM_';
			break;
		case "Cocoa Brown":
			color = '#61433A';
			swatch = '_CCBR_';
			break;
		case "Eggshell":
			color = '#DCD8D5';
			swatch = '_EGSL_';
			break;
		case "Terracotta":
			color = '#666';
			swatch = '_TRCT_';
			break;
		case "Indigo Black":
			color = '#171518';
			swatch = '_IDBL_';
			break;
		case "Pearl":
			color = '#FF6633';
			swatch = '_PRL_';
			break;
        case "White":
		  color = '#F2F2E0';
          swatch = '_WHIT_';
          break;
		case "Mist":
			color = '#66CCCC';
			swatch = '_MIST_';
			break;
		case "Blue 031A":
			color = '#33CCFF';
			swatch = '_BLUE31A_';
			break;
		case "Ruby":
			color = '#CC0066';
			swatch = '_RUBY_';
			break;
		case "Galaxy":
			color = '#006666';
			swatch = '_GLXY_';
			break;
		case "Rose":
			color = '#FF6666';
			swatch = '_ROSE_';
			break;
		case "Bleached Chambray":
			color = '#99CCFF';
			swatch = '_CHMB_';
			break;
		case "White 069A":
			color = '#FFFFFF';
			swatch = '_WHIT69A_';
			break;
		case "White 067A":
			color = '#FFFFFF';
			swatch = '_WHIT67A_';
			break;
		case "White 065A":
			color = '#FFFFFF';
			swatch = '_WHIT65A_';
			break;
		case "Blue 069B":
			color = '#33CCFF';
			swatch = '_BLUE69B_';
			break;
        case "Pacific 019B":
			color = '#99CCFF';
			swatch = '_PCFC19B_';
			break;
        case "Black 001":
			color = '#000000';
			swatch = '_BLK001_';
			break;
        case "Copen Blue":
			color = '#99CCCC';
			swatch = '_COPE_';
			break;
        case "Blue":
			color = '#0099FF';
			swatch = '_BLUE_';
			break;
        case "Kyoto":
			color = '#FF9900';
			swatch = '_KYOT_';
			break;
        case "Zen Blue":
			color = '#66CCFF';
			swatch = '_ZBLU_';
			break;
        case "Yacht Club":
			color = '#66FFCC';
			swatch = '_YACL_';
			break;
        case "Structure":
			color = '#336666';
			swatch = '_STRU_';
			break;
        case "Calligraphy":
			color = '#CCCC99';
			swatch = '_CALL_';
			break;
        case "Starflower":
		  color = '#FFFF99';
          swatch = '_STAR_';
          break;
        case "City Square":
			color = '#FF3333';
			swatch = '_CITY_';
			break;
        case "Handblock":
		  color = '#CCCC99';
          swatch = '_HAND_';
          break;
        case "STUCCO":
			color = '#CCCCFF';
			swatch = '_STUC_';
			break;
        case "Take":
			color = '#CCCC00';
			swatch = '_TAKE_';
			break;
        case "Sky 453":
			color = '#A1D5D7';
			swatch = '_SKY453_';
			break;
        case "Sea Foam 332":
		  color = '#8ACFC4';
          swatch = '_SFOM332_';
          break;
        case "Yellow":
		  color = '#FFFF99';
          swatch = '_YELL_';
          break;
        case "Royal 425":
		  color = '#073CA8';
          swatch = '_ROYL425_';
          break;
        case "Sherbet 823":
		  color = '#FFE291';
          swatch = '_SHBT823_';
          break;
        case "Green":
		  color = '#339966';
          swatch = '_GREEN_';
          break;
        case "Tan 217":
		  color = '#B3A590';
          swatch = '_TAN217_';
          break;
        case "Cream 012":
		  color = '#CC9966'
          swatch = '_CREAM012_'
          break;
        case "Rust":
		  color = '#CC0000'
          swatch = '_RUST_'
          break;
		case "Mist 047A":
			color = '#66CCCC';
			swatch = '_MIST047A_';
			break;
        case "Pebble 017A":
		  color = '#ACAC96';
          swatch = '_PEBB017A_';
          break;
        case "Sage 300":
		  color = '#A1B79D';
          swatch = '_SAGE300_';
          break;
        case "Stone 008B":
		  color = '#E6DABA';
          swatch = '_STON008B_';
          break;
        case "Red 003":
		  color = '#FA2020';
          swatch = '_RED003_';
          break;
        case "Peach 831":
		  color = '#FF9966';
          swatch = '_PCH831_';
          break;
		case "Shadow 001":
		  color = '#56555A';
		  swatch = '_SHAD001_';
		  break;
        case "Dean 249":
		  color = '#996633';
          swatch = '_DEAN249_';
          break;
        case "Indigo 406":
		  color = '#01018F';
          swatch = '_INDI406_';
          break;
        case "Dark Grey":
		  color = '#666666';
          swatch = '_DKGREY_';
          break;
        case "Purple":
		  color = '#9966cc';
          swatch = '_PURP_';
          break;
        case "Leaf 346":
		  color = '#86A486';
          swatch = '_LEAF346_';
          break;
        case "Smoke 10":
		  color = '#515050';
          swatch = '_SMOK10_';
          break;
		case "White 100":
			color = '#FFFFFF';
			swatch = '_WHIT100_';
			break;
        case "Navy 012":
		  color = '#3C365E';
          swatch = '_NAVY012_';
          break;
        case "Crystal":
		  color = '#515050';
          swatch = '_CRYS_';
          break;
		case "Adobe 010":
		  color = '#C06B4E';
		  swatch = '_ADOB010_';
		  break;
		case "Sepia 808":
		  color = '#A27F6B';
		  swatch = '_SEPI808_';
		  break;
        case "Khaki 211":
		  color = '#BEA082';
          swatch = '_KHAK211_';
          break;
        case "Butter":
		  color = '#FFFF99';
          swatch = '_BUTTR_';
          break;

      }
      if (i == 0) {
        dSwatch = swatch;
      }
      strReturnVal += "<div id='d" + swatch + "' style='background-color:" + color + ";float: left;margin-left: 5px; margin-right: 5px; margin-top: 2px; ' class='swatches' onClick='javascript:changeFeature(\"" + swatch + "\", \""+fm+"\", \""+product+"\", this);'><img id='" + swatch + "' src='/images/"+ product + swatch + "S.jpg' style='width:0px; height:0px;'></div>";
    }
	
    var div = document.createElement('div');
    div.innerHTML = strReturnVal + "</div>"
    if (document.getElementById('s1')) {
    	var s1 = document.getElementById('s1');
    	var width = '98%';
    }
    else {
    	var s1 = document.getElementById('localS1');
    	var width= '298px';
    }
    s1.appendChild(div);
    s1.style.width=width;
    s1.style.fontSize='.65em';
    s1.style.paddingBottom='5px';
    changeFeature(dSwatch);
  }
  
  function goToDetails(product_id) {
	   var href = '/product_info.php/products_id/' + product_id;
	   href += '/color_id/' + document.forms["cart_quantity_popup"].elements["id[1]"].value;
	   window.location = href;
	   return false;
  }
  

  function AttachEvent(elementObj, eventName, eventHandlerFunctionName)
  {
    if (elementObj.addEventListener) 
    { // Non-IE browsers
      elementObj.addEventListener(eventName, eventHandlerFunctionName, false);		
    } 
    else if (elementObj.attachEvent) 
    { // IE 6+
      elementObj.attachEvent('on' + eventName, eventHandlerFunctionName);
    } 
    else 
    { // Older browsers 
      var currentEventHandler = elementObj['on' + eventName];
      if (currentEventHandler == null)    	  
      {
        elementObj['on' + eventName] = eventHandlerFunctionName;
      } 
      else 
      {
        elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }
      }
    }
  }
  
  function showPopup(success) {
	  if (success) {
		  alert('Success');
	  } else {
		  alert('Failed');
	  } 
  }
  
  function addToCartCallback(data) {
	  if (data == 'success') {
		  showPopup(true);
	  } else {
		  showPopup(false);  
	  }
  }
  
  function addToCart(pid) {
	 var form =   document.forms["cart_quantity_popup"];
	 var fData = formData(form);
	 return jx.load('/addtocart.php?p_id='+pid + '&' +fData,function(data){addToCartCallback(data)},'text','post');
  }
  
  function formData(oForm)
  {
	  var data = new Array();
	  
	  var item = 0;
	  // Iterate over the form elements collection to construct the
		// label-value pairs.
		for (i=0,len=oForm.elements.length; i<len; ++i){
			oElement  = oForm.elements[i];
			oDisabled = oElement.disabled;
            oName     = oElement.name;

			// Do not submit fields that are disabled or
			// do not have a name attribute value.
			if(!oDisabled && oName)
			{
              oName  = encodeURIComponent(oName)+'=';
              oValue = encodeURIComponent(oElement.value);

				switch(oElement.type)
				{
                  // Safari, Opera, FF all default opt.value from .text if
                  // value attribute not specified in markup
					case 'select-one':
                      if (oElement.selectedIndex > -1) {
                          opt = oElement.options[oElement.selectedIndex];
                          data[item++] = oName + encodeURIComponent(
                              (opt.attributes.value && opt.attributes.value.specified) ? opt.value : opt.text);
                      }
                      break;
					case 'select-multiple':
                      if (oElement.selectedIndex > -1) {
                          for(j=oElement.selectedIndex, jlen=oElement.options.length; j<jlen; ++j){
                              opt = oElement.options[j];
                              if (opt.selected) {
                                  data[item++] = oName + encodeURIComponent(
                                      (opt.attributes.value && opt.attributes.value.specified) ? opt.value : opt.text);
                              }
                          }
                      }
						break;
					case 'radio':
					case 'checkbox':
						if(oElement.checked){
                          data[item++] = oName + oValue;
						}
						break;
					case 'file':
						// stub case as XMLHttpRequest will only send the file path as a string.
					case undefined:
						// stub case for fieldset element which returns undefined.
					case 'reset':
						// stub case for input type reset button.
					case 'button':
						// stub case for input type button elements.
						break;
					case 'submit':
						break;
					default:
                      data[item++] = oName + oValue;
				}
			}
		}

		return data.join('&');

  }
  
  
  function showEmailBox(modelName,productId) {
	  var referbox = document.getElementById('refer-friend');
	  
	  referbox.style.display = 'block';
	   
	  var left = (document.body.clientWidth / 2) + 00;
	  		var top = 600;
	    if (document.body.scrollTop > top) {
	        top = document.body.scrollTop + 10;
	    }
	    else if (top+referbox.clientHeight > document.body.scrollTop+document.body.clientHeight) {
	    	top = document.body.scrollTop + document.body.clientHeight - referbox.clientHeight;
	    }
	    
	    referbox.style.top = top + 'px';
	    referbox.style.left = left + 'px';
	  
	  document.getElementById('item-num').innerHTML = modelName;
	  document.getElementById('refer-img').src = document.getElementById('mainImage').src;
	  document.getElementById('friend-email').focus();
  }
  
  function closeRefer() {
	  document.getElementById('refer-friend').style.display = 'none';
	  document.getElementById('friend-email').value = '';
	  document.getElementById('sender-name').value = '';
	  document.getElementById('sender-email').value = '';
	  document.getElementById('message').value = '';
	  return false;
  }
  
  function sendToFriendCallback(data) {
	  if (data == 'success') {
		 alert('Message has been sent succesfully to your friend.');
	  } else {
		  alert('Message failed to send, please try again later.');
	  }
	  closeRefer();
  }
  function sendMe() {
	  if (document.getElementById('friend-email').value == '' ||
	  document.getElementById('sender-name').value == '' ||
	  document.getElementById('sender-email').value == ''  ||
	  document.getElementById('message').innerHTML == '')
	  {
		  alert('One or more fields is missing a value, all fields are required.');
		  return false;
	  }
	  
	 var form =   document.forms["sendtofriend"];
	 var fData = formData(form);
	 var pid = 123123123123;
	 jx.load('/sendtofriend.php?p_id='+pid + '&' +fData,function(data){sendToFriendCallback(data)},'text','post');

	return false;
  }
  
  function showZoom() {
	  var main = document.getElementById('mainImage');
	   var zoomImage = document.getElementById('zoom-image');
	  var src = main.src;
	  var splitted = src.split('_');
	  zoomImage.src = splitted[0] + '_' + splitted[1] + '_' + '600_' + splitted[2];
	  
	  var referbox = document.getElementById('zoom-box');
		 
	  referbox.style.display = 'block';
		 
	  referbox.style.top = getScreenCenterY() - 300 + 'px';
	  referbox.style.left = getScreenCenterX() - 300 + 'px';
	  
  }
  function close600Box() {
	  var zoomImage = document.getElementById('zoom-image');
	  var referbox = document.getElementById('zoom-box');
      referbox.style.display = 'none';
	  zoomImage.src = '';
      
	  
  }
  
  function getScreenCenterY() {
	  var y = 0;
	
	  y = getScrollOffset()+(getInnerHeight()/2);
	
	  return(y);
  }

  function getScreenCenterX() {
	  return(document.body.clientWidth/2);
  }

  function getInnerHeight() {
	  var y;
	  if (self.innerHeight) // all except Explorer
	  {
	  y = self.innerHeight;
	  }
	  else if (document.documentElement &&  document.documentElement.clientHeight)
	  // Explorer 6 Strict Mode
	  {
	  y = document.documentElement.clientHeight;
	  }
	  else if (document.body) // other Explorers
	  {
	  y = document.body.clientHeight;
	  }
	  return(y);
  }

  function getScrollOffset() {
	  var y;
	  if (self.pageYOffset) // all except Explorer
	  {
	  y = self.pageYOffset;
	  }
	  else if (document.documentElement && document.documentElement.scrollTop)
	  // Explorer 6 Strict
	  {
	  y = document.documentElement.scrollTop;
	  }
	  else if (document.body) // all other Explorers
	  {
	  y = document.body.scrollTop;
	  }
	  return(y);
  }

  
