var eziCartReturnCallback;

jQuery(document).ready(function(){

	if(/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent))
	{
		var hash = window.location.hash.toString();
		var m = hash.match(/^#+ezi-cartadd\((\d+)\)/);
		if(m&&m[1])
		{
			document.cookie = "ezicartadd=" + encodeURIComponent(m[1]);

			window.location.replace(window.location.toString().replace(/#.*/, ""));
		}
		else
		{
			m = document.cookie.match(/ezicartadd=(\d+)/);
			if(m&&m[1])
			{
				if(typeof(eziCartReturnCallback) == "function")
					eziCartReturnCallback();
				else
					alert("Item was added to your cart");

				document.cookie = "ezicartadd=; expires=" + (new Date(0).toGMTString());
			}
		}
	}
	else
	{
		var hash = window.location.hash.toString();
		var m = hash.match(/^#+ezi-cartadd\((\d+)\)/);
		if(m&&m[1])
		{
			window.location.hash = "";
			
			if(typeof(eziCartReturnCallback) == "function")
				eziCartReturnCallback(m[1]);
			else
				alert("Item was added to your cart");
		}
	}

	jQuery("INPUT.ezi-cartreturn").click(function(){
		var ReturnElement = document.createElement("INPUT");
		ReturnElement.setAttribute("type","hidden");
		ReturnElement.setAttribute("name","return");
		ReturnElement.setAttribute("value",document.URL.replace(/#.*/, ""));
		this.form.appendChild(ReturnElement);
	});

});