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("<a id=\"items\" href=\"" + baseCgiUrl + "/order.cgi?storeid=" + storeId + "&function=show" + "\"><span>0 Items</span><\/a>");
  //document.write("<span id=\"price\">$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("<a href=\"" + baseCgiUrl + "/order.cgi?storeid=" + storeId + "&function=show" + "\" id=\"items\"><span>");
        document.write(tmp.substring(colon+1,end - start));
        if ((tmp.substring(colon+1,end - start)) == 1 )
        {
          document.write(" Item");
        }
        else
        {
          document.write(" Items");
        }
        document.write("<\/span><\/a>")
      }
     

      if (linecount == 3)  // Product Subtotal
      {
        tmp = cartvalues.substring(start,end);
        colon = tmp.indexOf(":", 0);
        //document.write("<span id=\"price\">");
        //document.write(tmp.substring(colon+1,end - start));
        //document.write("<\/span>");
      }

      start = end;
    }
    else
      break;
    }
  } // end while loop

  //close minicart HTML
}
/* end showCart() */


function openTopMenu(liObj){
	$(liObj).addClassName("over")
}
function closeTopMenu(liObj){
	$(liObj).removeClassName("over")
}

var currentMenu = null;
function openMenu(obj){
	if(currentMenu == $(obj).up().select("ul")[0]){
		return;
	}
	if(currentMenu){
		currentMenu.slideUp({duration: 0.3})
	}
	currentMenu = $(obj).up().select("ul")[0];
	//currentMenu.setStyle({display: "block"})	
	currentMenu.slideDown({duration: 0.3});
}
function applyImageAligments(obj, verticalAligment){
	var img = $(obj);
	var width = img.getWidth()
	
	if(width){
		var left = (159 - width)/2;
		img.setStyle({left: "" + left + "px"});
	}
	
	if(verticalAligment == "bottom"){
		img.setStyle({bottom: 0});
	}else if(verticalAligment == "middle"){
		var top = (112 - img.getHeight())/2;
		img.setStyle({top: "" + top + "px"})
	}
}

/*
function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;	
}
function writeCookie(name, value, seconds){
    var date = new Date();
    date.setTime(date.getTime()+(seconds*1000));
    var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";	
}

function processOnUnload(e) {
//	console.log("From processOnUnload: internalLink=" + internalLink)
	if(internalLink == false){
		writeCookie("showed", "true", 60*60*24*365)
		window.onbeforeunload = null;
		//window.location.href = "http://www.uniquevanities.com/get-discount.html"; 
		
		var formContent = '<h1>Limited Time Discount</h1>'

		formContent += '<p><strong>Get 10% OFF Your Order</strong></p>'
		formContent += '<p>Simply enter your name and e-mail address into the form below and you will instantly receive a discount code to take 10% off your order!</p>'
		formContent += '<form method="post" action="http://lists.serverhost.net/form.php?form=864" id="frmSS864" onsubmit="return ss_checkForm(this)">'
		formContent += '<input type="hidden" name="format" value="t">'
		formContent += '<table border="0" cellpadding="2" class="myForm">'
		formContent += '<tr valign="middle">'
		formContent += '<td>First Name:</td>'
		formContent += '<td><div class="ss_notreqbox" style="margin: 0;"><input type="text" name="firstname" value=""></div></td>'
		formContent += '</tr>'
		formContent += '<tr valign="middle">'
		formContent += '<td><span class="required">*</span> E-mail Address:</td>'
		formContent += '<td><div class="ss_reqbox" style="margin: 0;"><input type="text" name="email" value="" class="emailaddress" /></div></td>'
		formContent += '</tr>'
		formContent += '<tr>'
		formContent += '<td></td>'
		formContent += '<td>'
		formContent += '<input type="submit" value="Send Me My Discount Code">'
		formContent += '</td>'
		formContent += '</tr>'
		formContent += '</table>'
		formContent += '</form>'

		formContent += '<p>After you fill out the form go check your e-mail, there will be a discount code inside.  Come back to UniqueVanities.com and enter the code during checkout and your discount will be applied! Need help in choosing the best Bathroom Vanity or Vessel Sink? Call us – we are a Professional Bathroom Remodeler in Dallas! 1-866-526-1843.</p>'

		formContent += '<p>IMPORTANT: we hate spam as much as you do and we will hold your contact information in the strictest confidence!</p>'

		
		
		$$(".content").each(function(o){o.update(formContent)}) 
		alert("Home Remodeling can be costly! To help minimize the costs we’ll email you an exclusive discount for 10% OFF your order from UniqueVanities.com!"); 
		return "\n\nBuying a bathroom vanity is a BIG decision! Feel confident in your online shopping experience!\n\n";
	}
}
//do nothing on order.cgi page
if(document.location.href.indexOf("order.cgi") == -1){

	var pages = readCookie("pages");
	if(pages == null){
		writeCookie("pages", "1", 60*10);	
	}else{
		writeCookie("pages", parseInt(pages) + 1, 60*10);
	}	

	internalLink = true;
	var numberOfPages = 4;
//var numberOfPages = 0;

if(readCookie("showed") == null && parseInt(readCookie("pages")) >= numberOfPages){	
	window.onload = function(e){		
		window.onbeforeunload = processOnUnload;
		$$("a").each(function(obj){

			obj.observe("click", function(e){

				var link = Event.element(e).readAttribute("href");
				if(link.indexOf("http") == 0){
					if(link.indexOf("uniquevanities.com") > -1){
						internalLink = true;
					}
				}else{
					//no http means that link is local!!!
					internalLink = true;
				}
			})			
		})
		$$("form").each(function(obj){
			obj.observe("submit", function(e){
				internalLink = true;
			})
		})
		internalLink = false;
	}
}

}
*/
