// e.js - Show ebay products from search results rss feed

// Version: 1.1
// Revisions:
//	1.1: Forced overall ad block height to be number of ads shown multiplied by a table
//	row height factor set by new constant e_tabRowHeight. Thus, for now anyway, the
//	e_adHeight value is not used, even though it may be set explicitly in the web
//	page (in the JavaScript) that's showing the ebay products.
//	This change coincides with a change made in the main ebay RSS products listing
//	engine script in which the CSS was modified so that each row of the products
//	table is set to this same height value. 5/3/09


// -- defaults --
var e_adEngine = 'http://www.medianowhosting.com/cgi-bin/ebay/ebayprods.cgi';
var e_npDefault = 5; // Max num prods to show
var e_adWidthDefault = 500;
var e_adHeightDefault = 500;
var e_adFrameBorder = 0;
var e_skDefault; // search key (search str query used as key in rss db)
// -- -- -- -- -- -- -- -- -- --

// -- constants --
var e_tabRowHeight = 105;
// -- -- -- -- -- -- -- -- -- --

var w = window; 
var e_pUrl = w.location;

if ( w.e_np == null ) {
	e_np = e_npDefault;
}

if (w.e_adWidth == null) {
  e_adWidth = e_adWidthDefault;
}

if (w.e_adHeight == null) {
  e_adHeight = e_adHeightDefault;
}

if (w.e_sk == null) {
  e_sk = e_skDefault;
}

// Get site topic and append to engine url
if ( w.e_site == null ) {
	w.e_site = 'none';
}
e_adEngine += '?s=' + w.e_site;

// Parent page url; append it to ad engine URL; set the 'u' parameter in the URL
if ( e_pUrl != null ) {
	var urlStr = new String(e_pUrl);
	var rootPageName;
	if ( e_sk == null )
		rootPageName = urlRootFileName(urlStr);
	else
		rootPageName = e_sk;

	// var urlParamVal = e_pUrl.replace(/ /g, '%20');
	e_adEngine += '&u=' + rootPageName;
	//alert(e_adEngine);
}

e_adEngine += '&np=' + e_np;

//alert(e_adEngine);
doIframe();


function dq(v){ /* double quote */
	return v!=null?'"'+v+'"':'""'
}
function doIframe() {
	e_adHeight = e_np * e_tabRowHeight;
	document.write('<ifr' + 'ame' +
				' name="e_adsFrame"' +
				' width=' + dq(e_adWidth) +
				' height=' + dq(e_adHeight) + 
				' frameborder=' + dq(e_adFrameBorder) +
				' src=' + dq(e_adEngine) + 
				' marginwidth="0"' +
				' marginheight="0"' +
				' vspace="0"' +
				' hspace="0"' +
				' allowtransparency="true"' +
				' scrolling="no"></ifr' + 'ame>');
}

// Takes string argument representing URL; returns root filename portion.
// e.g. Input str: http://www.example.com/mypage.html --> Returns: mypage
function urlRootFileName(str) { 
	var slash = '/';
	if (str.match(/\\/)) { 
		slash = '\\';
	} 
	return str.substring(str.lastIndexOf(slash) + 1, str.lastIndexOf('.')) 
} 