// Load dynamic content



function handleChange(event)
{
	// Ignore root
	if (event.path == "/") return;
	
	// Load content
	//document.getElementById("content").innerHTML = document.getElementById("content").innerHTML + "<br />Loading " + event.path;
	//alert(event.path);
	ajx("content", event.path)


}



function LoadContent(path)
{
	ajx("content", path)
}

function ajx(div, include) {
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){
	
			}
		}
	}
	else return false
	page_request.open('GET', include, false) //get page synchronously 
	page_request.send(null)
	writecontent(page_request, div, include)
}

function writecontent(page_request, div, include){
	if (window.location.href.indexOf("http")==-1 || page_request.status==200)
	var str = page_request.responseText
	
	// strip to content between these tags 
	str=str.replace(/[^~]*(<!-- Start Content -->)/, "")
	str=str.replace(/(<!-- End Content -->)[^~]*/, "")
	
	newDiv = document.getElementById(div)
	newDiv.innerHTML=str;

	var x = newDiv.getElementsByTagName("script");   

	for(var i=0;i<x.length;i++){ 
		eval(x[i].text);   
	}
	window.scrollTo(0, 0);

}

function getContent(x){
	document.title = "View";
	ajx('content', x)
	//alert(x);	
}

function doAjaxFixFromHotLinking() {
	var path  =  String(window.location.pathname);

	if (path.length > 1)
	{	
		window.location = 'http://'+ window.location.hostname +'/#' + path;
	}
}


function ajaxLink(ele) {

	var link  = ele.href.replace('http://'+ window.location.hostname +'/', '#/');
	link = link.substring(0, link.indexOf('?'));
	window.location = link;
	return false;
}
