// JavaScript Document
var Locals = { spidertext:null,
				bugwin:null
	         
	
}
function HighlightWord(word) {
	//alert(AJS.$('SpiderText').innerHTML.replace(/\\bוואלה\\b/g,'test'))
	
	//var reg = new RegExp('וואלה', 'gi');
	//word = word.replace(/\\s/gi,'\\s')
	var myreg =  new RegExp('(>[^<]*?)('+word+')([^>]*?<)', "gi")
	var wordreg = new RegExp('(\\\\|-|!|\\?|\\.|\\+|\\s|>|<|,|\'|\\)|\\(|:|/|@|=)('+word+')(\\\\|-|!|\\?|\\.|\\+|\\s|>|<|,|\'|\\)|\\(|:|/|@|=)', "gi")


	var matchs = Locals.spidertext.match(myreg)
	var htmlcode = Locals.spidertext
	for (var i=0;i<matchs.length;i++) 
	{

		var tmp = matchs[i].replace(wordreg,'$1<span style="background-color:yellow">$2</span>$3')

		var matchreg = new RegExp(matchs[i], "gi")
//alert(matchreg)
		htmlcode = htmlcode.replace(matchreg,	tmp)	
		
	
	}
	
	htmlcode = htmlcode.replace(/\@quation mark\@/g,'?')
	htmlcode = htmlcode.replace(/\@slash\@/g,'\\')
	htmlcode = htmlcode.replace(/\@plus\@/g,'+')
	htmlcode = htmlcode.replace(/@doller@/g,'$')
	htmlcode = htmlcode.replace(/@rightb@/g,')')
	htmlcode = htmlcode.replace(/@leftb@/g,'(')
	htmlcode = htmlcode.replace(/@rightb2@/g,']')
	htmlcode = htmlcode.replace(/@leftb2@/g,'[')
	htmlcode = htmlcode.replace(/@star@/g,'*')
	htmlcode = htmlcode.replace(/@pipe@/g,'|')
	htmlcode = htmlcode.replace(/@quote@/g,'"')
	htmlcode = htmlcode.replace(/@singlequote@/g,'\'')
	
	
	AJS.$('SpiderText').innerHTML = htmlcode
	
	
//	AJS.$('SpiderText').innerHTML = Locals.spidertext.replace(myreg,'$1<span style="background-color:yellow">$2</span>$3')
	HideVisualAids(AJS.$('hideVA').checked)
	
	if (AJS.isMozilla()) {
		window.pageYOffset=0
	} else {
		document.body.scrollTop=0

	}
	
	
	
}

function HideVisualAids(show) {
	
	var view = AJS.$('SpiderText')
	
	var imgs = view.getElementsByTagName('IMG')
	
	if (!show) {
		for (var i = 0;i<imgs.length;i++) {
			AJS.hideElement(imgs[i].parentNode)	
		}
	}
	else {
		for (var i = 0;i<imgs.length;i++) {
			AJS.showElement(imgs[i].parentNode)	
		}
	}
	
}
