function addOnClick(sObj, func) {
 if(sObj==null) { return; }
 if(sObj.addEventListener) {
  sObj.addEventListener("click", func, false);
 } else if(sObj.attachEvent) {
  sObj.attachEvent("onclick", func);
 } else {
  if(typeof sObj.onclick!='function') {
   sObj.onclick=func;
  } else {
   sObj.oldonclick=sObj.onclick;
   sObj.onclick=function() { sObj.oldonclick();func(); }
  }
 }
}

function getScrollTop() {
 var pos = 0;
 if(window.innerHeight && window.pageYOffset) {
  pos = window.pageYOffset;
 } else if(document.documentElement && document.documentElement.scrollTop) {
  pos = document.documentElement.scrollTop;
 } else if(document.body) {
  pos = document.body.scrollTop;
 }
 return pos;
}

function getBrowserWidth() {
 var pos = 0;
 if(window.innerWidth) {
  pos = window.innerWidth;
 } else if(document.documentElement.clientWidth) {
  pos = document.documentElement.clientWidth;
 } else if(document.body && document.body.offsetWidth) {
  pos = document.body.offsetWidth;
 }
 return pos;
}

function getBrowserHeight() {
 var pos = 0;
 if(window.innerHeight) {
  pos = window.innerHeight;
 } else if(document.documentElement.clientHeight) {
  pos = document.documentElement.clientHeight;
 } else if(document.body && document.body.offsetHeight) {
  pos = document.body.offsetHeight;
 }
 return pos;
}

function getWidth(sObj) {
 if(sObj==null) { return -1; }
 if(sObj.offsetWidth) { return sObj.offsetWidth; }
 if(sObj.width) { return parseInt(sObj.width); }
 if(sObj.style && sObj.style.width) { return parseInt(sObj.style.width); }
 return 0;
}

function getHeight(sObj) {
 if(sObj==null) { return -1; }
 if(sObj.offsetHeight) { return sObj.offsetHeight; }
 if(sObj.height) { return parseInt(sObj.height); }
 if(sObj.style && sObj.style.height) { return parseInt(sObj.style.height); }
 return 0;
}

function addCart(item_name) {
 if(document.createElement) {
  var iObj;
  var sObj=document.getElementById('xCartFrame');
  if(sObj!=null) { sObj.parentNode.removeChild(sObj); }
  iObj=document.getElementsByTagName('body');
  if(iObj==null || iObj.length==0) {
   iObj=document;
  } else {
   iObj=iObj[0];
  }
  sObj=document.createElement('iframe');
  sObj.id='xCartFrame';
  sObj.src='http://www.smartluck.com/cgi/order-x.pl?cart_add='+item_name;
  sObj.style.backgroundColor='#fff';
  sObj.style.zIndex='999999999';
  sObj.style.position='absolute';
  sObj.style.height='350px';
  sObj.style.width='800px';
  sObj.style.top=(getScrollTop()+(getBrowserHeight()-getHeight(sObj))/2)+'px';
  sObj.style.left=((getBrowserWidth()-getWidth(sObj))/2)+'px';
  sObj.style.border='5px solid #ff0';
  if(typeof(sObj.style.BorderRadius)!='undefined') {
   sObj.style.BorderRadius="8px";
  } else if(typeof(sObj.style.MozBorderRadius)!='undefined') {
   sObj.style.MozBorderRadius="8px";
  } else if(typeof(sObj.style.WebkitBorderRadius)!='undefined') {
   sObj.style.WebkitBorderRadius="8px";
  }
  iObj.appendChild(sObj);
  return true;
 } else {
  return false;
 }
}

function getCookie(cName) {
 var ca = document.cookie.split(';');
 for(var i=0;i<ca.length;i++) {
  while (ca[i].charAt(0)==' ') { ca[i]=ca[i].substring(1,ca[i].length); }
  if(ca[i].indexOf(cName+'=')==0) { return ca[i].substring(cName.length+1,ca[i].length); }
 }
 return '';
}

function updateCartIcon() {
 var cont=getCookie('cart2');
 if(cont.length>0) {
  var itm=document.getElementById('bnr_cart');
  if(itm!=null) {
   var imgObj=itm.getElementsByTagName('img');
   if(imgObj.length>0) { imgObj[0].src=imgObj[0].src.substring(0,imgObj[0].src.lastIndexOf('/')+1)+'cart-cart-full.png'; }
  }
 }
} addOnLoad(updateCartIcon);
