function addToCart(itemId , itemName , itemPrice )
{
	//alert()
 // get products attributes
 var reg=/\'/g
 var t1= new Array('0','0','0','0');
 var t2= new Array('0','0','0','0');
 if (document.frm && document.frm.attribute_group1)
 {
 	 t1 = document.frm.attribute_group1.value.split('~');
 }
 if (document.frm && document.frm.attribute_group2)
 {
 	 t2 = document.frm.attribute_group2.value.split('~');
	 
 }
 if (document.frm)
 {
 	itemPrice=Number(document.frm.originalPrice.value)+Number(t1[3])+Number(t2[3]);
}
// case of no-cookie -> create new cookie with first item.
if (getCookie('cart')==null)
 {
   var now = new Date();
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	//alert(itemName)

itemName=itemName.replace(reg, "&#39;")

	//itemName=itemName.replace("'","&#39;")
		//alert(itemName)
    setCookie('cart', itemId+'~'+itemName+'~'+itemPrice+'~1~'+t1[0]+'~'+t1[1]+'~'+t2[0]+'~'+t2[1], now );
    updateCart();
 }
 else
 {
   
    var arr = getCookie('cart').toString().split("|");
   /*// Case of existing item -> add 1 to quantity
   for (var i=0; i<arr.length ; i++)
   {
       var subArr = arr[i].split('~')
       if(subArr[0]==itemId)
       {
           
           subArr[3]++;
           arr[i]=subArr.join('~');
           setCookie('cart', arr.join('|'), now );
           updateCart();
           return;
       }
       
  }
*/
itemName=itemName.replace(reg, "&#39;")
   arr.push(itemId+'~'+itemName+'~'+itemPrice+'~1~'+t1[0]+'~'+t1[1]+'~'+t2[0]+'~'+t2[1]);
   setCookie('cart', arr.join('|'), now );
   updateCart();
 }
}
function updateCart()
{
    var d = window.document.getElementById('cartItems')
    var t=0;
    var str='<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"CartTable\">'
    if(getCookie('cart')!=null)
    {
    var arr = getCookie('cart').toString().split("|");
    for (var i=0; i<arr.length ; i++)
   {
        
        t+=(arr[i].split('~')[2]*arr[i].split('~')[3])
        str+=   '<tr align=\"left\"><td>'+arr[i].split('~')[1]+'</td><td align=\"center\">'+arr[i].split('~')[3]+'</td><td align=\"right\">'+arr[i].split('~')[2]+'$</td></tr>'
    }
    str+='</table>'
    window.document.getElementById('cartTotal').innerHTML=(Math.round(t*100)/100)+'$';
    d.innerHTML=str;
    }
}
function setCookie(name, value, expires, path, domain, secure) {
var reg=/\'/g
value=value.replace(reg, "&#39;")
  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));
}
// this deletes the cookie when called
function clearCookie(name){
setCookie('cart', '', '' );
}


//clearCookie('cart');


function setPrice()
{
	var originalPrice = Number(document.frm.originalPrice.value)
	if ((typeof(document.frm.attribute_group1) == 'object'))
	{
		var attribute_group1 = document.frm.attribute_group1.value;
		var t1= Number(attribute_group1.split('~')[3]);
	
	}
	else 
	{
		//var attribute_group1 = 0;
		var t1=0;
	}
	if ((typeof(document.frm.attribute_group2) == 'object'))
	{
		var attribute_group2 = document.frm.attribute_group2.value;
		var t2 = Number(attribute_group2.split('~')[3])
	
	}
	else 
	{
		//var attribute_group2 = 0;
		var t2=0;
	}
	var total = Math.round((t1+t2+originalPrice)*100)/100
	window.document.getElementById('priceDiv').innerText='$'+total
}

////////////////////////////////////////////////////
// Modal Dialog Box
// copyright 8th July 2006 by Stephen Chapman
// http://javascript.about.com/
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function $(x){return document.getElementById(x);}
function scrollFix(){var obol=$('ol');obol.style.top=posTop()+'px';obol.style.left=posLeft()+'px'}
function sizeFix(){var obol=$('ol');obol.style.height=pageHeight()+'px';obol.style.width=pageWidth()+'px';}
function kp(e){ky=e?e.which:event.keyCode;if(ky==88||ky==120)hm();return false}
function inf(h){tag=document.getElementsByTagName('select');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('iframe');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('object');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;}
function sm(obl, wd, ht){var h='hidden';var b='block';var p='px';var obol=$('ol'); var obbxd = $('mbd');obbxd.innerHTML = $(obl).innerHTML;obol.style.height=pageHeight()+p;obol.style.width=pageWidth()+p;obol.style.top=posTop()+p;obol.style.left=posLeft()+p;obol.style.display=b;var tp=posTop()+((pageHeight()-ht)/2)-12;var lt=posLeft()+((pageWidth()-wd)/2)-12;var obbx=$('mbox');obbx.style.top=(tp<0?0:tp)+p;obbx.style.left=(lt<0?0:lt)+p;obbx.style.width=wd+p;obbx.style.height=ht+p;inf(h);obbx.style.display=b;return false;}
function hm(){var v='visible';var n='none';$('ol').style.display=n;$('mbox').style.display=n;inf(v);document.onkeypress=''}
function initmb(){var ab='absolute';var n='none';var obody=document.getElementsByTagName('body')[0];var frag=document.createDocumentFragment();var obol=document.createElement('div');obol.setAttribute('id','ol');obol.style.display=n;obol.style.position=ab;obol.style.top=0;obol.style.left=0;obol.style.zIndex=998;obol.style.width='100%';frag.appendChild(obol);var obbx=document.createElement('div');obbx.setAttribute('id','mbox');obbx.style.display=n;obbx.style.position=ab;obbx.style.zIndex=999;var obl=document.createElement('span');obbx.appendChild(obl);var obbxd=document.createElement('div');obbxd.setAttribute('id','mbd');obl.appendChild(obbxd);frag.insertBefore(obbx,obol.nextSibling);obody.insertBefore(frag,obody.firstChild);
window.onscroll = scrollFix; window.onresize = sizeFix;}
window.onload = initmb;
                  