window.YEXT_SERVER_URL = 'http://chiropractorphonebook.com/';
window.jsonYextLoadScript = function(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e); 
}
window.loadYextCssFile = function(url)
{
	var headID = document.getElementsByTagName("head")[0];
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = url;
	cssNode.media = 'screen';
	headID.appendChild(cssNode);
}


window.onYextDataLoaded = function(data)
{
	document.getElementById('chiropractorphonebook-widget').innerHTML =  data;
	var links = document.getElementById('chiropractorphonebook-widget').getElementsByTagName('a');
 	for(var i=0;links!=null && i<links.length;i++)
	{
		if(links[i].className=='yext-paginator-link')
		  links[i].onclick = function(){ 
		    jsonYextLoadScript(this.href);
		    return false;
		  }
		
	}
}
window.getSearchParams = function()
{
	var pageName = location.href;
	//set the filename as search parameters(without file extension)
	var ind = pageName.indexOf('?');
	if(ind>0)
	 pageName  = pageName.substring(0,ind-1);
	ind = pageName.lastIndexOf('.');
	if(ind>0)
	 pageName  = pageName.substring(0,ind);
	ind = pageName.lastIndexOf('/');
	if(ind>0)
	 pageName  = pageName.substring(ind+1);
 
	return 'search=custom:'+pageName;
}


document.write('<div id="chiropractorphonebook-widget">Loading data...</div>');
loadYextCssFile(YEXT_SERVER_URL+"chiropractic/data-widget.css");
jsonYextLoadScript(YEXT_SERVER_URL+"chiropractic/?format=export_jsonp&"+getSearchParams());

 

