query = document.location.search; q1 = query.indexOf('?page='); 
tocut ='?page=/content/'; xquery = query.substr(tocut.length);

if (query=='?page=' || (q1==-1 && query !='')){location.replace('/');exit;};
hierarchy = xquery.split('/').reverse();

loading = '<h2 id=\'loading\'>Loading...</h2>'; path ='';
levels = new Array('primary','secondary','tertiary','quaternary').reverse();
jax = new XMLHttpRequest(); //mozilla

function redirect() { // hierarchy.length!=0 &&
if ((current = hierarchy.pop()) && current!='index.php'){
path+='/' +current; load('content'+ path, levels.pop());}
}

function replace_content(section) {
if(jax.readyState==4) {
if(jax.status!=200) {location.replace('/')} else {
mbs=document.getElementById('crumbs');if(mbs){mbs.parentNode.removeChild(mbs)};
document.getElementById(section).innerHTML=jax.responseText;
redirect();}}
}

function load(page, section) { 
document.getElementById(section).innerHTML = loading;
if(window.ActiveXObject){jax = new ActiveXObject('Microsoft.XMLHTTP')}; //m$
jax.onreadystatechange = function(){replace_content(section)};
jax.open('GET',page, true); jax.send(null);
return false
}

function inject(stylesheet) {
head = document.getElementsByTagName('head')[0];         
node = document.createElement('link');
node.type ='text/css'; node.rel ='stylesheet';
node.href ='scripting/stylesheets/' +stylesheet;
head.appendChild(node);
}

function store() {
code = document.getElementById('primary');
if (code) {original = code.innerHTML};
}

function revert() {
document.getElementById('primary').innerHTML=original;
}

