function show_add_to_cart_section(context, json_page, product_id) {
	var json_sku_info = '';

	/* Grab the latest state of infomation for the skus as a JSON string */
    new Ajax.Request(json_page, {
            method: 'get',
            parameters: {product_id: product_id},
            onSuccess: function(transport) {
                    json_sku_info = transport.responseJSON;
                    //alert(json_sku_info);
					
					/* Maintain state based on the sku info in the JSON string */
					if(json_sku_info.length == 1){
						/* If there's only 1 sku, we don't need to use the smart dropdown logic */
						if(json_sku_info[0].INSTOCK != 'true'){
							/* If it's out of stock, we show the out of stock button and banner */
							$('submit_img').src = context + '/images/sold-out.gif';
							$('submit_link').onclick = '';
							if (json_sku_info[0].TYPE == 'LIMITED')
								$('banner_span').className = 'soldout';
							else
								$('banner_span').className = 'out';
						}else{		
							/* We don't need to expose the dropdowns, just quietly populate the dropdown with the designated
							values and marked them as the selected options */
							$('color_select').options.length = 0;
							$('size_select').options.length = 0;
							if(json_sku_info[0].COLOR != null){								
								var opt = document.createElement('option');
								opt.text = json_sku_info[0].COLOR;
								opt.value = json_sku_info[0].COLOR_ID;
								$('color_select').options.add(opt);
							}
							if(json_sku_info[0].SIZE != null){
								var opt = document.createElement('option');
								opt.text = json_sku_info[0].SIZE;
								opt.value = json_sku_info[0].SIZE_ID;
								$('size_select').options.add(opt);
							}
							if(json_sku_info[0].ALMOSTGONE == 'true'){
								$('banner_span').className = 'almostgone';
							}
						}
					}else{
						/* smart dropdown logic */
						$('color_select').onchange = function(){handle_sku_states(json_sku_info, context)};	
						$('size_select').onchange = function(){handle_sku_states(json_sku_info, context)};
						handle_sku_states(json_sku_info, context);
					}
                    
                                        
                	/* Expose shopping cart form */
					$('product_add_to_cart_div').style.display = '';
					
					/* re-render the dropdowns with the jNice look-n-feel */
					if (!(jQuery.browser.msie && jQuery.browser.version < 7)) {
						jQuery.jNice.SelectUpdate($('color_select'));
						jQuery.jNice.SelectUpdate($('size_select'));
					}
					
					/* For non IE browsers, we have to manually align the qty field with the dropdowns since jNice dropdowns play by their own rules... */
					if (!jQuery.browser.msie){
						$('quantity').style.marginTop = '-6px';
					}
					
      		}
    });
}

/* Primarily handles the smart dropdown logic */
function handle_sku_states(json_string, context){
	var color_group = {};
	var size_group = {};
	var sorted_color_options = new Array();
	var sorted_size_options = new Array();
	var color_selected_index = $('color_select').options.selectedIndex;
	var size_selected_index = $('size_select').options.selectedIndex;
	var color_selected_value = $('color_select').options[$('color_select').options.selectedIndex].value; 
	var size_selected_value = $('size_select').options[$('size_select').options.selectedIndex].value;
	var color_selected_text = $('color_select').options[$('color_select').options.selectedIndex].text; 
	var size_selected_text = $('size_select').options[$('size_select').options.selectedIndex].text;
	var at_least_one_in_stock = 'false';
	
	/* If dropdown isn't pre-selected, empty it out so we can repopulate it again */
	if(color_selected_index == 0){
		/* Empty everything except the default option for repopulation */
		$('color_select').options.length = 1;
	}else{
		/* Empty everything except the default and selected option */
		$('color_select').options.length = 2;
		$('color_select').options[1].value = color_selected_value; 
		$('color_select').options[1].text = color_selected_text; 
		$('color_select').options.selectedIndex = 1;
		at_least_one_in_stock = 'true';
		color_selected_index = 1;
	}
	if(size_selected_index == 0){
		/* Empty everything except the default option for repopulation */
		$('size_select').options.length = 1;
	}else{
		/* Empty everything except the default and selected option */
		$('size_select').options.length = 2;
		$('size_select').options[1].value = size_selected_value; 
		$('size_select').options[1].text = size_selected_text; 
		$('size_select').options.selectedIndex = 1;
		at_least_one_in_stock = 'true';
		size_selected_index = 1;
	}
	

	var color_counter = 0;
	var size_counter = 0;
	var needs_sorting = false;
	for(var x = 0; x < json_string.length; x++){
		var color_value = json_string[x].COLOR;
		var size_value = json_string[x].SIZE;

		/* Make sure color dropdown exists, color option isn't already in dropdown, and color dropdown wasn't preselected */
		if(color_value != null && color_group[color_value] == null && color_selected_index == 0){
			$('color_span').style.display = '';
		
			if(size_selected_index == 0 || size_selected_text == size_value){
				needs_sorting = true;
				color_group[color_value] = '1';
				var opt = document.createElement('option');
				if(json_string[x].INSTOCK == 'true'){
					opt.text = json_string[x].COLOR;
					at_least_one_in_stock = 'true';
				}else{
					opt.text = json_string[x].COLOR + '-out of stock';
					opt.disabled = 'disabled';					
				}
				opt.value = json_string[x].COLOR_ID;
				sorted_color_options[color_counter] = new Array(2);
				sorted_color_options[color_counter][0] = json_string[x].COLOR_PRIORITY;
				sorted_color_options[color_counter++][1] = opt;
			}		
		}
		if(size_value != null && size_group[size_value] == null && size_selected_index == 0){
			$('size_span').style.display = '';
			
			if(color_selected_index == 0 || color_selected_text == color_value){
				needs_sorting = true;
				size_group[size_value] = '1';
				var opt = document.createElement('option');
				if(json_string[x].INSTOCK == 'true'){
					opt.text = json_string[x].SIZE;
					at_least_one_in_stock = 'true';
				}else{
					opt.text = json_string[x].SIZE + '-out of stock';
					opt.disabled = 'disabled';					
				}
				opt.value = json_string[x].SIZE_ID;
				sorted_size_options[size_counter] = new Array(2);
				sorted_size_options[size_counter][0] = json_string[x].SIZE_PRIORITY;
				sorted_size_options[size_counter++][1] = opt;
			}
		}
	}
	
	/* If the dropdown only has one option, make sure it isn't showing "out of stock" */
	if(sorted_color_options.size() == 1){		
		sorted_color_options[0][1].text = sorted_color_options[0][1].text.replace('-out of stock', '');
		sorted_color_options.disabled = '';
	}
	/* If the dropdown only has one option, make sure it isn't showing "out of stock" */
	if(sorted_size_options.size() == 1){		
		sorted_size_options.size[0][1].text = sorted_size_options.size[0][1].text.replace('-out of stock', '');
		sorted_size_options.disabled = '';
	}
	
	if(needs_sorting){
		sorted_color_options.sort(sort_sku_options);
		sorted_size_options.sort(sort_sku_options);
		
		for(var a = 0; a < sorted_color_options.length; a++){
			$('color_select').options.add(sorted_color_options[a][1]);
		}
		for(var b = 0; b < sorted_size_options.length; b++){
			$('size_select').options.add(sorted_size_options[b][1]);
		}
	}
	
	/* eric: none of their product has more than one color option, we preselect the color if there is only one */
	//if ($('color_select').options.length == 2){
    //	$('color_select').options.selectedIndex = 1;
     //   color_selected_index = 1;
	//}
	
	/* re-render the dropdowns with the jNice look-n-feel */
	if (!(jQuery.browser.msie && jQuery.browser.version < 7)) {
			jQuery.jNice.SelectUpdate($('color_select'));
			jQuery.jNice.SelectUpdate($('size_select'));
	}	
	
	/* Now that jQuery has re-render the dropdown, we have to assign it the proper pre-selected option */
	if(needs_sorting){
		$('color_select').options.selectedIndex = color_selected_index;
		$('size_select').options.selectedIndex = size_selected_index;
	}
	
	/* Change to out of stock button and disable it if not one sku is in-stock */
	if(at_least_one_in_stock == 'false'){
		$('submit_img').src = context + '/images/sold-out.gif';
		$('submit_link').onclick = '';
		$('banner_span').className = 'out';
	}else{
		if (sorted_color_options.size() > 1){
			$('banner_span').className = 'morecolors';
		}
	}

}

function sort_sku_options(a,b){
	if (a[0] < b[0])return -1;
	if (a[0] > b[0])return 1;
	return 0 ;
}

function submit_checkout_form(context_path){
	// Validate customer has selected all necessary options
	
	//short term solution for ie7 bug.
	if($('size_select').options.length == 2)
        $('size_select').options.selectedIndex = 1;

	
	if ($('color_select').options[$('color_select').selectedIndex].value == 'select' ||
		$('size_select').options[$('size_select').selectedIndex].value == 'select')
	{
		alert('Please select all options.');
		return false;
	}
	
	if ($('size_select').options[$('size_select').selectedIndex].text.indexOf('out of stock') >= 0)
	{
		alert('Option selected is out of stock.');
		return false;
	}
	
	if( $('quantity').value > 0 ){

	}else{
		alert('Please enter a quantity');
		return false;
	}
	
	// POST - async post because the user does NOT get taken to the shopping cart by design
	new Ajax.Request(context_path + '/servlet/Cart', {
		method: 'post',
		onSuccess: function(transport) {
			if (transport.getHeader("ACDC_ERROR") == 't') {
				$('checkout_message').style.display = '';
				$('checkout_message').innerHTML = '<strong>Your item cannot be added to cart.</strong>';
			} else {			
				// Upon success we display a message as well as update the numItems count in the header 
				$('checkout_message').style.display = '';
				 $('checkout_message').innerHTML = '<strong>Item has been added to your cart!</strong> <a href="' + context_path + '/agent/login?toshipping=true">Checkout</a>';
				new Ajax.Request(context_path + '/templates/ajax/numItems.jsp',
				  {
				    method:'get',
				    parameters: {randid: Math.random()},
				    onSuccess: function(transport){
				      $('numItems').innerHTML = transport.responseText;
				    },
				    onFailure: function(){  }
				  });
			}
		},
		postBody: get_form_values('checkout_form')
	});
	
	
}
