window.onload				= init;
//////////////////////
function trim(str)
{
	try{
		return str.replace(/^\s+|\s+$/g,'');
	}
	catch (e){
		return str;
	}
}
//////////////////////
function init()
{
	if(	init.active)	return;
	{
		init.active	=	true
		//window.setTimeout('InitColor()',750); 	
	}
	try{
		window.event.cancelBubble	= true;
		window.focus();
	}
	catch(e){}
	//InitColor();
}
//////////////////////
function InitColor()
{
	window.clearTimeout();
	//DISABLED COLORED PHRASES, BY TAL, 04 APRIL 2005
	//return;
	// color search words
	var data = document.all["PageHeader1_SearchWords"]
	try
	{
		var container = document.all["main_content"]
		if(data && !isnull(data.SearchWords) && container){
			multiColorMark(data.SearchWords,container)
		}
	}catch(e){}
}
//////////////////////
function isnull(arg)
{
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}
//////////////////////
function nvl()
{
	for (var i=0; i<arguments.length; i++) {
		if (!isnull(arguments[i])) return arguments[i];
	}
	return null;
}	
//////////////////////
function openWindow(sUrl,iHeight,iWidth,sParams)
{
	var params = ",status=no,toolbar=no,menubar=no,location=no";
	if(sParams)params = sParams;
	var size = "";
	try{
		iHeight = parseInt(iHeight);
		iWidth = parseInt(iWidth);
		var bFullSize = false;
		if(iWidth>window.screen.width) bFullSize=true;
		if(iHeight>window.screen.height) bFullSize=true;
		if(bFullSize)
		{
			size = "full=yes";
		}
		else{
			size = "height="+iHeight+",width="+iWidth;
		}
	}catch(e){}
	window.open(sUrl,"_blank",size+params);
}
//////////////////////////////////////////
function multiColorMark(searchString,o)
{
	try
	{
		if(!o) return;
		if(searchString=="") return;
		var colors		= ["#FFF8B2","#FFF8B2","#FFF8B2","#FFF8B2","#FFF8B2"];
		searchString	= searchString.replace(/\+/gim," ");
		var arr			= searchString.split("@");
		for(var j=0; j<arr.length; j++)
		{
			//if(trim(arr[j])=="")	continue;
			var word = arr[j].split(";")[0];
			if(trim(word).length < 2) continue;

			markText(word,o,colors[j%4],arr[j].split(";")[1]);
		}
	}
	catch(e){throw new Error(" multiColorMark() "+e.description)}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//*	Mark text in a given object
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function checkWord(word,text){
		var re=new RegExp("(\\s\\w?("+word+")\\s)|(^\\w?("+word+")\\s)|(^\\w?("+word+")$)|(\\s\\w?("+word+")$)","i")
		return text.search(re)
}
var c=0
	function markText(sText,oObject,sColor,sId)
	{
		var i=0
		// the color of the markup
		if(!sColor) sColor='yellow';
		// create first level objects
		var aPreviusObjects = [oObject];
		// while previus level has items
		while(aPreviusObjects.length>0)
		{
			// current level items
			var aLevelObjects = [];
			i++
			// loop previus level items
			for(var iPrevIndex in aPreviusObjects)
			{
				// get current level items
				var oNodes = aPreviusObjects[iPrevIndex].childNodes;
				// collect text nodes
				var aLevelTextNodes=[];
				// loop current level items
				for(var iCurrIndex=0;iCurrIndex<oNodes.length;iCurrIndex++)
				{
					// get item reference
					var oItem = oNodes.item(iCurrIndex);
					// if text node
					if(oItem.nodeName=='#text')
					{
						aLevelTextNodes.push(oItem);
					}
					else{
						// not text node add to current level item array
						if(oItem.className != "text_block2"&&oItem.className != "general_title")
						aLevelObjects.push(oItem);
					}
				}
				// loop all text nodes
				for(var iTextIndex in aLevelTextNodes)
				{
					// get item reference
					var oItem = aLevelTextNodes[iTextIndex];
					if(c<1){
					}
					c++;
					// search string first index
					var iFoundIndex = -1;
					// if text node contains search string
					if((iFoundIndex=String(oItem.nodeValue).indexOf(sText))>-1)
					{
						// loop while more instances
						while(iFoundIndex>-1)
						{
							// get start text node
							oItem = oItem.splitText(iFoundIndex);
							//check if there is alerady a link
							var parent = oItem.parentNode
							if(oItem.parentNode.nodeName == "SPAN"){
							}
							str = oItem.nodeValue 
							var space = str.substring(iFoundIndex+sText.length,iFoundIndex+sText.length+1)
								// create a span and insert before found text
								var oSpan =	document.createElement("SPAN");
								//oSpan.style.background=sColor;
								oSpan.style.textDecoration = "underline";
								oSpan.style.cursor='hand';
								oItem.parentNode.insertBefore(oSpan,oItem);
								//oItem.parentNode.insertBefore(link,oItem);
								// slice remaining text and insert to span
								var oSearchItem = oItem.splitText(sText.length);
								
								oSpan.appendChild(oItem);
								oSpan.onclick = function(){openTerm(sId);};
								oItem = oSearchItem;
							
							// search on remaining text
							iFoundIndex=String(oItem.nodeValue).indexOf(sText);
						}
					}
				}
			}
			// set previus level item array
			aPreviusObjects = aLevelObjects;
		}
	}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function openTerm(id){
	var url			= HOST+ "Templates/Term/Term.aspx?lang="+LANG+"&DocID="+id;
	openWindow(url,275,389)
}
//'''''''''''''''''''''''''''''''''
function displayDiv(theObj, elName, arrow)
{
	var Obj = document.getElementById(elName);
	if(Obj){
		if(Obj.style.display=="none"){
			Obj.style.display = "block";
			if(arrow)
				theObj.style.backgroundImage = "url(../../Images/"+LANG+"/Homepage/arrow_opened.gif)";
		}
		else{
			Obj.style.display = "none";
			if(arrow)
				theObj.style.backgroundImage = "url(../../Images/"+LANG+"/Homepage/arrow_closed.gif)";
		}
	}
}
