// Nothing in this file should be dependant on jquery 
// Juse in case this is used on the TDP side.

function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className))a.push(els[i]);
	return a;
}

/*
	var search_options_values = new Array();
	search_options_values["All"] = "";
	search_options_values["Food &amp; Fitness"] = "tdp";
	search_options_values["Members"] = "user";
*/

// THIS IS FRIGGIN UGLY and I'll get back to it when I come back
// DO NOT CHANGE THIS TO JQUERY, because it will break the TDP side
// AND THE WRATH OF TED WILL COME DOWN ON YOU.
function select_search_option(key, self) {

	var classname = "site_search_options";
	var search_options = getElementsByClassName(classname);

	// Unselect the hilight on all site searches.
	for (i=0; i<search_options.length; i++) {
		var li_list = search_options[i].getElementsByTagName("li");
		for(var j in li_list) {
			li_list[j].id = "";
		}
	}

	// Hilight the current node, on BOTH search boxes. 
	for (i=0; i<search_options.length; i++) {
		var li_list = search_options[i].getElementsByTagName("li");
		// for(var j in li_list) {
			for(var j=0; j<li_list.length; j++) {
			if(li_list[j].innerHTML == self.innerHTML) {
				li_list[j].id = "selected_site_search";
			}
		}
	}

	var search_mode_header = document.getElementById("search_mode_header");
	var search_mode_footer = document.getElementById("search_mode_footer");

	search_mode_header.value = key;
	search_mode_footer.value = key;
}

// Might want to try event bubbling so it doesnt scan the page?
function noFollowJS() {
	var elementList = getElementsByClassName("jsNoFollow");
	for(var i=0; i<elementList.length; i++) {
		element = elementList[i];
		if(element.className.match("_blank") != null ) {
			var target = "_blank";
		} else {
			var target = "_parent";
		}
		element.innerHTML = '<a href="'+element.title+'" rel="nofollow" target="'+target+'">'+element.innerHTML+'</a>';
	}
}

var originalOnload = window.onload;
window.onload = function() {
	if(typeof originalOnload === "function") {
		originalOnload();
	}
	noFollowJS()
}