//	global.js
//	2007-11-13 usp - created
//	2007-11-26 usp - edits

// cancelEvent()
//
function cancelEvent( evt )
{
	if ( evt.preventDefault ) evt.preventDefault();
	else evt.returnValue = false;
}

// sourceElement( )
//	Returns the event source element
//
function sourceElement( evt )
{
	if ( evt.target ) return evt.target;
	else return evt.srcElement;
}

// findNextElement( )
// Iterates through the DOM tree in forward order.
//
function findNextElement( node )
{
	// descend into subtopics first
	if ( node.firstChild != null ) return node.firstChild;
	// visit next sibling
	if ( node.nextSibling != null ) return node.nextSibling;
	// ascend to parent siblings
	while ( node.parentNode != null ) 
	{
		node = node.parentNode;
		if ( node.nextSibling != null ) return  node.nextSibling;
	}
}

// findPreviousElement( )
// Iterates through the DOM tree in reverse order.
//
function findPreviousElement( node )
{
	// move left and down if possible
	if ( node.previousSibling != null ) 
	{
		// move to previous sibling
		node = node.previousSibling;
		
		// descend into subtree in reverse order
		while ( node.lastChild != null ) node = node.lastChild;
		return node;
	}
	// ascend parent
	if ( node.parentNode != null ) return node.parentNode;
}

// createXHR
// Creates a XMLHttpRequest oject
//
function createXHR()
{
    var xhr;
    if ( window.XMLHttpRequest )
    {
    	try { xhr = new XMLHttpRequest(); } 
    	catch( e ) { }
    } 
    else if ( window.ActiveXObject ) 
    {
       	try { xhr = new ActiveXObject( "Msxml2.XMLHTTP" ); } 
       	catch( e ) 
       	{  
       		try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } 
       		catch( e ) { }
		}
    }
	return xhr;
}

// removes spam blockers from a mail url, and creates a
// full mail url from parameters
//
function sendmail( evt )
{
 	// cancel std event handling
 	cancelEvent( evt );
 	// remove spam blocker
 	var url = event.srcElement.href.replace( ".no-spam@please.", "@" );
 	url = url.replace( "remove spam blocker, ", "" );
 	url = url.replace( new RegExp(" ", "g"), "%20" );
 	url = url.replace( new RegExp("\\x0d\\x0a", "g"), "%0d%0a" );
 	// open email window
 	window.open( url );
}

// Compensates for Firefox not having a currentStyle property
//
function getCurrentStyle( element, styleName )
{
	if ( element.currentStyle != null ) return element.currentStyle.getAttribute( styleName ); // ie6
	else if ( document.defaultView && document.defaultView.getComputedStyle ) return document.defaultView.getComputedStyle( element, null ).getPropertyValue( styleName ); // firefox
	else return element.style.getAttribute( styleName );  // hopefully that works for others
}
