var term = '';
//
// google.js
// Google Highlighter
//
// Copyright(C)2001 - 2003
// Cal Henderson <cal@iamcal.com>
//
// Thanks to Ian Beveridge for bugfixes
//
// This code may be freely redistributed,
// providing this message remains intact.
//

var matheplanet_text_color = '#000000';

var matheplanet_link_colors = new Array('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff');

function go_matheplanet(terms){
	terms = terms.replace(/\"/g,"");
	var terms_split = terms.split(' ');
	var c = 0;
	for(var i=0; i<terms_split.length; i++){
		term = terms_split[i];
                if(term=='') continue;
	        term = term.replace(/\$/g," ");
		highlight_matheplante2(document.getElementById('searchresults0'),matheplanet_link_colors[c],0);
		c = (c == matheplanet_link_colors.length-1)?0:c+1;
	}
}

function go_matheplanet2(terms){
	terms = terms.replace(/\"/g,"");
	var terms_split = terms.split(' ');
	var c = 0;
	for(var i=0; i<terms_split.length; i++){
		term = terms_split[i];
	        term = term.replace(/\$/g," ");
		highlight_matheplante2(document.getElementById('searchresults0'),matheplanet_link_colors[c],0);
		c = (c == matheplanet_link_colors.length-1)?0:c+1;
	}
}

function highlight_matheplante2(container, color,doit){
	var term_low = term.toLowerCase();

	for(var i=0; i<container.childNodes.length; i++){
		var node = container.childNodes[i];

		if (doit==1 && node.nodeType == 3){
			var data = node.data;
			var data_low = data.toLowerCase();
			if (data_low.indexOf(term_low) != -1){
				//term found!
				var new_node = document.createElement('SPAN');
				node.parentNode.replaceChild(new_node,node);
				var result;
				while((result = data_low.indexOf(term_low)) != -1){
					new_node.appendChild(document.createTextNode(data.substr(0,result)));
					new_node.appendChild(create_node_matheplanet(document.createTextNode(data.substr(result,term.length)),color));
					data = data.substr(result + term.length);
					data_low = data_low.substr(result + term.length);
				}
				new_node.appendChild(document.createTextNode(data));
			}
		}else{
//alert('type='+node.nodeType);
//alert('nodeName='+node.nodeName);
//alert(doit);
//return;
//document.writeln('.');
var mpname='';
if(!document.all)
{
   var upperNodeName=node.nodeName.toUpperCase();
   if(upperNodeName=='SPAN')
   {
       mpname=node.getAttribute('CLASS');
   //alert(upperNodeName);
   //if(mpname!=null) alert(mpname);
   }
   if(upperNodeName=='TR')
   {
       mpname=node.getAttribute('CLASS');
   }
}
else
{
   mpname = node.name;
}
//document.writeln(node.nodeName+'='+mpname+'/');

                        if(mpname=='nomore')
                        {
                            doit = 0;
                            //alert('name='+node.name);
                        }
                        else if(mpname=='mpgoback')
                        {
                            //alert('name='+node.name);
                            return;
                        }
                        else if(mpname=='searchresults1')
                        {
                            //alert('name='+node.name);
                            doit = 1;
                        }

			//recurse
			highlight_matheplante2(node, color,doit);
		}
	}
}
function highlight_matheplante(container, color,doit){
	var term_low = term.toLowerCase();

	for(var i=0; i<container.childNodes.length; i++){
		var node = container.childNodes[i];

		if (doit==1 && node.nodeType == 3){
			var data = node.data;
			var data_low = data.toLowerCase();
			if (data_low.indexOf(term_low) != -1){
				//term found!
				var new_node = document.createElement('SPAN');
				node.parentNode.replaceChild(new_node,node);
				var result;
				while((result = data_low.indexOf(term_low)) != -1){
					new_node.appendChild(document.createTextNode(data.substr(0,result)));
					new_node.appendChild(create_node_matheplanet(document.createTextNode(data.substr(result,term.length)),color));
					data = data.substr(result + term.length);
					data_low = data_low.substr(result + term.length);
				}
				new_node.appendChild(document.createTextNode(data));
			}
		}else{
                        if(node.name=='nomore')
                            doit = 0;
                        else if(node.name=='mpgoback')
                            return;
                        else if(node.name=='searchresults1')
                            doit = 1;

			//recurse
			highlight_matheplante(node, color,doit);
		}
	}
}

function create_node_matheplanet(child, color){
	var node = document.createElement('SPAN');
	node.style.backgroundColor = color;
	node.style.color = matheplanet_text_color;
	node.appendChild(child);
	return node;
}
