var isie = (document.all) ? true : false;

var cardcount = 0;

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters)) 
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				img.style.display = 'block';
				
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<div " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></div>" 
				img.outerHTML = strNewHTML
				
				i = i-1
			}
		}
	}
	
	for (var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		{
			img.style.display = 'block';
		}
	}
}

function updateCart(cartcollection)
{
	 var totalamount = cartcollection.jsonobj.totalcleanprice;

   	 if (cartcollection.jsonobj.shippingcosts == 0)
   	 {
     	document.getElementById('tr_1a').style.display = 'none';
   	 }
   	 else
   	 {
   	 	
   	 	if (isie)
   	 	{
   	 		document.getElementById('tr_1a').style.display = 'block';
   	 	}
   	 	else
   	 	{
   	 		document.getElementById('tr_1a').style.display = 'table-row';
   	 	}
   	 	
   	 }
   	 
   	 document.getElementById("quantity").innerHTML = cartcollection.jsonobj.totalquantity;
   	 document.getElementById("description2").innerHTML = cartcollection.jsonobj.totalprice;
   	 
}

window.onload = function ()
{
	// png's voor IE6 aanpassen
	//correctPNG();
	
}

function showHideElement(source, target)
{	
	if(document.getElementById(source).checked == 1)
	{
		document.getElementById(target).style.display = 'block';
	}
	else
	{
		document.getElementById(target).style.display = 'none';
	}
}

function changeQuantity(objectinstanceid, count, udcsizeitemid, udccoloritemid, path)
{
	if (udcsizeitemid == '' || udcsizeitemid == undefined)
	{
		new Ajax.Request('/_ctrl/shop/cart/add/'+objectinstanceid+'/'+count+'/', {
				onSuccess: function(transport) {
					//document.getElementById('price_'+objectinstanceid).innerHTML = transport.responseText;
					document.location.href= path + '/_ctrl/shop/cart/list';
				}
			});
	}
	else
	{
		new Ajax.Request('/_ctrl/shop/cart/add/'+objectinstanceid+'/'+count+'/'+ udcsizeitemid +'/'+ udccoloritemid +'', {
				onSuccess: function(transport) {
					//document.getElementById('price_'+objectinstanceid).innerHTML = transport.responseText;
					document.location.href= path + '/_ctrl/shop/cart/list';
				}
			});
	}
}

function changeAddButton(objectinstanceid, url)
{
	document.getElementById('add').href = '/_ctrl/shop/cart/add/'+objectinstanceid+'/1/' + document.getElementById('udcsizeitemid').value + '/' + document.getElementById('udccoloritemid').value;
}


function SwapImage(element)
{
	this.active = element;
}

	SwapImage.prototype.swap = function(element, id, src, lightboxsrc)
	{
		if (this.active.id != element.id)
		{
			element.className = 'active';
			
			document.getElementById(id).src = src;
			
			this.active.className = '';
			this.active = element;
			
			document.getElementById('related_lightbox').href = lightboxsrc;
		}
	}