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); 
}


function changeQuantity(objectinstanceid, count, udcsizeitemid, udccoloritemid)
{
    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';
            }
        });
    
}

/**
* @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);
     }
     
}



window.onload = function ()
{
	// png's voor IE6 aanpassen
	correctPNG();
	
	// swf object schrijven
//	var so = new SWFObject("/video.swf", "video", "388", "269", "8");
//	so.addParam("quality", "high");
//	so.addParam("wmode", "transparent");
//	so.addParam("salign", "t");
//	so.write("flashmovie");
}



function formHandler ()
{
	
}

	formHandler.prototype.Send = function (formname, method, action)
	{
		document.forms[formname].method = method;
		document.forms[formname].action = action;
		document.forms[formname].submit();
	}
	
	var formHandler = new formHandler();
	


