// dealsalert.js
// (c) 2008, Android Technologies, Inc.
// NOTE(1): All iframes that will be set to ad server content need to have the className "ati_adserver".
// NOTE: Properties to be passed on to the adserver should be stored in attributes belonging to the
//			target IFRAME TAG (HTML) with the same name as the eBay Editor Kit variable, but prefixed
//			with "ati_".  For example: eksize -> <IFRAME NAME="ati_adserver ID="ati_adserver" ati_eksize="1"></IFRAME>

/*
	EXAMPLE:
	
	var gAdServerProperties = new Array();
	gATI_AdServerProperties.seeds = "dogs|cats|birds";
*/

// Courtesy of Hunlock.com.
// Object.prototype.getElementsByClass = function (searchClass, tag) 
// Changed Object prototype assignation to vanilla function that
//  references the document object directly instead of using "this".
// IE was rejecting the previous style.
function getElementsByClass(searchClass, tag)
{      
   var returnArray = [];
   tag = tag || '*';
   // var els = this.getElementsByTagName(tag);
   var els = document.getElementsByTagName(tag);
   var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
   for (var i = 0; i < els.length; i++) {
      if ( pattern.test(els[i].className) ) {
         returnArray.push(els[i]);
      }
   }
   return returnArray;
} // function getElementsByClass(searchClass, tag)

// Find all the ad server iframes and set their SRC attribute to our ad server.
// var adServerTargets = document.getElementsByClass("ati_adserver", "iframe");
var adServerTargets = getElementsByClass("ati_adserver", "iframe");

if (adServerTargets.length > 0)
{
	var fullUrl =
		"http://www.wordblogger.com/service/get-ebay-ad-code.php?url="
		+ escape(document.location.href);
		
	for (var i = 0; i < adServerTargets.length; i++)
	{
		var iframe = adServerTargets[i];
		
		// Now pass all of the IFRAME's attribute that have the "ati_" previx on to the 
		//  Ad Server.
		for (var j = 0; j < iframe.attributes.length; j++)
		{
			var attrName = iframe.attributes[j].nodeName;
			
			if (attrName.substr(0, 4) == "ati_")
			{
				attrVal = iframe.attributes[j].nodeValue;
				fullUrl +=
					"&" + attrName.substr(4) + "=" + attrVal;
			}
		} // for(j)
		
		// Set the iframe's SRC property to the fully qualified ad server call.
		iframe.src = fullUrl;
	} // for(i)
} // if (adServerTargets.length > 0)
