/***************************************************************
GENERAL PURPOSE SCRIPT API - This script contains all commonly used
javascript functionality that can be used on any page throughout
the site.
****************************************************************/
function Redirect(url){
	window.location = url;
}

///TRIGGER A POSTBACK
function Submit(){
	var f = document.forms["Form"];
	if(f == null) 
		f = document.Form; 
	if(f == null) 
		f = document.forms[0]; 
	f.submit();
}
/***************************************************************
TRACING - This is a simple tracing/debugging mechanism used
to display and track information by any script on the site.

To enable tracing, simply call EnableTracing() from the onload 
event of the <body> tag. (e.g. <body onload='EnableTracing();'>...)

To disable tracing, call DisableTracing()
****************************************************************/
var trace;
function EnableTracing(){
	trace = new Tracing();
	trace.Enable();
	window.onerror = WriteEx;
}
function DisableTracing(){
	if(trace == null)
		return;
	trace.Disable();
}
function Write(msg){
	if(trace == null)
		return;
	trace.Write(msg);
}
function WriteEx(ex){
	if(trace == null)
		return false;
	trace.WriteEx(ex);
	return true;
}
function Tracing(){
		var width = '400px';
		var max_height = '800px';
		var min_height = '25px'
		var right = '0px';
		var top = '0px';
		var bg = '#FFF';
		var zIndex = '10000000';
		var position = 'absolute';
		var id = 'edifice_tracer';
		var list;
		var div;
		function enable(){	
			list = document.createElement("select");
			list.id = id;
			list.style.top = top;
			list.style.right = right;
			list.style.position = position;			
			list.style.width = width;
			list.style.height = min_height;	
			list.multiple = "true";
			list.style.borderStyle = 'solid';
			list.style.borderWidth = '1px';
			list.style.borderColor = 'black';
			list.style.zindex = zIndex;
			list.onmouseover = Expand;
			list.onmouseout = Contract;
			document.body.appendChild(list);
			
			window.onerror = writeEx;
		}
		function Expand(){
			list.style.height = max_height;
		}
		function Contract(){
			list.style.height = min_height;
		}
		function write(msg){
			var newOption = new Option();
			newOption.text = msg;
			newOption.value = msg;
			list.options.add(newOption);
			Expand();
		}
		function writeEx(ex){
			var o = new Option();
			o.text = ex.name;
			o.value = ex.name;	
			list.options.add(o);	
			o = new Option();
			o.text = 'ERROR: '+ex.name;
			o.value = ex.name;
			list.options.add(o);
			
			o = new Option();
			o.text = '   Msg:'+ex.message;
			o.value = ex.message;
			list.options.add(o);			
			
			o = new Option();
			o.text = '   Desc:'+ex.description;
			o.value = ex.description;
			list.options.add(o);	
						
			o = new Option();
			o.text = '\t\t File:'+ex.fileName;
			o.value = ex.number;
			list.options.add(o);
			
			o = new Option();
			o.text = '   Line:'+ex.lineNumber;
			o.value = ex.number;
			list.options.add(o);
			
			o = new Option();
			o.text = '   Num:'+ex.number;
			o.value = ex.number;
			list.options.add(o);			
		}

		function disable(){
			document.body.removeChild(list);
			list = null;
		}
		this.Enable = enable;
		this.Disable = disable;
		this.Write = write;
		this.WriteEx = writeEx;
}
