This is an old revision of the document!


Discount Logic Helper

The following form can be used to help you create discount logic, whether that be for a product discount as a link or in a form, or a category discount or coupon.

To start, simply choose the type of discount you'd like to create, create the tiers to match what you're looking to achieve, and copy the output to the relevant place you're adding the discount to.

If you're creating a product discount, you'll be copying either the link or the form output to add into your relevant link or form. If you're using a third-party module to manage your products, you may need to copy the logic into your website management setup.

If you're creating a coupon or a category discount, you'll be copying the logic output into the discount details input in the FoxyCart administration. You'll also need to set the other settings for the discount in the form in the FoxyCart administration as well, similar to what you have set here.

<HTML>

<script type="text/javascript">/*! jQuery UI - v1.8.23 - 2012-08-15

* https://github.com/jquery/jquery-ui * Includes: jquery.ui.core.js * Copyright © 2012 AUTHORS.txt; Licensed MIT, GPL */ (function(a,b){function c(b,c){var e=b.nodeName.toLowerCase();if(“area”===e){var f=b.parentNode,g=f.name,h;return!b.href||!g||f.nodeName.toLowerCase()!==“map”?!1:(h=a(“img[usemap=#”+g+“]”)[0],!!h&&d(h))}return(/input|select|textarea|button|object/.test(e)?!b.disabled:“a”==e?b.href||c:c)&&d(b)}function d(b){return!a(b).parents().andSelf().filter(function(){return a.curCSS(this,“visibility”)===“hidden”||a.expr.filters.hidden(this)}).length}a.ui=a.ui||{};if(a.ui.version)return;a.extend(a.ui,{version:“1.8.23”,keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}}),a.fn.extend({propAttr:a.fn.prop||a.fn.attr,_focus:a.fn.focus,focus:function(b,c){return typeof b==“number”?this.each(function(){var d=this;setTimeout(function(){a(d).focus(),c&&c.call(d)},b)}):this._focus.apply(this,arguments)},scrollParent:function(){var b;return a.browser.msie&&/(static|relative)/.test(this.css(“position”))||/absolute/.test(this.css(“position”))?b=this.parents().filter(function(){return/(relative|absolute|fixed)/.test(a.curCSS(this,“position”,1))&&/(auto|scroll)/.test(a.curCSS(this,“overflow”,1)+a.curCSS(this,“overflow-y”,1)+a.curCSS(this,“overflow-x”,1))}).eq(0):b=this.parents().filter(function(){return/(auto|scroll)/.test(a.curCSS(this,“overflow”,1)+a.curCSS(this,“overflow-y”,1)+a.curCSS(this,“overflow-x”,1))}).eq(0),/fixed/.test(this.css(“position”))||!b.length?a(document):b},zIndex:function©{if(c!==b)return this.css(“zIndex”,c);if(this.length){var d=a(this[0]),e,f;while(d.length&&d[0]!==document){e=d.css(“position”);if(e===“absolute”||e===“relative”||e===“fixed”){f=parseInt(d.css(“zIndex”),10);if(!isNaN(f)&&f!==0)return f}d=d.parent()}}return 0},disableSelection:function(){return this.bind1)||0,d&&(c-=parseFloat(a.curCSS(b,“border”+this+“Width”,!0))||0),f&&(c-=parseFloat(a.curCSS(b,“margin”+this,!0))||0)}),c}var e=d===“Width”?[“Left”,“Right”]:[“Top”,“Bottom”],f=d.toLowerCase(),g={innerWidth:a.fn.innerWidth,innerHeight:a.fn.innerHeight,outerWidth:a.fn.outerWidth,outerHeight:a.fn.outerHeight};a.fn[“inner”+d]=function©{return c===b?g[“inner”+d].call(this):this.each(function(){a(this).css(f,h(this,c)+“px”)})},a.fn[“outer”+d]=function(b,c){return typeof b!=“number”?g[“outer”+d].call(this,b):this.each(function(){a(this).css(f,h(this,b,!0,c)+“px”)})}}),a.extend(a.expr[“:”],{data:a.expr.createPseudo?a.expr.createPseudo(function(b){return function©{return!!a.data(c,b)}}):function(b,c,d){return!!a.data(b,d[3])},focusable:function(b){return c(b,!isNaN(a.attr(b,“tabindex”)))},tabbable:function(b){var d=a.attr(b,“tabindex”),e=isNaN(d);return(e||d>=0)&&c(b,!e)}}),a(function(){var b=document.body,c=b.appendChild(c=document.createElement(“div”));c.offsetHeight,a.extend(c.style,{minHeight:“100px”,height:“auto”,padding:0,borderWidth:0}),a.support.minHeight=c.offsetHeight===100,a.support.selectstart=“onselectstart”in c,b.removeChild©.style.display=“none”}),a.curCSS||(a.curCSS=a.css),a.extend(a.ui,{plugin:{add:function(b,c,d){var e=a.ui[b].prototype;for(var f in d)e.plugins[f]=e.plugins[f]||[],e.plugins[f].push([c,d[f]])},call:function(a,b,c){var d=a.plugins[b];if(!d||!a.element[0].parentNode)return;for(var e=0;e<d.length;e++)a.options[d[e][0]]&&d[e][1].apply(a.element,c)}},contains:function(a,b){return document.compareDocumentPosition?a.compareDocumentPosition(b)&16:a!==b&&a.contains(b)},hasScroll:function(b,c){if(a(b).css(“overflow”)===“hidden”)return!1;var d=c&&c===“left”?“scrollLeft”:“scrollTop”,e=!1;return b[d]>0?!0:(b[d]=1,e=b[d]>0,b[d]=0,e)},isOverAxis:function(a,b,c){return a>b&&a<b+c},isOver:function(b,c,d,e,f,g){return a.ui.isOverAxis(b,d,f)&&a.ui.isOverAxis(c,e,g)}})})(jQuery);;/*! jQuery UI - v1.8.23 - 2012-08-15 * https://github.com/jquery/jquery-ui * Includes: jquery.ui.widget.js * Copyright © 2012 AUTHORS.txt; Licensed MIT, GPL */ (function(a,b){if(a.cleanData){var c=a.cleanData;a.cleanData=function(b){for(var d=0,e;(e=b[d])!=null;d++)try{a(e).triggerHandler(“remove”)}catch(f){}c(b)}}else{var d=a.fn.remove;a.fn.remove=function(b,c){return this.each(function(){return c||(!b||a.filter(b,[this]).length)&&a(“*”,this).add([this]).each(function(){try{a(this).triggerHandler(“remove”)}catch(b){}}),d.call(a(this),b,c)})}}a.widget=function(b,c,d){var e=b.split(“.”)[0],f;b=b.split(“.”)[1],f=e+“-”+b,d||(d=c,c=a.Widget),a.expr[“:”][f]=function©{return!!a.data(c,b)},a[e]=a[e]||{},a[e][b]=function(a,b){arguments.length&&this._createWidget(a,b)};var g=new c;g.options=a.extend(!0,{},g.options),a[e][b].prototype=a.extend(!0,g,{namespace:e,widgetName:b,widgetEventPrefix:a[e][b].prototype.widgetEventPrefix||b,widgetBaseClass:f},d),a.widget.bridge(b,a[e][b])},a.widget.bridge=function(c,d){a.fn[c]=function(e){var f=typeof e==“string”,g=Array.prototype.slice.call(arguments,1),h=this;return e=!f&&g.length?a.extend.apply(null,[!0,e].concat(g)):e,f&&e.charAt(0)===“_”?h:(f?this.each(function(){var d=a.data(this,c),f=d&&a.isFunction(d[e])?d[e].apply(d,g):d;if(f!==d&&f!==b)return h=f,!1}):this.each(function(){var b=a.data(this,c);b?b.option(e||{})._init():a.data(this,c,new d(e,this))}),h)}},a.Widget=function(a,b){arguments.length&&this._createWidget(a,b)},a.Widget.prototype={widgetName:“widget”,widgetEventPrefix:“”,options:{disabled:!1},_createWidget:function(b,c){a.data(c,this.widgetName,this),this.element=a©,this.options=a.extend(!0,{},this.options,this._getCreateOptions(),b);var d=this;this.element.bind(“remove.”+this.widgetName,function(){d.destroy()}),this._create(),this._trigger(“create”),this._init()},_getCreateOptions:function(){return a.metadata&&a.metadata.get(this.element[0])[this.widgetName]},_create:function(){},_init:function(){},destroy:function(){this.element.unbind(“.”+this.widgetName).removeData(this.widgetName),this.widget().unbind(“.”+this.widgetName).removeAttr(“aria-disabled”).removeClass(this.widgetBaseClass+“-disabled ”+“ui-state-disabled”)},widget:function(){return this.element},option:function(c,d){var e=c;if(arguments.length===0)return a.extend({},this.options);if(typeof c==“string”){if(d===b)return this.options[c];e={},e[c]=d}return this._setOptions(e),this},_setOptions:function(b){var c=this;return a.each(b,function(a,b){c._setOption(a,b)}),this},_setOption:function(a,b){return this.options[a]=b,a===“disabled”&&this.widget()[b?“addClass”:“removeClass”](this.widgetBaseClass+“-disabled”+“ ”+“ui-state-disabled”).attr(“aria-disabled”,b),this},enable:function(){return this._setOption(“disabled”,!1)},disable:function(){return this._setOption(“disabled”,!0)},_trigger:function(b,c,d){var e,f,g=this.options[b];d=d||{},c=a.Event©,c.type=(b===this.widgetEventPrefix?b:this.widgetEventPrefix+b).toLowerCase(),c.target=this.element[0],f=c.originalEvent;if(f)for(e in f)e in c||(c[e]=f[e]);return this.element.trigger(c,d),!(a.isFunction(g)&&g.call(this.element[0],c,d)===!1||c.isDefaultPrevented())}}})(jQuery);;/*! jQuery UI - v1.8.23 - 2012-08-15 * https://github.com/jquery/jquery-ui * Includes: jquery.ui.mouse.js * Copyright © 2012 AUTHORS.txt; Licensed MIT, GPL */ (function(a,b){var c=!1;a(document).mouseup(function(a){c=!1}),a.widget(“ui.mouse”,{options:{cancel:“:input,option”,distance:1,delay:0},_mouseInit:function(){var b=this;this.element.bind(“mousedown.”+this.widgetName,function(a){return b._mouseDown(a)}).bind(“click.”+this.widgetName,function©{if(!0===a.data(c.target,b.widgetName+“.preventClickEvent”))return a.removeData(c.target,b.widgetName+“.preventClickEvent”),c.stopImmediatePropagation(),!1}),this.started=!1},_mouseDestroy:function(){this.element.unbind(“.”+this.widgetName),this._mouseMoveDelegate&&a(document).unbind(“mousemove.”+this.widgetName,this._mouseMoveDelegate).unbind(“mouseup.”+this.widgetName,this._mouseUpDelegate)},_mouseDown:function(b){if©return;this._mouseStarted&&this._mouseUp(b),this._mouseDownEvent=b;var d=this,e=b.which==1,f=typeof this.options.cancel==“string”&&b.target.nodeName?a(b.target).closest(this.options.cancel).length:!1;if(!e||f||!this._mouseCapture(b))return!0;this.mouseDelayMet=!this.options.delay,this.mouseDelayMet||(this._mouseDelayTimer=setTimeout(function(){d.mouseDelayMet=!0},this.options.delay));if(this._mouseDistanceMet(b)&&this._mouseDelayMet(b)){this._mouseStarted=this._mouseStart(b)!==!1;if(!this._mouseStarted)return b.preventDefault(),!0}return!0===a.data(b.target,this.widgetName+“.preventClickEvent”)&&a.removeData(b.target,this.widgetName+“.preventClickEvent”),this._mouseMoveDelegate=function(a){return d._mouseMove(a)},this._mouseUpDelegate=function(a){return d._mouseUp(a)},a(document).bind(“mousemove.”+this.widgetName,this._mouseMoveDelegate).bind(“mouseup.”+this.widgetName,this._mouseUpDelegate),b.preventDefault(),c=!0,!0},_mouseMove:function(b){return!a.browser.msie||document.documentMode>=9||!!b.button?this._mouseStarted?(this._mouseDrag(b),b.preventDefault()):(this._mouseDistanceMet(b)&&this._mouseDelayMet(b)&&(this._mouseStarted=this._mouseStart(this._mouseDownEvent,b)!==!1,this._mouseStarted?this._mouseDrag(b):this._mouseUp(b)),!this._mouseStarted):this._mouseUp(b)},_mouseUp:function(b){return a(document).unbind(“mousemove.”+this.widgetName,this._mouseMoveDelegate).unbind(“mouseup.”+this.widgetName,this._mouseUpDelegate),this._mouseStarted&&(this._mouseStarted=!1,b.target==this._mouseDownEvent.target&&a.data(b.target,this.widgetName+“.preventClickEvent”,!0),this._mouseStop(b)),!1},_mouseDistanceMet:function(a){return Math.max(Math.abs(this._mouseDownEvent.pageX-a.pageX),Math.abs(this._mouseDownEvent.pageY-a.pageY))>=this.options.distance},_mouseDelayMet:function(a){return this.mouseDelayMet},_mouseStart:function(a){},_mouseDrag:function(a){},_mouseStop:function(a){},_mouseCapture:function(a){return!0}})})(jQuery);;/*! jQuery UI - v1.8.23 - 2012-08-15 * https://github.com/jquery/jquery-ui * Includes: jquery.ui.sortable.js * Copyright © 2012 AUTHORS.txt; Licensed MIT, GPL */ (function(a,b){a.widget(“ui.sortable”,a.ui.mouse,{widgetEventPrefix:“sort”,ready:!1,options:{appendTo:“parent”,axis:!1,connectWith:!1,containment:!1,cursor:“auto”,cursorAt:!1,dropOnEmpty:!0,forcePlaceholderSize:!1,forceHelperSize:!1,grid:!1,handle:!1,helper:“original”,items:“> *”,opacity:!1,placeholder:!1,revert:!1,scroll:!0,scrollSensitivity:20,scrollSpeed:20,scope:“default”,tolerance:“intersect”,zIndex:1e3},_create:function(){var a=this.options;this.containerCache={},this.element.addClass(“ui-sortable”),this.refresh(),this.floating=this.items.length?a.axis===“x”||/left|right/.test(this.items[0].item.css(“float”))||/inline|table-cell/.test(this.items[0].item.css(“display”)):!1,this.offset=this.element.offset(),this._mouseInit(),this.ready=!0},destroy:function(){a.Widget.prototype.destroy.call(this),this.element.removeClass(“ui-sortable ui-sortable-disabled”),this._mouseDestroy();for(var b=this.items.length-1;b>=0;b–)this.items[b].item.removeData(this.widgetName+“-item”);return this},_setOption:function(b,c){b===“disabled”?(this.options[b]=c,this.widget()[c?“addClass”:“removeClass”](“ui-sortable-disabled”)):a.Widget.prototype._setOption.apply(this,arguments)},_mouseCapture:function(b,c){var d=this;if(this.reverting)return!1;if(this.options.disabled||this.options.type==“static”)return!1;this._refreshItems(b);var e=null,f=this,g=a(b.target).parents().each(function(){if(a.data(this,d.widgetName+“-item”)==f)return e=a(this),!1});a.data(b.target,d.widgetName+“-item”)==f&&(e=a(b.target));if(!e)return!1;if(this.options.handle&&!c){var h=!1;a(this.options.handle,e).find(“*”).andSelf().each(function(){this==b.target&&(h=!0)});if(!h)return!1}return this.currentItem=e,this._removeCurrentsFromItems(),!0},_mouseStart:function(b,c,d){var e=this.options,f=this;this.currentContainer=this,this.refreshPositions(),this.helper=this._createHelper(b),this._cacheHelperProportions(),this._cacheMargins(),this.scrollParent=this.helper.scrollParent(),this.offset=this.currentItem.offset(),this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left},a.extend(this.offset,{click:{left:b.pageX-this.offset.left,top:b.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()}),this.helper.css(“position”,“absolute”),this.cssPosition=this.helper.css(“position”),this.originalPosition=this._generatePosition(b),this.originalPageX=b.pageX,this.originalPageY=b.pageY,e.cursorAt&&this._adjustOffsetFromHelper(e.cursorAt),this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]},this.helper[0]!=this.currentItem[0]&&this.currentItem.hide(),this._createPlaceholder(),e.containment&&this._setContainment(),e.cursor&&(a(“body”).css(“cursor”)&&(this._storedCursor=a(“body”).css(“cursor”)),a(“body”).css(“cursor”,e.cursor)),e.opacity&&(this.helper.css(“opacity”)&&(this._storedOpacity=this.helper.css(“opacity”)),this.helper.css(“opacity”,e.opacity)),e.zIndex&&(this.helper.css(“zIndex”)&&(this._storedZIndex=this.helper.css(“zIndex”)),this.helper.css(“zIndex”,e.zIndex)),this.scrollParent[0]!=document&&this.scrollParent[0].tagName!=“HTML”&&(this.overflowOffset=this.scrollParent.offset()),this._trigger(“start”,b,this._uiHash()),this._preserveHelperProportions||this._cacheHelperProportions();if(!d)for(var g=this.containers.length-1;g>=0;g–)this.containers[g]._trigger(“activate”,b,f._uiHash(this));return a.ui.ddmanager&&(a.ui.ddmanager.current=this),a.ui.ddmanager&&!e.dropBehaviour&&a.ui.ddmanager.prepareOffsets(this,b),this.dragging=!0,this.helper.addClass(“ui-sortable-helper”),this._mouseDrag(b),!0},_mouseDrag:function(b){this.position=this._generatePosition(b),this.positionAbs=this._convertPositionTo(“absolute”),this.lastPositionAbs||(this.lastPositionAbs=this.positionAbs);if(this.options.scroll){var c=this.options,d=!1;this.scrollParent[0]!=document&&this.scrollParent[0].tagName!=“HTML”?(this.overflowOffset.top+this.scrollParent[0].offsetHeight-b.pageY<c.scrollSensitivity?this.scrollParent[0].scrollTop=d=this.scrollParent[0].scrollTop+c.scrollSpeed:b.pageY-this.overflowOffset.top<c.scrollSensitivity&&(this.scrollParent[0].scrollTop=d=this.scrollParent[0].scrollTop-c.scrollSpeed),this.overflowOffset.left+this.scrollParent[0].offsetWidth-b.pageX<c.scrollSensitivity?this.scrollParent[0].scrollLeft=d=this.scrollParent[0].scrollLeft+c.scrollSpeed:b.pageX-this.overflowOffset.left<c.scrollSensitivity&&(this.scrollParent[0].scrollLeft=d=this.scrollParent[0].scrollLeft-c.scrollSpeed)):(b.pageY-a(document).scrollTop()<c.scrollSensitivity?d=a(document).scrollTop(a(document).scrollTop()-c.scrollSpeed):a(window).height()-(b.pageY-a(document).scrollTop())<c.scrollSensitivity&&(d=a(document).scrollTop(a(document).scrollTop()+c.scrollSpeed)),b.pageX-a(document).scrollLeft()<c.scrollSensitivity?d=a(document).scrollLeft(a(document).scrollLeft()-c.scrollSpeed):a(window).width()-(b.pageX-a(document).scrollLeft())<c.scrollSensitivity&&(d=a(document).scrollLeft(a(document).scrollLeft()+c.scrollSpeed))),d!==!1&&a.ui.ddmanager&&!c.dropBehaviour&&a.ui.ddmanager.prepareOffsets(this,b)}this.positionAbs=this._convertPositionTo(“absolute”);if(!this.options.axis||this.options.axis!=“y”)this.helper[0].style.left=this.position.left+“px”;if(!this.options.axis||this.options.axis!=“x”)this.helper[0].style.top=this.position.top+“px”;for(var e=this.items.length-1;e>=0;e–){var f=this.items[e],g=f.item[0],h=this._intersectsWithPointer(f);if(!h)continue;if(g!=this.currentItem[0]&&this.placeholder[h==1?“next”:“prev”]()[0]!=g&&!a.ui.contains(this.placeholder[0],g)&&(this.options.type==“semi-dynamic”?!a.ui.contains(this.element[0],g):!0)){this.direction=h==1?“down”:“up”;if(this.options.tolerance==“pointer”||this._intersectsWithSides(f))this._rearrange(b,f);else break;this._trigger(“change”,b,this._uiHash());break}}return this._contactContainers(b),a.ui.ddmanager&&a.ui.ddmanager.drag(this,b),this._trigger(“sort”,b,this._uiHash()),this.lastPositionAbs=this.positionAbs,!1},_mouseStop:function(b,c){if(!b)return;a.ui.ddmanager&&!this.options.dropBehaviour&&a.ui.ddmanager.drop(this,b);if(this.options.revert){var d=this,e=d.placeholder.offset();d.reverting=!0,a(this.helper).animate({left:e.left-this.offset.parent.left-d.margins.left+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollLeft),top:e.top-this.offset.parent.top-d.margins.top+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollTop)},parseInt(this.options.revert,10)||500,function(){d._clear(b)})}else this._clear(b,c);return!1},cancel:function(){var b=this;if(this.dragging){this._mouseUp({target:null}),this.options.helper==“original”?this.currentItem.css(this._storedCSS).removeClass(“ui-sortable-helper”):this.currentItem.show();for(var c=this.containers.length-1;c>=0;c–)this.containers[c]._trigger(“deactivate”,null,b._uiHash(this)),this.containers[c].containerCache.over&&(this.containers[c]._trigger(“out”,null,b._uiHash(this)),this.containers[c].containerCache.over=0)}return this.placeholder&&(this.placeholder[0].parentNode&&this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.options.helper!=“original”&&this.helper&&this.helper[0].parentNode&&this.helper.remove(),a.extend(this,{helper:null,dragging:!1,reverting:!1,_noFinalSort:null}),this.domPosition.prev?a(this.domPosition.prev).after(this.currentItem):a(this.domPosition.parent).prepend(this.currentItem)),this},serialize:function(b){var c=this._getItemsAsjQuery(b&&b.connected),d=[];return b=b||{},a©.each(function(){var c=(a(b.item||this).attr(b.attribute||“id”)||“”).match(b.expression||/(.+)[-=_](.+)/);c&&d.push2)}),!d.length&&b.key&&d.push(b.key+“=”),d.join(“&”)},toArray:function(b){var c=this._getItemsAsjQuery(b&&b.connected),d=[];return b=b||{},c.each(function(){d.push(a(b.item||this).attr(b.attribute||“id”)||“”)}),d},_intersectsWith:function(a){var b=this.positionAbs.left,c=b+this.helperProportions.width,d=this.positionAbs.top,e=d+this.helperProportions.height,f=a.left,g=f+a.width,h=a.top,i=h+a.height,j=this.offset.click.top,k=this.offset.click.left,l=d+j>h&&d+j<i&&b+k>f&&b+k<g;return this.options.tolerance==“pointer”||this.options.forcePointerForContainers||this.options.tolerance!=“pointer”&&this.helperProportions[this.floating?“width”:“height”]>a[this.floating?“width”:“height”]?l:f<b+this.helperProportions.width/2&&c-this.helperProportions.width/2<g&&h<d+this.helperProportions.height/2&&e-this.helperProportions.height/2<i},_intersectsWithPointer:function(b){var c=this.options.axis===“x”||a.ui.isOverAxis(this.positionAbs.top+this.offset.click.top,b.top,b.height),d=this.options.axis===“y”||a.ui.isOverAxis(this.positionAbs.left+this.offset.click.left,b.left,b.width),e=c&&d,f=this._getDragVerticalDirection(),g=this._getDragHorizontalDirection();return e?this.floating?g&&g==“right”||f==“down”?2:1:f&&(f==“down”?2:1):!1},_intersectsWithSides:function(b){var c=a.ui.isOverAxis(this.positionAbs.top+this.offset.click.top,b.top+b.height/2,b.height),d=a.ui.isOverAxis(this.positionAbs.left+this.offset.click.left,b.left+b.width/2,b.width),e=this._getDragVerticalDirection(),f=this._getDragHorizontalDirection();return this.floating&&f?f==“right”&&d||f==“left”&&!d:e&&(e==“down”&&c||e==“up”&&!c)},_getDragVerticalDirection:function(){var a=this.positionAbs.top-this.lastPositionAbs.top;return a!=0&&(a>0?“down”:“up”)},_getDragHorizontalDirection:function(){var a=this.positionAbs.left-this.lastPositionAbs.left;return a!=0&&(a>0?“right”:“left”)},refresh:function(a){return this._refreshItems(a),this.refreshPositions(),this},_connectWith:function(){var a=this.options;return a.connectWith.constructor==String?[a.connectWith]:a.connectWith},_getItemsAsjQuery:function(b){var c=this,d=[],e=[],f=this._connectWith();if(f&&b)for(var g=f.length-1;g>=0;g–){var h=a(f[g]);for(var i=h.length-1;i>=0;i–){var j=a.data(h[i],this.widgetName);j&&j!=this&&!j.options.disabled&&e.push([a.isFunction(j.options.items)?j.options.items.call(j.element):a(j.options.items,j.element).not(“.ui-sortable-helper”).not(“.ui-sortable-placeholder”),j])}}e.push([a.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):a(this.options.items,this.element).not(“.ui-sortable-helper”).not(“.ui-sortable-placeholder”),this]);for(var g=e.length-1;g>=0;g–)e[g][0].each(function(){d.push(this)});return a(d)},_removeCurrentsFromItems:function(){var a=this.currentItem.find(“:data(”+this.widgetName+“-item)”);for(var b=0;b<this.items.length;b++)for(var c=0;c<a.length;c++)a[c]==this.items[b].item[0]&&this.items.splice(b,1)},_refreshItems:function(b){this.items=[],this.containers=[this];var c=this.items,d=this,e=a.isFunction(this.options.items),f=this._connectWith();if(f&&this.ready)for(var g=f.length-1;g>=0;g–){var h=a(f[g]);for(var i=h.length-1;i>=0;i–){var j=a.data(h[i],this.widgetName);j&&j!=this&&!j.options.disabled&&(e.push([a.isFunction(j.options.items)?j.options.items.call(j.element[0],b,{item:this.currentItem}):a(j.options.items,j.element),j]),this.containers.push(j))}}for(var g=e.length-1;g>=0;g–){var k=e[g][1],l=e[g][0];for(var i=0,m=l.length;i<m;i++){var n=a(l[i]);n.data(this.widgetName+“-item”,k),c.push({item:n,instance:k,width:0,height:0,left:0,top:0})}}},refreshPositions:function(b){this.offsetParent&&this.helper&&(this.offset.parent=this._getParentOffset());for(var c=this.items.length-1;c>=0;c–){var d=this.items[c];if(d.instance!=this.currentContainer&&this.currentContainer&&d.item[0]!=this.currentItem[0])continue;var e=this.options.toleranceElement?a(this.options.toleranceElement,d.item):d.item;b||(d.width=e.outerWidth(),d.height=e.outerHeight());var f=e.offset();d.left=f.left,d.top=f.top}if(this.options.custom&&this.options.custom.refreshContainers)this.options.custom.refreshContainers.call(this);else for(var c=this.containers.length-1;c>=0;c–){var f=this.containers[c].element.offset();this.containers[c].containerCache.left=f.left,this.containers[c].containerCache.top=f.top,this.containers[c].containerCache.width=this.containers[c].element.outerWidth(),this.containers[c].containerCache.height=this.containers[c].element.outerHeight()}return this},_createPlaceholder:function(b){var c=b||this,d=c.options;if(!d.placeholder||d.placeholder.constructor==String){var e=d.placeholder;d.placeholder={element:function(){var b=a(document.createElement(c.currentItem[0].nodeName)).addClass(e||c.currentItem[0].className+“ ui-sortable-placeholder”).removeClass(“ui-sortable-helper”)[0];return e||(b.style.visibility=“hidden”),b},update:function(a,b){if(e&&!d.forcePlaceholderSize)return;b.height()||b.height(c.currentItem.innerHeight()-parseInt(c.currentItem.css(“paddingTop”)||0,10)-parseInt(c.currentItem.css(“paddingBottom”)||0,10)),b.width()||b.width(c.currentItem.innerWidth()-parseInt(c.currentItem.css(“paddingLeft”)||0,10)-parseInt(c.currentItem.css(“paddingRight”)||0,10))}}}c.placeholder=a(d.placeholder.element.call(c.element,c.currentItem)),c.currentItem.after(c.placeholder),d.placeholder.update(c,c.placeholder)},_contactContainers:function(b){var c=null,d=null;for(var e=this.containers.length-1;e>=0;e–){if(a.ui.contains(this.currentItem[0],this.containers[e].element[0]))continue;if(this._intersectsWith(this.containers[e].containerCache)){if(c&&a.ui.contains(this.containers[e].element[0],c.element[0]))continue;c=this.containers[e],d=e}else this.containers[e].containerCache.over&&(this.containers[e]._trigger(“out”,b,this._uiHash(this)),this.containers[e].containerCache.over=0)}if(!c)return;if(this.containers.length===1)this.containers[d]._trigger(“over”,b,this._uiHash(this)),this.containers[d].containerCache.over=1;else if(this.currentContainer!=this.containers[d]){var f=1e4,g=null,h=this.positionAbs[this.containers[d].floating?“left”:“top”];for(var i=this.items.length-1;i>=0;i–){if(!a.ui.contains(this.containers[d].element[0],this.items[i].item[0]))continue;var j=this.containers[d].floating?this.items[i].item.offset().left:this.items[i].item.offset().top;Math.abs(j-h)<f&&(f=Math.abs(j-h),g=this.items[i],this.direction=j-h>0?“down”:“up”)}if(!g&&!this.options.dropOnEmpty)return;this.currentContainer=this.containers[d],g?this._rearrange(b,g,null,!0):this._rearrange(b,null,this.containers[d].element,!0),this._trigger(“change”,b,this._uiHash()),this.containers[d]._trigger(“change”,b,this._uiHash(this)),this.options.placeholder.update(this.currentContainer,this.placeholder),this.containers[d]._trigger(“over”,b,this._uiHash(this)),this.containers[d].containerCache.over=1}},_createHelper:function(b){var c=this.options,d=a.isFunction(c.helper)?a(c.helper.apply(this.element[0],[b,this.currentItem])):c.helper==“clone”?this.currentItem.clone():this.currentItem;return d.parents(“body”).length||a(c.appendTo!=“parent”?c.appendTo:this.currentItem[0].parentNode)[0].appendChild(d[0]),d[0]==this.currentItem[0]&&(this._storedCSS={width:this.currentItem[0].style.width,height:this.currentItem[0].style.height,position:this.currentItem.css(“position”),top:this.currentItem.css(“top”),left:this.currentItem.css(“left”)}),(d[0].style.width==““||c.forceHelperSize)&&d.width(this.currentItem.width()),(d[0].style.height==”“||c.forceHelperSize)&&d.height(this.currentItem.height()),d},_adjustOffsetFromHelper:function(b){typeof b==“string”&&(b=b.split(” ”)),a.isArray(b)&&(b={left:+b[0],top:+b[1]||0}),“left”in b&&(this.offset.click.left=b.left+this.margins.left),“right”in b&&(this.offset.click.left=this.helperProportions.width-b.right+this.margins.left),“top”in b&&(this.offset.click.top=b.top+this.margins.top),“bottom”in b&&(this.offset.click.top=this.helperProportions.height-b.bottom+this.margins.top)},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var b=this.offsetParent.offset();this.cssPosition==“absolute”&&this.scrollParent[0]!=document&&a.ui.contains(this.scrollParent[0],this.offsetParent[0])&&(b.left+=this.scrollParent.scrollLeft(),b.top+=this.scrollParent.scrollTop());if(this.offsetParent[0]==document.body||this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()==“html”&&a.browser.msie)b={top:0,left:0};return{top:b.top+(parseInt(this.offsetParent.css(“borderTopWidth”),10)||0),left:b.left+(parseInt(this.offsetParent.css(“borderLeftWidth”),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition==“relative”){var a=this.currentItem.position();return{top:a.top-(parseInt(this.helper.css(“top”),10)||0)+this.scrollParent.scrollTop(),left:a.left-(parseInt(this.helper.css(“left”),10)||0)+this.scrollParent.scrollLeft()}}return{top:0,left:0}},_cacheMargins:function(){this.margins={left:parseInt(this.currentItem.css(“marginLeft”),10)||0,top:parseInt(this.currentItem.css(“marginTop”),10)||0}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var b=this.options;b.containment==“parent”&&(b.containment=this.helper[0].parentNode);if(b.containment==“document”||b.containment==“window”)this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,a(b.containment==“document”?document:window).width()-this.helperProportions.width-this.margins.left,(a(b.containment==“document”?document:window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top];if(!/^(document|window|parent)$/.test(b.containment)){var c=a(b.containment)[0],d=a(b.containment).offset(),e=a©.css(“overflow”)!=“hidden”;this.containment=[d.left+(parseInt(a©.css(“borderLeftWidth”),10)||0)+(parseInt(a©.css(“paddingLeft”),10)||0)-this.margins.left,d.top+(parseInt(a©.css(“borderTopWidth”),10)||0)+(parseInt(a©.css(“paddingTop”),10)||0)-this.margins.top,d.left+(e?Math.max(c.scrollWidth,c.offsetWidth):c.offsetWidth)-(parseInt(a©.css(“borderLeftWidth”),10)||0)-(parseInt(a©.css(“paddingRight”),10)||0)-this.helperProportions.width-this.margins.left,d.top+(e?Math.max(c.scrollHeight,c.offsetHeight):c.offsetHeight)-(parseInt(a©.css(“borderTopWidth”),10)||0)-(parseInt(a©.css(“paddingBottom”),10)||0)-this.helperProportions.height-this.margins.top]}},_convertPositionTo:function(b,c){c||(c=this.position);var d=b==“absolute”?1:-1,e=this.options,f=this.cssPosition==“absolute”&&(this.scrollParent[0]==document||!a.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,g=/(html|body)/i.test(f[0].tagName);return{top:c.top+this.offset.relative.top*d+this.offset.parent.top*d-(a.browser.safari&&this.cssPosition==“fixed”?0:(this.cssPosition==“fixed”?-this.scrollParent.scrollTop():g?0:f.scrollTop())*d),left:c.left+this.offset.relative.left*d+this.offset.parent.left*d-(a.browser.safari&&this.cssPosition==“fixed”?0:(this.cssPosition==“fixed”?-this.scrollParent.scrollLeft():g?0:f.scrollLeft())*d)}},_generatePosition:function(b){var c=this.options,d=this.cssPosition==“absolute”&&(this.scrollParent[0]==document||!a.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,e=/(html|body)/i.test(d[0].tagName);this.cssPosition==“relative”&&(this.scrollParent[0]==document||this.scrollParent[0]==this.offsetParent[0])&&(this.offset.relative=this._getRelativeOffset());var f=b.pageX,g=b.pageY;if(this.originalPosition){this.containment&&(b.pageX-this.offset.click.left<this.containment[0]&&(f=this.containment[0]+this.offset.click.left),b.pageY-this.offset.click.top<this.containment[1]&&(g=this.containment[1]+this.offset.click.top),b.pageX-this.offset.click.left>this.containment[2]&&(f=this.containment[2]+this.offset.click.left),b.pageY-this.offset.click.top>this.containment[3]&&(g=this.containment[3]+this.offset.click.top));if(c.grid){var h=this.originalPageY+Math.round3),left:f-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+(a.browser.safari&&this.cssPosition==“fixed”?0:this.cssPosition==“fixed”?-this.scrollParent.scrollLeft():e?0:d.scrollLeft())}},_rearrange:function(a,b,c,d){c?c[0].appendChild(this.placeholder[0]):b.item[0].parentNode.insertBefore(this.placeholder[0],this.direction==“down”?b.item[0]:b.item[0].nextSibling),this.counter=this.counter?++this.counter:1;var e=this,f=this.counter;window.setTimeout(function(){f==e.counter&&e.refreshPositions(!d)},0)},_clear:function(b,c){this.reverting=!1;var d=[],e=this;!this._noFinalSort&&this.currentItem.parent().length&&this.placeholder.before(this.currentItem),this._noFinalSort=null;if(this.helper[0]==this.currentItem[0]){for(var f in this._storedCSS)if(this._storedCSS[f]==“auto”||this._storedCSS[f]==“static”)this._storedCSS[f]=“”;this.currentItem.css(this._storedCSS).removeClass(“ui-sortable-helper”)}else this.currentItem.show();this.fromOutside&&!c&&d.push(function(a){this._trigger(“receive”,a,this._uiHash(this.fromOutside))}),(this.fromOutside||this.domPosition.prev!=this.currentItem.prev().not(“.ui-sortable-helper”)[0]||this.domPosition.parent!=this.currentItem.parent()[0])&&!c&&d.push(function(a){this._trigger(“update”,a,this._uiHash())});if(!a.ui.contains(this.element[0],this.currentItem[0])){c||d.push(function(a){this._trigger(“remove”,a,this._uiHash())});for(var f=this.containers.length-1;f>=0;f–)a.ui.contains(this.containers[f].element[0],this.currentItem[0])&&!c&&(d.push(function(a){return function(b){a._trigger(“receive”,b,this._uiHash(this))}}.call(this,this.containers[f])),d.push(function(a){return function(b){a._trigger(“update”,b,this._uiHash(this))}}.call(this,this.containers[f])))}for(var f=this.containers.length-1;f>=0;f–)c||d.push(function(a){return function(b){a._trigger(“deactivate”,b,this._uiHash(this))}}.call(this,this.containers[f])),this.containers[f].containerCache.over&&(d.push(function(a){return function(b){a._trigger(“out”,b,this._uiHash(this))}}.call(this,this.containers[f])),this.containers[f].containerCache.over=0);this._storedCursor&&a(“body”).css(“cursor”,this._storedCursor),this._storedOpacity&&this.helper.css(“opacity”,this._storedOpacity),this._storedZIndex&&this.helper.css(“zIndex”,this._storedZIndex==“auto”?“”:this._storedZIndex),this.dragging=!1;if(this.cancelHelperRemoval){if(!c){this._trigger(“beforeStop”,b,this._uiHash());for(var f=0;f<d.length;f++)d[f].call(this,b);this._trigger(“stop”,b,this._uiHash())}return this.fromOutside=!1,!1}c||this._trigger(“beforeStop”,b,this._uiHash()),this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.helper[0]!=this.currentItem[0]&&this.helper.remove(),this.helper=null;if(!c){for(var f=0;f<d.length;f++)d[f].call(this,b);this._trigger(“stop”,b,this._uiHash())}return this.fromOutside=!1,!0},_trigger:function(){a.Widget.prototype._trigger.apply(this,arguments)===!1&&this.cancel()},_uiHash:function(b){var c=b||this;return{helper:c.helper,placeholder:c.placeholder||a([]),position:c.position,originalPosition:c.originalPosition,offset:c.positionAbs,item:c.currentItem,sender:b?b.element:null}}}),a.extend(a.ui.sortable,{version:“1.8.23”})})(jQuery);;</script>

<script type="text/javascript">
jQuery(document).ready(function() {
	jQuery("#discount_remove_0, span.discount_symbol, #discount_tier_repeat_holder, #discount_select_product_type_holder").hide();
	jQuery("input[name='discount_selector']").click(function() {
		updateDiscountStyle();
	});
	jQuery("a#addTier").click(function() {
		addTier();
		return false;
	});
	// Remove button
	jQuery("a[id^='discount_remove']").live('click', function() {
		var id = parseInt(this.id.replace("discount_remove_", ""));
		jQuery("#tier_"+id).slideUp("fast", function() { 
			jQuery(this).remove(); 
			updateDiscountLogic();
		});
		return false;
	});
	// Inputs
	jQuery("input.logic_modifier").live("keyup", function() {
		validateInput(this);
		updateDiscountLogic();
	});
	// Selects
	jQuery("select.logic_modifier").live('change', function() {
		updateDiscountLogic();
	})
	jQuery("#discount_method").change(function() {
		updateSymbolDisplay();
	});
	jQuery("#discount_type").change(function() {
		updateDiscountType();
	});
	jQuery("#result_logic").change(function() {
		updateFormFromLogic();
	})
	jQuery("#discount_tiers").sortable({ 
									handle: 'span.sortable_handle', 
									axis: 'y', 
									containment: 'parent',
									cursor: 'n-resize',
									tolerance: 'pointer',
									stop: function(event, ui) { 
										updateTierIdents();
										updateDiscountLogic();
									}
								});
	updateDiscountStyle();
	updateDiscountLogic();
	updateSymbolDisplay();
});
function updateDiscountStyle() {
	var discount_style = jQuery("input[name='discount_selector']:checked").val() || "product";
	if (discount_style == "product") {
		jQuery(".discount_style_product").show();
		jQuery(".discount_style_category").hide();
	} else {
		jQuery(".discount_style_product").hide();
		jQuery(".discount_style_category").show();
	}
}
function updateSymbolDisplay() {
	var parts = jQuery("#discount_method").val().split("_");
	if (parts[0] == "price") {
		jQuery(".discount_tier_wrapper .discount_symbol_dollar").show();
		jQuery("input.discount_tier").addClass("discount_input_dollar");
	} else {
		// Amount only allows whole numbers, validate all the tiers
		jQuery(".discount_tier").each(function() {
			validateInput(this);
		})
		jQuery(".discount_tier_wrapper .discount_symbol_dollar").hide();
		jQuery("input.discount_tier").removeClass("discount_input_dollar");
	}
	jQuery(".discount_amount_wrapper .discount_symbol").hide();
	if (parts[1] == "amount") {
		jQuery(".discount_amount_wrapper .discount_symbol_dollar").show();
		jQuery("input.discount_amount").addClass("discount_input_dollar").removeClass("discount_input_percent");
	} else {
		jQuery(".discount_amount_wrapper .discount_symbol_percent").show();
		jQuery("input.discount_amount").addClass("discount_input_percent").removeClass("discount_input_dollar");
	}
}
function updateDiscountType() {
	var type = jQuery("#discount_type").val();
	if (type == "repeat") {
		jQuery("#discount_tier_repeat_holder").show();
	} else {
		jQuery("#discount_tier_repeat_holder").hide()
		jQuery("#discount_tier_repeat").val("");
	}
}
function updateDiscountLogic() {
	var method = jQuery("#discount_method").val();
	var name = jQuery("#discount_name").val();
	var type = jQuery("#discount_type").val();
	var tiers = (type == "") ? [] : [type];
	var lastTier = -1;
	var validTiers = true;
	var hasValidTier = false;
	// Only allow 1 tier for repeats
	if (type == "repeat") {
		// Remove all existing tiers except for the first one
		jQuery(".discount_tier_row:not(#tier_0)").remove();
	}
	jQuery(".discount_tier_row").each(function() {
		var id = parseInt(getTierDetails(this.id)[2]);
		var tier = jQuery("#discount_tier_"+id).val();
		var operator = jQuery("#discount_operator_"+id).val();
		var amount = jQuery("#discount_amount_"+id).val();
		jQuery(this).removeClass("discount_tier_error discount_tier_invalid");
		if (tier == "" && amount == "") {
			// Empty fields, don't do anything
			validTiers = false;
		} else {
			// Something has a value, check it
			tier = parseFloat(tier);
			amount = parseFloat(amount);
			// Been changed, not a new input anymore
			jQuery(this).removeClass("discount_tier_new");
			if (!isNaN(tier) && !isNaN(amount) && tier > lastTier) {
				// Valid tier
				tiers.push(tier + operator + amount);
				lastTier = tier;
				hasValidTier = true;
			} else if (!isNaN(tier) && !isNaN(amount) && tier <= lastTier) {
				// Valid tiers, but not increased over previous amount
				jQuery(this).addClass("discount_tier_error");
				validTiers = false;
			} else if (isNaN(tier) || isNaN(amount)) {
				// Somethings not valid
				jQuery(this).addClass("discount_tier_invalid");
				validTiers = false;
			} else {
				validTiers = false;
			}
		}
	});
	/*if (type == "repeat") {
		var repeatingTier = parseFloat(jQuery("#discount_tier_repeat").val());
		if (!isNaN(repeatingTier)) {
			tiers.push(repeatingTier);
			//jQuery("#discount_tier_repeat_holder").removeClass("discount_tier_error");
		} else {
			//jQuery("#discount_tier_repeat_holder").addClass("discount_tier_error");
		}
	} else {
		jQuery("#discount_tier_repeat_holder").hide().val("");
	}*/
	if (validTiers) {
		addTier();
	}
	if (hasValidTier) {
		// Fill in logic
		var logic = (type == "repeat") ? tiers[0] + "|" + tiers[1] : tiers.join("|");
		jQuery("#result_logic").val(logic);
		if (method != "" && name != "") {
			jQuery("#result_link").val("discount_" + method + "=" + name + "{" + logic + "}");
			jQuery("#result_form").val("<input type=\"hidden\" name=\"discount_" + method + "\" value=\"" + name + "{" + logic + "}\" />");
		} else {
			jQuery("#result_link").val("");
			jQuery("#result_form").val("");
		}
	} else {
		jQuery("#result_logic").val("");
	}
}
function updateFormFromLogic() {
	var logic = jQuery("#result_logic").val();
	// Optional - Discount Method, Discount Name, Discount Type
	// Required - Tiers made up of something like 1.2-3 or 1+2
	//var re = /(?:discount_([\_|\w]+))?\=?(.+)?(?:\{(?:(\w+)\|)?((?:[\d|\.]+[\+\-\ ]+[\d|\.]+)+)\})/;
	//var re = /(discount[\_|\w]+)?\=?(.+)?(?:\{(?:(\w+)\|)?([\d|\.|\||\-|\+]+)\})/;
	/*
		1 - Discount Method
		2 - Discount Name
		3 - Discount Type
		4 - Tiers
		5 - Repeating Tier
	*/
	var re = /(?:discount_((?:quantity|price)_(?:amount|percentage))=)?([^{=\n\r]+?)\{(?:(allunits|incremental|repeat|single)\|)?((?:[\d.]+[+-][\d.]+(?=\||})\|?)+)(?:\|([\d.])(?=}))?\}/;
	if (re.test(logic)) {
		var parts = re.exec(logic);
		if (parts[1] != undefined) {
			jQuery("#discount_method").val(parts[1]);
			updateSymbolDisplay();
		}
		if (parts[2] != undefined) {
			jQuery("#discount_name").val(parts[2]);
		}
		if (parts[3] != undefined) {
			jQuery("#discount_type").val(parts[3]);
			updateDiscountType();
		}
		var tiers = parts[4].split("|");
		//var tre = /([\d|\.]+)([\+\-\ ]+)([\d|\.]+)/;
		var tre = /([\d|\.]+)([\+\-\ ]+)([\d|\.]+)/;
		// Remove all existing tiers except for the first one
		jQuery(".discount_tier_row:not(#tier_0)").remove();
		for (var t in tiers) {
			if (tre.test(tiers[t])) {
				var tparts = tre.exec(tiers[t]);
				if (jQuery("#tier_" + t).length == 1) {
					jQuery("input#discount_tier_" + t).val(tparts[1]);
					// Correct for space
					if (tparts[2] == " ") {
						tparts[2] = "+";
					}
					jQuery("input#discount_operator_" + t).val(tparts[2]);
					jQuery("input#discount_amount_" + t).val(tparts[3]);
				} else {
					addTier(tparts[1], tparts[2], tparts[3]);
				}
			}
		}
		/*if (parts[5] != undefined && jQuery("#discount_type").val() == "repeat") {
			jQuery("#discount_tier_repeat").val(parts[5]);
		}*/
		//jQuery("#tier_0").remove();
		updateSymbolDisplay();
		updateTierIdents();
		updateDiscountLogic();
	} else {
		// Not a valid discount string
	}
}
function addTier(tier, operator, amount) {
	// Only allow 1 tier for repeats
	if (jQuery("#discount_type").val() == "repeat") {
		// Remove all existing tiers except for the first one
		jQuery(".discount_tier_row:not(#tier_0)").remove();
	} else {
		tier = parseFloat(tier) || "";
		operator = operator || "-";
		amount = parseFloat(amount) || "";
		var newTier = jQuery(".discount_tier_row:last").clone().attr("style", "").addClass("discount_tier_new")
		newTier.find("input[name^='discount_tier']").val(tier);
		newTier.find("select[name^='discount_operator']").val(operator);
		newTier.find("input[name^='discount_amount']").val(amount);
		newTier.hide().appendTo("#discount_tiers").slideDown("fast", function() {
		});
		updateTierIdents();
	}
}
function updateTierIdents() {
	i = 0;
	jQuery("#discount_tiers").children().each(function() {
		jQuery(this).attr("id", getTierDetails(jQuery(this).attr("id"))[1] + i);
		jQuery(this).find("input, select, label, a").each(function() {
			switch (this.tagName.toLowerCase()) {
				case "input":
				case "select":
					var newName = getTierDetails(jQuery(this).attr("name"))[1] + i;
					jQuery(this).attr("name", newName).attr("id", newName);
					break;
				case "label":
					jQuery(this).attr("for", getTierDetails(jQuery(this).attr("for"))[1] + i);
					break;
				case "a":
					jQuery(this).attr("id", getTierDetails(jQuery(this).attr("id"))[1] + i);
					break;
			}
		});
		if (i == 0) {
			jQuery("#discount_remove_0").hide();
		} else {
			jQuery("#discount_remove_" + i).show();
		}
		i++;
	});
}
// Check that the entered value is a number, and if a tier, is inbetween the surrounding tiers
function validateInput(obj) {
	var el = jQuery(obj);
	var id = parseInt(getTierDetails(obj.name)[2]);
	var val = obj.value;
	var method = jQuery("#discount_method").val();
	var isValid = true;
	var isEmpty = false;
	if (!el.hasClass("validate_number")) {
		return true;
	}
	if (val != "") {
		val = parseFloat(val);
		if (isNaN(val)) {
			el.val("");
			isValid = false;
		}
		if (isValid && el.hasClass("discount_tier")) {
			if (method.indexOf("quantity") > -1) {
				// Only allow whole numbers for quantity tiers
				val = parseInt(val);
				el.val(val);
			}
			if (jQuery("#discount_tier_" + (id - 1)).length > 0) {
				if (val <= parseFloat(jQuery("#discount_tier_" + (id - 1)).val())) {
					//el.val("");
					isValid = false;
				}
			}
			if (jQuery("#discount_tier_" + (id + 1)).length > 0) {
				if (val >= parseFloat(jQuery("#discount_tier_" + (id + 1)).val())) {
					//el.val("");
					isValid = false;
				}
			}
		}
	}
	if (!isValid) {
		el.addClass("discount_input_error");
	} else {
		el.removeClass("discount_input_error");
	}
	return isValid;
}
function getTierDetails(str) {
	var re = /(\D*)(\d*)/;
	return re.exec(str);
}
</script>
<style type="text/css">
	#discount_selectors li {
		margin:0 0 5px 70px;
	}
	#discount_selectors input {
		margin-right:7px;
	}
	#discount_tiers {
		list-style:none;
		padding-left:0;
		padding-top:0px;
		padding-bottom:10px;
		margin:0 0 0 75px;
	}
	.discount_tier_row {
		padding:4px 0;
	}
	.discount_tier_error {
		background-color:#FFBABA;
	}
	.discount_tier_error input,
	input.discount_input_error {
		border:1px solid #D8000C;
	}
	.discount_tier_invalid {
		background-color:#F1F1F1;
	}
	.discount_tier_new {
		background-color:#FEEFB3;
	}
	.discount_tier_wrapper,
	.discount_amount_wrapper {
		display:inline-block;
		position:relative;
	}
	.discount_tier,
	.discount_amount,
	#discount_tier_repeat {
		width:70px;
		display:inline;
		margin:0;
	}
	.discount_input_dollar,
	.discount_input_percent {
		/*width:70px;*/
	}
	.discount_input_dollar {
		width:58px;
		padding-left:12px;
	}
	.discount_input_percent {
		width:55px;
		padding-right:15px;
	}
	.discount_symbol {
		top:4px;
		position:absolute;
		color:#666;
		font-size:0.9em;
	}
	.discount_symbol_dollar {
		left:3px;
	}
	.discount_symbol_percent {
		right:3px;
	}
	li {
		margin-bottom:5px;
	}
	#discount_name,
	#results input {
		width:600px;
	}
	.sortable_handle {
		background-color:#CCC;
		cursor:n-resize;
	}
	ol {
		margin:0;
		padding:0;
	}
	ol li {
		list-style:none;
	}
	label.pre {
		width:70px;
		display:inline-block;
	}
	a#addTier {
		margin-left:70px;
	}
	input,
	select {
		padding:2px;
	}
</style>
<form id="coupons">
	<h3>What type of discount are you creating?</h3>
	<ol id="discount_selectors">
		<li>
			<label for="discount_selector_product"><input type="radio" id="discount_selector_product" name="discount_selector" value="product" checked="checked" />Product Discount</label>
		</li>
		<li>
			<label for="discount_selector_category"><input type="radio" id="discount_selector_category" name="discount_selector" value="category" />Category Discount</label>
		</li>
		<li>
			<label for="discount_selector_coupon"><input type="radio" id="discount_selector_coupon" name="discount_selector" value="coupon" />Coupon</label>
		</li>
	</ol>
	<h3>Create your discount</h3>
	<ol>
		<li>
			<label for="discount_method" class="pre">Method: </label>
			<select id="discount_method" name="discount_method" class="logic_modifier">
				<option value="quantity_amount">Discount by an amount based on the quantity</option>
				<option value="quantity_percentage">Discount by a percentage based on the quantity</option>
				<option value="price_amount">Discount by an amount based on the price in this category</option>
				<option value="price_percentage">Discount by a percentage based on the price in this category</option>
			</select>
		</li>
		<li class="discount_style_product">
			<label for="discount_name" class="pre">Name: </label>
			<input type="text" id="discount_name" name="discount_name" class="logic_modifier" />
		</li>
		<li>
			<label for="discount_type" class="pre">Type: </label>
			<select id="discount_type" name="discount_type" class="logic_modifier">
				<option value="">Default</option>
				<option value="allunits">All-Units</option>
				<option value="incremental">Incremental</option>
				<option value="repeat">Repeat</option>
				<option value="single">Single</option>
			</select>
		</li>
		<li>
			<ul id="discount_tiers">
				<li id="tier_0" class="discount_tier_row">
					<span class="sortable_handle">&equiv;</span>
					<label for="discount_tier_0">From</label>
					<div class="discount_tier_wrapper">
						<span class="discount_symbol discount_symbol_dollar">$</span>
						<input type="text" id="discount_tier_0" name="discount_tier_0" class="logic_modifier discount_tier validate_number" />
					</div>
					<select id="discount_operator_0" name="discount_operator_0" class="logic_modifier discount_operator">
						<option value="-">decrease by</option>
						<option value="+">increase by</option>
					</select>
					<div class="discount_amount_wrapper">
						<span class="discount_symbol discount_symbol_dollar">$</span>
						<input type="text" id="discount_amount_0" name="discount_amount_0" class="logic_modifier discount_amount validate_number" />
						<span class="discount_symbol discount_symbol_percent">%</span>
					</div>
					<a id="discount_remove_0" class="discount_remove icon" href="#">- Remove</a>
				</li>
			</ul>
		</li>
		<!--
			<div id="discount_tier_repeat_holder">
				<label for="discount_tier_0">Repeating at </label>
				<input type="text" id="discount_tier_repeat" name="discoutn_tier_repeat" class="logic_modifier" />
			</div>
		-->
		<li>
			<a id="addTier" class="icon-text" href="#">Add a tier</a>
		</li>
	</ol>
	<h3>Resulting Code</h3>
	<ol id="results">
		<li>
			<label for="result_logic" class="pre">Logic:</label>
			<input type="text" id="result_logic"></input>
		</li>
		<li class="discount_style_product">
			<label for="result_link" class="pre">Link:</label>
			<input type="text" id="result_link"></input>
		</li>
		<li class="discount_style_product">
			<label for="result_form" class="pre">Form:</label>
			<input type="text" id="result_form"></input>
		</li>
	</ol>
</form></HTML>
1)
a.support.selectstart?“selectstart”:“mousedown”)+“.ui-disableSelection”,function(a){a.preventDefault()})},enableSelection:function(){return this.unbind(“.ui-disableSelection”)}}),a(“<a>”).outerWidth(1).jquery||a.each([“Width”,“Height”],function(c,d){function h(b,c,d,f){return a.each(e,function(){c-=parseFloat(a.curCSS(b,“padding”+this,!0
2)
b.key||c[1]+“[]”)+“=”+(b.key&&b.expression?c[1]:c[2]
3)
g-this.originalPageY)/c.grid[1])*c.grid[1];g=this.containment?h-this.offset.click.top<this.containment[1]||h-this.offset.click.top>this.containment[3]?h-this.offset.click.top<this.containment[1]?h+c.grid[1]:h-c.grid[1]:h:h;var i=this.originalPageX+Math.round((f-this.originalPageX)/c.grid[0])*c.grid[0];f=this.containment?i-this.offset.click.left<this.containment[0]||i-this.offset.click.left>this.containment[2]?i-this.offset.click.left<this.containment[0]?i+c.grid[0]:i-c.grid[0]:i:i}}return{top:g-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+(a.browser.safari&&this.cssPosition==“fixed”?0:this.cssPosition==“fixed”?-this.scrollParent.scrollTop():e?0:d.scrollTop(

Site Tools