<!--

var dragOn=0
var dragDiv=null;
var dragX=0,dragY=0;
var zMax=0;
var dragInit=0;

window.onload = chain_event_handler(window.onload, PositionConsole);


var tempfunction = 0;
function chain_event_handler(code1, code2) {
	var func1;
	var func2;
	var body = '';

	if(code1) {
		var rexp = /function\s+(\w+)/;
		var results = rexp.exec(code1);
		if(results)
			func1 = results[1];	
	} else
		return code2;

	if(code2) {
		var rexp = /function\s+(\w+)/;
		var results = rexp.exec(code2);
		if(results)
			func2 = results[1];
	} else
		return code1;


	
	var body;
        var result
        if(document.all || 1) {
        		if(func1) {
        			//code1 is a function, so call it.
                        	body = 'this.call_' + tempfunction + '=' + code1 + "\n";                   
                        	body += 'this.call_' + tempfunction + "(event);";

	                       	tempfunction++;
                        	
                        } else {
                        	//code1 is an expression, so evaluate it.
                        	body = code1 + ";\n";
                        }

                        if(func2) {
                        	body += 'this.call_' + tempfunction + '=' + code2 + "\n";
                        	body += 'this.call_' + tempfunction + "(event);";
                       	tempfunction++;
                        }  else {
                        	body += code2 + ";\n";
                        }

                        	
        } else {
               		if(func1) {
	      			//code1 is a function, so call it.
                        	body = 'this.' + func1 + '=' + func1 + "\n";
                        	body += 'this.' + func1 + "();";
                        } else {
                        	//code1 is an expression, so evaluate it.
                        	body = code1 + ";\n";
                        }

                        if(func2) {
                        	body += 'this.' + func2 + '=' + func2 + "\n";
                        	body += 'this.' + func2 + "();";
                        }  else {
                        	body += code2 + ";\n";
                        }

                        /*
                        if(func1) {
                        	body += code1 + "\n";
                        	body += func1 + '.call(this,event)';
                        }
                        
                        if(func2) {
				body += code2 + ";\n";
                        	body += func2 + '.call(this,event)';
                        }
                        
                        */	
                     	

        }
	return new Function("event",body);

}

function PositionConsole()
{
	if(document.cookie) {
		//init
//		drag('editConsole');
	
		if(document.getElementById("editConsole")) {
			//check mode
			//if(!( queryString("WBCMODE")=="AuthoringReedit" || queryString("WBCMODE")=="AuthoringNew") ) {

				var value = readCookie("cmsnav");
				if(value) {
					var pos = value.split('|');
					editConsole.style.left = pos[0];
					editConsole.style.top = pos[1];
				}
			//}			
			editConsole.style.visibility = "";
		}
		
		if (readCookie("cmsnavhidden") == "true")
		{
			editConsoleOptions.style.display="none";			
		}
	}       
}

function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

function PageQuery(q) {
	if(q.length > 1) 
		this.q = q.substring(1, q.length);
	else 
		this.q = null;
	this.keyValuePairs = new Array();

	if(q)
	{
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
	
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}

			return false;
	}
			
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}

		return a;
	}

	this.getLength = function() { return this.keyValuePairs.length; } 
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') 
			c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value)
{
	document.cookie = name+"="+value+";path=/";
}

function initDrag() {
	if (document.layers) 
		document.captureEvents(Event.MOUSEMOVE|Event.MOUSEDOWN|Event.MOUSEUP);
	document.onmousemove=dragf;
	document.onmousedown=dragf;
	document.onmouseup=dragf;
	dragDiv=null;
	dragInit=1;
	if (document.getElementsByTagName) 
		zMax=document.getElementsByTagName('DIV').length;
	else if (document.all) 
		zMax=document.body.all.tags("DIV").length;
	else if (document.layers) 
		zMax=document.layers.length;
}

function dragf(arg) {
	ev=arg?arg:event;
	
	if (dragDiv && ev.type=='mousedown') {
		dragOn=1;
		dragX=(ev.pageX?ev.pageX:ev.clientX)-parseInt(dragDiv.style.left);
		dragY=(ev.pageY?ev.pageY:ev.clientY)-parseInt(dragDiv.style.top);
		dragDiv.style.zIndex=zMax++; // remove this line to preserve z-indexes
		return false;
	}
	if (ev.type=='mouseup') {
		dragOn=0;
	}
	if (dragDiv && ev.type=='mousemove' && dragOn) {
		dragDiv.style.left=(ev.pageX?ev.pageX:ev.clientX)-dragX;
		dragDiv.style.top=(ev.pageY?ev.pageY:ev.clientY)-dragY;
		return false;
	}
	if (ev.type=='mouseout') {
		
		if(dragDiv && dragDiv.style)
			createCookie("cmsnav", dragDiv.style.left + "|" + dragDiv.style.top);

		if (!dragOn) 
			dragDiv=null;
	}
}

function drag(div) {
	if (!dragInit) 
		initDrag();
	if (!dragOn) {
		dragDiv= document.getElementById ? document.getElementById(div): document.all ? document.all[div] : document.layers ? document.layers[div] : null;
		if(dragDiv) {
			if (document.layers) 
				dragDiv.style=dragDiv;
			
			dragDiv.onmouseout=dragf;
		}
	}
}

function OpenCloseDiv(divName){
	if (divName.style.display == "none") {
		divName.style.display="block";
		createCookie("cmsnavhidden", "false");
	}
	else 
	{
		divName.style.display="none";
		createCookie("cmsnavhidden", "true");
	}
}



function toolbar(action, id) {
	var title; 
	var windowParam;
		
	if(action == "bookmark") {
		if(document.all) {
			window.external.AddFavorite(window.location, document.title);
		}
	}
	else if(action == "email") {
		var URLParam = "?guid="+id; 
		windowParam = 'toolbar=no,location=no,directories=no,menubar=no,status=no,resizable=yes,scrollbars=yes,width=640,height=480'; window.open("/hbagc-cms/emailthispage.aspx"+URLParam, "Email", windowParam); 
	}
	else if(action == "print") {
		var URLParam = "?guid="+id; 
		windowParam = 'toolbar=yes,location=no,directories=yes,menubar=yes,status=yes,resizable=yes,scrollbars=yes'; window.open("/hbagc-cms/printfriendly.aspx"+URLParam, "Print", windowParam); 
	}
}

//-->