/* javascript component called 11222009-03:31AM with id(s) stud_testing */

// ensures same ad can't display in two slots of the same size
// ensures removing ad from the array also removes any ads in the same grouping
function removeFromAdList(alist, html) {
	// parse html for grouping value from the id attribute of the img tag
	var imgTag = html.substr(html.indexOf("<img"));
	var groupMatch="";
	// if there's an id in this img tag, pull the value into group
	if (imgTag.indexOf('id=') != -1) {
		groupMatch = imgTag.substr(imgTag.indexOf('id='));
		// groupMatch represents the banner ad grouping defined by the business
		groupMatch = groupMatch.substr(0,groupMatch.indexOf('"',4)+1);
	}
	// define a clean array to temporarily hold all ads that can be used elsewhere on the page
	var tmp = new Array();
	var j = 0;
	for (var i = 0; i < alist.length; i++) {
		// if this array index doesn't match the html coming in AND there is a non-blank group and that group isn't in this array index
		if (alist[i] != html && (groupMatch == '' || alist[i].indexOf(groupMatch) == -1)) { tmp[j] = alist[i] ; j++ }
	}
	return tmp;
}

// gets a random member of the array for that slot
function getAds(pos) {
	var ad_ar = eval('window.' + pos);
	if (ad_ar && ad_ar.length > 0) {
		var rndNum = Math.floor(Math.random() * ad_ar.length);
		var html = ad_ar[rndNum];
		document.write(html);
		//trackAdImpression(html);
		if (pos == 'top' || pos == 'bottom') {
			if (window.bottom) {
				bottom = removeFromAdList(bottom, html);
			} else if (window.bottom_left) {
				bottom_left = removeFromAdList(bottom_left, html);
				bottom_right = removeFromAdList(bottom_right, html);
			}
		} else if (pos == 'bottom_left') {
			bottom_right = removeFromAdList(bottom_right, html);
		}
	}
}

// gets 2 random and different ads from an array and writes them out
function getDoubleAds(pos) {
	var ad_ar = eval('window.' + pos);
	if (ad_ar && ad_ar.length > 0) {
		document.write('<div id="ads">');
		var rndNum = Math.floor(Math.random() * ad_ar.length);
		document.write(ad_ar[rndNum]);
		//trackAdImpression(ad_ar[rndNum]);
		ad_ar = removeFromAdList(ad_ar, ad_ar[rndNum]);
		// is there anything left in the array to write a second ad
		if (ad_ar.length > 0) {
			rndNum = Math.floor(Math.random() * ad_ar.length);
			document.write(ad_ar[rndNum]);
			//trackAdImpression(ad_ar[rndNum]);
		}
		document.write('</div>');
	}
}


// gets a random member of the array (with getAds) and displays within HTML
function getAdsHTML(pos) {
	// prevent from breaking if not called correctly
	// calling with 'bottom' might mean one bottom array or two arrays for bottom_left and bottom_right
	if (pos == 'bottom') {
		if (!window.bottom && !window.bottom_left) { return }
	} else {
		if (!eval('window.' + pos)) { return }
	}

	if (pos == 'left') {
		getAds(pos);
	}
	else if (pos == 'bottom') {
		document.write('' +
			'<table cellpadding="0" cellspacing="0" border="0">' +
			'<tr><td><img src="/images/null_1x1.gif" width="16" height="1" border="0" alt=""/></td>' +
			'<td>' );
		if (window.bottom) { getAds('bottom'); } else { getAds('bottom_left'); }
		document.write( '</td>' +
			'<td><img src="/images/null_1x1.gif" width="4" height="1" border="0" alt=""/></td>' +
			'<td>' );
		if (window.bottom) { getAds('bottom'); } else { getAds('bottom_right'); }
		document.write( '</td></tr></table>' );
	}
	else {
		getAds(pos);
	}
}

var left = new Array();

 
left[0] = '<a href="http://apps.collegeboard.com/ut/AffiliateJumpPage.jsp?AffiliateID=1&BannerID=ba_189513&DestURL=http%3A%2F%2Fwww.collegeboard.com%2Fstudent%2Ftesting%2Fclep%2Fabout.html"><img src="/ad/images/ba_37401.gif" width="182" height="70" alt="Register for the CLEP exam" border="0" bannerId="ba_189513"/></a>';
 
left[1] = '<a href="http://apps.collegeboard.com/ut/AffiliateJumpPage.jsp?AffiliateID=1&BannerID=ba_189795&DestURL=http%3A%2F%2Fwww.collegeboard.com%2Fhtml%2Fnewsletters%2Fnewsletters.html"><img src="/ad/images/ba_38826.gif" width="182" height="70" alt="Stay on Top of Important Dates and Deadlines" border="0" bannerId="ba_189795"/></a>';

