/*
  $Id: lc1.js,v 1.2 2007/03/09 12:31:17 pmorrill Exp $
*/

//
// global variables
//
var	winRight	 = 0;
var 	winBottom	 = 0;
var	ctrlPanel	 = null;
var	panelUrl	 = '';

function popwin(url,name,width,height,options) {
	win_size();

	var x = ( width < winRight ? (winRight - width)/2 : 50 );
	var y = ( height < winBottom ? (winBottom-height)/2 : 50 );

	//
	// default options:
	//
	if ( ! options || options == '' ) options = 'scrollbars=yes,resizable=yes';

	var opts = 'width='+width+',height='+height+',screenx='+x+',screeny='+y+',left='+x+',top='+y+','+options;
	popup = window.open(url,name,opts);
	popup.focus();
}

function popup_window(url,name,width,height,options) {
	win_size();

	var x = ( width < winRight ? (winRight - width)/2 : 50 );
	var y = ( height < winBottom ? (winBottom-height)/2 : 50 );

	//
	// to initiate correct sub-nesting of templates, we add a parameter
	//
	var rg = new RegExp(/\/$/);
	var tp = ( rg.test(url) ? 'pop.htm' : '' );

	//
	// non-path_info version
	//
//	var rg = new RegExp(/\?\w+=.+/);
//	var tp = ( rg.test(url) ? '&type=pop' : '?type=pop' );


	//
	// default options:
	//
	if ( ! options || options == '' ) options = 'scrollbars=yes,resizable=yes';

	popup = window.open(url+tp,name,'width='+width+',height='+height+',screenx='+x+',screeny='+y+',left='+x+',top='+y+','+options);
	popup.focus();
}

function close_popup() {
	if ( confirm('Any changes that you have not yet saved will be lost') ) window.close();
}

function jumpTo(list,refer) {
	if ( list.options[list.selectedIndex].value == 0 ) return;
	location.href=refer+list.options[list.selectedIndex].value;
}

function select_checks(form,on) {
	for (var i = 0; i < form.elements.length; i++) {
		var s = form.elements[i];
		if ( s.type == 'checkbox' ) { s.checked = on; }
	}
}

function select_all(on) {
	select_checks(document.theform,on);
}

function set_focus(f,e) {
	if ( f && f.elements[e] ) {
		f.elements[e].focus();
		f.elements[e].select();
	}
}

//
// just try to get the window size
//
function win_size() {
	if ( window.innerWidth ) winRight = window.innerWidth;
	if ( window.innerHeight ) winBottom = window.innerHeight;
	if ( winRight == 0 ) winRight = document.body.clientWidth;
	if ( winBottom == 0 ) winBottom = document.body.clientHeight;
	if ( winBottom > 800 ) winBottom = 800;
}

function control_panel(url,keep) {
	if ( ctrlPanel && panelUrl == url && keep == 0 ) { ctrlPanel.close(); ctrlPanel = null; return; }
	popup = window.open(url,'pControl','width=750,height=150,screenx=20,screeny=30,left=20,top=30,modal=yes,scrollbars=yes,resizable=yes,toolbar=no');
	popup.focus();
	panelUrl = url;
	ctrlPanel = popup;
}

function destroy_panel() {
	if ( ctrlPanel ) ctrlPanel.close();
}

function href_parent(url) {
	if ( opener ) opener.document.location.href=url;
}

function popup_dom(what) {
	popup_window('/admin/dumpdom.php?dom='+what+'&type=popup','dViewer',700,600,'scrollbars=yes,resizable=yes');
}

function dump(theObj,nodestr) {
	var tx = '';
	var c = 0;
	if ( theObj.tagName ) {
		tx = "&nbsp;Tag: "+theObj.tagName+"&nbsp;|&nbsp;";
	}
	if ( theObj.firstChild ) {
		var ch = theObj.firstChild;
		var n = 0;
		for ( var j = 0; j < theObj.childNodes.length; j++ ) {
			ch = theObj.childNodes[j];
			if ( ch.tagName )	{ cx += " <a href=\"javascript:document.location.href='/admin/dumpdom.php?dom="+nodestr+".childNodes["+j+"]'\" >"+ch.tagName+"</a>"; n++; }
		}
		tx += "&nbsp;"+ n +" children: "+cx;
		tx += '<p />';
	}
	tx += "<table width=\"80%\" align=\"center\" bgcolor=\"#000000\" cellspacing=\"1\" cellpadding=\"2\">";
	tx += "<tr bgcolor=\"#efefde\"><td align=\"center\"><b>Property</b></td><td align=\"center\"><b>Descend</b></td></tr>";
	var props = new Array();
	for (var i in theObj) { props.push(i); }
	props.sort();
	for (var i = 0; i < props.length; i++) {
		str = props[i];
		tx += "<tr  bgcolor=\"#ffffff\"><td><a href=\"javascript:alert(eval('opener"+nodestr+'.'+str+"'))\">"+str+"</a></td><td><a href=\"javascript:document.location.href='/admin/dumpdom.php?dom="+nodestr+'.'+str+"'\">Descend</a></td></tr>";
	}
	tx+="</table>"

	return tx;
}

var posx = 0;
var posy = 0;
var targ = null;
var rollover_delay = 100;

//
// get the mouse coords for the event
//
function getMouseXY(e) {

	if ( !e ){ 
		var e = window.event
		targ = e.srcElement;
	}

	if ( e.srcElement ) targ = e.srcElement;
	else targ = e.target;
	
	// calculate mouse coordinates
	if ( e.pageX || e.pageY ) {
		posx=e.pageX;
		posy=e.pageY;
	} else if ( e.clientX || e.clientY ) {
		posx=e.clientX;
		posy=e.clientY;
		// check for scroll offsets in IE 6
		if(document.documentElement.scrollLeft || document.documentElement.scrollTop){
			posx+=document.documentElement.scrollLeft;
			posy+=document.documentElement.scrollTop;
		}
	}
}

//
// rollover glossary definition display
//
function glossary(e,str) {
	//
	// get mouse coordinates, then create a div and display it at that pt
	//
	getMouseXY(e);

	var div=document.getElementById('popup');
	if( !div ) {
		var div = document.createElement('div');
		div.setAttribute('id','popup');
		div.onmouseover=kill_timer;
		div.onmouseout=delayed_rollover_hide;
		div.innerHTML='';
		div.innerHTML=str;
		div.className='popupdiv_glossary';
		document.getElementsByTagName('body')[0].appendChild(div);
	}

	// move pop-up DIV element
	div.style.top = posy-15 + 'px';
	if ( posx > (winRight * 0.75) ) {
		var x = posx - div.offsetWidth;
		div.style.left = x + 'px';
	}
	else div.style.left = posx+5 + 'px';
}

function hidePopupDiv(){
	to = 0;
	var div=document.getElementById('popup');
	if(!div){return};
	div.parentNode.removeChild(div);
}

function kill_timer() { 
	clearTimeout(dh);
}

function delayed_rollover_hide() {
	dh = setTimeout('hidePopupDiv()',rollover_delay);
	to = 1;
}

