/*
Author:	Chris Winberry
Date:	07/05/2002
Desc:	Dynamically builds IFRAME/ILAYER tags for external partner sites to display BN navigation
*/
var jsIframe_js = true; /* For checking if the script has loaded */
var jsIframe_isNS4 = document.layers && (parseInt(navigator.appVersion) >= 4) && (parseInt(navigator.appVersion) <= 5);

function jsIframe_buildIframe (which, querystring, env) {
	var isBNU = (env == "bnu");
	var isStoreLocator = (env == "storelocator");
	var width;
	var height = 0;
	var src;
	var name;
	var ilayer;
	var iframe;
	var hasSourceid;

	if (isBNU) { env = "web"; }
	
	if (isStoreLocator){ 
		if (querystring.toString().toLowerCase().indexOf("btob") > -1) {
			env = "btob";
		}
		else {
			env = "web";
		}
	}
	
	hasSourceid = (querystring.toString().toLowerCase().indexOf("sourceid=") >= 0);
	if (querystring.toString().toLowerCase().indexOf("btob") > -1) {
		env = "btob";
		}

	switch (which) {
		case "jsIframe_nav_top_noqsearch" :
			querystring = "qs=n" + ((querystring.length > 0) ? "&" + querystring : "");
			height = -2;
		case "jsIframe_nav_top" :
			if (isBNU) {
				querystring = "bar=bnu" + ((querystring.length > 0) ? "&" + querystring : "");
				}
			width	= "100%";
			if (isBNU) {
				height += 166;
				}
			else if (isStoreLocator) {
				height += 180;
				}
			else if (env == "web") {
				height += 190;
				}
			else if (hasSourceid) {
				height += 190;
				}
			else {
				height += 190;
				}
			src		= "http://" + ((env == "web") ? "www.barnesandnoble.com" : "btob.barnesandnoble.com") + "/include/iframe/navbariframe.asp?" + querystring;
			name	= "navbar";
			ilayer	= false;
			iframe	= "ALIGN=\"CENTER\" FRAMEBORDER=\"0\" MARGINHEIGHT=\"0\" MARGINWIDTH=\"0\" SCROLLING=\"NO\"";
			break;
		case "jsIframe_nav_bot" :
			width	= "100%";
			height	= 142;
			src		= "http://" + ((env == "web") ? "www.barnesandnoble.com" : "btob.barnesandnoble.com") + "/include/iframe/bottomlinksiframe.asp?" + querystring;
			name	= "bottombar";
			ilayer	= false;
			iframe	= "ALIGN=\"CENTER\" FRAMEBORDER=\"0\" MARGINHEIGHT=\"0\" MARGINWIDTH=\"0\" SCROLLING=\"NO\"";
			break;
		case "jsIframe_nav_promo_www" :
		case "jsIframe_nav_promo_btob":
		case "jsIframe_nav_promo_gift":
		case "jsIframe_nav_promo_fiction":
		case "jsIframe_nav_promo_kids":
		case "jsIframe_nav_promo_webnonfict":
		case "jsIframe_nav_promo_btobnonfict" :
			if (jsIframe_isNS4) { return(true); }
			width	= 470;
			height	= 89;
			name	= "extra";
			ilayer	= false;
			iframe	= "ALIGN=\"LEFT\" FRAMEBORDER=\"0\" MARGINHEIGHT=\"0\" MARGINWIDTH=\"0\" SCROLLING=\"NO\"";
			switch (which) {
				case "jsIframe_nav_promo_www" :
				case "jsIframe_nav_promo_btob" :
				case "jsIframe_nav_promo_gift" :
				case "jsIframe_nav_promo_fiction" :
				case "jsIframe_nav_promo_kids" :
				case "jsIframe_nav_promo_webnonfict" :
				case "jsIframe_nav_promo_btobnonfict" :
					// Temporary, until ASP fix goes in -CW
					if (env == "web") {
						src = "http://" + ((env == "web") ? "www.barnesandnoble.com" : "btob.barnesandnoble.com") + "/promo/iframe/webpromo.asp?" + querystring;
						}
					else {
						src = "http://" + ((env == "web") ? "www.barnesandnoble.com" : "btob.barnesandnoble.com") + "/promo/iframe/btobpromo.asp?" + querystring;
						}
					break;
				}
			break;
		default :
			return(false);
		}

	return(_jsIframe_renderIframe(width, height, src, name, ilayer, iframe));
	}

function _jsIframe_renderIframe (width, height, src, name, ilayerAttrib, iframeAttrib) {
	document.write(
		"<ILAYER WIDTH=\"" + width + "\" HEIGHT=\"" + height + "\" SRC=\"" + src + "\"" +
		" NAME=\"" + name + "\"" + (ilayerAttrib ? (" " + ilayerAttrib) : "") + ">" +
		"<IFRAME WIDTH=\"" + width + "\" HEIGHT=\"" + height + "\" SRC=\"" + src + "\"" +
		" NAME=\"" + name + "\"" + (iframeAttrib ? (" " + iframeAttrib) : "") + ">" +
		"</IFRAME></ILAYER>"
		);
		
	return(true);
	}
