// START UPSELL SUPPORT V2.06
var inupsell = false;
var invertical = false;
var inmain = false;
var upsellcurrentcol;
var upsellcolwidth;
var upsellverticalcolumns;
var upsellhorizontalcolumns;

// set the window name to unique value
Now = new Date();
var WindowName = "W" + Now.getTime();
window.name = WindowName;

function startupsellvertical(){	// start Upsell Popup Product in vertical column to right of Main product
  inupsell = true;
  invertical = true;
  if (upsellverticalcolumns > 1)
    {
    if ( upsellcurrentcol++ == 0 ) 
      {
      document.write('<table width="100%"><tr>');
      }
    if ( upsellcurrentcol > upsellverticalcolumns ) 
      {
      document.write('</tr><tr>');
      upsellcurrentcol = 1;
      }
    document.write('<td valign=top width="' + upsellcolwidth + '">');
    }
}

function startupsellhorizontal(){	// start Upsell Popup Product in horizontal rows below Main product
  inupsell = true;
  if ( upsellcurrentcol++ >= upsellhorizontalcolumns ) 
    {
    document.write('<br clear="all">');
    upsellcurrentcol = 0;
    }
}

function endupsell(){
  if ( inmain ) 
    {
    if ( invertical && (upsellverticalcolumns > 1) )document.write('</tr></table>');
    document.write('</div></td></tr></table></td></tr>');
    }
  upsellcurrentcol = 0;
  inupsell = false;
  invertical = false;
}

function startupsellmain(){  // start of main product that contains upsell items
  endupsell();
  upsellcolwidth = Math.floor(100 / upsellverticalcolumns);
  inmain = true;
}

function startupsellhorizontalmain(){  // start of main product that contains upsell items horizontal layout
  endupsell();
  inmain = true;
}

function startnormal(){   // start of normal product
  endupsell();
  inmain = false;
}

function extinfobuttonimage(imagecode){ 
  if (! inupsell)
    {
    document.write(imagecode);
    }
}

function upsellimage(thisimage, sizes, name){   // display product image (scale down big upsell images)
  if (thisimage != 'NETQUOTEVAR:IMAGEFILE')	// that's what we see if there's no image
    {
    var imgbits = sizes.match(/(\d+)\D+(\d+)/);
    if ( imgbits != null )
      {
      if ( imgbits[2] > upsellimagewidth )
        {
        var sdown = upsellimagewidth / imgbits[2];
        imgbits[1] = Math.floor(imgbits[1] * sdown);
        imgbits[2] = upsellimagewidth;
        }
      if ( imgbits[1] > upsellimagemaxheight )
        {
        sdown = upsellimagemaxheight / imgbits[1];
        imgbits[1] = upsellimagemaxheight;
        imgbits[2] = Math.floor(upsellimagewidth * sdown);
        }
      document.write('<img border=0 src="' + thisimage + '" HEIGHT=' + imgbits[1] + ' WIDTH=' + imgbits[2] 
                   + ' alt=" ' + name + '">');
      }
    else
      {
      document.write('Bad sizes: ' + sizes);
      }
    }
}
// END UPSELL SUPPORT