// --- http://www.alistapart.com/articles/crossbrowserscripting/
/* is this stuff defined? */
if (!document.ELEMENT_NODE) {
	document.ELEMENT_NODE = 1;
	document.ATTRIBUTE_NODE = 2;
	document.TEXT_NODE = 3;
	document.CDATA_SECTION_NODE = 4;
	document.ENTITY_REFERENCE_NODE = 5;
	document.ENTITY_NODE = 6;
	document.PROCESSING_INSTRUCTION_NODE = 7;
	document.COMMENT_NODE = 8;
	document.DOCUMENT_NODE = 9;
	document.DOCUMENT_TYPE_NODE = 10;
	document.DOCUMENT_FRAGMENT_NODE = 11;
	document.NOTATION_NODE = 12;
}

document._importNode = function(node, allChildren) {
	/* find the node type to import */
	switch (node.nodeType) {
		case document.ELEMENT_NODE:
			/* create a new element */
			var newNode = document.createElement(node.nodeName);
			/* does the node have any attributes to add? */
			if (node.attributes && node.attributes.length > 0)
				/* add all of the attributes */
				for (var i = 0, il = node.attributes.length; i < il;)
					newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
			/* are we going after children too, and does the node have any? */
			if (allChildren && node.childNodes && node.childNodes.length > 0)
				/* recursively get all of the child nodes */
				for (var i = 0, il = node.childNodes.length; i < il;)
					newNode.appendChild(document._importNode(node.childNodes[i++], allChildren));
			return newNode;
			break;
		case document.TEXT_NODE:
		case document.CDATA_SECTION_NODE:
		case document.COMMENT_NODE:
			return document.createTextNode(node.nodeValue);
			break;
	}
};
// ---

function pH7Aero(page)
{
	// TURNING OFF THIS "FEATURE"
	return;
	
	// Get the content to swap with
	doXMLHttpRequest(page);
	
	// The pH7Aero_swap function will be called by the XMLHttpRequest.onreadystatechange method, i.e. getXMLHttpRes
}

function pH7Aero_swap()
{
	// TURNING OFF THIS "FEATURE"
	return;
	
	var center=document.getElementById('center');
	var center_hoover=document.getElementById('center_hoover');
	var temp=center.cloneNode(true);
	
	// Remove old content
	if(center.hasChildNodes())
	{
		while(center.childNodes.length >= 1)
		{
			center.removeChild(center.firstChild);
		}
	}
	
	// Move new content
	if(center_hoover.hasChildNodes())
	{
		while(center_hoover.childNodes.length >= 1)
		{
			center.appendChild(center_hoover.firstChild); // Moves the node
		}
	}

	// Store the old content
	if(temp.hasChildNodes())
	{
		while(temp.childNodes.length >= 1)
		{
			center_hoover.appendChild(temp.firstChild);  // Moves the node
		}
	}
}

function pH7Aero_cleanup()
{
	// TURNING OFF THIS "FEATURE"
	return;
	
	// Swap the content
	pH7Aero_swap();
	
	// Cleanup the temp storage
	var center_hoover=document.getElementById('center_hoover');
	if(center_hoover.hasChildNodes())
	{
		while(center_hoover.childNodes.length >= 1)
		{
			center_hoover.removeChild(center_hoover.firstChild);
		}
	}
}

function doXMLHttpRequest(page)
{
	// This function does the AJAX request
	xmlhttp=getXMLHttpObject();
	if(xmlhttp==null)
	{
		// The browser does not support AJAX!
		return;
	}
	var url="ajax.php";
	url=url+"?page="+page;
	xmlhttp.onreadystatechange=getXMLHttpRes;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function getXMLHttpRes()
{
	if(xmlhttp.readyState == 4) // Request completed
	{
		// These following lines get the response and update the page
		/*var response = xmlhttp.responseXML.documentElement;
		var page = response.getElementsByTagName('body')[0];
		if(page.nodeType != document.ELEMENT_NODE)
			page=page.nextSibling;
		var target_div=document.getElementById('center_hoover');
		
		// Get all nodes
		if(page)
		{
			if(page.hasChildNodes())
			{
				while(page.childNodes.length >= 1)
				{
					importedNode = document._importNode(page.firstChild, true);
					target_div.appendChild(importedNode);
					if(!document.importNode) // Refresh hack
						target_div.innerHTML = target_div.innerHTML;
						
					// Remove the node to avoid infinite loop
					page.removeChild(page.firstChild);
				}
		
				// Show the result
				pH7Aero_swap();
			}
		}*/
		
		document.getElementById('center_hoover').innerHTML=xmlhttp.responseText;

		// Show the result
		pH7Aero_swap();
	}
}

function getXMLHttpObject()
{
	var xhr;
	try
	{
		// The following "try" blocks get the XMLHTTP object for various browsers...
		// IE7+, Firefox, Chrome, Opera, Safari
		xhr = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			// IE6, IE5
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e2)
		{
			xhr = false;
		}
	}

	// Return the XMLHTTP object
	return xhr;
}

// This executes when the page first loads.
var xmlhttp = getXMLHttpObject();
