﻿try{document.execCommand("BackgroundImageCache",false,true)}catch(err){}var Spry;if(!Spry){Spry={}}if(!Spry.Widget){Spry.Widget={}}Spry.Widget.Rating=function(a,b){Spry.Widget.Rating.Notifier.call(this);this.init(a,b)};Spry.Widget.Rating.KEY_ENTER=13;Spry.Widget.Rating.KEY_LEFT=37;Spry.Widget.Rating.KEY_RIGHT=39;Spry.Widget.Rating.Notifier=function(){this.observers=[];this.suppressNotifications=0};Spry.Widget.Rating.Notifier.prototype.addObserver=function(b){if(!b){return}var a=this.observers.length;for(var c=0;c<a;c++){if(this.observers[c]==b){return}}this.observers[a]=b};Spry.Widget.Rating.Notifier.prototype.removeObserver=function(a){if(!a){return}for(var b=0;b<this.observers.length;b++){if(this.observers[b]==a){this.observers.splice(b,1);break}}};Spry.Widget.Rating.Notifier.prototype.notifyObservers=function(b,d){if(!b){return}if(!this.suppressNotifications){var a=this.observers.length;for(var c=0;c<a;c++){var e=this.observers[c];if(e){if(typeof e=="function"){e(b,this,d)}else{if(e[b]){e[b](this,d)}}}}}};Spry.Widget.Rating.Notifier.prototype.enableNotifications=function(){if(--this.suppressNotifications<0){this.suppressNotifications=0;Spry.Effect.Rating.showError("Unbalanced enableNotifications() call!\n")}};Spry.Widget.Rating.Notifier.prototype.disableNotifications=function(){++this.suppressNotifications};Spry.Widget.Rating.prototype=new Spry.Widget.Rating.Notifier();Spry.Widget.Rating.prototype.constructor=Spry.Widget.Rating;Spry.Widget.Rating.prototype.init=function(b,c){this.element=this.getElement(b);this.containerInitialClass="ratingInitialState";this.containerReadOnlyClass="ratingReadOnlyState";this.containerRatedClass="ratingRatedState";this.readOnlyErrClass="ratingReadOnlyErrState";this.starDefaultClass="ratingButton";this.starFullClass="ratingFull";this.starHalfClass="ratingHalf";this.starEmptyClass="ratingEmpty";this.starHoverClass="ratingHover";this.counterClass="ratingCounter";this.movePrevKeyCode=Spry.Widget.Rating.KEY_LEFT;this.moveNextKeyCode=Spry.Widget.Rating.KEY_RIGHT;this.doRatingKeyCode=Spry.Widget.Rating.KEY_ENTER;this.afterRating="currentValue";this.enableKeyboardNavigation=true;this.allowMultipleRating=true;this.method="GET";this.postData=null;this.ratingValueElement=null;this.ratingValue=0;this.saveUrl=null;this.hasFocus=null;this.rateHandler=null;Spry.Widget.Rating.setOptions(this,c,true);this.stars=Spry.Widget.Rating.getElementsByClassName(this.element,this.starDefaultClass);if(this.stars.length==0){this.showError("No star elements in the container "+(typeof b=="string"?b:""));return}for(var a=0;a<this.stars.length;a++){this.stars[a].starValue=a+1}if(this.saveUrl&&this.postData){this.method="POST"}if(this.ratingValueElement){this.ratingValueElement=this.getElement(this.ratingValueElement);this.ratingValue=parseFloat(this.ratingValueElement.getAttribute("value"));if(isNaN(this.ratingValue)){this.ratingValue=0}}if(this.stars.length<2){this.showError("The rating widget must have at least two stars!");return}if(this.ratingValue>this.stars.length){this.showError("Rating initial value must not exceed the number of stars!");return}if(this.counter){this.updateCounter(this.ratingValue)}this.setValue(this.ratingValue);if(this.readOnly){this.setState("readonly")}else{this.setState("initial")}this.attachBehaviors()};Spry.Widget.Rating.prototype.getState=function(){return this.currentState};Spry.Widget.Rating.prototype.setState=function(b){var a;this.currentState=b;this.removeClassName(this.element,this.containerInitialClass);this.removeClassName(this.element,this.containerReadOnlyClass);this.removeClassName(this.element,this.containerRatedClass);switch(b){case"readonly":a=this.containerReadOnlyClass;break;case"rated":a=this.containerRatedClass;if(!this.allowMultipleRating){this.addClassName(this.element,this.containerReadOnlyClass);b="readonly"}break;default:b="initial";a=this.containerInitialClass;break}this.addClassName(this.element,a)};Spry.Widget.Rating.prototype.removeMessage=function(c,a){switch(c){case this.readOnlyErrClass:case this.containerRatedClass:if(!a){this.removeClassName(this.element,c)}else{var b=this;setTimeout(function(){b.removeClassName(b.element,c);if(c==b.containerRatedClass&&b.containerRatedClass!="readonly"){b.addClassName(b.element,b.containerInitialClass)}},a)}break}};Spry.Widget.Rating.prototype.attachBehaviors=function(){this.event_handlers=[];for(var b=0;b<this.stars.length;b++){var a=this;var d=this.stars[b];this.event_handlers.push([d,"click",function(f){a.onRate(f||event)}]);if(!this.readOnly){this.event_handlers.push([d,"mouseover",function(f){a.onFocus(f||event)}]);this.event_handlers.push([d,"mouseout",function(f){a.onBlur(f||event)}])}this.enableKeyboardNavigation=(this.enableKeyboardNavigation&&d.attributes.getNamedItem("tabindex"));if(this.enableKeyboardNavigation&&!this.readOnly){this.event_handlers.push([d,"focus",function(f){a.onFocus(f||event)}]);this.event_handlers.push([d,"blur",function(f){a.onBlur(f||event)}]);this.event_handlers.push([d,"keydown",function(f){a.keyDown(f||event)}])}}for(var c=0;c<this.event_handlers.length;c++){Spry.Widget.Rating.addEventListener(this.event_handlers[c][0],this.event_handlers[c][1],this.event_handlers[c][2],false)}Spry.Widget.Rating.addEventListener(window,"unload",this.destroy,false)};Spry.Widget.Rating.prototype.getValue=function(){return this.ratingValue};Spry.Widget.Rating.prototype.setValue=function(b){if(this.ratingValueElement){this.ratingValueElement.value=b}this.ratingValue=b;this.updateCounter(this.ratingValue);for(var a=0;a<this.stars.length;a++){this.resetClasses(this.stars[a]);if(b>=1){this.addClassName(this.stars[a],this.starFullClass);b--}else{if(b>=0.5&&b<1){this.addClassName(this.stars[a],this.starHalfClass);b=0}else{this.addClassName(this.stars[a],this.starEmptyClass)}}}};Spry.Widget.Rating.prototype.onFocus=function(c){this.hasFocus=true;if(this.currentState==="readonly"||(this.currentState==="rated"&&!this.allowMultipleRating)){return}var b=(c.target)?c.target:c.srcElement;for(var a=0;a<=b.starValue;a++){this.addClassName(this.stars[a-1],this.starHoverClass)}this.updateCounter(a-1)};Spry.Widget.Rating.prototype.onBlur=function(c){this.hasFocus=false;if(this.currentState==="readonly"||(this.currentState==="rated"&&!this.allowMultipleRating)){return}var b=(c.target)?c.target:c.srcElement;for(var a=0;a<=b.starValue;a++){this.removeClassName(this.stars[a-1],this.starHoverClass)}this.updateCounter(this.ratingValue)};Spry.Widget.Rating.prototype.onRate=function(c){this.notifyObservers("onPreRate");if(this.currentState=="rated"&&!this.allowMultipleRating){return}if(this.currentState=="readonly"){this.removeClassName(this.element,this.containerRatedClass);this.addClassName(this.element,this.readOnlyErrClass);return}this.setState("rated");var b=(c.target)?c.target:c.srcElement;this.setValue(b.starValue);try{if(this.saveUrl){this.saveUrlHandler(b.starValue)}if(typeof this.rateHandler=="function"){this.rateHandler()}}catch(a){this.showError(a)}this.notifyObservers("onPostRate")};Spry.Widget.Rating.prototype.keyDown=function(d){if(this.currentState=="rated"&&!this.allowMultipleRating){return}var b=d.keyCode;if(!this.hasFocus||(b!=this.movePrevKeyCode&&b!=this.moveNextKeyCode&&b!=this.doRatingKeyCode)){return true}var c=(d.target)?d.target:d.srcElement;var a=c.starValue-1;switch(b){case this.movePrevKeyCode:if(a>0){this.stars[a-1].focus()}break;case this.moveNextKeyCode:if(a<this.stars.length-1){this.stars[a+1].focus()}break;case this.doRatingKeyCode:this.onRate(d);break;default:break}return Spry.Widget.Rating.stopEvent(d)};Spry.Widget.Rating.prototype.updateCounter=function(a){if(this.counter){this.ratingCounter=Spry.Widget.Rating.getElementsByClassName(this.element,this.counterClass)[0];this.ratingCounter.innerHTML="["+a+"/"+this.stars.length+"]"}};Spry.Widget.Rating.prototype.saveUrlHandler=function(c){this.newSaveUrl=this.saveUrl.replace(/@@ratingValue@@/,c);var b={};if(this.postData){this.newPostData=this.postData.replace(/@@ratingValue@@/,c);b.headers={"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};b.postData=this.newPostData}var a=this;b.errorCallback=function(d){a.onLoadError(d)};this.pendingRequest=Spry.Widget.Rating.loadURL(this.method,this.newSaveUrl,true,function(d){a.onLoadSuccess(d,c)},b)};Spry.Widget.Rating.prototype.onLoadSuccess=function(b,c){this.notifyObservers("onServerUpdate",b);if(this.afterRating=="serverValue"){var a=parseFloat(b.xhRequest.responseText);if(!isNaN(a)){this.setValue(a)}}};Spry.Widget.Rating.prototype.onLoadError=function(a){this.notifyObservers("onServerError",a)};Spry.Widget.Rating.prototype.getElement=function(a){if(a&&typeof a=="string"){return document.getElementById(a)}return a};Spry.Widget.Rating.prototype.destroy=function(){if(this.event_handlers){for(var a=0;a<this.event_handlers.length;a++){Spry.Widget.Rating.removeEventListener(this.event_handlers[a][0],this.event_handlers[a][1],this.event_handlers[a][2],false)}}try{delete this.element}catch(b){}try{delete this.stars}catch(b){}try{delete this.counter}catch(b){}try{delete this.ratingValueElement}catch(b){}try{delete this.event_handlers}catch(b){}};Spry.Widget.Rating.prototype.addClassName=function(b,a){if(!b||!a||(b.className&&b.className.search(new RegExp("\\b"+a+"\\b"))!=-1)){return}b.className+=(b.className?" ":"")+a};Spry.Widget.Rating.prototype.removeClassName=function(b,a){if(!b||!a||(b.className&&b.className.search(new RegExp("\\b"+a+"\\b"))==-1)){return}b.className=b.className.replace(new RegExp("\\s*\\b"+a+"\\b","g"),"")};Spry.Widget.Rating.prototype.resetClasses=function(c){var a=[this.starFullClass,this.starHalfClass,this.starEmptyClass,this.starHoverClass];for(var b=0;b<a.length;b++){this.removeClassName(c,a[b])}};Spry.Widget.Rating.prototype.showError=function(a){alert("Spry.Widget.Rating ERROR: "+a)};Spry.Widget.Rating.addEventListener=function(c,b,d,a){try{if(c.addEventListener){c.addEventListener(b,d,a)}else{if(c.attachEvent){c.attachEvent("on"+b,d,a)}}}catch(f){}};Spry.Widget.Rating.removeEventListener=function(c,b,d,a){try{if(c.removeEventListener){c.removeEventListener(b,d,a)}else{if(c.detachEvent){c.detachEvent("on"+b,d,a)}}}catch(f){}};Spry.Widget.Rating.hasClassName=function(b,a){if(typeof element=="string"){element=document.getElementById(element)}if(!b||!a||!b.className||b.className.search(new RegExp("\\b"+a+"\\b"))==-1){return false}return true};Spry.Widget.Rating.getElementsByClassName=function(a,d){var c=[];var e=a.getElementsByTagName("*");for(var b=0;b<e.length;b++){if(Spry.Widget.Rating.hasClassName(e[b],d)){c.push(e[b])}}return c};Spry.Widget.Rating.stopEvent=function(a){if(a.preventDefault){a.preventDefault()}else{a.returnValue=false}if(a.stopPropagation){a.stopPropagation()}else{a.cancelBubble=true}return false};Spry.Widget.Rating.setOptions=function(d,c,a){if(!c){return}for(var b in c){if(a&&c[b]==undefined){continue}d[b]=c[b]}};Spry.Widget.Rating.msProgIDs=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0"];Spry.Widget.Rating.createXMLHttpRequest=function(){var a=null;try{if(window.ActiveXObject){while(!a&&Spry.Widget.Rating.msProgIDs.length){try{a=new ActiveXObject(Spry.Widget.Rating.msProgIDs[0])}catch(b){a=null}if(!a){Spry.Widget.Rating.msProgIDs.splice(0,1)}}}if(!a&&window.XMLHttpRequest){a=new XMLHttpRequest()}}catch(b){a=null}if(!a){Spry.Widget.Rating.prototype.showError("Failed to create an XMLHttpRequest object!")}return a};Spry.Widget.Rating.loadURL=function(i,b,c,h,f){var d=new Spry.Widget.Rating.loadURL.Request();d.method=i;d.url=b;d.async=c;d.successCallback=h;Spry.Widget.Rating.setOptions(d,f);try{d.xhRequest=Spry.Widget.Rating.createXMLHttpRequest();if(!d.xhRequest){return null}if(d.async){d.xhRequest.onreadystatechange=function(){Spry.Widget.Rating.loadURL.callback(d)}}d.xhRequest.open(d.method,d.url,d.async,d.username,d.password);if(d.headers){for(var a in d.headers){d.xhRequest.setRequestHeader(a,d.headers[a])}}d.xhRequest.send(d.postData);if(!d.async){Spry.Widget.Rating.loadURL.callback(d)}}catch(g){if(d.errorCallback){d.errorCallback(d)}else{Spry.Widget.Rating.prototype.showError("Exception caught while loading "+b+": "+g)}d=null}return d};Spry.Widget.Rating.loadURL.callback=function(a){if(!a||a.xhRequest.readyState!=4){return}if(a.successCallback&&(a.xhRequest.status==200||a.xhRequest.status==0)){a.successCallback(a)}else{if(a.errorCallback){a.errorCallback(a)}}};Spry.Widget.Rating.loadURL.Request=function(){var b=Spry.Widget.Rating.loadURL.Request.props;var c=b.length;for(var a=0;a<c;a++){this[b[a]]=null}this.method="GET";this.async=true;this.headers={}};Spry.Widget.Rating.loadURL.Request.props=["method","url","async","username","password","postData","successCallback","errorCallback","headers","userData","xhRequest"];