function getPos(id)
{
	var obj = document.getElementById(id);
	
	var pos = {left:0, top:0};

	if(typeof obj.offsetLeft != 'undefined') {
		while(obj) {
			pos.left += obj.offsetLeft;
			pos.top += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else {
		pos.left = obj.left;
		pos.top = obj.top;
	}

	return pos;
}

function maxPosition()
{
	var iMaxPos = -Number.MAX_VALUE;

	for(var i = 0; i < maxPosition.arguments.length; i++) {
		if(maxPosition.arguments[i] > iMaxPos) {
			iMaxPos = maxPosition.arguments[i];
		}
	}
	return iMaxPos;
}

function setObjectHeight(id, height)
{
	var obj = document.getElementById(id);
	obj.style.height = height + "px";
}

function getObjectHeight(id)
{
	var obj = document.getElementById(id);
	var iObjectHeight = 0;
	iObjectHeight = obj.offsetHeight;
	return parseInt(iObjectHeight);
}

function getWindowInnerSize(win)
{
	if(!win) win = window;
		var objWin = new Object();
		if(typeof win.innerWidth != 'undefined') {
			objWin.width = win.innerWidth;
			objWin.height = win.innerHeight;
		} else {
			var obj = getBody(win);
			objWin.width = parseInt(obj.clientWidth);
			objWin.height = parseInt(obj.clientHeight);
		}
		return objWin;
}

function getBody(w)
{
	return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;
}

function positionFooter(sLeftColPHId, sMiddleColPHId, sRightColPHId, sFooterId)
{
	var iSecNavPos = getPos(sLeftColPHId).bottom; //leftnav bottom
	var iContentPos = getPos(sMiddleColPHId).top; //footer spacer top
	var iContextPos = getPos(sRightColPHId).bottom; //rightnav bottom
	
	var iWindowInnerHeight = getWindowInnerSize().height; 
	
	//Get the height for the main middle area content and the footer spacer: 
	var iWindowMinPos = iWindowInnerHeight - getObjectHeight(sFooterId); 
	
	//Get the max. value of the leftnav bottom, 0, the rightnav bottom and 
	//	the height for the main middle area content + the footer spacer: 
	var iMaxValue = maxPosition(iSecNavPos, 0, iContextPos, iWindowMinPos);
	
	//Set the footer spacer height variable to a height of 0: 	
	var iContentFooterPHHeight = 0;
	
	//If the there is more height than the main middle area content and a footer spacer of height 0 need, 
	//add this additional height to the footer spacer height variable: 
	if(iMaxValue > iContentPos) 
	{
		iContentFooterPHHeight = iMaxValue - iContentPos;
	}
	
	//Set the footer spacer height to the footer spacer height variable's value: 
	setObjectHeight(sMiddleColPHId, iContentFooterPHHeight);
}

var autocomplete;

function initOnload()
{
	//positionFooter("sec-nav-zone", "content-footer-placeholder", "context-zone", "footer-zone");
	//autocomplete = new AutoComplete();
	filters();
}

function initResize()
{
	//positionFooter("sec-nav-zone", "content-footer-placeholder", "context-zone", "footer-zone");
}

window.onresize = initResize;
window.onload = initOnload;
////Alternative for window.onload:
//window.onload=function()
//{
//	initOnload();
//}

//START: Fix IE 6 Text Selection Bug
if(window.createPopup && document.compatMode && document.compatMode=="CSS1Compat")
{
	document.onreadystatechange = function fixIE6AbsPos() {
		if( !document.body ) { return; }
		document.body.style.height = document.documentElement.scrollHeight + 'px';
	}
}
//END: Fix IE 6 Text Selection Bug

//START: Search Help Popup
function openWindow(location, width, height, name, toolbar, scrollbars, status, resizable, otherAttrib)
{
	//openWindow object properties
	this.location=(location != null) ? location:'#';
	this.width=(width != null) ? width:'612';
	this.height=(height != null) ? height:'378';
	this.name=(name != null) ? name:'help';
	this.toolbar=(toolbar != null) ? toolbar:'0';
	this.scrollbars=(scrollbars != null) ? scrollbars:'1';
	this.status=(status != null) ? status:'0';
	this.resizable=(resizable != null) ? resizable:'no';
	this.otherAttrib=(otherAttrib != null) ? otherAttrib:'';
	this.leftPos=120;
	this.topPos=90;

	//open method opens a window
	this.open=function()
	{
		this.name = window.open(this.location, this.name, 'toolbar='+this.toolbar+',status='+this.status+',scrollbars='+this.scrollbars+',resizable='+this.resizable+','+this.otherAttrib+',left='+this.leftPos+',top='+this.topPos+',height='+this.height+',width='+this.width);
	}
}

function searchHelp(sUrl)
{
	var oWin = new openWindow(sUrl);
	oWin.open();
}
//END: Search Help Popup

//START: Filter
var activeFilter;
var activeList;

function closeFilter()
{
	if(activeFilter) activeFilter.className = "filter";
	if(activeList) activeList.className = "filter-list";
}

function destroyFilterObjects()
{
	activeFilter = null;
	activeList = null;
}

function stopEvents(evt)
{
	if(document.all) {
		event.cancelBubble = true;
	} else {
		evt.stopPropagation();
	}
}

function filters()
{
	var searchFilters = document.getElementById("search-filters");
	if(!searchFilters) return;
	var filters = searchFilters.getElementsByTagName("dt");
	
	for(var i=0; i<filters.length; i++) {
		if(filters[i].className=="filter") {
			var filter = filters[i];
			var list = returnNextSiblingByClassName(filter,"filter-list");
			var opendList = list.getElementsByTagName("dl")[0];
			var arrow = filter.getElementsByTagName("a")[0];
			arrow.filter = filter;
			arrow.list = list;

			var closeLink = list.getElementsByTagName("a")[0];
			closeLink.filter = filter;
			closeLink.list = list;

			opendList.onclick = function(evt)
			{
				stopEvents(evt);
			}

			arrow.onclick = function(evt)
			{
//				autocomplete.hideDiv();
				this.blur();
				if(activeFilter) {
					closeFilter();
					if(activeFilter == this.filter) {
						destroyFilterObjects();
						return;
					}
				}
				this.filter.className = "filter-opened";
				this.list.className += " show";
				activeFilter = this.filter;
				activeList = this.list;
				stopEvents(evt);
			}

			closeLink.onclick = function()
			{
				this.blur();
				closeFilter();
				destroyFilterObjects();
			}
		}
	}
	
	document.onclick = function()
	{
		if(activeFilter) {
			closeFilter();
			destroyFilterObjects();
		}
//		autocomplete.hideDiv();
	}
}

function returnNextSiblingByClassName(obj,className)
{
	currentNode = obj;
	while(currentNode) {
		currentNode = currentNode.nextSibling;
		if(currentNode.className==className) return currentNode;
	}
}


//END: filter
// CR 397 - new functions
	function getDocFormat ( type ) {
		if (type.search(/PDF|pdf/)  != -1) 
			document.write( '<span class="fba_pdf">&nbsp;</span>&nbsp;');
		else if (type.search(/Word|DOC|doc/)  != -1)
			document.write( '<span class="fba_doc">&nbsp;</span>&nbsp;');
		else if (type.search(/ZIP|zip/)  != -1)
			document.write( '<span class="fba_zip">&nbsp;</span>&nbsp;');
		else if (type.search(/Web Page|HTM|htm/)  != -1)
			document.write( '<span class="fba_htm">&nbsp;</span>&nbsp;');
		else
			document.write( '<span class="fba_file">&nbsp;</span>&nbsp;');						
	}
	
	function getDocSize ( size ) {
		if (size > 1024*1024) {
			document.write( parseInt(size/(1024*1024)) + 'Mb' );
		} else if (size > 1024) {
			document.write( parseInt(size/1024) + 'kb' );
		} else if (size > 0) {
			document.write( '1kb' );
		}
		if (size > 0) 
			document.write( '<span class="pipe"> | </span>');		
	}
	
	function getTruncatedUrl ( txt ) {
		try {
			if (txt.length > 80) 
				txt = txt.substring(0, 32) + '...' + txt.substring(txt.length-45);
		} catch(err) {}		
		document.write( txt );				
	}
	
	function highlightText ( txt, pattern ) {
		try {
			var regex = new RegExp( pattern,'ig');
			var matches = regex.exec(txt);
		
			if (matches != null) {
				for (var i = 0; i < matches.length; ++i) {
					txt = txt.replace(matches[i], '<b>' + matches[i] + '</b>');
				}
			}
		} catch(err) {}	
		document.write( txt );	
	}			    
	
	function toggleUsedFilter( element ) {
		if ( $( element + '-off' ).style.display == 'none') {
			hideUsedFilter();
			$( element + '-off' ).show();
			$( element + '-on' ).hide();		
		} else {
			hideUsedFilter();
			$( element + '-off' ).hide();
			$( element + '-on' ).show();		
		}
		jQuery('div.IK_dropdown_content').hide();
		jQuery('div.usedFilter_display').show();	
	}
	
	function hideUsedFilter() {
		jQuery('div.usedFilter_on').hide();
		jQuery('div.usedFilter_off').show();
	}
		
