
//===================================================================
// fix problems with lazy browsers not updating screens with CSS rules
// the server side code sets top flags to trigger the required hacks
function CSSTriggerHack(el)
{
	if (!el)
		return;
	// IE7 is bad on CSS triggering with attribute selectors		
	if (top.__styleTriggerHack && top.__styleTriggerHack != 0)				
		el.style.styleTriggerHack = 1;	// IE is crazy - just add a non existant style
	// Safari 1.3 is bad on CSS triggering with attribute selectors		
	if (top.__inlineSafariTriggerHack && top.__inlineSafariTriggerHack != 0)		
	{
		if (el.ownerDocument.defaultView && el.ownerDocument.defaultView.getComputedStyle)
		{
			// there is usually always a background color - so use that
			var cssStyle = el.ownerDocument.defaultView.getComputedStyle(el, '');
			if (cssStyle && cssStyle.getPropertyValue && cssStyle.getPropertyValue('background-color'))
				el.style.backgroundColor=cssStyle.getPropertyValue('background-color');
		}
	}
};

function CSSTriggerStyleHack(el, style)
{
	if (!el)
		return;
	// IE7 is bad on CSS triggering with attribute selectors		
	if (top.__styleTriggerHack && top.__styleTriggerHack != 0)		
	{
		if (el.currentStyle && el.currentStyle[style])
			el.style[style]=el.currentStyle[style];
	}
	top.CSSTriggerHack(el);
};

function CSSExpanderHack(div, subdiv, isopen)
{
	CSSTriggerHack(div);
	if (top.__inlineMenuExpander && top.__inlineMenuExpander != 0 && subdiv)
		subdiv.style.display = (isopen ? 'block' : 'none');
};

//============================================================================
// coping with different browsers DOM access

function GetText(el)
{
	if (top.__useInnerText)
		return el.innerText;
	return el.textContent;
};

function SetText(el, txt)
{
	if (top.__useInnerText)
		el.innerText = txt;
	else
		el.textContent = txt;
};

function EventAsText(e)
{
	var s = e.toString() + '\n';
	s+= 'e.bubbles=' + e.bubbles + '\n';
	s+= 'e.cancelable=' + e.cancelable + '\n';
	s+= 'e.currentTarget=' + e.currentTarget + '\n';
	if (e.currentTarget)
		s+= 'e.currentTarget.id=' + e.currentTarget.id + '\n';
	s+= 'e.eventPhase=' + e.eventPhase + '\n';
	if (e.target)
	{
		s+= 'e.target=' + e.target + '\n';
		s+= 'e.target.id=' + e.target.id + '\n';
	}
	else	// and for the benefit of the "before release, it's obsolete" IE7
		s+= 'e.srcElement=' + e.srcElement + '\n';
	s+= 'e.timeStamp=' + e.timeStamp + '\n';
	s+= 'e.type=' + e.type + '\n';
	return s;
};

//===================================================================
// the following functions are purely here to get around IE7 being the
// equivalent of a badly cooked silage heap. IE stinks.

function HasAttribute(ctl, name)
{
	if (!ctl || ctl == undefined)
		return false;
	if (!ctl.hasAttribute)
	{
		// Then we are probably in that programming dunghill called IE7.
		// Because it doesn't support Element::hasAttribute, you have to use 
		// a non-conformat Element::getAttribute with a non-standard null case.
		// This is very ambiguous & gives very sloppy (and potentially dangerous) code.
		// Thank god that avionics aren't written using microsoft code - it would give
		// very final solutions.
		// So far the only advantage of IE7 over IE6 is that it understands some CSS2.x
		// and it actually knows what a Event.CAPTURING_PHASE is... Nope - doesn't know that either
		if (!ctl.getAttribute)
			return false;
		if (ctl.getAttribute(name) != null)	// looks like IE returns null if it doesn't exist
			return true;
		return false;
	}
	return ctl.hasAttribute(name);
};

function Target(e)
{
	if (!e.target)
	{
		// IE7 still hasn't made it into the 21st century & doesn't 
		// understand DOM except badly or incorrectly
		return e.srcElement;
	}
	return e.target;
};

function InCapturePhase(e)
{
	if (!e.eventPhase)
		return true;	// ?? IE7 again..
	return e.eventPhase == Event.CAPTURING_PHASE;
};

function IsVisible(item)
{
	return true;
};

function IsEditable(item)
{
	return true;
};

//=====================================================================
// 
// Nick 5 Sept 2008 - bloody IE6 not supporting Attribute Selectors
// Emulate selector behaviour by embedding in the className
// 
// It works like so:
// For IE6, instead of say <div class='Class1' selected=1> we embed
// <div class='Class1 Selected1' selected=1>

// The key thing is that EVERY time you call IE6SetClassAttribute for a given DOM object
// you need to pass the same selectorPrefix.  That way we can remove the old
// class name when applying a new attribute value
// eg. IE6SetClassAttribute(x, "Selected", 1) sets className='Class1 Selected1'
// then we call IE6SetClassAttribute(x, "Selected", 2) to set className='Class1 Selected2'
// But if we then call IE6SetClassAttribute(x, "DifferentPrefix_Selected", "0") we get
// className='Class1 Selected2 DifferentPrefix_Selected0'

// Note:  Make sure your prefix doesn't match a substring for another class name that
// may be applied to any given object.  eg. the following will get the wrong match
// className='MyClass1' + IE6SetClassAttribute(x, "ass", 3)
// what you really want is className='MyClass1 MyClass2 ass3', but you will actually get className='MyClass3 MyClass2'
function IE6SetClassAttribute(me, attributePrefix, attributeValue)
{
    if (!top.__isIE6)
        return;
    if (!me)
        return;
    if (attributeValue < 0 || attributeValue > 9)
    {
        alert("IE6SetClassAttribute: Error: attributeValue should be 0..9");
        return;
    }
    // regular expression match for prefix plus any single char after that
    var searchFor = new RegExp(attributePrefix + ".");
    if (me.className.search(searchFor) != -1)
        me.className = me.className.replace(searchFor, attributePrefix + attributeValue);
    else
        me.className = me.className + " " + attributePrefix + attributeValue;       // we haven't added this attribute yet - append to the end
};


