<!--

// name - name of the cookie

// value - value of the cookie

// [expires] - expiration date of the cookie (defaults to end of current session)

// [path] - path for which the cookie is valid (defaults to path of calling document)

// [domain] - domain for which the cookie is valid (defaults to domain of calling document)

// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission

// * an argument defaults when it is assigned null as a placeholder

// * a null placeholder is not required for trailing omitted arguments

function SetCookie(name, value, expires, path, domain, secure) {

  var curCookie = name + "=" + escape(value) +

      ((expires) ? "; expires=" + expires.toGMTString() : "") +

      ((path) ? "; path=" + path : "") +

      ((domain) ? "; domain=" + domain : "") +

      ((secure) ? "; secure" : "");

  document.cookie = curCookie;

}



// name - name of the desired cookie

// * return string containing value of specified cookie or null if cookie does not exist

function GetCookie(name) {

  var dc = document.cookie;

  var prefix = name + "=";

  var begin = dc.indexOf("; " + prefix);

  if (begin == -1) {

    begin = dc.indexOf(prefix);

    if (begin != 0) return null;

  } else

    begin += 2;

  var end = document.cookie.indexOf(";", begin);

  if (end == -1)

    end = dc.length;

  return unescape(dc.substring(begin + prefix.length, end));

}



// name - name of the cookie

// [path] - path of the cookie (must be same as path used to create cookie)

// [domain] - domain of the cookie (must be same as domain used to create cookie)

// * path and domain default if assigned null or omitted if no explicit argument proceeds

function DeleteCookie(name, path, domain) {

  if (GetCookie(name)) {

    document.cookie = name + "=" + 

    ((path) ? "; path=" + path : "") +

    ((domain) ? "; domain=" + domain : "") +

    "; expires=Thu, 01-Jan-70 00:00:01 GMT";

  }

}



// date - any instance of the Date object

// * hand all instances of the Date object to this function for "repairs"

function fixdate(date) {

  var base = new Date(0);

  var skew = base.getTime();

  if (skew > 0)

    date.setTime(date.getTime() - skew);

}

function ShowBSells()

{

var FeaturedIndex = new Array;

var elems = 0;

do

{

  idx = Math.floor( Math.random() * Featured.length );

  var IdxFound = false;

  for (i = 0; i < FeaturedIndex.length; i++ )

  {

    if (FeaturedIndex[i] == idx)

    {

      IdxFound = true;

      break;

    }

  }

  if (!IdxFound)

  {

    FeaturedIndex[elems] = idx;

    elems = elems + 1;

  }

} while (FeaturedIndex.length < FeaturedN);



document.write("<table border=0 cellpadding=0 cellspacing=0 width=100% class=spec-table>");

j = 0;

var inTr = false;

for (i = 0 ; i < FeaturedIndex.length; i++)

{

    if (j==0)

    {

        document.write("<tr valign=top>");

        inTr = true;

    }

    document.write("<td width=50% class=spec-table-cell" + j + ">");

    document.write( String(Featured[FeaturedIndex[i]]).replace(/`/gi, "'") );

    document.write("</td>");

    

    j++;

    if (j==FeaturedColumns)

    {

        j = 0;

        inTr = false;

    }

}

if (inTr)

    document.write("</tr>");

document.write("</table>");

}

function ShowBSells2()
{
	for (k = 0; k < FeaturedCategories; k++ )
	{
		var FeaturedIndex = new Array;
		var elems = 0;
		do
		{
		  FLength = eval("Featured"+k+".length");
		  idx = Math.floor( Math.random() * FLength );
		  var IdxFound = false;
		  for (i = 0; i < FeaturedIndex.length; i++ )
		  {
			if (FeaturedIndex[i] == idx)
			{
			  IdxFound = true;
			  break;
			}
		  }
		  if (!IdxFound)
		  {
			FeaturedIndex[elems] = idx;
			elems = elems + 1;
		  }
		} while (FeaturedIndex.length < 2);

		featLabel = eval("FeaturedTitle" + k);
		featLabelLink = eval("FeaturedTLink" + k);
		document.write("<label class=homeFeatLabel><a href="+featLabelLink+">" + featLabel + "</a></label>");
		document.write("<table border=0 cellpadding=0 cellspacing=0 width=100% class=spec-table>");
		j = 0;
		var inTr = false;
		for (i = 0 ; i < FeaturedIndex.length; i++)
		{
			if (j==0)
			{
				document.write("<tr valign=top>");
				inTr = true;
			}
			document.write("<td width=50% class=spec-table-cell" + j + ">");
			outFeat = eval("Featured" + k + "[FeaturedIndex[i]]");
			document.write( String(outFeat).replace(/`/gi, "'") );
			document.write("</td>");
			
			j++;
			if (j==FeaturedColumns)
			{
				j = 0;
				inTr = false;
			}
		}
		if (inTr) document.write("</tr>");
		document.write("</table>");
	}
}

//----------------- tabs
var nTabs = 6;

function ResetTabs()
{
	if (document.getElementById)
	{
		document.write ("<style>#tabs .tab { display: none }</style>");
	}
}
function SwitchTab(tab)
{
	if (document.getElementById)
	{
		for (var i = 1; i < nTabs + 1; i++)
		{
			var tabbtn = document.getElementById("tablink" + i);
			if (tabbtn)
			{
				if (i != tab)
					tabbtn.className = "";
				else
					tabbtn.className = "selected";
			}
			var tabcontent = document.getElementById("tab" + i);
			if (tabcontent)
			{
				if (i != tab)
					tabcontent.style.display = "none";
				else
					tabcontent.style.display = "block";
			}
		}
	}
}

// ------------------ menu
var menuimg;
var menuitem;

function SwapMenu(id)
{
    if (id)
    {
        menuimg = document.images[id].src;
        menuitem = id;
        document.images[id].src = "http://site.kleargear.com/officetoys/geektoys/computergifts/geekshirts/menuarrow-geek-toys.gif";
    }
    else
        document.images[menuitem].src = menuimg;
}

function ClearAll()

{

	DeleteCookie("Path");

	document.location.reload();

}

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)

{

    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 )

  {

      document.write("<div id=recenthistory>");

      document.write("<table border=0 cellpadding=0 cellspacing=0 width=100%>");

      

      document.write("<tr id=recentheader><td colspan=10>");

      document.write("<table border=0 width=100% cellpadding=4 cellspacing=0><tr><td>")

      document.write("Recently Viewed " + ( type=="Items" ? "Items" : "Categories" ) );

      document.write("</td><td align=right><a href=javascript:ClearAll()>Clear All</a></td></tr></table></td></tr>");



      document.write("<tr valign=bottom>");

      for ( i = trail.length - 1; i >= 0; i-- )

      {

        elem = trail[i].split("|");

        if ( elem[0].length > 0 )

        {

            document.write("<td style='padding: 2px'>");

            if ( typeof(elem[2]) != 'undefined' && elem[2].length > 0)

            {

                document.write ( "<a href=" + elem[0] + ".html><img border=0 align=absmiddle src=" + elem[2] + "></a>" );

            }

            document.write("</td><td width=10>&nbsp;</td>");

        }

      }

      document.write("</tr><tr valign=top>");

      for ( i = trail.length - 1; i >= 0; i-- )

      {

        elem = trail[i].split("|");

        if ( elem[0].length > 0 )

        {

            document.write("<td style='padding: 2px'>");

            document.write( "<a href=" + elem[0] + ".html>" + unescape(elem[1]) + "</a>");

            if (typeof(elem[3]) != 'undefined' && elem[3] != '' && elem[3] != 'undefined')

                document.write(" $" + elem[3]);

            document.write("</td><td width=10>&nbsp;</td>");

        }

      }



      document.write("</tr></table></div>");

  }

}
//-->
