/* Updated Sept 29, 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()
{

var bn_abRegex = /[0-9]+\.[A-Z]&g&s/g;
var bn_abCaseARegex = /[0-9]+\.A&g&s/g;
if (bnPolicy.get("inf","cd").match(bn_abRegex))
{
	if (bnPolicy.get("inf","cd").match(bn_abCaseARegex)){		
      if(document.getElementById("bn_baynote_recs")) 
		(document.getElementById("bn_baynote_recs")).style.display = "block";
	  if(document.getElementById("bn_baynote_recs2")) 
		(document.getElementById("bn_baynote_recs2")).style.display = "none";
	  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 = "none";
	  if(document.getElementById("bn_baynote_recs2")) 
		(document.getElementById("bn_baynote_recs2")).style.display = "block";
      if(document.getElementById("bn_baynote_recs")) 
		(document.getElementById("bn_baynote_recs")).style.display = "block";
	}
} else {
   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://urbanout-www.baynote.net";
     } else {
       baynote_tag.server = "http://urbanout-www.baynote.net";
     }
	 
	//for test environment urls (convert to production urls)
	if(bn_location_href.match(/(https?:\/\/.*)(\/urban\/catalog\/productdetail\.jsp)(.*)/)){
		baynote_tag.url = bn_location_href.replace(/(https?:\/\/.*)(\/urban\/catalog\/productdetail\.jsp)(.*)/,  "http://www.urbanoutfitters.com$2$3");
	}
	
	baynote_tag.customerId="urbanout";
	baynote_tag.code="www";
	baynote_tag.type="guide";				
	baynote_tag.guide= guideType;
	bnResourceManager.waitForResource("Policy", "baynote_policyLoaded()");
	baynote_tag.show();
}

function baynote_getSearchTerm() {
  var searchTerm = baynote_getUrlParam("q");  
  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;
}