eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('h(41 l==\'2K\'||!l.3Y.2I("1.6"))1q("l-z 2D 3R l 2D >= 1.6.0");h(l.r.1u){l.r.2s=1C(2e.3L.2I(/3K\\/([\\d\\.\\+]*)/)[1]);l.r.3I=(l.r.2s<3H)}h(l.r.3G){l.r.1H=1C(2e.3E.24(\';\')[1].3C().24(\' \')[1]);l.r.3B=l.r.1H==6;l.r.3A=l.r.1H==7}l.3z=9(){g I};l.3v=9(){g P};i z={3t:{},T:{}};q.x(1f.20,{x:q.x.3o(),17:1f.20.17.3m(9(a,b){h(!b)g 8;h(!b.28(\'W\'))g a(b);i c=b.W;2h b.W;a(b);c.2l(b,8);b.W=c;g 8}),3e:9(a,b){i c={};c[a]=b;g 8.17(c)},1U:9(a){g 8.y[a].3b()},2p:9(){$A(B).2w().Y(9(a){8[a]=(9(){g 8[a].11(8,B)}).v(8.y)},8);g 8},33:9(a){8.y[a]=2K;g 8},32:9(a){2h 8.y[a];g 8},1s:9(a,b){8.y[a]=8.y[b];g 8},30:9(a,b){b=b.1p();8.1s(a+"2Y"+b,a);8.1s(a,a+"2X"+b);g 8}});q.x(2W.y,{2V:9(a){g 2G(a==1?8:(8/a).F()*a)}});q.x(2J.y,{1p:9(){i a=8.2R().2Q();g a.2P(0).2O()+a.2N(1)},2Z:9(){i a=2L Z(\'2S\');a.2T=8;g a.12()}});q.x(2U.y,{1h:9(){g!8.1r},31:9(){g 8.1t().2B===q?8.35():{}},2z:9(a){i b=8[a];8.2y(a,1);g b},2x:9(a){i b;37((b=8.38(a))!=-1)8.2z(b);g a},2u:9(a){i b=$A(B);b.2t();8.2y.11(8,[a,0].39(b));g 8}});Z.17({1x:9(a){g{2q:a.3a,2o:a.3d}},2m:9(a){g Z.3f(a.2k,a.2j)},1y:9(a,b){a=$(a);h(B.1r==3)b={1B:b,1E:B[2]};a.2k=b.1B;a.2j=b.1E;g a},2d:9(a,b){i c=1C($(a).3g(b));g 2b(c)?18:c},3h:9(a,b){a=$(a);b=2J.3i(b);a.3j(s.3l(b));g a}});s.3n=9(a){h(s.23)a.2l(s);1O s.K(\'3p:23\',a)};q.x(s.1Z,{2m:s.1Z.3q,1y:9(a){Z.1y(l.r.1u?s.1X:s.1W,a)},1x:9(){g Z.1x(l.r.1u?s.1X:s.1W)}});(9(){z.1V={W:9(a){a.2p($w(\' 1T O 1R 1Q 2n \'))},1T:9(a){h(!8.28(\'j\'))8.j=8.O();8.j=q.x(8.j,a||{})},O:9(){i a=8.2B.3u,1c=a&&a.y;g(1c&&1c.O)?q.x(1c.O(),8.j):q.3w(8.j)},1R:9(){1K(8,B,I)},1Q:9(){1K(8,B,P)},2n:9(){8.1R.11(8,B);8.1Q.11(8,B)}};9 1K(d,e,f){e=$A(e).2w();h(e.1h())e=q.3D(d.O());e.Y(9(b){i c=(f?\'3F\':\'3J\')+b.1p();d[c]=d[c]||(f?9(a){g 8.j[b]=a}:9(){g 8.j[b]})})}})();z.S=1f.2f(z.1V,{j:{1D:"1g",p:".1A",k:".16",o:".o",1w:"1v",14:\'3O\',2C:\'3S\'},2E:9(c,d){8.1T(d);8.C=$(c);8.2F=8.C.2F;8.o=8.C.12(8.j.o).3V();8.N=8.o.1n();8.p=8.j.p==I?18:8.C.12(8.j.p);8.k=8.j.k==I?18:8.C.12(8.j.k);8.L=(8.j.1D=="1g"?"1B":"1E");8.1l=(8.j.1D=="1g"?"2q":"2o");8.n=8.1j();8.u=8.H()/8.n;i e=8.j.1w;h(e=="1v")e=t.F(8.u);[8.p,8.k].Y(9(a){h(!a)g;i b=(a==8.k?"16":"1A")+8.j.2C;a.R=8.E.v(8,(a==8.k?-1:1)*e*8.n);a.K("1d",a.R).K("3M",9(){a.1b(b)}.v(8)).K("2M",9(){a.19(b)}.v(8))},8);8.U()},3Z:9($G){[8.p,8.k].Y(9(a){h(!a)g;a.15("1d",a.R)},8);8.C.2x();8.m(\'3X\')},m:9(a,b){b=b||{};b.13=8;g 8.C.m(\'13:\'+a,b)},K:9(a,b){8.C.K(\'13:\'+a,b.v(8));g 8},15:9(a,b){8.C.15(\'13:\'+a,b);g 8},1m:9(a,b){h(a>0)a=0;1O{i c=8.N.1t().2H()[8.L]+8.n;i d=8.H();h(a+c<d)a+=d-(a+c);a=t.3U(a,0)}h(b)8.o.3N[8.L]=a+"2r";g a},E:9(a){h(8.X)g 8;i b=8.J()+a;b=8.1m(b,I);a=b-8.J();h(a!=0){8.X=P;8.m("E:2i");i c=8;8.o.1z("2g:0.5",{1J:0.2,1M:9(){c.o.1z(c.L+": "+b+"2r",{1J:0.4,3s:0.2,1M:9(){c.o.1z("2g:1",{1J:0.2,1M:9(){c.X=I;c.U().m("E:21",{2t:a/c.H()})}})}})}})}g 8},3k:9(a){h(8.X||a<0||a>8.N.1r||a==8.M()||2b(2G(a)))g 8;g 8.E((8.M()-a)*8.n)},U:9(){8.2a();8.1F();g 8},2a:9(){i a=8.J();i b="1A"+8.j.14;h(8.p.Q(b)&&a!=0){8.p.19(b);8.m(\'p:1o\')}h(!8.p.Q(b)&&a==0){8.p.1b(b);8.m(\'p:1i\')}},1F:9(){i a=8.1k();i b=8.H();i c="16"+8.j.14;h(8.k.Q(c)&&a!=b){8.k.19(c);8.m(\'k:1o\')}h(!8.k.Q(c)&&a==b){8.k.1b(c);8.m(\'k:1i\')}},1j:9(){g 8.N.34().2A()[8.1l]},M:9(){g-8.J()/8.n},1k:9(){h(8.o.1n().1h())g 0;g 8.J()+8.N.1t().2H()[8.L]+8.n},J:9(){g 8.o.2d(8.L)},H:9(){g 8.o.36.2A()[8.1l]},2v:9(){8.u=8.H()/8.n;i b=8.j.1w;h(b=="1v")b=t.F(8.u);[8.p,8.k].Y(9(a){h(!a)g;a.15("1d",a.R);a.R=8.E.v(8,(a==8.k?-1:1)*b*8.n);a.K("1d",a.R)},8);8.1m(8.J(),P);8.U().m(\'3c\');g 8}});z.T.S=1f.2f(z.S,{j:{n:-1,10:18},2E:9($G,d,e){h(!e.10)1q("10 2c 29 27 26 z.T.S");h(!e.n)1q("n 2c 29 27 26 z.T.S");$G(d,e);8.D=0;8.V=P;8.1G=8.1I.v(8);8.1Y=9(a,b,c){8.1I(b,c);8.E(a)}.v(8);8.1a.v(8).3r({1P:{1S:0,1e:t.22(8.u)-1},1N:8.1G})},1a:9(a){8.1L=P;2L T.3x(8.j.10,q.x({1U:"3y"},a));8.m("25:2i");g 8},E:9($G,a){h(8.X||8.1L)g 8;i b=(-a)/8.n;h(8.V&&b>0&&8.M()+8.u+b-1>8.D){i c=8.D+1;i d=t.22(c+8.u-1);8.1a({1P:{1S:c,1e:d},1N:8.1Y.3P(a).v(8)});g 8}1O $G(a)},1I:9(a,b){8.1L=I;8.m("25:21");h(!b)b=a.3Q;8.V=b.3T;8.D=t.3W(8.D,b.1e);8.N=8.o.2u({40:b.42}).1n();g 8.U()},1j:9(){g 8.j.n},2v:9($G){i a=8.u;$G();h(t.F(8.u)-t.F(a)>=1&&8.V){h(8.M()+t.F(8.u)>=8.D){i b=t.F(8.M()+t.F(8.u)-8.D);8.1a({1P:{1S:8.D+1,1e:8.D+b},1N:8.1G})}}g 8},1F:9($G){i a=8.1k();i b=8.H();i c="16"+8.j.14;h(8.k.Q(c)&&a!=b){8.k.19(c);8.m(\'k:1o\')}h(!8.k.Q(c)&&a==b&&!8.V){8.k.1b(c);8.m(\'k:1i\')}}});',62,251,'||||||||this|function|||||||return|if|var|options|nextButton|Prototype|fire|elementSize|container|previousButton|Object|Browser|document|Math|nbVisible|bind||extend|prototype|UI||arguments|element|endIndex|scroll|floor|super|currentSize|false|currentPosition|observe|posAttribute|currentIndex|elements|allOptions|true|hasClassName|clickHandler|Carousel|Ajax|updateButtons|hasMore|methodsAdded|animating|each|Element|url|apply|down|carousel|disabledButtonSuffix|stopObserving|next_button|addMethods|null|removeClassName|runRequest|addClassName|ancestor|click|to|Class|horizontal|empty|disabled|computeElementSize|currentLastPosition|dimAttribute|checkScroll|childElements|enabled|camelcase|throw|length|aliasMethod|last|WebKit|auto|scrollInc|getScrollDimensions|setScrollOffset|morph|previous_button|left|parseFloat|direction|top|updateNextButton|updateHandler|IEVersion|update|duration|addOptionsAccessors|requestRunning|afterFinish|onSuccess|else|parameters|optionsSetter|optionsGetter|from|setOptions|method|Options|documentElement|body|updateAndScrollHandler|viewport|Methods|ended|ceil|loaded|split|request|for|required|hasOwnProperty|is|updatePreviousButton|isNaN|option|getNumStyle|navigator|create|opacity|delete|started|scrollTop|scrollLeft|call|getScrollOffset|optionsAccessor|height|classMethod|width|px|WebKitVersion|shift|insert|updateSize|flatten|remove|splice|removeAt|getDimensions|constructor|overButtonSuffix|library|initialize|id|parseInt|positionedOffset|match|String|undefined|new|mouseout|slice|toUpperCase|charAt|camelize|dasherize|div|innerHTML|Array|snap|Number|With|Without|makeElement|aliasMethodChain|extractOptions|removeMethod|undefMethod|first|pop|parentNode|while|indexOf|concat|scrollWidth|valueOf|sizeUpdated|scrollHeight|addMethod|_returnOffset|getStyle|appendText|interpret|appendChild|scrollTo|createTextNode|wrap|whenReady|methodize|dom|getScrollOffsets|defer|delay|Abstract|superclass|trueFunction|clone|Request|GET|falseFunction|IE7|IE6|strip|keys|appVersion|set|IE|420|Safari2|get|AppleWebKit|userAgent|mouseover|style|_disabled|curry|responseJSON|require|_over|more|min|firstDescendant|max|destroyed|Version|destroy|bottom|typeof|html'.split('|'),0,{}));

var Stepper = Class.create({
 initialize: function(target) {
 this.target_id = target;
 this.target = $(this.target_id);
 this.rem = new Element("div", { 'id': this.target_id+"_rem"});
 this.add = new Element("div", { 'id': this.target_id+"_add"});
 this.rem.update("-");
 this.add.update("+");
 this.target.insert({before:this.rem});
 this.target.insert({after:this.add});
 this.AddObservers();
 },

 Increase: function(e) {
 this.Update(1);
 Event.stop(e);
 },
 
 Decrease: function(e) {
 this.Update(-1);
 Event.stop(e);
 },
 
 Update: function(offset) {
 var current = (Number($F(this.target)) > 0) ? Number($F(this.target)) : 1;
 var new_value = current + offset;
 new_value = (new_value>99) ? 99 : new_value;
 new_value = (new_value<1) ? 1 : new_value;
 this.target.setValue(new_value);
 },
 
 AddObservers: function() {
 $(this.add).observe('click', this.Increase.bindAsEventListener(this));
 $(this.rem).observe('click', this.Decrease.bindAsEventListener(this)); 
 }

});

/**
 * WDCA - Sweet Tooth
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the WDCA SWEET TOOTH POINTS AND REWARDS 
 * License, which extends the Open Software License (OSL 3.0).
 * The Sweet Tooth License is available at this URL: 
 * http://www.wdca.ca/solutions_page_sweettooth/Sweet_Tooth_License.php
 * The Open Software License is available at this URL: 
 * http://opensource.org/licenses/osl-3.0.php
 * 
 * DISCLAIMER
 * 
 * By adding to, editing, or in any way modifying this code, WDCA is 
 * not held liable for any inconsistencies or abnormalities in the 
 * behaviour of this code. 
 * By adding to, editing, or in any way modifying this code, the Licensee
 * terminates any agreement of support offered by WDCA, outlined in the 
 * provided Sweet Tooth License. 
 * Upon discovery of modified code in the process of support, the Licensee 
 * is still held accountable for any and all billable time WDCA spent 
 * during the support process.
 * WDCA does not guarantee compatibility with any other framework extension. 
 * WDCA is not responsbile for any inconsistencies or abnormalities in the
 * behaviour of this code if caused by other framework extension.
 * If you did not receive a copy of the license, please send an email to 
 * contact@wdca.ca or call 1-888-699-WDCA(9322), so we can send you a copy 
 * immediately.
 * 
 * @category [TBT]
 * @package [TBT_Rewards]
 * @copyright Copyright (c) 2009 Web Development Canada (http://www.wdca.ca)
 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
 * General Sweet Tooth (rewards) utility functions.
 *
 * @category TBT
 * @package TBT_Rewards
 * @author WDCA Sweet Tooth Team <contact@wdca.ca>
 */


/**
 * <b>Requires rewards/js/captions.phtml template </b>
 * @param amount
 * @param currency_id
 * @return
 */
function getPointsString(amount, currency_id) {
 s = amount + ' ';
 if(currency_map[currency_id] != '' && currency_map[currency_id] != ' ') {
 s = s + currency_map[currency_id] + " ";
 }
 if(amount > 1) {
 s += CAPTION_POINTS;
 } else {
 s += CAPTION_POINT;
 }
 return s;
}




/**
 * WDCA - Sweet Tooth
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the WDCA SWEET TOOTH POINTS AND REWARDS 
 * License, which extends the Open Software License (OSL 3.0).
 * The Sweet Tooth License is available at this URL: 
 * http://www.wdca.ca/solutions_page_sweettooth/Sweet_Tooth_License.php
 * The Open Software License is available at this URL: 
 * http://opensource.org/licenses/osl-3.0.php
 * 
 * DISCLAIMER
 * 
 * By adding to, editing, or in any way modifying this code, WDCA is 
 * not held liable for any inconsistencies or abnormalities in the 
 * behaviour of this code. 
 * By adding to, editing, or in any way modifying this code, the Licensee
 * terminates any agreement of support offered by WDCA, outlined in the 
 * provided Sweet Tooth License. 
 * Upon discovery of modified code in the process of support, the Licensee 
 * is still held accountable for any and all billable time WDCA spent 
 * during the support process.
 * WDCA does not guarantee compatibility with any other framework extension. 
 * WDCA is not responsbile for any inconsistencies or abnormalities in the
 * behaviour of this code if caused by other framework extension.
 * If you did not receive a copy of the license, please send an email to 
 * contact@wdca.ca or call 1-888-699-WDCA(9322), so we can send you a copy 
 * immediately.
 * 
 * @category [TBT]
 * @package [TBT_Rewards]
 * @copyright Copyright (c) 2009 Web Development Canada (http://www.wdca.ca)
 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
 * Redemption drop down methods
 *
 * @category TBT
 * @package TBT_Rewards
 * @author WDCA Sweet Tooth Team <contact@wdca.ca>
 */

var rSlider;
var usesSelect;
var usesCaption;
var usesContainer;


/**
 * 
 */
function getProductPriceBeforeRedemptions() {
 var priceBeforeRedemptions = 0;
 if(optionsPrice.optionPrices.config != undefined) {
 priceBeforeRedemptions = optionsPrice.optionPrices.config + optionsPrice.productPriceBeforeRedemptions;
 } else {
 priceBeforeRedemptions = optionsPrice.productPriceBeforeRedemptions;
 }

 return priceBeforeRedemptions;
 
}

/**
 * 
 * @param rule_id
 * @return
 */
function feignPriceChange(rule_id) {
 var newPrice = $(new_price_dom_id);
 var oldPrice = $(old_price_dom_id);
 var numUses = getRedemptionUses();
 numUses = (numUses == "") ? 1 : parseInt(numUses);
 if(rule_id == null) {
 rule_id = $('redemption_rule').value;
 }

 if(!show_lowest_price) { return; }
 
 if(oldPrice == null) {
 oldPrice = newPrice.cloneNode(true);
 newPrice.up().insertBefore(oldPrice, newPrice);
 oldPrice.id = old_price_dom_id;
 oldPrice.removeClassName('price');
 oldPrice.addClassName('old-price');
 do_hide_old_price = true;
 }

 var finalPrice;
 if(optionsPrice.optionPrices.config != undefined) {
 if(optionsPrice.optionPrices.config > 0) {
 finalPrice = optionsPrice.productPriceBeforeRedemptions;
 } else {
 finalPrice= getProductPriceBeforeRedemptions();
 }
 } else {
 finalPrice = getProductPriceBeforeRedemptions();
 }
 if(rule_id == "") {
 if(do_hide_old_price) oldPrice.hide();
 optionsPrice.productPrice = finalPrice;
 optionsPrice.reload();
 } else {
 if(do_hide_old_price) oldPrice.show();
 var price_disposition = rule_options[rule_id]['price_disposition'];
 //Edited 2/24/2010 7:41:46 AM : prices that set "to_fixed" discount should also 
 if(rule_options[rule_id]['discount_action'] == 'by_fixed' && rule_options[rule_id]['new_price_flt'] <= 0.0000) {
 optionsPrice.productPrice = 0;
 optionsPrice.minusDisposition = 9999999999; // hack to make sure the price stays at 0;
 } else {
 optionsPrice.productPrice = finalPrice - price_disposition*numUses;
 }
 //Edited
 //points_caption = rule_options[rule_id]['points_caption'];
 points_amount = rule_options[rule_id]['amount'];
 points_currency_id = rule_options[rule_id]['currency_id'];
 points_caption = getPointsString(points_amount*numUses, points_currency_id);
 
 optionsPrice.reload();
 
 var points_with = " " + CAPTION_WITH + " " + points_caption ;
 if(newPrice.down() != null) {
 newPrice.down().innerHTML = newPrice.down().innerHTML + points_with ;
 } else if(newPrice.down() == null && newPrice != null) {
 newPrice.innerHTML = newPrice.innerHTML + points_with;
 } else {
 // don't know where it is so just don't show the points thing.
 }
 }
 //newPrice.toggle();
}

/**
 * 
 * @param rule_id
 * @param retain_value
 * @return
 */
function updateRemptionUsesSelector(rule_id, retain_value) {
 
 var init_value = retain_value ? retain_value : usesSelect.value ;
 
 if(rule_id == '') { 
 usesContainer.hide(); 
 } else { 
 usesSelect.innerHTML = '';
 var uses = 1;
 var amt = rule_options[rule_id]['amount'];
 var curr = rule_options[rule_id]['currency_id'];
 var max_uses = rule_options[rule_id]['max_uses'];
 var relevant_customer_points = customer_points ? customer_points[curr] : default_guest_points;
 var price_disposition = rule_options[rule_id]['price_disposition'];
 var nextPrice = getProductPriceBeforeRedemptions() - price_disposition;
 
 usesSelect.hide();
 usesCaption.hide();
 if(max_uses == 1 || max_uses == null) {
 usesCaption.innerHTML = CAPTION_YOU_WILL_SPEND + " " + getPointsString(uses*amt, curr);
 usesCaption.show();
 } else {
 while(relevant_customer_points >= amt*uses) {
 var oOption = document.createElement("option");
 oOption.text = getPointsString(uses*amt, curr);
 if(show_discount_in_uses_selector) {
 oOption.text = oOption.text + " ( - "+ optionsPrice.formatPrice(price_disposition*uses) +")";
 }
 oOption.value = uses;
 usesSelect.appendChild(oOption);
 uses++;
 if (nextPrice <= 0 || (uses > max_uses && max_uses != 0)) break;
 nextPrice = getProductPriceBeforeRedemptions() - price_disposition*uses;
 }
 if(retain_value) {
 if(init_value > uses) {
 init_value = max_uses;
 }
 usesSelect.setValue(init_value);
 } else {
 usesSelect.setValue(1);
 }
 usesSelect.show();
 }
 usesContainer.show();
 }
}
/**
 * WDCA - Sweet Tooth
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the WDCA SWEET TOOTH POINTS AND REWARDS 
 * License, which extends the Open Software License (OSL 3.0).
 * The Sweet Tooth License is available at this URL: 
 * http://www.wdca.ca/solutions_page_sweettooth/Sweet_Tooth_License.php
 * The Open Software License is available at this URL: 
 * http://opensource.org/licenses/osl-3.0.php
 * 
 * DISCLAIMER
 * 
 * By adding to, editing, or in any way modifying this code, WDCA is 
 * not held liable for any inconsistencies or abnormalities in the 
 * behaviour of this code. 
 * By adding to, editing, or in any way modifying this code, the Licensee
 * terminates any agreement of support offered by WDCA, outlined in the 
 * provided Sweet Tooth License. 
 * Upon discovery of modified code in the process of support, the Licensee 
 * is still held accountable for any and all billable time WDCA spent 
 * during the support process.
 * WDCA does not guarantee compatibility with any other framework extension. 
 * WDCA is not responsbile for any inconsistencies or abnormalities in the
 * behaviour of this code if caused by other framework extension.
 * If you did not receive a copy of the license, please send an email to 
 * contact@wdca.ca or call 1-888-699-WDCA(9322), so we can send you a copy 
 * immediately.
 * 
 * @category [TBT]
 * @package [TBT_Rewards]
 * @copyright Copyright (c) 2009 Web Development Canada (http://www.wdca.ca)
 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
 * This is a mod to the Script.aculo.us Control.Slider utility to make it smooth slide.
 * <b>Depends on:</b> Control.Slider, Effect.Move 
 *
 * @category TBT
 * @package TBT_Rewards
 * @author WDCA Sweet Tooth Team <contact@wdca.ca>
 */

var SmoothSlider = Class.create();
SmoothSlider.prototype = Control.Slider.prototype;
SmoothSlider.prototype.setValue = function(sliderValue, handleIdx){
 if(!this.active) {
 this.activeHandleIdx = handleIdx || 0;
 this.activeHandle = this.handles[this.activeHandleIdx];
 this.updateStyles();
 }
 handleIdx = handleIdx || this.activeHandleIdx || 0;
 if(this.initialized && this.restricted) {
 if((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
 sliderValue = this.values[handleIdx-1];
 if((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
 sliderValue = this.values[handleIdx+1];
 }
 sliderValue = this.getNearestValue(sliderValue);
 this.values[handleIdx] = sliderValue;
 this.value = this.values[0]; // assure backwards compat
 
 // WDCA CODE BEGIN -->>
 if(this.slideFxBusy == true) {
 if(this.slideFx) {
 this.slideFx.cancel();
 this.slideFxBusy = false;
 this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] = this.translateToPx(sliderValue);
 }
 } else {
 this.slideFxBusy = true;
 //Edited 10/03/2010 4:37:21 AM : to fix IE7-8 bug
 var translated_value = this.translateToPx(sliderValue);
 if(translated_value != "NaNpx") { 
 var move_x = this.isVertical() ? 0 : parseInt(translated_value);
 var move_y = this.isVertical() ? parseInt(translated_value) : 0;
 this.slideFx = new Effect.Move(this.handles[handleIdx], {
 x: move_x, 
 y: move_y,
 mode:'absolute',
 duration: 0.5,
 afterFinish: function() {
 this.slideFxBusy = false;
 }.bindAsEventListener(this)
 });
 }
 }
 // <<-- WDCA CODE END

 this.isMoving = false;
// this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] = this.translateToPx(sliderValue); // WDCA COMMENTED THIS

 this.drawSpans();
 if(!this.dragging || !this.event) this.updateFinished();
 };


/**
 * WDCA - Sweet Tooth
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the WDCA SWEET TOOTH POINTS AND REWARDS 
 * License, which extends the Open Software License (OSL 3.0).
 * The Sweet Tooth License is available at this URL: 
 * http://www.wdca.ca/solutions_page_sweettooth/Sweet_Tooth_License.php
 * The Open Software License is available at this URL: 
 * http://opensource.org/licenses/osl-3.0.php
 * 
 * DISCLAIMER
 * 
 * By adding to, editing, or in any way modifying this code, WDCA is 
 * not held liable for any inconsistencies or abnormalities in the 
 * behaviour of this code. 
 * By adding to, editing, or in any way modifying this code, the Licensee
 * terminates any agreement of support offered by WDCA, outlined in the 
 * provided Sweet Tooth License. 
 * Upon discovery of modified code in the process of support, the Licensee 
 * is still held accountable for any and all billable time WDCA spent 
 * during the support process.
 * WDCA does not guarantee compatibility with any other framework extension. 
 * WDCA is not responsbile for any inconsistencies or abnormalities in the
 * behaviour of this code if caused by other framework extension.
 * If you did not receive a copy of the license, please send an email to 
 * contact@wdca.ca or call 1-888-699-WDCA(9322), so we can send you a copy 
 * immediately.
 * 
 * @category [TBT]
 * @package [TBT_Rewards]
 * @copyright Copyright (c) 2009 Web Development Canada (http://www.wdca.ca)
 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
 * Sweet Tooth RedemptionSlider
 * @requires js/tbt/scriptaculous/SmoothSlider.js
 *
 * @category TBT
 * @package TBT_Rewards
 * @author WDCA Sweet Tooth Team <contact@wdca.ca>
 */

var RedemptionSlider = Class.create({
 /**
 * Constructor
 * @param sliderHandleId
 * @param sliderRailId
 * @param sliderCaptionId
 * @param sliderValueboxId
 * @return
 */
 initialize: function(sliderHandleId, sliderRailId, sliderCaptionId, sliderValueboxId) {
 this.sliderHandleId = sliderHandleId;
 this.sliderRailId = sliderRailId;
 this.sliderCaptionId = sliderCaptionId;
 this.sliderValuebox = $(sliderValueboxId);
 this.sliderData = {
 minimum: 1,
 maximum: 1,
 sliderValue: 1,
 step: 1, 
 range: $R(0, 100),
 values: $R(0, 100),
 onSlide: this.slideListener.bind(this),
 onChange: this.changeListener.bind(this)
 }; 
 this.regenerateSlider(1, 1, 1, 1);
 this.sliderCaption = $(sliderCaptionId);
 this.points_per_use = 1;
 this.points_currency = -1;
 this.oldRuleId = -1;
 this.oldProductPrice = -1;
 },

 /**
 * 
 */
 changeListener: function(val) {
 this.setExternalValue(val);
 feignPriceChange();
 },
 
 /**
 * 
 * @param val
 * @return
 */
 slideListener: function(val) {
 this.changeListener(val);
 },
 
 /**
 * 
 * @return
 */
 getValue: function () {
 return this.slider.value;
 },
 
 /**
 * 
 * @return
 */
 getUses: function () {
 return this.getValue();
 },
 

 /**
 * Calculates the maximum uses based on the final product price
 * and how many points the customer has.
 * @param max_uses : max uses from the rule model
 * @param points_per_use : how many points are required for each use of the rule?
 * @param cp : how many points in the currency of the rule does the customer have
 * @param pp : what is the price of the product?
 * @param pp_disp : what is the disposition in product price after the rule has been applied? 
 * @return integer
 */
 getRealMaxUses: function(max_uses, points_per_use, cp, pp, pp_disp) {
 var lowest_max_uses = max_uses;
 
 // Check max points that can be spent on product price
 // befor the price goes to 0;
 var max_pp_uses = pp/pp_disp;
 max_pp_uses = parseInt(max_pp_uses) + ( (max_pp_uses - parseInt(max_pp_uses) > 0) ? 1 : 0 ); // add remainder
 if(max_pp_uses < lowest_max_uses) {
 lowest_max_uses = max_pp_uses;
 }
 
 // Check customer points balance
 var max_cp_uses = parseInt(cp/points_per_use);
 if(max_cp_uses < lowest_max_uses) {
 lowest_max_uses = max_cp_uses;
 }
 
 return lowest_max_uses;
 },
 
 /**
 * Regenerates the slider JS model
 * @param min
 * @param max
 * @param step
 * @param initial_value
 * @return
 */
 regenerateSlider: function(min, max, step, initial_value) {
 if(this.slider != null) { 
 this.slider.dispose();
 }
 this.sliderData.minimum = min;
 this.sliderData.maximum = max;
 this.sliderData.step = step;
 this.sliderData.range = $R(min, max);
 if(step == 1) {
 this.sliderData.values = $R(min, max);
 } else {
 var vals=new Array(); vals.push(min);
 $R(min, max-1).each( function(v){ if(v%step==0){ vals.push(v+step); } } );
 this.sliderData.values = vals;
 }
 this.sliderData.sliderValue = initial_value;
 this.slider = new SmoothSlider(this.sliderHandleId, this.sliderRailId, this.sliderData);
 },
 
 
 /**
 * Sets the value in the input box and what is displayed to the user.
 * @param val
 * @return
 */
 setExternalValue: function(val) {
 this.sliderCaption.innerHTML = getPointsString(val*this.points_per_use, this.points_currency);
 this.sliderValuebox.value = this.getUses();
 },
 
 incr: function() {
 this.slider.setValue(this.slider.value+this.sliderData.step);
 },
 
 decr: function() {
 this.slider.setValue(this.slider.value-this.sliderData.step);
 },
 
 maximize: function() {
 this.slider.setValue(this.sliderData.maximum);
 },
 
 isMaxed: function() {
 return (this.getValue() == this.sliderData.maximum);
 }

});
/**
 * WDCA - Sweet Tooth
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the WDCA SWEET TOOTH POINTS AND REWARDS 
 * License, which extends the Open Software License (OSL 3.0).
 * The Sweet Tooth License is available at this URL: 
 * http://www.wdca.ca/solutions_page_sweettooth/Sweet_Tooth_License.php
 * The Open Software License is available at this URL: 
 * http://opensource.org/licenses/osl-3.0.php
 * 
 * DISCLAIMER
 * 
 * By adding to, editing, or in any way modifying this code, WDCA is 
 * not held liable for any inconsistencies or abnormalities in the 
 * behaviour of this code. 
 * By adding to, editing, or in any way modifying this code, the Licensee
 * terminates any agreement of support offered by WDCA, outlined in the 
 * provided Sweet Tooth License. 
 * Upon discovery of modified code in the process of support, the Licensee 
 * is still held accountable for any and all billable time WDCA spent 
 * during the support process.
 * WDCA does not guarantee compatibility with any other framework extension. 
 * WDCA is not responsbile for any inconsistencies or abnormalities in the
 * behaviour of this code if caused by other framework extension.
 * If you did not receive a copy of the license, please send an email to 
 * contact@wdca.ca or call 1-888-699-WDCA(9322), so we can send you a copy 
 * immediately.
 * 
 * @category [TBT]
 * @package [TBT_Rewards]
 * @copyright Copyright (c) 2009 Web Development Canada (http://www.wdca.ca)
 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
 * Sweet Tooth PointsSlider
 * @requires js/tbt/rewards/points/RedemptionSlider.js
 *
 * @category TBT
 * @package TBT_Rewards
 * @author WDCA Sweet Tooth Team <contact@wdca.ca>
 */

var PointsSlider = Class.create(RedemptionSlider, {
 /**
 * Changes the redemption rule for this points slider
 * @param rule_id
 * @return
 */
 changeRule: function(rule_id) {
 var init_value = this.getValue() ;
 if(init_value == null) init_value = 1;
 
 var uses = 1;
 if(rule_id == '') { //no rule selected
 usesContainer.hide(); 
 } else { 
 var amt = parseInt(rule_options[rule_id]['amount']);
 var curr = parseInt(rule_options[rule_id]['currency_id']);
 var max_uses = parseInt(rule_options[rule_id]['max_uses']);
 this.points_per_use = amt;
 this.points_currency = curr;
 if(max_uses == 0) {
 max_uses = parseInt(getProductPriceBeforeRedemptions())*1000 + 1;
 }
 var relevant_customer_points = customer_points ? customer_points[curr] : default_guest_points;
 var price_disposition = rule_options[rule_id]['price_disposition'];
 var product_price = getProductPriceBeforeRedemptions();
 max_uses = this.getRealMaxUses(max_uses, this.points_per_use, relevant_customer_points, product_price, price_disposition);
 if(max_uses > 1) {
 if(init_value > max_uses) {
 init_value = max_uses;
 }
 //Edited 15/01/2010 7:08:59 PM : if the next (commented) line is false, it means that there
 // is a posibility that mutliple point usages will yield the same discount:
 // For Example if points are worth $0.0017 USD, using 1-5 points will yield a $0.01 USD 
 // discount after discounts.
 //Math.round(price_disposition*Math.pow(10, optionsPrice.priceFormat.precision)) > 0

 this.regenerateSlider(1, max_uses, 1, init_value);
 this.slider.setValue(init_value);
 usesContainer.show();
 
 } else {
 this.regenerateSlider(1, 1, 1, 1);
 usesContainer.hide(); 
 }
 }

 // Reset the slider to 1 if the rule has changed.
 if(this.oldRuleId != rule_id) {
 this.slider.setValue(1);
 this.oldRuleId = rule_id;
 }
 
 }

});
