<div style="height:300px;">
	<div>
		<label><?=__("Select Pharmacy to View/Edit")?></label>
	</div>
	<div id="pharmacySelectAutoCompleteDiv"></div>
	<input style="margin-left: 30px;" type="button" value="Add Pharmacy Record" onclick="addPharmacy();"/>
	<br style="clear:all;"/>
	<div id="pharmacyEditTabContainer" style="height:400px;width:100%;"></div>
</div>
<script>
var pharmacyId = 0;
function addPharmacy() {
	adminPharmacyTabbarAttachContent("tab_pharmacyDetails","<?=$this->baseUrl?>/admin-pharmacies.raw/add");
	pharmacyEditTabbar.setTabActive("tab_pharmacyDetails");
	localRefreshCurrentTab();
}

var pscb = dijit.byId("pharmacySelectAutoCompleteDiv");
if (pscb != undefined) { 
	pscb.destroyRecursive();
	pscb = null;
}
var psac = new dojox.data.QueryReadStore({url:"<?=$this->baseUrl?>/admin-pharmacies/auto-complete",requestMethod:"get"},"pharmacySelectAutoComplete");
pscb = new dijit.form.FilteringSelect({name:"pharmacySelectAutoCompleteId",autocomplete:true,store:psac},"pharmacySelectAutoCompleteDiv");
pscb.validate = function () {
	return true;
};
dojo.connect(pscb,"onChange","loadPharmacy");
function loadPharmacy(id) {
	if (id) {
		pharmacyId = id;
		onPharmacyTabbarClick("tab_pharmacyDetails");
		pharmacyEditTabbar.setTabActive("tab_pharmacyDetails");
		localRefreshCurrentTab();
	}
}

function localRefreshCurrentTab() {
	pharmacyEditTabbar.forceLoad(pharmacyEditTabbar.getActiveTab());        
}

pharmacyEditTabbar = new dhtmlXTabBar("pharmacyEditTabContainer","top","25");
pharmacyEditTabbar.setImagePath("<?=$this->baseUrl?>/img/");
pharmacyEditTabbar.setStyle("silver");
pharmacyEditTabbar.setSkinColors("#FFFFFF,#FFFACD");
pharmacyEditTabbar.addTab("tab_pharmacyDetails","<?=__('Pharmacy Details')?>","145");
pharmacyEditTabbar.addTab("tab_pharmacyePrescribeDetails","<?=__('ePrescribe Details')?>","145");
pharmacyEditTabbar.addTab("tab_pharmacyHealthCloudLoadDetails","<?=__('Load Pharmacies')?>","145");

function adminPharmacyTabbarAttachContent(id,url) {
	dojo.xhrGet({
		url: url,
		handleAs: "text",
		load: function(data,ioArgs) {
			pharmacyEditTabbar.setContentHTML(id,data);
			return data;
		},
		error: function(response, ioArgs) {
			console.error("HTTP status code: ", ioArgs.xhr.status);
			return response;
		}
	});
}

function onPharmacyTabbarClick(id) {
	switch(id) {
		case "tab_pharmacyDetails":
			adminPharmacyTabbarAttachContent(id,"<?=$this->baseUrl?>/admin-pharmacies.raw/edit?pharmacyId="+pharmacyId);
			break;
		case "tab_pharmacyePrescribeDetails":
			adminPharmacyTabbarAttachContent(id,"<?=$this->baseUrl?>/admin-eprescribe.raw/edit-pharmacy?pharmacyId="+pharmacyId);
			break;
		case "tab_pharmacyHealthCloudLoadDetails":
			adminPharmacyTabbarAttachContent(id,"<?=$this->baseUrl?>/admin-pharmacies.raw/healthcloud-sync");
			break;
		default:
			break;
	}
	return true;
}
pharmacyEditTabbar.setOnSelectHandler(onPharmacyTabbarClick);
pharmacyEditTabbar.setTabActive("tab_pharmacyDetails");
</script>
