	
	function init_test() {
		globalQuery = getUnEscapedString(getSearchQuery());
		loadJSON(getSearchURL(globalQuery,'getSearch'));
		loadJSON(getRelatedSuggestionsURL(globalQuery,'getRelatedSuggestions'));
		loadJSON(getBooksURLXSLT(globalQuery,'getBooksXSLT'));
		loadJSON(getNewsURL(globalQuery,'getNews'));
		loadJSON(getImagesURL(globalQuery,'getImages'));
		loadJSON(getAnswersURL(globalQuery,'getAnswers'));
		loadJSON(getCJURL(globalQuery,'getCJ'));
//		loadJSON(getBooksURL(globalQuery,'getBooks'));
	}
	
	function loadJSON(url) {
	  var headID = document.getElementsByTagName("head")[0];         
	  var newScript = document.createElement('script');
	      newScript.type = 'text/javascript';
	      newScript.src = url;
	  headID.appendChild(newScript);
	}
	
	function getRelatedSuggestions(obj) {
		var resultset = obj.ResultSet;
		//Need to figure out what to do if there are no results
		if (resultset.Result){		
			var result = resultset.Result;
			var topic = "";
			var rootURL = location.href.split("?");
			
			for(i = 0; i < resultset.Result.length; i++){
				topic += "<a class=\"leftmenu\" href=\"" + rootURL[0] + "?q=" + escape(result[i]) + "\" title=\"" + result[i] + "\">" + result[i] + "</a> "
			}
			
			document.getElementById("divRelatedSuggestions").innerHTML = topic;			
		}
		else {
			//retry once with term from meta data			
			loadJSON(getRelatedSuggestionsURL(getMetaPageTopic(),"getRelatedSuggestionsRetry"))
		}
	}
	
	function getRelatedSuggestionsRetry(obj) {
		var resultset = obj.ResultSet;
		//Need to figure out what to do if there are no results
		if (resultset.Result){		
			var result = resultset.Result;
			var topic = "";
			var rootURL = location.href.split("?");
			
			for(i = 0; i < resultset.Result.length; i++){
				topic += "<a class=\"leftmenu\" href=\"" + rootURL[0] + "?q=" + escape(result[i]) + "\" title=\"" + result[i] + "\">" + result[i] + "</a> "
			}
			
			document.getElementById("divRelatedSuggestions").innerHTML = topic;			
		}
	}
	
	function getRelatedSuggestionsURL(query, callback) {
		return('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=n0D4of3V34G_1eW383HYCC.Kcd_Tq_DZTLLZal6ElSSPlY1w6MR1xAGWUOfG04AnMEsF1a7en.FLxYdmXPM-&output=json&query=' + escape(query) + '&callback=' + callback)
	}

	function getImages(obj) {
		var resultset = obj.ResultSet;
		//Need to figure out what to do if there are no results
		if (resultset.totalResultsReturned > 0){		
			var result = resultset.Result;
			//var thumbnail = result.Thumbnail;
			var section = "";
			
			for(i = 0; i < resultset.Result.length; i++){
				section += "<a href=\""+ result[i].ClickUrl +"\"><img src=\"" + result[i].Thumbnail.Url + "\" height=\"100px\" width=\"100px\"></a> "
			}
			
			document.getElementById("divImages").innerHTML = section;			
		}
		else{
			loadJSON(getImagesURL(getMetaPageTopic(),"getImagesRetry"));
		}
		init();
	}
		
	function getImagesRetry(obj) {
		var resultset = obj.ResultSet;
		//Need to figure out what to do if there are no results
		if (resultset.totalResultsReturned > 0){		
			var result = resultset.Result;
			//var thumbnail = result.Thumbnail;
			var section = "";
			
			for(i = 0; i < resultset.Result.length; i++){
				section += "<a href=\""+ result[i].ClickUrl +"\"><img src=\"" + result[i].Thumbnail.Url + "\" height=\"100px\" width=\"100px\"></a> "
			}
			
			document.getElementById("divImages").innerHTML = section;			
		}
		init();
	}

	function getImagesURL(query, callback) {
		return('http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=n0D4of3V34G_1eW383HYCC.Kcd_Tq_DZTLLZal6ElSSPlY1w6MR1xAGWUOfG04AnMEsF1a7en.FLxYdmXPM-&results=4&output=json&query=' + escape(query) + '&callback=' + callback)
	}
	
	function getMetaPageTopic(){
		if (document.getElementsByName) {
			var metaArray = document.getElementsByName('metaPageTopic');
			for (var i=0; i<metaArray.length; i++) {
			return (metaArray[i].content)
			}
		}
		init();
	}

	function getAnswers(obj) {
		var all = obj.all;
		//Need to figure out what to do if there are no results
		//alert(all.count);
		if (all.count > 0){		

			var rootURL = location.href.split("?");
		
			var question = all.questions;
			//var thumbnail = result.Thumbnail;
			var section = "";
			
			for(i = 0; i < all.count; i++){
				section += "<p><a href=\""+ question[i].Link +"\">"+ question[i].Subject + "</a></p><p><strong>Q:  </strong>"+ Left(question[i].Content,5000) + "</p><p><strong>A:  </strong>"+ Left(question[i].ChosenAnswer,5000) +"<br /></p> "
//				section += "<p><a href=\""+ rootURL[0] + "?q=" + escape(question[i].Subject) +"\">"+ question[i].Subject + "</a></p><p><strong>Q:  </strong>"+ Left(question[i].Content,500) + "</p><p><strong>A:  </strong>"+ Left(question[i].ChosenAnswer,500) +"<br /></p> "
			}
			//alert(section);
			document.getElementById("divAnswers").innerHTML = section;			
		}
		else{
			loadJSON(getAnswersURL(getMetaPageTopic(),"getAnswersRetry"));
		}
		init();
	}
		
	function getAnswersRetry(obj) {
		var all = obj.all;
		//Need to figure out what to do if there are no results
		
		if (all.count > 0){		

			var rootURL = location.href.split("?");
		
			var question = all.questions;
			//var thumbnail = result.Thumbnail;
			var section = "";
			
			for(i = 0; i < all.count; i++){
				section += "<p><a href=\""+ question[i].Link +"\">"+ question[i].Subject + "</a></p><p><strong>Q:  </strong>"+ Left(question[i].Content,5000) + "</p><p><strong>A:  </strong>"+ Left(question[i].ChosenAnswer,5000) +"<br /></p> "
//				section += "<p><a href=\""+ rootURL[0] + "?q=" + escape(question[i].Subject) +"\">"+ question[i].Subject + "</a></p><p><strong>Q:  </strong>"+ Left(question[i].Content,500) + "</p><p><strong>A:  </strong>"+ Left(question[i].ChosenAnswer,500) +"<br /></p> "
			}
			//alert(section);
			document.getElementById("divAnswers").innerHTML = section;			
		}
		init();
	}
	
	function getAnswersURL(query, callback) {
		return('http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=n0D4of3V34G_1eW383HYCC.Kcd_Tq_DZTLLZal6ElSSPlY1w6MR1xAGWUOfG04AnMEsF1a7en.FLxYdmXPM-&results=2&output=json&query=' + escape(query) + '&callback=' + callback)
	}
	
	function getNews(obj) {
		var resultset = obj.ResultSet;
		//Need to figure out what to do if there are no results
		if (resultset.totalResultsReturned > 0){		
			var result = resultset.Result;
			//var thumbnail = result.Thumbnail;
			var section = "";
			
			for(i = 0; i < resultset.Result.length; i++){
				section += "<div class=\"boxitem\"><a href=\""+ result[i].Url +"\">" + result[i].Title + "</a> "+ result[i].NewsSource +"<br /></div> "
			}
			
			document.getElementById("divNews").innerHTML = section;			
		}
		else{
			loadJSON(getNewsURL(getMetaPageTopic(),"getNewsRetry"));
		}
		init();
	}
		
	function getNewsRetry(obj) {
		var resultset = obj.ResultSet;
		//Need to figure out what to do if there are no results
		if (resultset.totalResultsReturned > 0){		
			var result = resultset.Result;
			//var thumbnail = result.Thumbnail;
			var section = "";
			
			for(i = 0; i < resultset.Result.length; i++){
				section += "<div class=\"boxitem\"><a href=\""+ result[i].Url +"\">" + result[i].Title + "</a> "+ result[i].NewsSource +"<br /></div> "
			}
			
			document.getElementById("divNews").innerHTML = section;			
		}
		init();
	}

	function getNewsURL(query, callback) {
		return('http://search.yahooapis.com/NewsSearchService/V1/newsSearch?appid=n0D4of3V34G_1eW383HYCC.Kcd_Tq_DZTLLZal6ElSSPlY1w6MR1xAGWUOfG04AnMEsF1a7en.FLxYdmXPM-&results=3&output=json&query=' + escape(query) + '&callback=' + callback)
	}
	
	function getSearch(obj) {
		var resultset = obj.ResultSet;
		//Need to figure out what to do if there are no results
		if (resultset.totalResultsReturned > 0){		
			var result = resultset.Result;
			//var thumbnail = result.Thumbnail;
			var section = "";
			var url = "";
			
			for(i = 0; i < resultset.Result.length; i++){
				url = cleanURL(result[i].Url)
				section += "<h1><a href = \"" + result[i].ClickUrl + "\" class=\"homeheadlink\">" + result[i].Title + "</a></h1><p>" + result[i].Summary + "</p><span class=\"hometeaser_category\">" + url + "</span><br /><br /> "
			}
			
			document.getElementById("divSearch").innerHTML = section;			
		}
		else{
			loadJSON(getNewsURL(getMetaPageTopic(),"getSearchRetry"));
		}
		init();
	}
		
	function getSearchRetry(obj) {
		var resultset = obj.ResultSet;
		//Need to figure out what to do if there are no results
		if (resultset.totalResultsReturned > 0){		
			var result = resultset.Result;
			//var thumbnail = result.Thumbnail;
			var section = "";
			
			for(i = 0; i < resultset.Result.length; i++){
				section += "<h1><a href = \"" + result[i].ClickUrl + "\" class=\"homeheadlink\">" + result[i].Title + "</a></h1><p>" + result[i].Summary + "</p><span class=\"hometeaser_category\">" + result[i].Url + "</span><br /><br /> "
			}
			
			document.getElementById("divSearch").innerHTML = section;			
		}
		init();
	}

	function getSearchURL(query, callback) {
		return('http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=n0D4of3V34G_1eW383HYCC.Kcd_Tq_DZTLLZal6ElSSPlY1w6MR1xAGWUOfG04AnMEsF1a7en.FLxYdmXPM-&results=3&output=json&query=' + escape(query) + '&callback=' + callback)
	}

	function getBooksXSLT(obj) {
		var itemset = obj.ItemSet;
		//Need to figure out what to do if there are no results
		//alert(itemset.TotalResults);
		if (itemset.TotalResults > 0){		
			var item = itemset.Item;
			//var thumbnail = result.Thumbnail;
			var leftsection = "";
			var rightsection = "";
			
			for(i = 0; i < item.length - 1; i++){
			
				//put first 5 books on left, next 5 on right
				if(i < 5) {			
					leftsection += "<a class=\"leftmenu\" href=\"" + item[i].url + "\" title=\"" + item[i].title + "\">" + item[i].title + "</a>"
				}
				else {
					rightsection += "<a href=\"" + item[i].url + "\">" + item[i].title + "</a><br /><br />"
				}
			}
			
			document.getElementById("divBooksLeft").innerHTML = leftsection;			
			document.getElementById("divBooksRight").innerHTML = rightsection;			
		}
		else{
			loadJSON(getBooksURLXSLT(getMetaPageTopic(),"getBooksRetryXSLT"));
		}
		init();
	}
		
	function getBooksRetryXSLT(obj) {
		var itemset = obj.ItemSet;
		//Need to figure out what to do if there are no results
		if (itemset.TotalResults > 0){		
			var item = itemset.Item;
			var leftsection = "";
			var rightsection = "";
			
			for(i = 0; i < item.length - 1; i++){
			
				//put first 5 books on left, next 5 on right
				if(i < 5) {			
					leftsection += "<a class=\"leftmenu\" href=\"" + item[i].url + "\" title=\"" + item[i].title + "\">" + item[i].title + "</a>"
				}
				else {
					rightsection += "<a href=\"" + item[i].url + "\">" + item[i].title + "</a><br /><br />"
				}
			}
			
			document.getElementById("divBooksLeft").innerHTML = leftsection;			
			document.getElementById("divBooksRight").innerHTML = rightsection;			
		}
		init();
	}

	function getBooksURLXSLT(query, callback) {
//		return('http://xml-us.amznxslt.com/onca/xml?Service=AWSECommerceService&SubscriptionId=13Y9VH9AW3B6WBG8MN82&AssociateTag=topicriver-20&Operation=ItemSearch&Style=' + escape('http://infomadesimple.com/_mactest/ajsonCategorySearch.xsl') + '&ContentType=text/javascript&ItemPage=1&SearchIndex=Books&ResponseGroup=Small,Offers&MerchantId=ATVPDKIKX0DER&Availability=Available&Condition=All&Keywords=' + escape(query) + '&CallBack=' + callback)
		return('http://xml-us.amznxslt.com/onca/xml?Service=AWSECommerceService&SubscriptionId=13Y9VH9AW3B6WBG8MN82&AssociateTag=topicriver-20&Operation=ItemSearch&Style=' + escape('http://topicriver.com/_bin/xslt/ajsonCategorySearch.xsl') + '&ContentType=text/javascript&ItemPage=1&SearchIndex=Books&ResponseGroup=Small,Offers&MerchantId=ATVPDKIKX0DER&Availability=Available&Condition=All&Keywords=' + escape(query) + '&CallBack=' + callback)
	
	}
		
	function getBooks(obj) {
		var itemset = obj.Items;
		//Need to figure out what to do if there are no results
		if (itemset.TotalResults > 0){		
			var item = itemset.Item;
			//var thumbnail = result.Thumbnail;
			var leftsection = "";
			var rightsection = "";
			for(i = 0; i < item.length; i++){
			
				//put first 5 books on left, next 5 on right
				if(i < 5) {			
					leftsection += "<a class=\"leftmenu\" href=\"" + item[i].DetailPageURL + "\" title=\"" + item[i].ItemAttributes.Title + "\">" + item[i].ItemAttributes.Title + "</a>"
				}
				else {
					rightsection += "<a href=\"" + item[i].DetailPageURL + "\">" + item[i].ItemAttributes.Title + "</a><br /><br />"
				}
			}
			
			document.getElementById("divBooksLeft").innerHTML = leftsection;			
			document.getElementById("divBooksRight").innerHTML = rightsection;			
		}
		else{
			loadJSON(getBooksURL(getMetaPageTopic(),"getBooksRetry"));
		}
		init();
	}
		
	function getBooksRetry(obj) {
		var itemset = obj.Items;
		//Need to figure out what to do if there are no results
		//alert(itemset.TotalResults);
		if (itemset.TotalResults > 0){		
			var item = itemset.Item;
			//var thumbnail = result.Thumbnail;
			var leftsection = "";
			var rightsection = "";
			
			for(i = 0; i < item.length; i++){
			
				//put first 5 books on left, next 5 on right
				if(i < 5) {			
					leftsection += "<a class=\"leftmenu\" href=\"" + item[i].DetailPageURL + "\" title=\"" + item[i].ItemAttributes.Title + "\">" + item[i].ItemAttributes.Title + "</a>"
				}
				else {
					rightsection += "<a href=\"" + item[i].DetailPageURL + "\">" + item[i].ItemAttributes.Title + "</a><br /><br />"
				}
			}
			
			document.getElementById("divBooksLeft").innerHTML = leftsection;			
			document.getElementById("divBooksRight").innerHTML = rightsection;			
		}
		init();
	}

	function getBooksURL(query, callback) {
		return('http://topicriver.com/_bin/php/amazonbooks.php?Keywords=' + escape(query) + '&callback=' + callback)
//		return('http://infomadesimple.com/_mactest/amazonBooks.php?Keywords=' + escape(query) + '&callback=' + callback)
	}
		
	function getCJ(obj) {
		var out = obj.out;
		if (out.count > 0){		
			var links = out.links;
			var linkdetail = links.LinkDetail;
			//var thumbnail = result.Thumbnail;
			var section = "";
			var prevLinkID = "";
			var j = 1
			for(i = 0; i < linkdetail.length; i++){
				if(linkdetail[i].linkId != prevLinkID) {
					if(linkdetail[i].linkCodeHTML != null) {
					  section += "<p>" + linkdetail[i].linkCodeHTML + "</p>"
					  prevLinkID = linkdetail[i].linkId
					  j++;
					  if(j>5) { //get only 5 results
					 	 break;
					  }
					}
				}
			}
			
			document.getElementById("divCJ").innerHTML = section;			
		}
		else{
			loadJSON(getCJURL(getMetaPageTopic(),"getCJRetry"));
		}
		init();
	}
	
	function getCJRetry(obj) {
		var out = obj.out;

		if (out.count > 0){		
			var links = out.links;
			var linkdetail = links.LinkDetail;
			//var thumbnail = result.Thumbnail;
			var section = "";
			var prevLinkID = "";
			var j = 1
			for(i = 0; i < linkdetail.length; i++){
				if(linkdetail[i].linkId != prevLinkID) {
					if(linkdetail[i].linkCodeHTML != null) {
					  section += "<p>" + linkdetail[i].linkCodeHTML + "</p>"
					  prevLinkID = linkdetail[i].linkId
					  j++;
					  if(j>5) { //get only 5 results
					 	 break;
					  }
					}
				}
			}
			
			document.getElementById("divCJ").innerHTML = section;			
		}
		init();
	}

	function getCJURL(query, callback) {
//	alert("in getCJURL");
//		alert('http://topicriver.com/_bin/php/cjlinks.php?query=' + escape(query) + '&callback=' + callback + '&linkType=Text%20Link&maxResults=20');
//		return('http://infomadesimple.com/_mactest/cjlinks.php?query=' + escape(query) + '&callback=' + callback + '&linkType=Text%20Link&maxResults=20')
		return('http://topicriver.com/_bin/php/cjlinks.php?query=' + escape(query) + '&callback=' + callback + '&linkType=Text%20Link&maxResults=20')
	}

	function Left(str, n){
		if (n <= 0)
		    return "";
		else if (n > String(str).length)
		    return str;
		else
		    return String(str).substring(0,n);
	}
	
	function Right(str, n){
	    if (n <= 0)
	       return "";
	    else if (n > String(str).length)
	       return str;
	    else {
	       var iLen = String(str).length;
	       return String(str).substring(iLen, iLen - n);
	    }
	}
	
	function cleanURL(url) {
		var rootURL = url.split("/");
		url = rootURL[2];
		return url;
	}

	function getFormattedDate() {
		var m_names = new Array("January", "February", "March", 
		"April", "May", "June", "July", "August", "September", 
		"October", "November", "December");
		
		var d = new Date();
		var curr_date = d.getDate();
		var sup = "";
		if (curr_date == 1 || curr_date == 21 || curr_date ==31)
		   {
		   sup = "st";
		   }
		else if (curr_date == 2 || curr_date == 22)
		   {
		   sup = "nd";
		   }
		else if (curr_date == 3 || curr_date == 23)
		   {
		   sup = "rd";
		   }
		else
		   {
		   sup = "th";
		   }
		
		var curr_month = d.getMonth();
		var curr_year = d.getFullYear();
		
		return(curr_date + "<SUP>" + sup + "</SUP> " 
		+ m_names[curr_month] + " " + curr_year);	
	}
	
	function dispDate(dateVal) {
		DaystoAdd=dateVal
		TodaysDate = new Date();
		TodaysDay = new Array('Sunday', 'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday');
		TodaysMonth = new Array('January', 'February', 'March','April', 'May','June', 'July', 'August', 'September','October', 'November', 'December');
		DaysinMonth = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
		function LeapYearTest (Year) {
		if (((Year % 400)==0) || (((Year % 100)!=0) && (Year % 4)==0)) {
		return true;
		}
		else {
		return false;
		}
		}
		CurrentYear = TodaysDate.getYear();
		if (CurrentYear < 2000) 
		CurrentYear = CurrentYear + 1900;
		currentMonth = TodaysDate.getMonth();
		DayOffset = TodaysDate.getDay();
		currentDay = TodaysDate.getDate();
		month = TodaysMonth[currentMonth];
		if (month == 'February') {
		if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) {
		DaysinMonth[1] = 29;
		}
		else {
		DaysinMonth[1] = 28;
		}
		}
		days = DaysinMonth[currentMonth];
		currentDay += DaystoAdd;
		if (currentDay > days) {
		if (currentMonth == 11) {
		currentMonth = 0;
		month = TodaysMonth[currentMonth];
		CurrentYear = CurrentYear + 1
		}
		else {
		month =
		TodaysMonth[currentMonth+1];
		}
		currentDay = currentDay - days;
		}
		DayOffset += DaystoAdd;
		function offsettheDate (offsetCurrentDay) {
		if (offsetCurrentDay > 6) {
		offsetCurrentDay -= 6;
		DayOffset = TodaysDay[offsetCurrentDay-1];
		offsettheDate(offsetCurrentDay-1);
		}
		else {
		DayOffset = TodaysDay[offsetCurrentDay];
		return true;
		}
		}
		offsettheDate(DayOffset);TheDate = DayOffset + ', ';
		TheDate += month + ' ';
		TheDate += currentDay + ', '; 
		if (CurrentYear<100) CurrentYear="19" + CurrentYear;
		TheDate += CurrentYear;
		document.write(' '+TheDate);
	}	
			

