window.addEvent('domready',function() {
	$('formcheckout').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop();
		//Empty the log and show the spinning indicator.
		var fadeFx = new Fx.Style("checkout_grid", 'opacity', {wait: false, duration: 500}).set(1);
		fadeFx.start(0);
		$("error_return").innerHTML = "";
		$("error_return").style.display = "none";
//		var log = $('log_res').empty().addClass('ajax-loading');
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) { 
			setTimeout(function(){
				$("error_return").style.display = "block";
				$("error_return").innerHTML = '<div class="success">Successfully Added This Product - <span style="color:#006003;cursor:pointer;text-decoration:underline" onclick="viewBasket(\'' + view_title + '\')">Click Here</span> to View Your Basket</div>';
				var fadeFx = new Fx.Style("checkout_grid", 'opacity', {wait: false, duration: 500}).set(0);
				fadeFx.start(1);
			}, 2000);
		}});
		//Send the form.
		this.send();
	});
});

function addtoCart(product_id){
	var bgPlatform = new Element('div', {id: 'bgplatform'});
	getwinsize();
	bgPlatform.setStyles({
		"left":"0px",
		"top":"0px",
		"z-index":"900",
		"width": (myWidth - 15) + "px",
		"height": $(window).getScrollSize().y + "px",
		"display":"block",
		"margin":"0px",
		"padding":"0px",
		"background-color":"black",
		"position":"absolute",
	});
	bgPlatform.inject(document.body);

	var platformBox = new Element('div', {id: 'platformbox'});
	platformBox.setStyles({
		"left":((myWidth - 720) / 2) + "px",
		"top": GoToTop + "px",
		"z-index":"910",
		"width": "700px",
		"height": "400px",
		"display":"none",
		"margin":"0px",
		"padding":"0px",
		"background-color":"transparent",
		"position":"absolute",
	});
	platformBox.inject(document.body);

	var fadeFx = new Fx.Style(bgPlatform, 'opacity', {wait: false, duration: 500, onComplete:function(){
		floatLayer(0,GoToTop,'platformbox').Fm();
	    var myRequest = new Request({
			method: 	'get',
			url:		'/shoppingcart/popup/addproduct/',
			onComplete: function(request){
					platformBox.innerHTML = request;
					platformBox.setStyles({"display":"block"});
					var newfadeFx = new Fx.Style(platformBox, 'opacity', {wait: false, duration: 500, onComplete:function(){
						clicked = false;

						$("popupclose").removeEvents("click");
						$("popupclose").addEvent("click", function(){
							if(!clicked){
								clicked = true;
								var newfadeFx = new Fx.Style(platformBox, 'opacity', {wait: false, duration: 500, onComplete:function(){
									platformBox.destroy();
									var fadeFx = new Fx.Style(bgPlatform, 'opacity', {wait: false, duration: 500, onComplete:function(){
										bgPlatform.destroy();
										clicked = false;
									}}).set(0.8);
									fadeFx.start(0);
								}}).set(1);
								newfadeFx.start(0);
							}
						});

					}}).set(0);
					newfadeFx.start(1);
			},
	    }).send("product_id="+product_id);
	}}).set(0);
	fadeFx.start(0.8);

	bgPlatform.addEvent("click", function(){
		if(!clicked){
			clicked = true;
			var newfadeFx = new Fx.Style(platformBox, 'opacity', {wait: false, duration: 500, onComplete:function(){
				platformBox.destroy();
				var fadeFx = new Fx.Style(bgPlatform, 'opacity', {wait: false, duration: 500, onComplete:function(){
					bgPlatform.destroy();
					clicked = false;
				}}).set(0.8);
				fadeFx.start(0);
			}}).set(1);
			newfadeFx.start(0);
		}
	});
}

function closeWindow(){
	$("popupclose").fireEvent("click");
	setTimeout(function(){
		location.reload(true);
	}, 1000);

}

function closeButtonWindow(){
	$("popupclose").fireEvent("click");
}

