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

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';
   	 	}
   	 	
   	 }
}

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)
{
	new Ajax.Request('/_ctrl/shop/cart/add/'+objectinstanceid+'/'+count+'/'+ udcsizeitemid +'/'+ udccoloritemid +'', {
			onSuccess: function(transport) 
			{
				document.location.href='/_ctrl/shop/cart/list';
			}
		});
}


Event.observe(window, 'load', function() 
{
	if ($('field-gateway'))
    {
	   
    	// Event.observe('payform', 'submit', function(event)
	    Event.observe('field-gateway', 'change', function(event)
		{
			
			if($('field-gateway').value == 'invoice')
			{
				$('button_invoice').show();
				$('paymentbutton').hide();
				//$('form1').writeAttribute('action', $('pay_url').value);
				//$('payaction').name = 'action1';
				
			}
			else
			{
				$('button_invoice').hide();
				$('paymentbutton').show();
				//$('form1').writeAttribute('action', '');
				//$('payaction').name = 'action';
				
			}
			
			
			return false;
			
		});
    }
}
);

/**
* @description: functie who's purpose is to perform an AJAX request to update the shoppingcart
*/

/*
function calculateNewPriceQuantity(event)
{
    var input = event.element();
    
    var updateknop = $('updatecartbtn');
    
    updateknop.value    = 'Updaten...';
    updateknop.disabled = true;
      
    var url = '/_ctrl/shop/cart/update/req/ajax';
   
    var AllOptions = 
    {
        method: 'get',
        parameters: { quantity: input.value, encodedid: input.id }, 
        onSuccess: function(oXHR, oJson)
        {
            updateknop.value = "Update winkelwagen";
            updateknop.disabled = false;
            
            updateCart(oXHR, oJson, input);
        },
        onFailure: function(oXHR, oJson)
        {
            alert('error helaas geen succes');
        }
    }   
    var myAjax = new Ajax.Request(url, AllOptions);
    
}

// when ajax request is succesfull, the retrieved data from the Json object needs to be placed inside the DOM structure
// this is where the updateCart function fits in.
function updateCart(oXHR, oJson, input)
{
    var cartobject = oXHR.responseText.evalJSON();
     
	var formatedid = input.id.split('_');
	var subtotalprice = $('subtot_'+formatedid[1]);
	var totalprice    = $('totalprice');
     	     
    subtotalprice.innerHTML    = '&euro; '+cartobject.subtotalprice;
    totalprice.innerHTML       = '&euro; '+cartobject.totalprice;
    input.value                = cartobject.quantity;  
     
     if(cartobject.errorkey != null)
     {
        alert(cartobject.errormessage);
     }
     
}
*/

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

function AlertMessage(language)
{
	if (language == 'nl')
	{
		alert ('U heeft al een buikband gekozen. Indien u deze wilt wijzigen, kunt u de eerder geselecteerde verwijderen uit de winkelwagen en een nieuwe toevoegen.');
	}
	else
	{
		alert ('You have already chosen a bellyband. If you would like to change, you can remove the first bellyband from your shopcart, and add a new bellyband.');
	}
	
}

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

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