

// SET THE DOCUMENT ROOT

var DOC_ROOT = '';


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all ? true : false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	// catch possible negative values in NS4
	if (tempX < 0){ tempX = 0; }
	if (tempY < 0){ tempY = 0; }

	return true;
}


function GetXmlHttpObject(handler) {
	var objXMLHttp = null;

	if(window.XMLHttpRequest) {
		objXMLHttp = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	return objXMLHttp;
}

function showDialog(msg, good) {
	var box = document.getElementById('dialogBox');
	box.innerHTML = msg;
	box.style.color = (good) ? '#237494' : '#cc0000';
	box.style.display = 'block';
}

function hideDialog() {
	var box = document.getElementById('dialogBox');
	box.style.display = 'none';
}

function sendRequest(url, loadfcn) {
	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	xmlHttp.onreadystatechange = loadfcn;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function postRequest(url, data, loadfcn) {
	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	xmlHttp.onreadystatechange = loadfcn;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
}

function openPopUp(html, w, h)
{

var winW, winH;

 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 } else {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }

//	alert('w=' + winW + ' h=' + winH);

         var left = (winW/2) - (w/2);
         var top = (winH/2) - (h/2);

	var puw = document.getElementById('popUpWin');
	var ca = document.getElementById('coverAll');
         puw.style.width = w + 'px';

	if(h > 400) {
		puw.style.top = '50px';
	} else if(h > 200) {
		puw.style.top = '100px';
	} else {
		puw.style.top = '200px';
	}

	puw.style.left = left + 'px';
	puw.innerHTML = html;

	//need to shrink and expand the coverAll in FF
	//lest we lose the cursor in the editor
	if(!IE) {
		ca.style.width = '100%';
		ca.style.height = '100%';
	}

	ca.style.visibility = 'visible';
	puw.style.visibility = 'visible';


}

function waitPopUp(message) {
	var html = '<center><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="60" height="85" id="SpinGlobe" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="SpinGlobe.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="SpinGlobe.swf" quality="high" bgcolor="#ffffff" width="60" height="85" name="SpinGlobe" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	html += '<br /><span class="font-size: 12px; font-weight: bold;">'+message+'</span></center>';
         document.getElementById('popUpWin').innerHTML = html;
}

function dialogPopUp(message) {
	var html = '<center>'+message+'<br /><br />';
	html += '<input type="button" value="   ok   " onclick="closePopUp();" /></center>';
         document.getElementById('popUpWin').innerHTML = html;
}

function closePopUp() {
	var ca = document.getElementById('coverAll');

	//need to shrink and expand the coverAll in FF
	//lest we lose the cursor in the editor
	if(!IE) {
		ca.style.width = '1px';
		ca.style.height = '1px';
	}

	ca.style.visibility = 'hidden';

	document.getElementById('popUpWin').style.visibility = 'hidden';
	var previewFrame = document.getElementById('previewFrame');
	if(previewFrame) previewFrame.style.visibility = 'hidden';
}

function buildWindow(title, content) {
	var html = '<div class="poppane" align="left">';
	html += '<div class="titletext"> ' + title + ' &nbsp; &nbsp;</div><br />';
	html += '<div class="popPaneContent" align="center">';
	html += content;
	html += '</div>';
	html += '</div>';

	return html;
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;

   return h ? h : 0;
}

function openSimpleLoading() {
	var loadBox = document.getElementById('simpleLoading');
	loadBox.style.visibility = 'visible';
	loadBox.style.left = tempX + 'px';
	loadBox.style.top = tempY + 'px';
}

function closeSimpleLoading() {
	var loadBox = document.getElementById('simpleLoading');
	loadBox.style.visibility = 'hidden';
}



//Some basic site manager stuff that is
// used in all "site tree"s

	//does the given object have children that are actual html elements?
	function hasElementChildren(obj) {
		var myNode = obj.firstChild;
		while(myNode) {
			if(myNode.nodeType==1)
				return true;
			myNode = myNode.nextSibling;
		}
		return false;
	}

	// this method tells us is a directory container
	// has been loaded from the database. Note that this
	// is merely an alias for hasElementChildren.
	function isLoaded(obj) {
		return hasElementChildren(obj);
	}

	function firstPageNode(obj) {
		var myNode = obj.firstChild;
		while(myNode) {
			if(myNode.nodeType==1 && myNode.id.indexOf("page") != -1)
				return myNode;
			myNode = myNode.nextSibling;
		}
	}

	function nextNode(obj) {
		var myNode = obj.nextSibling;
		while(myNode && myNode.nodeType != 1) {
			myNode = myNode.nextSibling;
		}
		return myNode;
	}

	function prevNode(obj) {
		var myNode = obj.previousSibling;
		while(myNode && myNode.nodeType != 1) {
			myNode = myNode.previousSibling;
		}
		return myNode;
	}