//products
//ship
//shipping
//cart
//purchase
//care_model
//cart/index.php

var $ = jQuery.noConflict();
//$(document).ready(function() {
		/*place jQuery actions here*/
		
		//var link = "/beta/cart"; // localhost
		var link = "https://www.ublanket.com/cart"; // remote
	//	var link = "http://localhost/beta/cart"; // local
		
		function addcart(id,qty,price,imageid,upid,remove,update) {
		
						
				/*var upsells = document.getElementsByName(id+'_upsells[]');
				
				var up ='';
					for(i=0;i<upsells.length;i++){ 
						if(upsells[i].checked){
							up = up + upsells[i].value + ',';
						} }
					
				up = up.substring(0, up.length-1);*/
				//	alert(up);
				// Get the product ID and the quantity
				var delivery = jQuery('input:radio[name=delivery]:checked').val();
				
				
				if(delivery!=null){
					name = "Delivery";
					id=200;
					qty=1;
					size=delivery;
					up='';
					if(delivery == "Standard"){
						price=0;
					}else if(delivery == "Rush"){
						price=30;
					}else if(delivery == "Overnight"){
						price=100;
					}
					
					
					imageid="https://www.ublanket.com/images/howto/bag.png";
					name=delivery+" "+"Shipping";
					
				  jQuery.post(link + "/add_cart_item",{ product_id: id, quantity: qty, up: up, imageid: imageid, price: price, delivery: delivery,update: update, ajax: '1' },function(result){
				    //alert('finished');
					jQuery('#cart_order').submit();
				
				  });
					
					
				}else{
					
				
				
				
				
				
				var upsell = jQuery('input:radio[name=styleoption]:checked').val();
				delivery='';
				up='';

				
				
				if(upsell == "noborder"){
					id=118;
					size='noborder';
					price=189;
					up="";
					imageid="https://www.ublanket.com/images/cart_noborder.png";
					name = "uBlanket - No Border";
				}else if(upsell == "border"){
					id=118;
					size='border';
					price=219;
					up="117_20_Border";
					imageid="https://www.ublanket.com/images/cart_border.png";
					name = "uBlanket Border";
				}else if(upsell == "sashing"){
					id=118;
					size='sashing';
					price=249;
					up="119_50_Sashing";
					imageid="https://www.ublanket.com/images/cart_sashing.png";
					name="uBlanket Sashing";
				}
				
				
				

				
				
			/*
				var id = $(this).find('input[name=product_id]').val();
				var qty = $(this).find('input[name=quantity]').val();
				var size = $(this).find('input[name=size]').val();
				var price = $(this).find('input[name=price]').val();
				
				alert(id+','+qty+','+price+','+imageid+','+remove);return false;
				
			*/	jQuery.post(link + "/add_cart_item", { product_id: id, quantity: qty, up: up, imageid: imageid, price: price, delivery: delivery,update: update, ajax: '1' },
					function(data, remove){
						// Interact with returned data
						jQuery('#cart_order').submit();
						
												/*if(data == 'true'){
						
						
						
						

						var msg = jQuery('.promptz');
						var height = jQuery(window).height();
						var width = jQuery(window).width();
						msg.css({
							'left' : width/2 - (msg.width() / 2),  // half width - half element width
							'top' : height/2 - (msg.height() / 2), // similar
							'z-index' : 15                        // make sure element is on top
						});
						
						
						jQuery('.promptz').fadeIn('fast').delay(1000).fadeOut('slow');
						}else{
							alert("Product does not exist");
						}*/
						
				 });
				}
				
			
			return false; // Stop the browser of loading the page defined in the form "action" parameter.
		}

	//});

	function empty()
	{					
			var upsell1;				
			var upsellsID = jQuery('.checkboxes').attr('checked', false);
			jQuery('.add').css('visibility','visible');
			jQuery('.remove').css('visibility','hidden');
		//var link = "http://localhost/beta/cart"; // Url to your application (including index.php/)
		var link = "https://www.ublanket.com/cart"; // Url to your application (including index.php/)
		
    	jQuery.get(link + "/empty_cart", function(){
    		jQuery.get(link + "/show_cart", function(cart){
  				jQuery("#cart_content").html(cart);
			});
		});
				
				

		return false;
	}

