<!--
/*******************************************************************************
Initialize everything
*******************************************************************************/
function init() {
	// resize everything
	window.onresize=positionAll;
	positionAll();
	initMenus();
	initTree();

	// load up first page
	openPage('geometry_upload.html');
}

function positionAll() {
	// tree
	$('tree').style.left		='0px';
	$('tree').style.top			='96px';
	$('tree').style.height		=(document.viewport.getHeight()-$('footer').getHeight()-96-10)+'px';

	// content area
	$('content').style.left		=$('tree').getWidth()+'px';
	$('content').style.top		='96px';
	$('content').style.width	=(document.viewport.getWidth()-$('tree').getWidth())+'px';
	$('content').style.height	=(document.viewport.getHeight()-$('footer').getHeight()-96-10)+'px';

	// footer
	$('footer').style.left		='0px';
	$('footer').style.top		=(document.viewport.getHeight()-$('footer').getHeight())+'px';
}

/*******************************************************************************
loads a javascript file dynamically using DOM as opposed to document.write();
once the script is loaded, script_file_name_init() will be called.

@script_filname		path to script
*******************************************************************************/
function includeDOM(script_filename) {
	var html_doc = document.getElementsByTagName('head').item(0);
	var js = document.createElement('script');
	js.setAttribute('language', 'javascript');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', script_filename);
	html_doc.appendChild(js);
}

/*******************************************************************************
universal ajax rexRquest function

@url		page to request
@callback	method called upon successful request
			method must have one parameter, which is an ajax request response object
@method		either 'post' or 'get'
			default is 'get'
@postData	if method is POST, then this is the post data object
*******************************************************************************/
function ajaxRequest(url,callback,method,postData) {
	method=(method==null)?'get':method;
	method=(method.toLowerCase()=='post')?'post':'get';
	var opt={
		method: method,
		onSuccess: callback,
		onFailure: ajaxFailure
	};
	new Ajax.Request(url,opt);
}

/*******************************************************************************
universal ajax request failure handler

@response	ajax request response object
*******************************************************************************/
function ajaxFailure(response) {
	alert(response.responseText);
}

/*******************************************************************************
opens the requested page and loads it into the main content

@page		url to desired page (absolute OR relative)
@method		GET or POST (default is 'get')
*******************************************************************************/
function openPage(page, method) {
	method=(method==null)?'get':method;
	method=(method.toLowerCase()=='post')?'post':'get';
	var opt = {
	    method: method,
	    onSuccess: displayPage,
	    onFailure: ajaxFailure
	}
	new Ajax.Request(page, opt);
}

/*******************************************************************************
displays a page in the content window

@response	ajax request response object
*******************************************************************************/
function displayPage(response) {
	// insert the HTML
	$('content').innerHTML=response.responseText;
	// include any external scripts
	var re=/\w*script.*src=["']{1}(.*)["']{1}/im;
	var matches=re.exec(response.responseText);
	if(matches!=null)
		includeDOM(matches[1]);
	// execute any code on the page
	response.responseText.evalScripts();
}

/*******************************************************************************
submits a form 'ajax-style' via an invisible IFrame and returns the results to
the callback function.

Typlical usage:
<form id="form1" action="formproc.php" method="post">
...
</form>
<button type="button" onclick="submitForm($('form1'),'callback');">Submit Form</button>

@form		form element
@callback	the name of the callback function (string) once the page is processed
			the form processing script will have to manually call this callback function
			the variable 'callback' will be sent as GET data
*******************************************************************************/
function submitForm(form,callback) {
	// here should we always show a "wait" message? probably
	$(form).action += '?callback='+callback;
	$(form).target='exec_frame';
	$(form).submit();
}
-->