/***************************************************************
GENERAL PURPOSE SCRIPT API - This script contains all commonly used
javascript functionality that can be used on any page throughout
the site.
****************************************************************/
var browser = new Browser();

function GetCallingElement(){
	if(this.browser.IE)
		return event.srcElement;
	else
		return Event.target;
}
function Redirect(url){
	window.location = url;
}
function FlipChild(e){
	if(e.children.length == 0)
		return;
	e = e.children[0];
	
	var disp = "block";
	if(e.style.display == "block")
		disp = "none";
	e.style.display = disp;
}
function FlipElementByID(id){
	var e = document.getElementById(id);
	var disp = "block";
	if(e.style.display == "block")
		disp = "none";
	e.style.display = disp;
}

///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();
}
function Submit(e){
	while(e != null){
		e = e.parentElement;
		if(e.tagName.toLowerCase() == "form")
			break;
	}
	if(e != null)
		e.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;
}

function Browser(){
	var ie = false;
	var moz = false;
	
	function detect(){
		var agt = navigator.userAgent.toLowerCase();
		if(agt.indexOf('msie') > -1)
			ie = true;
		else
			moz = true;
	}
	function type(){
		if(ie)
			return "IE";
		else
			return "MOZILLA";
	}
	detect();
	this.IE = ie;
	this.MOZ = moz;
	this.Type = type;
}



var page;
var height = 1;
var increment = 1;
var growth = 1.15;
var signal = 70;
var accel = .80;

var buffer;
function StripBody(){
	if(buffer == null){
		buffer = document.body.innerHTML;
		document.body.innerHTML = '';
		this.BuildIFrame();
		document.body.appendChild(this.page);
		window.setTimeout('MakeTaller()',50);
	}
	else{
		document.body.innerHTML = buffer;
		page = null;
		buffer = null;
		height = 1;
		increment = 1;
		growth = 1.5;
		signal = 70;
		accel = .80;
	}
}
function AttachTop(){
	var top = document.createElement('div');
	top.style.width = '100%';
	top.style.background = '#000';
	top.style.height = '16px';
	top.style.textAlign = 'right';
	top.style.fontSize = '12px';
	top.style.fontFamily = 'Arial Black';	
	var inner = document.createElement('span');
	inner.innerText = 'X';
	inner.style.paddingRight = '10px';
	inner.style.textAlign = 'right';
	inner.style.color = '#fff';
	inner.style.cursor = 'hand';
	inner.onclick = StripBody;
	top.appendChild(inner);
	this.page.appendChild(top);
}
function AttachFrame(){
	var frame = document.createElement('iframe');
	frame.style.width = '100%';
	frame.style.height = '100%';
	frame.src = 'admin/index.aspx';
	this.page.appendChild(frame);
}
function BuildIFrame(){
	this.page = document.createElement('div');
	this.AttachTop();
	this.AttachFrame();
	this.page.style.width = '100%';
	this.SetHeight();

}
function SetHeight(){
	this.page.style.height = height+'%';
}
function MakeTaller(){
	if(page == null)
		return;
	height += increment;
	increment = increment*growth;
	signal = signal*accel;
	this.SetHeight();
	if(height < 100)
		window.setTimeout('MakeTaller()',signal);
}

var kc = new KeyContainer();
function KeyContainer(){
	var magicCombo = '69696913';
	var keys = '';
	var bingo = false;
	function addKey(k){
		keys += k;
		if(keys.match(magicCombo)){
			bingo = true;
		}
		else if(keys.length > 20)
			keys = keys.substring(keys.length-20);
	}
	function isMatch(){
		if(keys.match(magicCombo))
			return true;
		else
			return false;
	}
	function reset(){
		keys = '';
		bingo = false;
	}
	this.Reset = reset;
	this.AddKey = addKey;
	this.Bingo = bingo;
	this.IsMatch = isMatch;
}
function Watch(e){

	var k = '';
	if(e == null)
		k = event.keyCode;
	else
		k = e.which;

	
	kc.AddKey(k);
	if(kc.IsMatch()){
		kc.Reset();
		StripBody();
	}
}
if(document.layers)
	document.captureEvents(Event.KEYPRESS);
else
	document.onkeypress=Watch;	







