try{document.execCommand("BackgroundImageCache",false,true)}catch(err){}var Rating=function(a,b){Rating.Notifier.call(this);this.init(a,b)};Rating.KEY_ENTER=13;Rating.KEY_LEFT=37;Rating.KEY_RIGHT=39;Rating.Notifier=function(){this.observers=[];this.suppressNotifications=0};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};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}}};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)}}}}}};Rating.Notifier.prototype.enableNotifications=function(){if(--this.suppressNotifications<0){this.suppressNotifications=0;Spry.Effect.Rating.showError("Unbalanced enableNotifications() call!\n")}};Rating.Notifier.prototype.disableNotifications=function(){++this.suppressNotifications};Rating.prototype=new Rating.Notifier();Rating.prototype.constructor=Rating;Rating.prototype.init=function(b,c){$this=this;$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=Rating.KEY_LEFT;$this.moveNextKeyCode=Rating.KEY_RIGHT;$this.doRatingKeyCode=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;Rating.setOptions($this,c,true);$this.stars=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()};Rating.prototype.getState=function(){return this.currentState};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)};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}};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++){Rating.addEventListener(this.event_handlers[c][0],this.event_handlers[c][1],this.event_handlers[c][2],false)}Rating.addEventListener(window,"unload",this.destroy,false)};Rating.prototype.getValue=function(){return this.ratingValue};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)}}}};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)};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)};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()}document.getElementById(this.triggerId).trigger({rating:b.starValue})}catch(a){this.showError(a)}this.notifyObservers("onPostRate")};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 Rating.stopEvent(d)};Rating.prototype.updateCounter=function(a){if(this.counter){this.ratingCounter=Rating.getElementsByClassName(this.element,this.counterClass)[0];this.ratingCounter.innerHTML="["+a+"/"+this.stars.length+"]"}};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=Rating.loadURL(this.method,this.newSaveUrl,true,function(d){a.onLoadSuccess(d,c)},b)};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)}}};Rating.prototype.onLoadError=function(a){this.notifyObservers("onServerError",a)};Rating.prototype.getElement=function(a){if(a&&typeof a=="string"){return document.getElementById(a)}return a};Rating.prototype.destroy=function(){if(this.event_handlers){for(var a=0;a<this.event_handlers.length;a++){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){}};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};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"),"")};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])}};Rating.prototype.showError=function(a){alert("Rating ERROR: "+a)};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){}};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){}};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};Rating.getElementsByClassName=function(a,d){var c=[];var e=a.getElementsByTagName("*");for(var b=0;b<e.length;b++){if(Rating.hasClassName(e[b],d)){c.push(e[b])}}return c};Rating.stopEvent=function(a){if(a.preventDefault){a.preventDefault()}else{a.returnValue=false}if(a.stopPropagation){a.stopPropagation()}else{a.cancelBubble=true}return false};Rating.setOptions=function(d,c,a){if(!c){return}for(var b in c){if(a&&c[b]==undefined){continue}d[b]=c[b]}};Rating.msProgIDs=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0"];Rating.createXMLHttpRequest=function(){var a=null;try{if(window.ActiveXObject){while(!a&&Rating.msProgIDs.length){try{a=new ActiveXObject(Rating.msProgIDs[0])}catch(b){a=null}if(!a){Rating.msProgIDs.splice(0,1)}}}if(!a&&window.XMLHttpRequest){a=new XMLHttpRequest()}}catch(b){a=null}if(!a){Rating.prototype.showError("Failed to create an XMLHttpRequest object!")}return a};Rating.loadURL=function(i,b,c,h,f){var d=new Rating.loadURL.Request();d.method=i;d.url=b;d.async=c;d.successCallback=h;Rating.setOptions(d,f);try{d.xhRequest=Rating.createXMLHttpRequest();if(!d.xhRequest){return null}if(d.async){d.xhRequest.onreadystatechange=function(){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){Rating.loadURL.callback(d)}}catch(g){if(d.errorCallback){d.errorCallback(d)}else{Rating.prototype.showError("Exception caught while loading "+b+": "+g)}d=null}return d};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)}}};Rating.loadURL.Request=function(){var b=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={}};Rating.loadURL.Request.props=["method","url","async","username","password","postData","successCallback","errorCallback","headers","userData","xhRequest"];
