function GenericPopup(src)
{
window.open(src, "win", "width=590,height=590,resizable=1,scrollbars=1,scrolling=auto")
}

function RemoveStr(src,target)
{
  var result = src;
  
  var i = result.indexOf(target);
  if ( i > -1 ) // if the elem is already stored, remove it first.
  {
    var left = result.substr(0,i);
    var right = result.substr(i + target.length);
    if (left.substr( left.length-1, 1 ) == ",")
    {
        left = left.substr(0, left.length - 1);
    }
    if (right.substr(0,1) == ",")
    {
        right = right.substr(1);
    }
    if (right.length > 0 && left.length > 0)
    {
      result = left + "," + right;
    }
    else if (left.length > 0)
    {
      result = left;
    }
    else
    {
      result = right;
    }
  }
  return (result);
}

function SaveSearch(frm)
{
  SaveTrail(frm.query.value,null,null,"Search",4);
}

function ShowSearches()
{
    var searches = GetCookie("Search");
    if (searches == null)
      searches = ""
    var trail = searches.split(",");
    while ( trail.length > 0 && trail[0] == "" )
    {
        trail.shift();
        l = trail.length;
    }

    if ( trail.length > 0 )
    {
        document.write("<label>Your Recent Searches</label>");
        for ( i = trail.length - 1; (i >= trail.length - 6) && (i >= 0); i-- )
        {
            document.write("<a href=http://search.store.yahoo.com/cgi-bin/nsearch?catalog=ytimes&query=" + escape(trail[i]) + ">" + unescape(trail[i]) + "</a><br>");
        }
    }
}

function SaveTrail(id,name,img,cookie,size,price)
{
  var path = "";
  var path = GetCookie(cookie);
  if (path == null)
    path = "";

  var elem;
  if (id && name)
  {
    elem = id + "|" + escape(name) + "|" + img + "|" + price;
  }
  else
  {
    elem = id;
  }
  path = RemoveStr(path,elem);
  var trail = path.split(",");
  var l = trail.push( elem );
  while ( trail.length > 0 && trail[0] == "" )
  {
    trail.shift();
    l = trail.length;
  }
  while ( l > parseInt(size) )
  {
    trail.shift();
    l = trail.length;
  }
  
  path = trail.toString();
  // make it expire in one day
  var dt = new Date();
  dt.setTime(dt.getTime() + 24 * 60 * 60 * 1000);
  SetCookie(cookie, path, dt);
}

function ShowTrail()
{
    var path = GetCookie("Path");
    if (path == null)
      path = "";

  var trail = path.split(",");
  while ( trail.length > 0 && trail[0] == "" )
  {
    trail.shift();
    l = trail.length;
  }

  if ( trail.length > 0 )
  {
      document.write("<b>Recently Viewed Categories:</b><br><div id=trail><ul>");
      for ( i = trail.length - 1; (i >= trail.length - 6) && (i >= 0); i-- )
      {
        elem = trail[i].split("|");
        if ( elem[0].length > 0 )
        {
            document.write ( "<li><a href=" + elem[0] + ".html>" + unescape(elem[1]) + "</a></li> ");
        }
      }
      document.write("</ul></div>");
  }
}

function ShowFullTrail(type, c, title)
{
    var ck = (type == "Items" ? "Path" : "Section");

    var path = GetCookie(ck);
    if (path == null)
      path = "";

  var trail = path.split(",");
  while ( trail.length > 0 && trail[0] == "" )
  {
    trail.shift();
    l = trail.length;
  }

  if ( trail.length > 0 )
  {
    var columns = ( c || 1);
    var NewRow = true;
    var InRow = false;
    var colwid = 100 / columns;
    
    if (!c)
        document.write("<div class=callout>");
    if (title)
    {
        document.write("<h5>" + title + "</h5>");
    }
    else
    {
        document.write("<img src='/lib/yhst-64629529285744/h_recentlyviewed.gif' alt='Recently Viewed Items' title='Recently Viewed Items' / width='224' height='54'>");
    }
    document.write("<table cellspacing=0>");
    var j = 1;
    for ( i = trail.length - 1; i >= 0; i-- )
    {
        if (NewRow)
        {
            document.write("<tr>");
            NewRow = false;
            InRow = true;
        }
        elem = trail[i].split("|");
        if ( elem.length > 0 )
        {
            document.write("<td>");
			document.write( "<a href=" + elem[0] + ".html>" );
            if (elem[2].length > 0)
            {
                document.write ( "<img border=0 align=absmiddle src=" + elem[2] + ">" );
            }
            document.write("</td><td class=descrip><a href=" + elem[0] + ".html>" + unescape(elem[1].replace(/`/gi, "'").replace(/%26%2396%3B/gi,"'")) + "</a>" );
            if (elem.length >= 4 && typeof(elem[3]) != 'undefined')
            {
                document.write("<div class=price>" + elem[3] + "<span class='note'>Ships Free</span></div>");
            }
            document.write("</td>");
        }
        if (j % columns == 0)
        {
            document.write("</tr>");
            NewRow = true;
            InRow = false;
        }
        j++;
    }
    if (InRow)
        document.write("</tr>");
    document.write("</table>");
    if (!c)
    {
        document.write("<img src='/lib/yhst-64629529285744/rtsidebox_btm.gif' alt / width='224' height='15'>");
        document.write("</div>");
    }
  }
}

function ShowFullTrailBottom(type, c, title) // used on the bottom of full pages
{
    var ck = (type == "Items" ? "Path" : "Section");

    var path = GetCookie(ck);
    if (path == null)
      path = "";

  var trail = path.split(",");
  while ( trail.length > 0 && trail[0] == "" )
  {
    trail.shift();
    l = trail.length;
  }

  if ( trail.length > 0 )
  {
    var columns = ( c || 1);
    var NewRow = true;
    var InRow = false;
    var colwid = 100 / columns;
    
    if (!c)
        document.write("<div class=recentFull>");
    if (title)
    {
        document.write("<h5>" + title + "</h5>");
    }
    else
    {
        document.write("<img src='/lib/yhst-10435526915688/h_recent.gif' alt='Recently Viewed Items' title='Recently Viewed Items' / width='195' height='29'>");
    }
    document.write("<table cellspacing=0>");
    var j = 1;
    for ( i = trail.length - 1; i >= 0; i-- )
    {
        if (NewRow)
        {
            document.write("<tr>");
            NewRow = false;
            InRow = true;
        }
        elem = trail[i].split("|");
        if ( elem.length > 0 )
        {
            document.write("<td><table class=item cellspacing=0><tr valign=bottom><td class=prodImg>");
			document.write( "<a href=" + elem[0] + ".html>" );
            if (elem[2].length > 0)
            {
                document.write ( "<img border=0 align=absmiddle src=" + elem[2] + ">" );
            }
            document.write("</td></tr><tr><td class=descrip><a href=" + elem[0] + ".html><h2>" + unescape(elem[1].replace(/`/gi, "'").replace(/%26%2396%3B/gi,"'")) + "</h2></a>" );
            if (elem.length >= 4 && typeof(elem[3]) != 'undefined')
            {
                document.write("<div class=price>" + elem[3] + " <span class='note'>Ships Free</span></div>");
            }
            document.write("</td></tr></table></td>");
        }
        if (j % columns == 0)
        {
            document.write("</tr>");
            NewRow = true;
            InRow = false;
        }
        j++;
    }
    if (InRow)
        document.write("</tr>");
    document.write("</table>");
    if (!c)
        document.write("</div>");
  }
}
