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 setClassName (object, name)
{
	var names 	= object.className.split(" ");
	var classes = "";
	
	if (names.length > 0 && name == "")
	{
		classes = names[0];
	}
	
	if (name != "")
	{
		classes = names[0] + " " + names[0] + "_active";
	}
	
	object.className = classes;
}

function replaceField(field)
{ 
    var password 	= document.createElement("input"); 
    
    password.type 	= "password"; 
    password.name 	= field.name; 
    password.id		= field.name; 
    
    field.parentNode.replaceChild(password, field); 
}

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 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 = '';
   	 	}
   	 	
   	 }
   	 
   	 document.getElementById("quantity").innerHTML = cartcollection.jsonobj.totalquantity;
   	 document.getElementById("description2").innerHTML = cartcollection.jsonobj.totalprice;
}

/*
function changeQuantity(objectinstanceid, count)
{
	
	new Ajax.Request('/_ctrl/shop/cart/add/'+objectinstanceid+'/'+count+'/', {
			onSuccess: function(transport) {
				//document.getElementById('price_'+objectinstanceid).innerHTML = transport.responseText;
				document.location.href='/_ctrl/shop/cart/list';
			}
		});
	
}


Event.observe(window, 'load', function() 
{
    // when an element with the id of cart exists and a key has occured, the calculatenewPrice will be triggered.
    
    if($('cart') != null)
    {
    	Event.observe('cart', 'keyup', calculateNewPriceQuantity);
    }
}
);


@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('mislukt om een ajax request uit te voeren.');
        }
    }   
    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,url)
{
	document.getElementById('add').href = url + '/_ctrl/shop/cart/add/'+objectinstanceid+'/1/' + document.getElementById('udcsizeitemid').value + '/';
	
}


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;
		}
	}
	
function scrollButton()
{
	
}

	scrollButton.prototype.scroll = function(url)
	{
		var scrollheight 			= document.documentElement.scrollTop;

		// cookie setten
		var today = new Date();
		var expire = new Date();
		nDays = 5;
		if (nDays==null || nDays==0) nDays=1
		{
			expire.setTime(today.getTime() + 3600000*24*nDays);
		}	
		
		document.cookie = "scrollheight="+scrollheight
		                 + ";expires="+expire.toGMTString();
		
		window.location = url;
	}
	
	scrollButton.prototype.autoscroll = function()
	{
		var cookieName = 'scrollheight';
		
		var theCookie=""+document.cookie;
		
 		var ind=theCookie.indexOf(cookieName);
 		if (ind==-1 || cookieName=="") return ""; 
 		var ind1=theCookie.indexOf(';',ind);
 		if (ind1==-1) ind1=theCookie.length; 
 		var scrollheight = theCookie.substring(ind+cookieName.length+1,ind1);
 		
 		setTimeout('window.scroll(0,'+ scrollheight +')', 100); // horizontal and vertical scroll increments
	}
	
	

var scrollButton = new scrollButton();
scrollButton.autoscroll();

