 
	var sURL = 'http://search.myway.com/search/' + (readCookie('d')==false?'AJ':readCookie('d')) + 'main.jhtml?' + 'st=site&ptnrS=' + readCookie('ptnrS') + '&searchfor=';

if (typeof(urchinTracker) == 'undefined') urchinTracker = function(a) { };
String.prototype.isUpperCase = function() {var c = this.charAt(0); return (c >= 'A') && (c <= 'Z');};
String.prototype.contains = function() { var c; for (var i = 0; i < arguments[0].length; i++) { c = arguments[0].charAt(i); if (this.indexOf(c)>-1) return true; } return false;}
String.prototype.endsWith = function(c) {return this.substring(this.length-c.length)==c;}
String.prototype.isAcronym = function() { var c,d = false; for (var i = 0; i < this.length; i++) if (this.charAt(i).isUpperCase()) d=true; else return false; return d&&this.length>1; }
function gE(a) { return document.getElementById(a); }

var text = '';
var mouseX,mouseY,PSX,PSY,closePS;
var PSW = 241;
var PSH = 107;
var nds = 'background-color:#F7F7F7;color:#277836;border-bottom: 1px solid;height:10px;'; //New Div Style -- might want to put this in a style block somewhere, but since it's all JS generated space doesn't matter and it might be best to keep it with the code
var wlist = '';
var tmp;
var pCount = 0;

function isName(w,b) {
	if (b == false)
		return false;
	switch(w) { case 'of':case 'de': return true; }
	if (w.match(/al-/)) return true;
	return false;
}

function searchLinkify() {
	var allwords = text.replace(/\-/g, '- ').replace(/<br><br>/ig,'<p>').split(/<p>/i);


	
	for (var ii = 1; ii < allwords.length; ii++) {
		text = '  '+allwords[ii];		

		var words = text.replace(/<.*?>/g, '').replace(/\n/g,' ').split(' ');

		var midword = false;
		var firstWord = true;	
		for (var i = 0; i < words.length-1; i++) {
			tmp = '';
			while (i < words.length && (words[i].isUpperCase() || isName(words[i],midword))) {
				midword = true;
				tmp += words[i] + ' ';
				i++;
			}
			
			tmp = tmp.substring(0,tmp.length-1);
			if (tmp.lastIndexOf(' o') == tmp.lastIndexOf(' ')) tmp = '';
			
			if (firstWord) {
				tmp = '';
				firstWord = false;
			}
			
			if(typeof(words[i]) != 'undefined' && words[i].endsWith('.')) firstWord = true;
		
			//not sure if this is a good idea
			if (tmp.endsWith('.')||tmp.endsWith(','))
				tmp = tmp.substring(0,tmp.length-1);
			//end potentially bad idea
		
			if(!psBlocked(tmp)&&(tmp!=''&&tmp.split(' ').length>1||tmp.isAcronym())) if ((text=doHighlight(tmp,text))&&!dejaUsed(tmp)) pCount++;
			allwords[ii] = text;
			if (pCount > 1) {
				pCount = 0;
				i = words.length;
			}
		}
	
	}
	text = '';
	for (var i = 0; i < allwords.length; i++) {
		text += allwords[i] + '<P>';
	}
	
	gE('article').innerHTML = text.replace(/\- /g, '-');
}
	
function dejaUsed(w) {
    var wr = w.replace(/[;:]/i, '');
    if(wlist.indexOf('|'+wr+'|') > -1)
		return true;
	else
		wlist+= '|' + wr + '|';
	return false;
}

function psBlocked(w) {
	switch (w) {case 'PM': case 'AM': return true;}
	if (w.indexOf('By ')==0) return true; //skip the byline
	var blocked = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday','Score','Log'];
	
	for (var i = 0 ; i < blocked.length; i++)
		if (w.indexOf(blocked[i])>-1) return true;
	return false;
}

function popDiv(t,x,y) {
    var nd;
	if(gE('popdiv_1'))
		nd = gE('popdiv_1')
	else
	    nd=document.createElement("DIV");	
	nd.id='popdiv_1';
	if (!document.all) {
		nd.style.backgroundColor = '#F7F7F7';
		nd.style.border = '1px #C2D4E8 solid';
	}
    nd.style.position="absolute";
    nd.innerHTML=t;
	nd.style.top = y+document.body.scrollTop;
	nd.style.left = x;
	if(!gE('popdiv_1'))
	    document.body.appendChild(nd)
	urchinTracker('/clicks/cprompt/opens');
}

function poweredTag() {
	var pt = '<div style="float:right;padding-right:5px;">Powered By ';
	switch (readCookie('d')) {
		case 'GG':
			pt += 'Google';
			break;
		case 'LS':
			pt += 'LookSmart';
			break;
		case 'AW':
			pt += 'Yahoo';
			break;
		case 'AJ':
		default:
			pt= '<img src=http://ak.imgfarm.com/bz/search/mw_slogo_AJ_alt.gif align=right>';
	}
	pt+=(pt.indexOf('AJ')<0?'</div>':'');
	return pt;
}
function showPopSearch(w) {
	clearTimeout(closePS);
	var x = PSX = (document.all?event.x:mouseX);
	var y = PSY = (document.all?event.y:(mouseY-document.body.scrollTop));
	
	var div = '<form onsubmit="doPopSearch(this);return false;"><div style = "width:'+PSW+'px;' + (document.all?'background-color:#F7F7F7;border: 1px #C2D4E8 solid;':'') + 'font-family:Arial, Sans-serif;font-size:12px;"><div style="padding:10 5 15 5 px;font-weight:bold;">Find out more. Search the web.<div style="padding-top:10px;"><input type=text name=searchfor value="&quot;'+w+'&quot;" style="width:160px;">&nbsp;<input type=submit value=Search></div></div><div style="padding:5 0 25 0 px;">' + poweredTag() + '</div></div></form>';
	 popDiv(div,x,y);
}

function hidePopSearch() {
	if (!document.all)
		mouseY = mouseY-document.body.scrollTop;
	if (mouseX > PSX && mouseX < PSX+PSW && mouseY > PSY && mouseY < PSY+PSH)
		setTimeout("hidePopSearch()", 1000);
	else
	  try{gE('popdiv_1').parentNode.removeChild(gE('popdiv_1'));}catch(e){}
}

function doPopSearch(f) {
	
	urchinTracker('/clicks/cprompt/search_submit');
	location.href='http://search.myway.com/search/'  + (readCookie('d')==false?'AJ':readCookie('d')) + 'main.jhtml?searchfor=' + f.searchfor.value + '&st=site&ptnrS=' + readCookie('ptnrS');	
	}


function doHighlight(w,t) {
	w = w.replace(/\n/ig, '');
	w = w.endsWith("'s")?w.substring(0,w.indexOf("'s")):w;	
	if (w.endsWith('.'))w=w.substring(0,w.length-1);			
	
	//if (w.indexOf('arp') > -1) {
		//alert(w + '\n\n' + t + '\n\n' + t.indexOf(w) + '\n\n' +  t.lastIndexOf('able') + '\n\n' + t.lastIndexOf('ABLE'))
	//}
	
	if ((t.indexOf('/thumbnails/')>-1) && (t.indexOf(w) < t.lastIndexOf('able')) || (t.indexOf(w) < t.lastIndexOf('ABLE'))){ //image caption
		return t;
}	else if (t.match(new RegExp(w + " ?\\(.*?\\)", "i"))) //location
		return t;
	else if (dejaUsed(w)) //already used
		return t;
	else if ((t.substring(2,2+w.length) == w) || (t.substring(t.indexOf(w)-2,t.indexOf(w)+w.length).contains('.'))) //beginning of a sentence
		return t;
	
	return ((w.contains('.,-')&&!isName(w,true))||!w.isUpperCase()||w.indexOf('I ')>-1||w.substring(w.length-2)==' I')?t:t.replace(new RegExp("[^>2]"+w), ' <a href="'  + sURL + '%22' + w.replace(/ /g, '+') + '%22" style="'+nds+'" onmouseover=showPopSearch(this.innerHTML) onmouseout=\'closePS=setTimeout("hidePopSearch()", 1000);\' onclick=urchinTracker("/clicks/cprompt/search_clicks")>' + w + '</a>');
}

function setEvents(e) {
	mouseX = (document.all?event.x:e.pageX);
	mouseY = (document.all?event.y:e.pageY);
}
function addMouseMoveEvent(func) {
  var oldonmousemove = document.onmousemove;
  if (typeof document.onmousemove != 'function') {
    document.onmousemove = func;
  } else {
    document.onmousemove = function() {
      if (oldonmousemove) {
        oldonmousemove();
      }
      func();
    }
  }
}

if (document.layers) document.captureEvents(Event.MOUSEMOVE);
addMouseMoveEvent(setEvents);

if (gE('article')) {
	text = '  ' + gE('article').innerHTML;
	searchLinkify();
}


