function showCart(){

var cookies=document.cookie;  //read in all cookies
var start = cookies.indexOf("ss_cart_" + serialNumber + "="); 
var cartvalues = "";
var linecount = 0;
var start1;
var end1;
var tmp;

if (start == -1)  //No cart cookie
{
  document.write("<span id=\"items\">Contains <strong>0</strong> Items<\/span>");
  document.write("<span id=\"price\">(Total: $00.00)<\/span>");
}
else   //cart cookie is present
{
  start = cookies.indexOf("=", start) +1;  
  var end = cookies.indexOf(";", start);  

  if (end == -1)
  {
    end = cookies.length;
  }

  cartvalues = unescape(cookies.substring(start,end)); //read in just the cookie data

  start = 0;
  while ((start = cartvalues.indexOf("|", start)) != -1)
  {
    start++;
    end = cartvalues.indexOf("|", start);
    if (end != -1)
    {
      linecount++;

      if (linecount == 2) // Total Quantity of Items
      {
        tmp = cartvalues.substring(start,end);
        colon = tmp.indexOf(":", 0);
         document.write("<span id=\"items\">Contains <strong>");
        document.write(tmp.substring(colon+1,end - start));
        document.write("</strong>")
        if ((tmp.substring(colon+1,end - start)) == 1 )
        {
          document.write(" Item");
        }
        else
        {
          document.write(" Items");
        }
        document.write("<\/span>")
      }
     

      if (linecount == 3)  // Product Subtotal
      {
        tmp = cartvalues.substring(start,end);
        colon = tmp.indexOf(":", 0);
        document.write("<span id=\"price\">(Total: ");
        document.write(tmp.substring(colon+1,end - start));
        document.write(")<\/span>");
      }

      start = end;
    }
    else
      break;
    }
  } // end while loop

  //close minicart HTML
}
/* end showCart() */

function fixSearchResults(){
	$$('.search-pipeline').each(function(element){
		if(element.next().nodeName == "DIV"){
			element.remove();
		}
	})
}
function initPage(){
	var viewportHeight = document.viewport.getHeight()
	var wrapperHeight = $$(".wrapper")[0].getHeight();	
	var newWrapperHeight = viewportHeight-(parseInt($$(".absfooter")[0].getHeight()) + parseInt($$(".wrapper")[0].getStyle("paddingTop")));
	if(wrapperHeight+parseInt($$(".absfooter")[0].getHeight()) < viewportHeight){
//		if(wrapperHeight < newWrapperHeight){
			$$(".wrapper")[0].setStyle({height: viewportHeight-(parseInt($$(".absfooter")[0].getHeight()) + parseInt($$(".wrapper")[0].getStyle("paddingTop")))+ "px"});
	//	}
	}
}


var outOfStockMessage = "Out of Stock";
var inStock = "In stock ([AMOUNT])"//
var useQunatityOnHand = true

function SetQuantityText(productId, id) {
	var obj = $(id);
	new Ajax.Request("getquantity.php?id=" + productId + "&rand=" + Math.random(), {
		method: "get",
		onSuccess: function(transport){
			var quantityonhand = parseInt(transport.responseXML.getElementsByTagName("result").item(0).getAttribute("quantityonhand"));
			if(isNaN(quantityonhand)){
				quantityonhand = -1;
			}
  			var outofstocklimit = parseInt(transport.responseXML.getElementsByTagName("result").item(0).getAttribute("outofstocklimit"));
  			if(isNaN(outofstocklimit)){
  				outofstocklimit = -1;
  			}
  			var quantity;
  			if(useQunatityOnHand == true){
  				quantity = quantityonhand
  			}else{
  				quantity = Math.max(quantityonhand, outofstocklimit)
  			}
  			var result = "";
			var className = "";
 			if(quantity <= 0){
 				result = outOfStockMessage
				className = "outofstock";
 			}else{
 				result = inStock.replace("[AMOUNT]", quantity)
				className = "instock";
 			}
			obj.addClassName(className)
 			obj.update(result)
			obj.up().setStyle({display: "block"});
		}
	})
}

