// JavaScript Document

function ajaxSearchShop(c,s,z,r,o) {
	var ajaxSS = ajaxObj;
	var frm = document.getElementById('searchShopForm');
	
	var c = c || frm.s_city.value; // city
	var s = s || frm.s_state[frm.s_state.selectedIndex].value; // state
	var z = z || frm.s_zip.value; // zip
	var r = r || frm.s_within[frm.s_within.selectedIndex].value; // range
	var o = o || 0; // offset
	
	var url = 'phpGets/searchShop.php?s_city='+encodeURIComponent(c)+'&s_state='+encodeURIComponent(s)+'&s_zip='+encodeURIComponent(z)+'&s_within='+encodeURIComponent(r)+'&offset='+encodeURIComponent(o);
	
	
	ajaxSS.doGet(url,showSearchShopResults);
	
}

function showSearchShopResults(guts) {
	var ajaxAbove = document.getElementById('ajaxAbove');
	var searchFrm = document.getElementById('searchShopForm');
	while(searchFrm.nodeName != 'TABLE') {
		if(searchFrm.nodeName == 'BODY') {
			break;
		}
		searchFrm = searchFrm.parentNode;
	}
	if(searchFrm.id == '') {
		searchFrm.id = 'searchFrm';
	}
	var ajaxBelow = document.getElementById('ajaxBelow');
	var btnShow = document.createElement('INPUT');
	    btnShow.id = 'btnShow';
		btnShow.type = "button";
		btnShow.value = "Redefine Search";
		btnShow.setAttribute("onclick","swapElements(document.getElementById('"+searchFrm.id+"'),document.getElementById('btnShow'));");
		btnShow.onclick = function(){swapElements(document.getElementById(searchFrm.id),document.getElementById('btnShow'));};
		btnShow.style.cssText = "margin:1em 0;padding:5px 10px; height:auto; width:auto; border:1px solid #1f54bc; color:#333; background-color:#fff;";

	// empty ajaxAbove
	while(ajaxAbove.childNodes.length > 0) {
		ajaxAbove.removeChild(ajaxAbove.childNodes[0]);
	}
	// add btn to ajaxAbove
	ajaxAbove.appendChild(btnShow);
	// hide form
	swapElements(btnShow,searchFrm);
	// show results
	ajaxBelow.innerHTML = guts;
}

