/*requires prototype.js*/
var Store = Class.create();
Store.prototype = {
	initialize : function(callback) {
		this.callback = callback;
	},
	
	getStores : function(zip,distance,country) {
		var HW = new StoreAjaxProvider(this.callback);		
		return HW.getStores(zip,distance,country);
	}		
}

function isArray(obj) 
{
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function getStores(zip,distance,country)
{	
	var store = new Store();	
	var aResults = store.getStores(zip,distance,country);
	if (isArray(aResults)) {
		var numResults = aResults.length;
		
		var code_array = [];		
		
		if (numResults > 0) {
			code_array.push("<div width=\"400\"><table border=\"0\" class=\"full_search\" cellpadding=\"1\" cellspacing=\"1\">");
			code_array.push("<tr><td class=\"search_title\">Store</td><td class=\"search_title\">Contact</td><td class=\"search_title\">Distance</td></tr>");
			
			for (i=0;i<=numResults-1;i++) {
				code_array.push("<tr>");
				code_array.push("<td><b>"+aResults[i].name+"</b><br /><div style=\"color: #666666; padding-top: 3px; padding-bottom: 10px; font-style: italic; font-size: 10px; \">"+aResults[i].street_address+"<br />"+aResults[i].city+" ,"+aResults[i].state+"<br />"+aResults[i].zipcode+"</div></td>");
				code_array.push("<td nowrap style=\"font-style: italic; color: #666666; \">"+aResults[i].telephone+"</td>");
				code_array.push("<td style=\"font-style: italic; color: #666666; \">"+aResults[i].dist+"</td>");
//				code_array.push("<td>"+aResults[i].dist+" ["+aResults[i].dir+"]</td>");
				code_array.push("</tr>");
			}
			
			code_array.push("</table></div>");
			$('store_list').innerHTML = code_array.join('\n');
		} else {
			$('store_list').innerHTML = "No stores were found within this distance.";
		}
	} else {
		$('store_list').innerHTML = aResults;
	}
				
}


	