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 ()
{
	correctPNG();
	
	// flvplayer - activex border weghalen in IE
	if (isie)
	{
		var objects = document.getElementsByTagName("object"); 
	    for(var i = 0; i != objects.length; i++) 
	    { 
			if (objects[i].id == '')
			{	        
	    		objects[i].outerHTML = objects[i].outerHTML; 
			}
	    }
    }
	
	
	var so = new SWFObject("/flash/slideshow.swf", "mymovie", "388", "280", "8", "transparent");
	
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.addVariable("baseurl", baseurl);
	so.addVariable("nodeid", nodeid);
	so.addVariable("objectinstanceid", objectinstanceid);
	so.addVariable("profileid", profileid);
	so.addVariable("marginx", marginx);
	so.addVariable("marginy", marginy);
	
	so.write("flashmovie");
	
	
	
}

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';
				}
			});
	}
}


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 = '/_ctrl/shop/cart/add/'+objectinstanceid+'/1/' + document.getElementById('udcsizeitemid').value + '/' + document.getElementById('udccoloritemid').value;
}

function toggle (id, display, hide)
{
	var element = document.getElementById(id);
	
	if (isie)
	{
		element.style.display = (element.style.display == 'none') ? '' : 'none';
	}
	else
	{
		element.style.display = (element.style.display == 'none') ? display : 'none';
	}
	
	if (hide && document.getElementById(hide))
	{
		document.getElementById(hide).style.display = 'none';
	}
}
