function ebayHandler() {
	
	var me = this;

	this.results = new Array();

	this.paginateResults = function(page) {

		if(typeof(page) == 'string')
			page = parseInt(page);

		var cont = document.getElementById('ebayResults');
			cont.style.display = 'block';
		var table = document.getElementById('collectibles_specific_value_table');

		if(table.tBodies.length == 0)
			table.appendChild(document.createElement('TBODY'));
		var tbody = table.tBodies[0];
		
		while(tbody.rows.length > 0)
			tbody.deleteRow(0);

		var pages = Math.ceil(me.results.length/10);
		var startFrom = (page-1)*10;
		if(me.results.length > (startFrom+10))
			var end = (startFrom+10);
		else
			var end = me.results.length;
		
		for(var i = startFrom; i < end; i++) {
			
			var row = tbody.insertRow(-1);
			
			var imageCell = row.insertCell(-1);
				imageCell.className = 'collectibles_specific_value_pic';
			if(me.results[i].getAttribute('image') != '') {
				var image = document.createElement('IMG');
					image.src = unescape(me.results[i].getAttribute('image'));
				imageCell.appendChild(image);
			} else
				imageCell.appendChild(document.createTextNode('\u00a0'));
				
			var nameCell = row.insertCell(-1);
				nameCell.className = 'collectibles_specific_value_item';
			var nameLink = document.createElement('A');
				if(me.results[i].getAttribute('url').indexOf('rover.ebay') == -1)
					nameLink.href = 'http://rover.ebay.com/rover/1/711-1751-2978-71/1?campid=5335816071&toolid=10013&mpre=' + me.results[i].getAttribute('url');
				else
					nameLink.href = unescape(me.results[i].getAttribute('url'));
				nameLink.setAttribute('target', '_blank');
				nameLink.appendChild(document.createTextNode(me.results[i].getAttribute('title')));
				nameCell.appendChild(nameLink);
				
			var dateCell = row.insertCell(-1);
				dateCell.className = 'collectibles_specific_value_price';
				dateCell.appendChild(document.createTextNode(me.results[i].getAttribute('endTime')));
				
			var valueCell = row.insertCell(-1);
				valueCell.className = 'collectibles_specific_value_price';
				valueCell.appendChild(document.createTextNode(me.results[i].getAttribute('price')));
				
			if(typeof(me.readonly) == 'undefined' || !me.readonly) {
				var selectCell = row.insertCell(-1);
					selectCell.className = 'collectibles_specific_value_select';
				var selectRadio = document.createElement('INPUT');
					selectRadio.setAttribute('type', 'radio');
					selectRadio.name = 'value';
					selectRadio.id = 'ebayId_'+me.results[i].getAttribute('id');
					if(typeof(me.isGuest) != 'undefined') {
						selectRadio.disabled = true;
						selectRadio.setAttribute('disabled', true);
					}
					selectRadio.onclick = function() {
						var tmp = this;
						while(tmp.nodeName != 'TR')
							tmp = tmp.parentNode;
						if(typeof(me.valueSelected) != 'undefined')
							me.valueSelected(tmp.cells[3].innerHTML, tmp.cells[1].innerHTML, this.id.split('_')[1]);
					}
					selectCell.appendChild(selectRadio);	
			}
		}
			
		if(table.getElementsByTagName('TFOOT').length == 0) {
			var tfoot = document.createElement('TFOOT');
			var row = tfoot.insertRow(-1);
			if(!row) {
				row = document.createElement('TR');
				tfoot.appendChild(row);
			}
			var cell = row.insertCell(-1);
			if(!cell) {
				cell = document.createElement('TD');
				row.appendChild(cell);
			}
			cell.setAttribute('colspan', 5);
			cell.colSpan = 5;
			table.appendChild(tfoot);
		}
		var tfoot = table.getElementsByTagName('TFOOT')[0].rows[0].cells[0];
		while(tfoot.childNodes.length > 0)
			tfoot.removeChild(tfoot.firstChild);
		
		if(me.results.length >= 10) {

			if(typeof(me.isGuest) != 'undefined') {
				tfoot.appendChild(document.createTextNode('You must Log In to save the value.'));	
			}
			var pagination = document.createElement('DIV');
				pagination.className = 'collectibles_specific_details_value_pagination';
				tfoot.appendChild(pagination);

			var totals = document.createElement('DIV');
				totals.appendChild(document.createTextNode(me.results.length + ' Collectibles found | Listing ' + page + ' of ' + pages));
				pagination.appendChild(totals);
				
			var startPage = 1;
			if(page < 5)
				startPage = 1;
			else if((page - 5) > 1)
				startPage = (page - 4);
			
			var endPage = pages;
			if(page < 5 && pages > 5)
				endPage = 5;
			else if((page + 5) < pages)
				endPage = (page + 4);
							
			for(var i = startPage; i <= endPage; i++) {
				if(i == page) {
					var el = document.createElement('STRONG');
						el.className = 'active';
						el.appendChild(document.createTextNode(i));
					pagination.appendChild(el);
				} else {
					var a = document.createElement('A');
						a.href = 'javascript:void(0)';
						a.id = 'page_' + i;							
						a.onclick = function() {
							ebay.paginateResults(this.id.split('_')[1]);
							//ebay.search(document.getElementById('collectibles_specific_value_search_input').value, this.id.split('_')[1]);
						};
						a.appendChild(document.createTextNode(i));
						pagination.appendChild(a);						
				}
			}
		} else {

		}

	}
	
	this.search = function(keywords, page, startDate, endDate) {

		if(keywords == '')
			return;
		
		var cont = document.getElementById('ebayResults');
			cont.style.display = 'block';
		var table = document.getElementById('collectibles_specific_value_table');
			
		if(!page)
			page = 1;
			
		var params = new Array();
			params['keywords'] = keywords;
			params['page'] = page;
		if(typeof(startDate) != 'undefined')
			params['startDate'] = startDate;
		if(typeof(endDate) != 'undefined')
			params['endDate'] = endDate;

		var type = document.getElementById('chkSearchType');
		if(type)
			params['type'] = type.checked;
			
			
		doRequest('http://www.collectionstation.com/ebay/search/post', function(res) {
			if(!res.responseXML) {
				alert(res.responseText);
				return;
			}
			
			var doc = res.responseXML.documentElement;
			var results = doc.getElementsByTagName('result');
			if(table.tBodies.length == 0)
				table.appendChild(document.createElement('TBODY'));
			var tbody = table.tBodies[0];
			
			while(tbody.rows.length > 0)
				tbody.deleteRow(0);
				
			var totalResults = parseInt(doc.getAttribute('totalResults'));
			var currentPage = parseInt(doc.getAttribute('currentPage'));
			var pageResults = results.length; 
			var pages = parseInt(doc.getAttribute('pages'));

			var row = tbody.insertRow(-1);
			var cell = row.insertCell(-1);
				cell.setAttribute('colspan', 5);
				cell.colSpan = 5;
				cell.id = 'dont_see';
				cell.style.textAlign = 'center';
				cell.appendChild(document.createTextNode('Don\'t see your collectible listed? Try editing the collectible name and search again.'));
			
			if(typeof(results[0]) != 'undefined') {
				while(tbody.rows.length > 0)
					tbody.deleteRow(0);

				me.results = results;			
				me.paginateResults(1);
			}
			
			//cont.style.display = 'block';
			
		}, params);
		
	}
	
}