ATCO = function() {	
	this.index_keys = '';
	this.xsshost = '';
	this.keyprefix = '';

	this.idlist = function () {
		
		var spans = document.getElementsByTagName("SPAN");
		var zerostat = false;
		var ids = new Array();
		for(i = 0; i < spans.length; i++) {
			var at = spans[i].getAttribute('id');
			if(at && at.indexOf("atco_") == 0) {
				var cid = at.substr(5, at.length);
				cid = cid.replace(/,/g, '');
				ids[ids.length] = cid;
				/*if(zerostat == false) {
					this.index_keys += 'cid=' + escape(cid);
					zerostat = true;
				} else {
					this.index_keys += ',' + escape(cid); 										
				}*/
			}
		}
		ids = ids.sort();
		var zerostat = false;		
		for(i = 0; i < ids.length; i++) {
			var cid = ids[i];
			if(zerostat == false) {
				this.index_keys += 'cid=' + escape(cid);
				zerostat = true;
			} else {
				this.index_keys += ',' + escape(cid); 										
			}
		}
	}
			
	// init index count...
	this.load = function(init_ob) {
		//alert('wa');
		this.idlist();
		this.xsshost = init_ob.xsshost;
		this.keyprefix = init_ob.keyprefix;
		this.xssCounts();
	}
	
	this.xssCounts = function() {		
		var script = document.createElement('script');
		var url = this.xsshost + '/IndexCount?prefix=' + this.keyprefix + '&' + this.index_keys;
		//alert(url);
		script.src = url;
		document.getElementsByTagName('head')[0].appendChild(script);				
	}
	
	this.updateCounts = function(xss_ob) {
		var ccounts = xss_ob.page_counts;
		for(i = 0; i < ccounts.length; i++) {
			var pagekey = 'atco_' + ccounts[i].pagekey.replace(/\w+\-/g, '');
			//alert(pagekey);
			var cspan = document.getElementById(pagekey);
			if(ccounts[i].count >= 1) {
				cspan.innerHTML = ccounts[i].count;
			} else {
				cspan.innerHTML = '0';								
			}
		}
	}
}
