/* Last Updated August 14, 2009
 * baynote_policyLoaded
 * 
 * Once the policy has loaded, check to see if the guide
 * is showing.  If not, show the default guide.
 */
function baynote_policyLoaded()
{
   if (bnPolicy.get("guide","ok"))
   {
      if(document.getElementById("bn_baynote_recs")) 
		(document.getElementById("bn_baynote_recs")).style.display = "block";
	  if(document.getElementById("bn_non_baynote_recs"))
		(document.getElementById("bn_non_baynote_recs")).style.display = "none";
   } else {
	  if(document.getElementById("bn_non_baynote_recs"))
		(document.getElementById("bn_non_baynote_recs")).style.display = "block";
      if(document.getElementById("bn_baynote_recs")) 
		(document.getElementById("bn_baynote_recs")).style.display = "none";
   }
}


function baynote_showGuide(guideType) {
	
	var bn_location_href = window.location.href;
	if(baynote_tag.url)
		bn_location_href = baynote_tag.url;
     if (bn_location_href.indexOf("https://") == 0) {
        baynote_tag.server = "https://adventure-www.baynote.net";
     } else {
		baynote_tag.server = "http://adventure-www.baynote.net";
     }
	
	//for test environment urls (convert to production urls)
	if(bn_location_href.match(/(https?)(:\/\/.*)(hmhd.*)/)){
		baynote_tag.url = bn_location_href.replace(/(https?)(:\/\/.*)(hmhd.*)/,  "$1://www.$3");
	}	 

	baynote_tag.customerId="adventure";
	baynote_tag.code="www";
	baynote_tag.type="guide";				
	baynote_tag.guide= guideType;
	bnResourceManager.waitForResource("Policy", "baynote_policyLoaded()");
	var query = baynote_getSearchTerm();
		if (query != "")
	baynote_tag.query = query; 
	baynote_tag.show();
}

function baynote_getSearchTerm() {
  var searchTerm = baynote_getUrlParam("keywords");  
  return unescape(searchTerm);
}

// Helper function to get the value of a parameter from URL. 
function baynote_getUrlParam(name) {

  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var pageUrl = baynote_getPageUrl();
  var results = regex.exec( pageUrl );
  if( results == null )
    return "";
  else
    return results[1];
}

function baynote_getPageUrl() {
	var pageUrl = baynote_tag.url; 
	if ( (typeof(pageUrl) == "undefined") || (pageUrl == null) || (pageUrl == ""))
	  pageUrl = window.location.href;
	return pageUrl;
}