// (c) AFS 2008

if(!this.AFSRequests){function AFSRequests(cookieName,limit){function save(){d=new Date();d.addYears(1);AFSCookies.setJSONCookie(cookieName,{d:data,l:limit},undefined,d);}
var data=AFSCookies.getJSONCookie(cookieName);if((typeof(data)=='object')&&(typeof(data.d)=='object')&&AFSBase.isset(data.d.length)&&(typeof(data.l)=='number')){limit=data.l;data=data.d;}
else{data=[];if(!AFSBase.isset(limit)){limit=10;}
save();}
this.add=function(label,date,count,queryString){var entry={label:label,date:date.getISOString(),count:count,queryString:queryString};for(var i=0;i<this.count();++i){var current=data[i];if(current.queryString==entry.queryString){data.splice(i,1);--i;}}
data.unshift(entry);while(this.count()>this.getLimit()){data.pop();}
save();callListeners();return this.count();}
this.get=function(index){if((index<0)||(index>=this.count())){return undefined;}
else{return new function(entry){var d=new Date();d.setISOString(entry.date);this.getLabel=function(){return entry.label;}
this.getDate=function(){return d;}
this.getCount=function(){return entry.count;}
this.getQueryString=function(){return entry.queryString;}}(data[index]);}}
this.remove=function(index){data.splice(index,1);save();callListeners();return this.count();}
this.clear=function(){data=[];save();callListeners();return this.count();}
this.count=function(){return data.length;}
this.iterator=function(){return new function(list){var index=0;this.hasNext=function(){return(index<list.count());}
this.next=function(){return list.get(index++);}
this.remove=function(){list.remove(index-1);}}(this);}
this.getLimit=function(){return limit;}
var listeners=[];this.addListener=function(func){if(AFSBase.isset(func)&&(typeof(func)=='function')){this.removeListener(func);listeners[listeners.length]=func;}}
this.removeListener=function(func){for(var i=0;i<listeners.length;++i){if(listeners[i]==func){listeners.splice(i,1);--i;}}}
function callListeners(){for(var i=0;i<listeners.length;++i){try{listeners[i].call(this);}
catch(e){window.setTimeout(function(){throw e},1);}}}};}