function remove_from_array( theArray, theIndex )
{
	if ( theIndex != -1 )
	{
		var _in = 0; 
		var _out = 0;
		var _ret = new Array();
		
		for ( _in = 0; _in < theArray.length; ++_in )
		{
			if ( _in != theIndex )
			{
				_ret[_out] = theArray[_in];
				++_out;
			}
		}
		
		return _ret;
	}
	else
	{
		return theArray;
	}
}

function index_in_array(theArray, theValue)
{
	var arLength = theArray.length;
	for(var i=0; i < arLength; ++i )
	{
		if (theArray[i] == theValue)
		{
			return i;
		}
	}

	return -1;
}

function remove_value_from_array( theArray, theValue )
{
	var index = index_in_array( theArray, theValue );
	return remove_from_array( theArray, index );
}

function remove_from_className( theClassName, theValue )
{
	var classes = remove_value_from_array( theClassName.split( " " ), theValue );
	return classes.join( " " );
}

function add_to_className( theClassName, theValue )
{
	var classes = theClassName.split( " " );
	if ( index_in_array( classes, theValue ) == -1 )
	{
		classes[ classes.length ] = theValue;
	}
	
	return classes.join( " " );
}

function remove_class_from_element( element, theClass )
{
	element.className = remove_from_className( element.className, theClass );
}

function add_class_to_element( element, theClass )
{
	element.className = add_to_className( element.className, theClass );
}

function does_element_have_class( element, theClass )
{
	if ( index_in_array( element.className.split( " " ), theClass ) > (-1) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function find_element( parentRoot, element_type, element_class )
{
	var elements = parentRoot.getElementsByTagName( element_type );
	
  for ( var i = 0; i < elements.length; ++i )
  {
  	if ( index_in_array( elements[i].className.split( " " ), element_class ) > -1 )
    {
//    	 alert( "Found element: " + elements[i].className );
       return elements[i];
    }
  }
   
  return false;
}

function append_element_after_element( to_append, where )
{
	var sib = where.nextSibling;
		
	if ( sib )
	{
		sib.parentNode.insertBefore( to_append, sib );
	}
	else
	{
		where.parentNode.appendChild( to_append );
	}
}

function find_elements_by_class( parentRoot, element_type, element_class )
{
	var elements = parentRoot.getElementsByTagName( element_type );
	var dst = new Array();
	
  for ( var i = 0; i < elements.length; ++i )
  {
  	if ( index_in_array( elements[i].className.split( " " ), element_class ) > -1 )
    {
//    	 alert( "Found element: " + elements[i].className );
			dst.push( elements[i] );
    }
  }
   
  return dst;
}

function find_element_by_name( parentRoot, element_type, element_name )
{
	var elements = parentRoot.getElementsByTagName( element_type );

  for ( var i = 0; i < elements.length; ++i )
  {
  	if ( elements[i].name == element_name )
  	{
  		return elements[i];
  	}
	}	
	
	return false;
}

function push_front_element( parent_element, child_element )
{
   var elements = parent_element.childNodes;
   
   if ( elements.length > 0 )
   {
      return parent_element.insertBefore( child_element, elements[0] );
   }
   else
   {
      return parent_element.appendChild( child_element );
   }
}

function import_node( destination_document, node_to_import )
{
	if ( destination_document.importNode )
	{
		return destination_document.importNode( node_to_import, true );
	}
	else
	{
		// IE Path, since IE doesn't support importNode
		
		var tmpNode = destination_document.createElement("div");
		tmpNode.innerHTML = node_to_import.outerHTML;
		return tmpNode.firstChild.cloneNode(true);
	}
}

function replace_whole_element_from_iframe( element_name )
{
	var cloned = import_node( parent.document, document.getElementById( element_name ) );
	var found = parent.document.getElementById( element_name );
	
	found.parentNode.replaceChild( cloned, found );
}

function is_element_child_of( child_element, parent_element )
{
	var checking = child_element.parentNode;
	
	while ( checking )
	{
		if ( checking == parent_element )
		{
			return true;
		}
		
		checking = checking.parentNode;
	}
	
	return false;
}

function jump_to_anchor( anchor_name )
{
	window.location.hash = anchor_name;
}

function jump_to_anchor_from_iframe( anchor_name )
{
	parent.window.location.hash = anchor_name;
}
/*
Script by RoBorg
RoBorg@geniusbug.com
http://javascript.geniusbug.com | http://www.roborg.co.uk
Please do not remove or edit this message
Please link to this website if you use this script!
*/
function clone(myObj)
{
	if(typeof(myObj) != 'object') return myObj;
	if(myObj == null) return myObj;

	var myNewObj = new Object();

	for(var i in myObj)
		myNewObj[i] = clone(myObj[i]);

	return myNewObj;
}
