    // Submit the product form using AJAX
	jQuery("form.product_form_custom").live('submit', function() {
	   var allowed = true;
       jQuery(".wpsc_select_variation_custom").each(function(index){
	       if(jQuery(this).val() == "0"){
	           var label = jQuery(this).prevAll("label");
	           alert("Please select value for "+label.text());
               jQuery(this).focus();
               allowed = false;
               return;
	       }
	   });
       if(!allowed)
            return false;
		// we cannot submit a file through AJAX, so this needs to return true to submit the form normally if a file formfield is present
		file_upload_elements = jQuery.makeArray(jQuery('input[type=file]', jQuery(this)));
		if(file_upload_elements.length > 0) {
			return true;
		} else {
			form_values = jQuery(this).serialize();
			// Sometimes jQuery returns an object instead of null, using length tells us how many elements are in the object, which is more reliable than comparing the object to null
			if(jQuery('#fancy_notification').length == 0) {
				jQuery('div.wpsc_loading_animation',this).css('visibility', 'visible');
			}
			jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
				eval(returned_data);
				jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');
                alert("Product added successfully")

				if(jQuery('#fancy_notification') != null) {
					jQuery('#loading_animation').css("display", 'none');
				//jQuery('#fancy_notificationimage').css("display", 'none');
				}

			});
			wpsc_fancy_notification(this);
			return false;
		}
	});
    // update the price when the variations are altered.
	jQuery(".wpsc_select_variation_custom").live('change', function() {
		jQuery('option[value="0"]', this).attr('disabled', 'disabled');
		parent_form = jQuery(this).parents("form.product_form_custom");
		form_values =jQuery("input[name=product_id], .wpsc_select_variation_custom",parent_form).serialize( );

		jQuery.post( 'index.php?update_product_price=true', form_values, function(returned_data) {
			variation_msg = '';
			eval(returned_data);
			if( product_id != null ) {
				if( variation_msg != '' ){
					if(variation_status){
						jQuery("div#stock_display_"+product_id).removeClass('out_of_stock');	
						jQuery("div#stock_display_"+product_id).addClass('in_stock');	
					}else{
						jQuery("div#stock_display_"+product_id).removeClass('in_stock');	
						jQuery("div#stock_display_"+product_id).addClass('out_of_stock');	
					}
					
					jQuery("div#stock_display_"+product_id).html(variation_msg);
				
				}
				if( typeof(price) !== 'undefined' && typeof(old_price) !== 'undefined' && typeof(you_save) !== 'undefined' && typeof(numeric_price) !== 'undefined' ) {
					target_id = "product_price_"+product_id;
					price_target_selector = "#" + target_id + ".pricedisplay, ." + product_id + " .currentprice";
					second_target_id = "donation_price_"+product_id;
					third_target_id = "old_product_price_"+product_id;
					yousave_target_id = "yousave_"+product_id;
					buynow_id = "BB_BuyButtonForm"+product_id;
					if(jQuery("input#"+target_id).attr('type') == 'text') {
						jQuery("input#"+target_id).val(numeric_price);
					} else {
						jQuery(price_target_selector).html(price);
						jQuery("#"+third_target_id).html(price);
						jQuery("#"+yousave_target_id).html(you_save);
					}
					jQuery("input#"+second_target_id).val(numeric_price);
				}
			}
		});
		return false;
	});
