/* IMPORTANT: overture keywords flat feed must be called in the html document prior to parsing this js file. */
//# window variable... will be assigned search result data from hidden iframe
var zSr=new Object();

//# Outputter Function
//#
//# create a reference to the div where the listings will be output.
//# parse array and build string containing html of the listings
//#	assign the html to the innerHTML of the div
//#
function show_listings(keywordsDiv, resultsDiv, showHeader) {
	var resultsDiv=document.getElementById(resultsDiv);
	var keywordsDiv=document.getElementById(keywordsDiv);
	var i=6; var rank=0;
	
	var html = '';
	
	if(showHeader)
		html = '<div id="keywordsDiv" class="sponsoredcontainer"><fieldset><legend>Sponsored Results:</legend><div class="legendcontentholder">'
 
                
                 // only needed for barkerrow
	
	//netscape code cant see this zSr variable in the iframe.
	while ( i < zSr.length ) {
		rank++;
		var desc     = zSr[i++];
		var unused   = zSr[i++];
		var clickURL = zSr[i++];
		var title    = zSr[i++];
		var sitehost = zSr[i++];
		var bidded   = zSr[i++];

		html += '<div id="legendcontentcontainer">' + '<div id="legendcontentheadtext">' +  title + '</div>'+
				'<div class="legendcontentdescriptiontext">'+
		   		'<a target="_new" href="' + clickURL +'" style="font-weight: normal;">' + desc +'</a>' + '<i>(' + sitehost + ')</i>'+
		   		'</div></div>';
	}
	html+= '<p style="clear:both;"><a href="javascript:void(hide_sponsor(\''+keywordsDiv.id+'\',\''+resultsDiv.id+'\'))" class="legendcontentdescriptiontext"><br />back to sponsors list</a></p></fieldset></div>';
 	resultsDiv.innerHTML=html;
	resultsDiv.style.display="block"; 
 	keywordsDiv.style.display="none";  
}
//# Hide divs when back button is fired off.
function hide_sponsor(keywordsDiv, resultsDiv) {
	//cross browser DOM way of controlling divs.
	document.getElementById(resultsDiv).style.display="none"; 
	document.getElementById(keywordsDiv).style.display="block"; 
}
//# Request search result data and call outputer function
//#
//# 1) Hidden blank iframe gets html written to it which
//#    makes the request to get search results data object and assignes the object to a variable on the top window
//# 2) calls show_listings function
//#
function get_results(kw, keywordsDiv, resultsDiv, showHeader){
	//url='http://cmxml.overture.com/d/search/p/bet/js/us/ctxt/?Partner=bet_linkspots_ctxt&ctxtKeywords='+escape(kw);
	url='http://cm.bet.overture.com/js_flat_1_0/?config=4114744702&source=bet_linkspots_ctxt&ctxtKeywords='+ escape(kw);
	html='<html><head><script language="JavaScript" src="'+url+'"></scr'+'ipt></head><body onload="top.zSr=zSr;";></body></html>'
	//alert(top.iframe0.document);
	
	a=top.iframe0.document; // will not work in netscape.
	a.open("text/html","replace");
	a.write(html);
	a.close();
	
	// give the html time to load in the iframe, the render the divs.
	setTimeout('show_listings(\''+keywordsDiv+'\', \''+resultsDiv+'\', '+showHeader+')',600);

	//show_listings(keywordsDiv, resultsDiv, showHeader);
}