
var dpopTimer = "";

function updateAndShowCartLink(aCount)
{
	document.getElementById('shoppingcart-link').style.display = 'block';
	if (aCount == '1')
	{
	  document.getElementById('shoppingcart-text').innerHTML = '1 item in shopping cart';
	}
	else
	{
	  document.getElementById('shoppingcart-text').innerHTML = aCount+' items in shopping cart';
	}
}

function showAddedToCart() 
{
	var popFullscreen = document.getElementById('obscure');
	var popLarge = document.getElementById('added-to-cart');
	var sheet = document.getElementById('sheet')
    
    var myScrollHeight = 3000;
    // Make fullscreen thing really full screen, and show it
    getSize();
    popFullscreen.style.height = myScrollHeight + 'px';
    popFullscreen.style.display = 'block';
    popFullscreen.style.visibility = 'visible';
	
    // Position pop-up
    myWidth = 800;

    popLarge.style.left = ((myWidth - popLarge.offsetWidth) / 2) + 'px';
    popLarge.style.top = (((myHeight - popLarge.offsetHeight) / 2) + myScroll - 300) + 'px';
    popLarge.style.visibility = 'visible';
    
    //refreshTimer = setTimeout("setLocation('"+elem.getAttribute("href")+"')", 1500);

}

function hideAddedToCart() 
{
	var popFullscreen = document.getElementById('obscure');
	var popLarge = document.getElementById('added-to-cart');

  popFullscreen.style.display = 'none';
  popLarge.style.visibility = 'hidden';
}

var xmlhttp;

function addToCart(id)
{
  //if (pageTracker) pageTracker._trackEvent("Shoppingcart", "Add", id);
	showAddedToCart();

	if (window.XMLHttpRequest)
	{ // code for all real browsers
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{  // code for IE5 and IE6
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null)
	{
		xmlhttp.onreadystatechange = shopHttpStateChange;
		xmlhttp.open("GET","/addtocart.ashx?add="+id,true);
		xmlhttp.send(null);
	}
	else
  {
  	alert("Your browser does not support XMLHTTP.");
  }
}

function shopHttpStateChange()
{
  //alert('state '+xmlhttp);
	if (xmlhttp.readyState==4)
  {
		//alert('state4 '+xmlhttp.status);
  	// 4 = "loaded"
  	if (xmlhttp.status==200)
    {
    	// 200 = OK
    	updateAndShowCartLink(xmlhttp.responseText);
    }
  	else
    {
    	alert("Problem retrieving XML data");
    }
  }
}

function actuallyHide() {
	var popDownload = document.getElementById('shoppopup');
		popDownload.style.visibility = 'hidden';
	/*if (dpopTimer != "")
	{
		dpopTimer = "";
		moveStart(popDownload, parseInt(popDownload.style.left), parseInt(popDownload.style.left), parseInt(popDownload.style.top), parseInt(popDownload.style.top) - 10, 15);		
		fadeElementSetup('dpop', 100, 0, 13, 1);
	}*/
}

// downloads

function switchDetailsVisibility(id)
{
	element = document.getElementById("div_"+id).style;
	if(element.visibility == "hidden")
	{
		element.visibility = "visible";
		element.display = "table-row";
		document.getElementById("link_"+id).innerHTML = "Hide Details";
	}
	else
	{
		element.visibility = "hidden";
		element.display = "none";
		document.getElementById("link_"+id).innerHTML = "Show Details";
	}
}
