
/*<version="1.6">*/

var gHMAgent 		= navigator.userAgent.toLowerCase();
var gHMVer	   		= parseInt(navigator.appVersion);
var gHM_IE  			= (gHMAgent.indexOf('msie') != -1);
var gHM_IE4			= ((gHM_IE) && (gHMVer >= 4));
var gHM_IE5			= ((gHM_IE) && (gHMVer >= 5));
var gHMCurrent		= null;

//
//
//

function FHM_GetElement( id )
{
	if( typeof(id) != "string" ) return id;

	if(document.getElementById)
		return document.getElementById(id);
	else if(document.all)
		return document.all(id);

	return null;
}


//
//
//

function FHM_GetEvent(e)
{
	if(typeof(e) == "object") return e;

	if(typeof(window) == "object" && typeof(window.Event) == "object") return window.Event;

	return window.event;
}


function FHM_GetEventTarget(e)
{
	if(typeof(e.srcElement) == "object") return e.srcElement;

	return e.target;
}


function FHM_OnMouseOver(e)
{
	e = FHM_GetEvent(e);
	
	gHMCurrent = FHM_GetEventTarget(e);

	if( typeof(BSPSPopupOnMouseOver) == "function")
		BSPSPopupOnMouseOver(e);
}




// 
//
//

function FHM_RunPopup( id, ref )
{
	if( !gHM_IE ) {

		return;
	}

	ref = FHM_GetElement(ref);
	var div = FHM_GetElement(id);

	if(!div) {

		alert( 'Missing element ' + id );

		return false;
	}

	if( div.style.display == "" ) {

		FHM_ClosePopup(div);

		return;
	}

	div.onclick = FHM_OnPopupClick;
	div.mIsPopup = true;

	var x = FHM_GetWindowLeft(ref);
	var y = FHM_GetWindowTop(ref);

	div.style.pixelLeft = x + 5;
	div.style.pixelTop = y + ref.offsetHeight + 5;

	div.style.display = "";

}



//
//
//

function FHM_ClosePopup(el)
{
	// -FIX- Filters

	el.style.display = "none";
}



// 
//
//

function FHM_GenericPopup( file, ref, block )
{
	if(gHM_IE) {

		if( block && ref ) {
			return FHM_RunPopup( block, ref );
		}
	}

	if(	typeof(BSSCPopup) == "function" ) {

		return BSSCPopup(file);
	}

	alert( 'Popups not supported in this browser' );

	return;
}




//
//
//

function FHM_OnPopupClick()
{
	var el = window.event.srcElement;

	while(!el.mIsPopup && el.parentElement)
		el = el.parentElement;

	FHM_ClosePopup(el);
}






//
//
//

function FHM_GetWindowLeft( el )
{
	if(!el) return 0;

	var coord = el.offsetLeft;
	var theBody = document.body;
	var parent = el.offsetParent;

	while( parent && parent != theBody ) {

		coord += parent.offsetLeft;

		coord -= parent.scrollLeft;

		parent = parent.offsetParent;
	}

	return coord;
}



//
//
//

function FHM_GetWindowTop( el )
{
	if(!el) return 0;

	var coord = el.offsetTop;
	var theBody = document.body;
	var parent = el.offsetParent;

	while( parent && parent != theBody ) {

		coord += parent.offsetTop;

		coord -= parent.scrollTop;

		parent = parent.offsetParent;
	}

	return coord;
}




//
//
//

function FHM_HTMLHelpPopup( ref, file )
{
	if( !gHM_IE ) {

		return FHM_GenericPopup( file );
	}

	ref = FHM_GetElement(ref);

	ref = FHM_FindA(ref);

	var text = "";
	if(ref) text = ref.getAttribute( "text" );

	if( typeof(HHCtrl) == "undefined" ||
	   !ref.currentStyle ) {

		return FHM_GenericPopup(file);
		return;
	}

	var textblockid = ref.getAttribute( "textblock" );
	if(textblockid) text = eval(textblockid);

	// -IE-

	var refStyle = ref.currentStyle;
	var hm = parseInt( refStyle.getAttribute( "hm-popup-horizontal-margins" ) );
	var vm = parseInt( refStyle.getAttribute( "hm-popup-vertical-margins" ) );
	var fg = -1;
	var bg = -1;

	if(isNaN(hm)) hm = 10;
	if(isNaN(vm)) vm = 10;

	var fam = refStyle.getAttribute( "hm-popup-font-family" );
	var ptsize = refStyle.getAttribute( "hm-popup-font-size" );
	var weight = refStyle.getAttribute( "hm-popup-font-weight" );
	var style = refStyle.getAttribute( "hm-popup-font-style" );
	var td = refStyle.getAttribute( "hm-popup-text-decoration" );
	var clr = refStyle.getAttribute( "hm-popup-color" );
	var bgclr = refStyle.getAttribute( "hm-popup-background-color" );

	if(fam == "") fam = "Arial";

	if(!ptsize || ptsize == "") {
		ptsize = "10";
	} else {
		var sizex = parseInt(ptsize);

		if(ptsize.indexOf("px") != -1) {
			sizex = sizex / 1.333;
		}

		ptsize = Math.round(sizex).toString();
	}

	var atts = "";
	if( weight == "bold" || weight == "700" ) {
		if(atts != "") atts += " ";
		atts += "BOLD";
	}
	if( style == "italic" ) {
		if(atts != "") atts += " ";
		atts += "ITALIC";
	}
	if( td && td.indexOf("underline") != -1 ) {
		if(atts != "") atts += " ";
		atts += "UNDERLINE";
	}

	var face = "";
	face = "";
	face += fam;
	face += ",";
	face += ptsize;
	face += ",";
	face += ",";	// Charset -FUT-
	
	face += atts;
	face += ",";

	if(clr && clr != "") {

		if( clr.charAt(0) == '#' ) {
			clr = "0x" + clr.substr(1, clr.length);
		}

		fg = parseInt(clr);
	}

	if(bgclr && bgclr != "") {
		if( bgclr.charAt(0) == '#' ) {
			bgclr = "0x" + bgclr.substr(1, bgclr.length);
		}
		bg = parseInt(bgclr);
	}

	if(isNaN(fg)) fg = -1;
	if(isNaN(bg)) bg = -1;

	HHCtrl.TextPopup( text, face, hm, vm, fg, bg );
}



//
//
//

function FHM_FindA(el)
{	
	var orig = el;

	while( el ) {
		if(el.tagName == "A") return el;
		el = el.parentElement;
	}
	return orig;
}


//
//
//

function FHM_FindToggleButton(el)
{
	while( el && !el.getAttribute('pulldownBody') && el.parentElement) {
		el = el.parentElement;
	}
	return el;
}




//
//
//

function FHM_FindToggleImage(el)
{	
	if(!el.children) {

		if(el.childNodes) {

			var len = el.childNodes.length;
			var i;

			for(i=0; i<len; i++) {

				var c = el.childNodes[i];

				if( c && c.tagName == "IMG" && c.getAttribute('button') == "true" ) {

					return c;
				}
			}			
		}
		
		return;
	}

	var len = el.children.length;
	var i;

	for(i=0; i<len; i++) {

		var c = el.children[i];

		if( c && c.tagName == "IMG" && c.getAttribute('button') == "true" ) {

			return c;
		}
	}

	return null;
}


//
//
//

function FHM_SwapImage(img)
{

	if(!img.getAttribute('origsrc')) img.setAttribute('origsrc', img.src);
			
	if(img.src == img.getAttribute('altsrc')) {
		img.src = img.getAttribute('origsrc');
	} else {
		img.src = img.getAttribute('altsrc');
		img.setAttribute('altsrc', img.src);
	}
}


//
//
//

function FHM_TogglePulldown(el)
{
	el = FHM_FindToggleButton( el );
	if(!el) return false; // error

	var target = el.getAttribute('pulldownBody');
	var targetEl = FHM_GetElement( target );

	if(!targetEl) return false; // error

	if(typeof(targetEl.style) == "undefined" ||
	   typeof(targetEl.style.display) == "undefined") {

		alert( 'Pulldowns not supported in this browser' );
		return false;
	}

	if( targetEl.style.display == "none" ) {
	
		var img = FHM_FindToggleImage(el);

		if(img) {

			FHM_SwapImage(img);
			
		}

		targetEl.style.display = "";

	} else {

		var img = FHM_FindToggleImage(el);

		if(img) {

			FHM_SwapImage(img);
		
		}

		targetEl.style.display = "none";	
	}

}



//
//
//

function FHM_FindToggleExpandingTextButton(el)
{
	while( el && !el.getAttribute('expandingTextBody') && el.parentElement) {
		el = el.parentElement;
	}
	return el;
}


//
//
//

function FHM_ToggleExpandingText(el)
{
	el = FHM_FindToggleExpandingTextButton( el );
	if(!el) return false; // error

	var target = el.getAttribute('expandingTextBody');
	var targetEl = FHM_GetElement( target );
	if(!targetEl) return false; // error

	if(typeof(targetEl.style) == "undefined" ||
	   typeof(targetEl.style.display) == "undefined") {

		alert( 'Expanding Text not supported in this browser' );
		return false;
	}

	if( targetEl.style.display == "none" ) {
	
		targetEl.style.display = "";

		var img = FHM_FindToggleImage(el);

		if( img ) {

			FHM_SwapImage(img);
		}

	} else {

		targetEl.style.display = "none";

		var img = FHM_FindToggleImage(el);

		if( img ) {

			FHM_SwapImage(img);
		}
	}

}



//
//
//

function FHM_StructureClick()
{
	if(!el.children) return; // IE only

	var el = window.event.srcElement;

	if( el.src ) {

		el = el.parentElement;	// click in img
	}

	var next = el.nextSibling;

	if(!next) return;

	var img = el.children[0];
	var d = next.currentStyle.display;

	if( img && !img.origsrc ) {
		img.origsrc = img.src;
	}

	if( d != "none" ) {

		next.style.display = "none";

		if(img) {
			img.src = img.origsrc;
		}
	}

	else {

		next.style.display = "";

		if(img) {
			img.src = img.altsrc;
		}
	}

}





function FHM_ActivateGlossary( font, windowName )
{
	if(!gHM_IE4) {
		return;
	}

	if( ((self == top) || (self == top.frames[0])) ) {

		if( typeof(document.body) == "object" ) {

			document.body.insertAdjacentHTML("beforeEnd", '<OBJECT ID="HHComponentActivator" CLASSID="CLSID:399CB6C4-7312-11D2-B4D9-00105A0422DF" width=0 height=0></OBJECT>');
			
			if(HHComponentActivator.object) {

				HHComponentActivator.Activate( "", windowName, font, "1", "0" );
			}
		}
	}
}
