function jumpNav( theObj ) {
	document.location.href = theObj.options[theObj.selectedIndex].value;
}

function checkUncheck( item ) {
	if(item.checked == true ) {
		checkAll(); 
	} else {
		uncheckAll();
	}
}

function checkAll( elem ) {
	if( elem ) {
		elem = byId(elem);
	}
	if( !elem || elem == null ) {
		elem = document;
	}
	var tempObj = null;
	var totalCount = 0;
	for( var i=0; i<document.forms.length; i++ ){
		for( var j=0; j<document.forms[i].elements.length; j++ ){
			tempObj = document.forms[i].elements[j];
			if( (tempObj.type) && (tempObj.type== "checkbox") && (tempObj.disabled== false) && (tempObj.className.search( 'nocheckall') == -1 )  && (isOffspringOf( tempObj, elem ) )) {
				tempObj.checked = true;
				selectInTable( tempObj );
				totalCount++;
			}
		}
	}

}

function showMore( elem ) {
	dojo.lfx.html.fadeShow('morejax', (fadeInRate)).play();
	setTimeout("showMore2('"+elem+"')", (fadeOutRate*5) );
}
function showMore2( elem ) {
	dojo.lfx.html.fadeHide('morejax', (fadeOutRate*1.5)).play();
	EZwipeIn(elem);
}
function showClump( elem ) {
	elem = byId(elem);
	if( elem.style.display=="block" ) {
		dojo.lfx.html.wipeOut(elem, (fadeInRate)).play();
	} else {
		elem.style.height="0px";
		elem.style.display="block";
		/*dojo.lfx.html.fadeShow(elem, (fadeInRate)).play();*/
		dojo.lfx.html.wipeIn(elem, (fadeInRate)).play();
	}
}

/****/ 
function uncheckAll( elem ) {
	//alert( 'in uncheckAll. init.' );
	var tempObj = null;
	if( elem ) {
		elem = xGetElementById(elem);
	}
	if( !elem || elem == null ) {
		elem = document;
	}
	for( var i=0; i<document.forms.length; i++ ){
		//alert( 'in uncheckAll. i == ' + i );
		for( var j=0; j<document.forms[i].elements.length; j++ ){
			//alert( 'in uncheckAll. j == ' + j );
			tempObj = document.forms[i].elements[j];
			if( (tempObj!= null && tempObj.type != null) && (tempObj.type == "checkbox"  || tempObj.type == "radio" ) && (tempObj.disabled== false) && (isOffspringOf( tempObj, elem ) )){
				tempObj.checked = false;
			}
		}
	}
	//alert( 'in uncheckAll. elems == ' + i );
	totalCount = 0;
}

var totalCount = 0;

function countSelected( elem ) {
	var theCount = 0;
	if( elem ) {
		elem = xGetElementById(elem);
	}
	if( !elem || elem == null ) {
		elem = document;
	}
	for( var i=0; i<document.forms.length; i++ ){
		for( var j=0; j<document.forms[i].elements.length; j++ ){
			tempObj = document.forms[i].elements[j];
			if( (tempObj.type) && (tempObj.type== "checkbox")  && ( tempObj.checked )  && (isOffspringOf( tempObj, elem ) )) {
				theCount++;
			}
		}
	}
	return theCount;
}


function toggleAdd( checkboxElem ) {
	checkboxElem = byId( checkboxElem );
	if( checkboxElem.checked ) {
		totalCount++;
	} else if( checkboxElem.checked == false ) {
		totalCount--;
	}
}

function checkCount( checkboxElem ) {
	checkboxElem = byId( checkboxElem );
	//alert( "totalCount == "+totalCount);
	if(  totalCount == 0 ) {
		checkboxElem.checked = false;
	} 
}




function disableAll( elem ) {
	var tempObj = null;
	if( elem ) {
		elem = xGetElementById(elem);
	}
	if( !elem || elem == null ) {
		elem = document;
	}
	for( var i=0; i<document.forms.length; i++ ){
		for( var j=0; j<document.forms[i].elements.length; j++ ){
			tempObj = document.forms[i].elements[j];
			if( (isOffspringOf( tempObj, elem ) )) {
				tempObj.disabled = true;
			}
		}
	}

}


/*function disableElem( elem ) {
	var tempObj = null;
	if( elem ) {
		elem = xGetElementById(elem);
	}
	if( !elem || elem == null ) {
		elem = document;
	}
	dojo.html.addClass(elem, 'disabled');
	disableAll( elem ); 
}


function enableElem( elem ) {
	var tempObj = null;
	if( elem ) {
		elem = xGetElementById(elem);
	}
	if( !elem || elem == null ) {
		elem = document;
	}
	dojo.html.removeClass(elem, 'disabled');
	enableAll( elem ); 
}*/


/****/ 
function enableAll( elem ) {
	//alert( 'in uncheckAll. init.' );
	var tempObj = null;
	if( elem ) {
		elem = xGetElementById(elem);
	}
	if( !elem || elem == null ) {
		elem = document;
	}
	dojo.html.removeClass(elem, 'disabled');
	for( var i=0; i<document.forms.length; i++ ){
		//alert( 'in uncheckAll. i == ' + i );
		for( var j=0; j<document.forms[i].elements.length; j++ ){
			//alert( 'in uncheckAll. j == ' + j );
			tempObj = document.forms[i].elements[j];
			if( (isOffspringOf( tempObj, elem ) )){
				tempObj.disabled = false;
			}
		}
	}
	//alert( 'in uncheckAll. elems == ' + i );
}


function isOffspringOf( childElem, parentElem ) {
	if( childElem == document || childElem.parentNode == null ) {
		return false;
	} else if ( childElem.parentNode == parentElem ) {
		return true; 
	} else {
		return isOffspringOf( childElem.parentNode, parentElem );
	}
}

function goToURL( destString ) {
	if( destString.length <= 1 ){
		return true;
	}
	else {
		/*alert( "destSting =[" + destString + "]" );*/
		if( destString.indexOf( "http://" ) == -1 ){
			destString = "http://"+destString;
		}
		location.href = destString;
	}
}

var rowNum = 1 ;
/*document.onLoad() = function{  rowNum = 1 };*/
function addRow2() {
	document.getElementById(("communityURL"+rowNum)).onfocus = null;
	rowNum++;
	var textNode = "";
	textNode += ('<tr class="communityRow" id="rowNum'+rowNum+'">');
	textNode += ('<td><input type="checkbox" checked="checked"/></td>');
	textNode += ('<td>URL <input size="30" id="communityURL'+rowNum+'"/></td>');
	textNode += ('<td><input size="16" /></td>');
	textNode += ('<td><input type="password" size="12" /></td>');				
	textNode += ('<td class="status"><span class="error"></span></td>');				
	textNode += ('<td class="reallybig"><a href="javascript:goToURL(communityURL'+rowNum+'.value);"> &rarr;&nbsp; </a></td>');			
	textNode += ('</tr>');
	document.getElementById("communityTable").innerHTML += textNode;	
}

function deleteThisRow(elem) {
	var parentRow = getFirstParentofType( elem, 'tr' );
	parentRow.innerHTML="";
}


function firstnameOut ( inputField ) {
	var theName = inputField.value;
	var obj = xGetElementById('firstnameOut');
	if( theName.length > 0 ) {
		obj.innerHTML = "<b>"+theName+"</b>";
	} else {
		obj.innerHTML = '<span class="gray">Firstname</span>';
	}

}

function lastnameOut ( inputField ) {
	var theName = inputField.value;
	var obj = xGetElementById('lastnameOut');
	if( theName.length > 0 ) {
		obj.innerHTML = theName.charAt(0)+".";
	} else {
		obj.innerHTML = '<span class="gray">[Lastinitial].</span>';
	}

}

function profileNameInit( inputField1, inputField2 ) {
	inputField1 = xGetElementById( inputField1 );
	inputField2 = xGetElementById( inputField2 );
	firstnameOut ( inputField1 ); 
	lastnameOut ( inputField2 );
}

function capitalizeMe ( inputField ) {
		/*var inputField = xGetElementById(inputField);
		myVal = inputField.value;
		if( myVal.length > 0 ) {
        	inputField.value[0] = myVal[0].toUpperCase();
		}*/
}

// xGetElementById, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}


var tinyMCEisOn = false;

function turnOnTinyMCE() {
	tinyMCEisOn = true;
}

var tinymce = null;

function istinyMCE() { // is tinyMCE active on this browser?
	//if( tinyMCEisOn )
	if( tinymce == null )
		return false;
	return true;
}


//var baseHref= null; // set to null if no base URL set
var baseTarget= "_top"; // always _top


function initHeaderFrame(frameId){
	var innerDoc = getIframeDocument ( frameId ); 
	if( innerDoc != null ) {
		var docHead = getOrCreate( 'head', innerDoc ); 
		var docBase = getOrCreate( 'base', docHead  ); 
	
		/*docbase.target= baseTarget;
		if( baseHref != null && baseHref != '') 
			docbase.href= baseHref;*/
			
		docBase.target= "_top";
		//docBase.href= "http://groupswim.com/";
	
		//docHead.innerHTML = '<base target="_top" href="http://blah/" />'+docHead.innerHTML;
		
		//alert( 'innerDoc.base=='+docbase+". target = "+docbase.target +". href = "+docbase.href );
	} else {
		//alert( 'innerDoc=='+innerDoc );
	}
}
	
	
	
function getIframeDocument ( frameId ) {
	var myframe = document.getElementById(frameId);
	//alert( 'myframe=='+myframe );
	var innerDoc = myframe;
	
	innerDoc = (myframe.contentDocument || myframe.contentWindow);
	
	//alert( 'innerDoc=='+innerDoc );
	if( innerDoc != null && innerDoc.document != null) {
    	innerDoc = innerDoc.document;
    }
    return innerDoc;
};

function getOrCreate( key, targetElem ) {
	//alert( 'targetElem='+targetElem);
	var doc = targetElem;
	if ( targetElem.ownerDocument != null ) 
		 doc = targetElem.ownerDocument;
	//alert( 'doc='+doc);
    var theElem = doc.getElementsByTagName(key);
	if(  theElem.length == 0 ) {
		theElem = doc.createElement(key);
		var firstNode = targetElem.childNodes[0];
		//targetElem.insertBefore(theElem,firstNode);
		targetElem.appendChild(theElem);
		//alert( "elem created/added. theElem = "+theElem);
	}
	else {
		theElem = theElem[0];
		//alert( "elem found. theElem = "+theElem);
	}
	return theElem;
}

/*function changeFrame() //test fucntion to eval frame access
{
  var oIframe = document.getElementById("customHeader");
  var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
  if (oDoc.document)
    oDoc = oDoc.document;
  alert( 'oDoc= '+oDoc ); 
  oDoc.body.style.backgroundColor = "#00f";
  return true;
}*/


function newWindow( url, width, height ) {
	newwindow=window.open(url,'name','height='+height+',width='+width);
	if (window.focus) {newwindow.focus()}
	return false;
}

function clearField( fieldId ) {
	var theField = xGetElementById(fieldId);
	theField.value="";
}

function checkOnEntry( theField ) {
	var theField = xGetElementById(theField);
	//alert( "theField.value ="+theField.value);
    if(  theField.value != null && theField.value != "" ) {
        selectInTable( theField );
    } else {
        deselectInTable( theField );
    }
}


var tagsLoaded = false;
var activeFlyout = null;
var fo_blink = null;
var fo_delay = 350; //best to keep this above fadeInRate + fadeOutRate to avoid flicker buggage
var fo_check = 1;
var wit_delay = 300;
var mytimer_on_ID = 0;
var mytimer_off_ID = 0;
var lockOn = false;
var marginOfError = 8; // this is the minimum distance you want the right edge of the popup from the edge of the page

var myMouseX = 0;
var myMouseY = 0;


var fadeInRate = 90;
var fadeOutRate = 250;

var isIE = false;
var isSaf = false;
var thebrowserName = navigator.appName;
if ( thebrowserName == "Microsoft Internet Explorer" )
	isIE = true;
else if ( navigator.vendor == "Apple Computer, Inc." )
	isSaf = true;

	
document.onmousemove = getMouseXY;


var fadeLockOut = false;

function hideElem( theElem ) {
	theElem = byId( theElem );
	if( theElem != null)
		theElem.style.display = "none";
}

function hideElem2( theElem ) {
	theElem = byId( theElem );
	if( theElem != null)
		theElem.style.visibility = "hidden";
}

function showElem( theElem ) {
	theElem = byId( theElem );
	if( theElem != null)
		theElem.style.display = "";
}
function showElem2( theElem ) {
	theElem = byId( theElem );
	if( theElem != null)
		theElem.style.visibility = "";
}



function EZslideOut( theElem ) {
	theElem = getFirstParentwithClass( theElem, 'mod' );
	dojo.lfx.slideIn( theElem, fadeOutRate ).play();
}

function EZslideIn( theElem ) {
	theElem = byId( theElem );
	if( theElem != null && theElem.style.display != "none" && theElem.style.width != "0px" ) 
		dojo.lfx.slideOut( theElem, fadeOutRate ).play();
}

function wipeOut( theElem ) {
	theElem = getFirstParentwithClass( theElem, 'mod' );
	dojo.lfx.wipeOut( theElem, fadeOutRate ).play();
}

function EZwipeOut( theElem ) {
	theElem = byId( theElem );
	if( theElem != null && theElem.style.display != "none" && theElem.style.height != "0px" ) 
		dojo.lfx.wipeOut( theElem, fadeOutRate ).play();
}

function EZwipeIn( theElem ) {
	theElem = byId( theElem );
	if(theElem != null && (theElem.style.display == "none"  || theElem.style.height == "0px") ) {
		theElem.style.display = "none";
		theElem.style.height = "0px";
		theElem.style.overflow = "hidden";
		theElem.height = 0;
		dojo.lfx.wipeIn( theElem, fadeOutRate ).play();
	}	
}

function EZwipeInH( theElem, targetWidth ) { // Horizontal wipe
	theElem = byId( theElem );
	// alert( 'EZwipeInH 1. theElem.style.width='+theElem.style.width );
	if(theElem != null ) {
		theElem.style.width = "0px";
		theElem.style.display = "block";
		theElem.style.visibility = "visibile";
		theElem.style.overflow = "hidden";
		theElem.style.opacity = ".8";
		
		// alert( 'EZwipeInH 2. theElem.style.width='+theElem.style.width );
		var anim = dojo.lfx.propertyAnimation(
			theElem,
			[
				// { property: "top", end:10},
				// { property: "left", end:10},
				{ property: "opacity", end: 1},
				{ property: "width", end:targetWidth}
				
			],
			fadeOutRate,
			dojo.lfx.easeInOut
		).play();
		// alert( 'EZwipeInH 3. theElem.style.width='+theElem.style.width );
	}	
}

function EZwipeOutH( theElem ) { // Horizontal wipe out
	theElem = byId( theElem );
	// alert( 'EZwipeInH 1. theElem.style.width='+theElem.style.width );
	if(theElem != null ) {
		
		// alert( 'EZwipeInH 2. theElem.style.width='+theElem.style.width );
		var anim = dojo.lfx.propertyAnimation(
			theElem,
			[
				// { property: "top", end:10},
				// { property: "left", end:10},
				{ property: "opacity", end: .8},
				{ property: "width", end:0}
				
			],
			fadeOutRate,
			dojo.lfx.easeInOut
		).play();
		// alert( 'EZwipeInH 3. theElem.style.width='+theElem.style.width );
	}	
}


function fadeShowLB( idOrElem, thefadeRate ) {
	if( idOrElem != null ) {
		waiting4fo = true;
		fadeShowLB2(idOrElem, thefadeRate);
		setTimeout("waiting4fo = false", (thefadeRate*3) );
	}
}

function fadeShowLB2( idOrElem, thefadeRate ) {
	if( idOrElem != null ) {
		var theBox = dojo.byId( idOrElem );
		theBox.style.display = "block";	 //show Post
		dojo.style.setOpacity(theBox, 0); // immediately set opacity to 0;
		dojo.lfx.html.fadeIn(theBox, thefadeRate).play();
	}
}


/****************

flyout

****************/

var activeDiscElem = null; 

function showFlyout(PostID, srcElem) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	var thePost = dojo.byId( PostID );
	var theElem = null;
	if( srcElem != null )
		theElem = dojo.byId( srcElem );
	if( activeFlyout != thePost ||  activeDiscElem != theElem ) { // skip if we're already showing*/
		clearTimeout(mytimer_on_ID);
		hideFlyout2(); 	// hide the active flyout
		activeFlyout = thePost; // make thePost the active flyout
		activeDiscElem = theElem;
		showFlyout2(); 	// show Post
	} else {
		return true; // do nothing;
	}
}

function showFlyout2() {
	// showPopupper();
	//lockOn = true;
	mytimer_on_ID = setTimeout("showFlyout3()", fo_delay);
}


function showFlyout3() {
	// showPopupper();
	clearTimeout(mytimer_on_ID);
	if( activeFlyout ) {
		positionFlyout();
		if( activeDiscElem ) {
			dojo.html.addClass(activeDiscElem,'active');
		}
		fadeShowLB(activeFlyout, fadeInRate);
		// hidePopupper();
	}
}

function positionFlyout() {
	if( activeFlyout ) {
		var adjustmentX = 0;
		var adjustmentY = 0;
		var offSetX = 3;
		var offSetY = 9;
		activeFlyout.style.visibility = "hidden";
		activeFlyout.style.display = "block";
			positionStemmer( activeFlyout, 'nw' );
			var flyoutWidth = dojo.style.getOuterWidth(activeFlyout); 
			var flyoutHeight = dojo.style.getOuterHeight(activeFlyout); 
		activeFlyout.style.display = "none";
		activeFlyout.style.visibility = "visible";
		//var totalWidth = getCanvasWidth() - marginOfError - ( flyoutWidth + myMouseX );
		var scrollLeft = dojo.html.getScrollLeft() ;
		var totalWidth = scrollLeft + dojo.html.getViewportWidth() - marginOfError - ( flyoutWidth + myMouseX );
		var scrollTop = dojo.html.getScrollTop() ;
		var totalHeight = scrollTop + dojo.html.getViewportHeight() - marginOfError - ( flyoutHeight + myMouseY );
		if( totalWidth < 0 && totalHeight > 0) {
			if( totalWidth < (0-flyoutWidth)) {
				adjustmentX = 0 - flyoutWidth;
				offSetX = 0-offSetX;
				positionStemmer( activeFlyout, 'ne' );
			} else {
				adjustmentX = -flyoutWidth/2;
				offSetX = 0;
				positionStemmer( activeFlyout, 'n' );
			}
		} else if( totalWidth < 0 && totalHeight < 0) {
			offSetY= 3;
			adjustmentY =  0 - flyoutHeight;
			if( totalWidth < (0-flyoutWidth)) {
				adjustmentX = 0 - flyoutWidth;
				offSetX = 0-offSetX;
				positionStemmer( activeFlyout, 'se' );
			} else {
				adjustmentX = -flyoutWidth/2;
				offSetX = 0;
				positionStemmer( activeFlyout, 's' );
			}
		} else if( totalWidth > 0 && totalHeight < 0) {
			adjustmentY = 0 - flyoutHeight;
			offSetY= 3;
			positionStemmer( activeFlyout, 'sw' );
		}

		//activeFlyout.style.backgroundPosition = (0-adjustmentX) + "px 0px";		// place popup (left) at the mouse X location
		activeFlyout.style.left = myMouseX + adjustmentX +"px";		// place popup (left) at the mouse X location
		activeFlyout.style.top = myMouseY + adjustmentY  + "px"; 	// place popup (top) at the mouse Y location
	}
}

function hideFlyout() {
	mytimer_off_ID = setTimeout("hideFlyout2()", fo_check);
	// hidePopupper();
	//document.onmousemove = null;
}

function hideFlyout2() {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	if( activeDiscElem ) {
		dojo.html.removeClass(activeDiscElem,'active');
	}
	if ( activeFlyout && activeFlyout.style ) {
		dojo.lfx.html.fadeHide(activeFlyout, fadeOutRate).play();
		//dojo.lfx.html.fadeHide(getStemmer(), fadeOutRate).play();
		//setTimeout("activeFlyout.style.display = 'none'", fadeRate); 	// hide Post
		activeFlyout = null;
		activeDiscElem = null;
		clearTimeout(mytimer_on_ID);
	}
	//lockOn = false;
}

function keepFO() {
	clearTimeout(mytimer_off_ID);

}


/*********************

File grid flyout

********************/
function showFileGridFlyout(popupID, srcElem) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	var thePopup = dojo.byId( popupID );
	var theElem = null;
	if( srcElem != null )
		theElem = dojo.byId( srcElem );
	if( activeFlyout != thePopup ||  activeDiscElem != theElem ) { // skip if we're already showing*/
		clearTimeout(mytimer_on_ID);
		hideFlyout2(); 	// hide the active flyout
		activeFlyout = thePopup; // make thePost the active flyout
		activeDiscElem = theElem;
		positionFileGridFO(srcElem, popupID);
		showFileGridFlyout2(); 	// show Post
	} else {
		return true; // do nothing;
	}
}
function showHideFileGridFlyout(popupID, srcElem) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	var thePopup = dojo.byId( popupID );
	var theElem = null;
	if( srcElem != null )
		theElem = dojo.byId( srcElem );
	if( activeFlyout != thePopup ||  activeDiscElem != theElem ) { // skip if we're already showing*/
		clearTimeout(mytimer_on_ID);
		hideFlyout2(); 	// hide the active flyout
		// activeFlyout.style.display="none";
		activeFlyout = thePopup; // make thePost the active flyout
		activeDiscElem = theElem;
		positionFileGridFO(srcElem, popupID);
		showFileGridFlyout3(); 	// show Post
	} else { // close
		EZwipeOutH(activeFlyout);
		if( activeDiscElem ) {
			dojo.html.removeClass(activeDiscElem,'active');
		}
		activeFlyout = null; // make thePost the active flyout
		activeTarget = null;
		return true; // do nothing;
	}
}

function showFileGridFlyout2() {
	// showPopupper();
	//lockOn = true;
	mytimer_on_ID = setTimeout("showFileGridFlyout3()", fo_delay);
}


function showFileGridFlyout3() {
	// showPopupper();
	clearTimeout(mytimer_on_ID);
	if( activeFlyout ) {
		if( activeDiscElem ) {
			dojo.html.addClass(activeDiscElem,'active');
		}
		//fadeShowLB( activeFlyout, fadeInRate );
		// activeFlyout.style.display="block";
		EZwipeInH(activeFlyout, 202);
		//EZslideIn(activeFlyout);
		// hidePopupper();
	}
}

function positionFileGridFO( userLink, userPopup ) {
	var thePopup = dojo.byId( userPopup );
	var userLink = dojo.byId( userLink );
	
	var linkCenterAdjWidth = dojo.style.getBorderBoxWidth( userLink ); //if the link img is smaller than 48x48, center the larger image over it
	var linkCenterAdjHeight = 0;
	var adjustmentX =  -2 ;
	var adjustmentY = -1 ;
	if( isSaf ) {
		var adjustmentX =  -1;
		var adjustmentY = 0 ;
	}
	thePopup.style.visibility = "hidden";
	thePopup.style.display = "block"; // I can't detect its size if display is 'none', but it pops up on some browsers when I check this info. So I display it hidden when I check it's stats.
		var flyoutWidth = dojo.style.getOuterWidth(thePopup); 
		
		//alert('here it is, popupid='+userPopup+', thePopup.style.top='+thePopup.style.top);
		//var linkHeight = dojo.style.getBorderBoxHeight(userLink);
	var xyPos = dojo.style.getAbsolutePosition( userLink, true );
	var fieldLeftEnd = xyPos.x;
	var fieldTopStart = xyPos.y;
	thePopup.style.display = "none"; // I can't detect its size if display is 'none', but it pops up on some browsers when I check this info. So I display it hidden when I check it's stats.
	thePopup.style.visibility = "visible";
	
 	thePopup.style.left = fieldLeftEnd+adjustmentX+linkCenterAdjWidth+"px";
 	thePopup.style.top = (fieldTopStart+adjustmentY)+"px";
}


/****************

flyout_2

****************/


function showDiscFlyout( PostID, discElem) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	var thePost = dojo.byId( PostID );
	var discElem = dojo.byId( discElem );
	if( activeFlyout == null || activeDiscElem != discElem ) { // skip if we're already showing*/
		clearTimeout(mytimer_on_ID);
		hideFlyout2(); 	// hide the active flyout
		activeFlyout = thePost; // make thePost the active flyout
		activeDiscElem = discElem; // make thePost the active flyout
		showDiscFlyout2(); 	// show Post
	} else {
		return true; // do nothing;
	}
}

function showDiscFlyout2() {
	// showPopupper();
	//lockOn = true;
	mytimer_on_ID = setTimeout("showDiscFlyout3()", fo_delay);
}


function showDiscFlyout3() {
	// showPopupper();
	clearTimeout(mytimer_on_ID);
	if( activeFlyout ) {
		positionDiscFlyout();
		fadeShowLB(activeFlyout, fadeOutRate);
		dojo.lfx.wipeIn( activeFlyout, fadeOutRate ).play();
		// hidePopupper();
	}
}

function positionDiscFlyout() {
	if( activeFlyout ) {
		var adjustmentX = 60;
		var adjustmentY = dojo.style.getInnerHeight(activeDiscElem) -10; 
		var xyPos = dojo.style.getAbsolutePosition( activeDiscElem, true );
		
		activeFlyout.style.left = xyPos.x + adjustmentX + "px";		// place popup (left) at the mouse X location
		activeFlyout.style.top = xyPos.y + adjustmentY + "px"; 	// place popup (top) at the mouse Y location
	}
}





/****************

tagsuggest

****************/

	function loadAllTagData() {
		// This line was previously triggered by body onload, but this tripped up dojo.addOnLoad()

		var tagData = dojo.byId('theTagData').innerHTML;
		tagData = tagData.substring(5, tagData.length);      // This strips off pre
		tagData = tagData.substring(0, tagData.length - 6);  // This strips off /pre
		dumpData(null, tagData, null);
	};
	


var alltagArray = new Array();
var global_tagsuggestID = "ts_1";

function dumpData(type, data, evt ) { /* creates a data structure (2d array) out of the space-delimted text data */
	//var theBox = dojo.byId( 'texter' );
	var lineDelimiter = /[\n\r]/;
	/*if( data.lastIndexOf( lineDelimiter ) == -1 ) {
		lineDelimiter = '\n';
	}*/
	
	/*"(\\s*)(\\s|,|;|:)(\\s*)"*/
	var valueDelimter = / +/;
	var singleTagArray = new Array();
	alltagArray = removeEmpties(data.split(lineDelimiter));
	if( alltagArray.length > 0 && alltagArray != null ) {
		for( var i=0; i< alltagArray.length; i++ ){
			singleTagArray = removeEmpties( alltagArray[i].split(valueDelimter) );
			// [0]= used by user, [1]= total count, [2]= the tag
			var singleTagArrayLength = singleTagArray.length;
			if ( singleTagArrayLength == 3 ) { // mediocre check to make sure the line was not malformed
				alltagArray[i] = singleTagArray;
			} else if (	singleTagArrayLength > 3 ) { // if there's more than three spaces, we have a tag with a space
				var tempArray = new Array(3);
				tempArray[0] = singleTagArray.shift();
				tempArray[1] = singleTagArray.shift();
				var sourceWord = singleTagArray.join("-");
				tempArray[2] = fromEntity2Text(sourceWord);

				//alert( "tempArray[2] = " +tempArray[2]  );
				alltagArray[i] = tempArray;
			} else {
				//skip it;
			}
		}
		alltagArray = masterSortTagArray( alltagArray ); 
	tagsLoaded = true;
	}		
  //  var msg = "Data dump:\n" + data;
  //  alert( msg );
	
}

function tagsuggest( TagField, suggestionbox, event ) {
	TagField = byId( TagField );
	var allWords = TagField.value;
	var allWordsLength = allWords.length;
	
	var parentForm = getFirstParentofType( TagField, 'form' );
	if( tagscroll < 0  && (allWordsLength == 0 || allWords.charAt(allWordsLength-1) == " " || allWords == null ) ) { 
		// if the last char is a space or the field is empty...
		hideTS(); // hide that TA menu....
		return false; // and skip this whole function.
	} else if ( tagsLoaded == false  ) { 
		// global var to tell us if we've successfully loaded the tags file. if we haven't...	
		hideTS(); // hide that TA menu....
		return false; // and skip this whole function.
	} else {
		;
	}
	
	globalTagsField = TagField;
	
	var thePopup = dojo.byId( "tagsuggestbox" );
	var suggestions = thePopup.getElementsByTagName('a');
	var suggestionsLength = suggestions.length;

	var keyPressed= getKeyCode(event);
	
	var wordArray = fieldValueToTagArray( allWords);
	
	if( keyPressed == KEY_DOWNARROW && (suggestionsLength > 0) ) { 
	// down arrow
		if( isSaf ) { // special code to catch safari double keyup event
			if( safLockout == false ) {safLockout = true;}
			else { safLockout = false; return false;}
		}
		if( tagscroll < suggestionsLength ) {
			if( tagscroll > -1 )  
				dojo.html.removeClass( suggestions[(tagscroll)], 'active' );
			tagscroll++;
			if( tagscroll < suggestionsLength ) {
				makeActive( suggestions[(tagscroll)] );
				disableSubmit( TagField );
			} else {
				enableSubmit();
				tagscroll = -1;
			}
		}
		return true;
	} else if( keyPressed == KEY_UPARROW && (suggestionsLength > 0) ) { 
	// up arrow
		LBselectInputLastChar(TagField); // move keyboard focus to end of selection
		if( isSaf ) { // special code to catch safari double keyup event
			if( safLockout == false ) {safLockout = true;}
			else { safLockout = false; return false;}
		}
		if( tagscroll > -1 ) {
			if( tagscroll < suggestionsLength ) dojo.html.removeClass( suggestions[(tagscroll)], 'active' );
			tagscroll--;
			if( tagscroll > -1 ) {
				makeActive( suggestions[(tagscroll)] );
				disableSubmit( TagField );
			} else {
				enableSubmit();
			}
		} else {
			tagscroll = suggestionsLength-1;
			if( tagscroll > -1 ) 
				makeActive( suggestions[(tagscroll)] );
			disableSubmit( TagField );
		}
		
		LBselectInputLastChar(TagField); // move keyboard focus to end of selection
		return true;
		
	} else if( keyPressed == KEY_SPACEBAR && (tagscroll > -1) ) { 
	// spacebar, with a suggestion highlighted
		//alert( "keyPressed = "+keyPressed+", tagscroll = "+tagscroll + ", suggestions[(tagscroll)].getAttribute('onclick') = "+ suggestions[(tagscroll)].getAttribute('onclick'));
		TagField.value = wordArray.join(" "); // add an extra space at the end.
		if( tagscroll < suggestionsLength ) {
			completeTS( suggestions[(tagscroll)] );
		}
		return true;
		
	} else if( keyPressed == KEY_ENTER && (tagscroll > -1) ) { 
	// return/enter, with a suggestion highlighted
		/*if( tagscroll < suggestionsLength ) {
			//var theWord = suggestions[(tagscroll)].childNodes[0].innerHTML;
			//completeTS( TagField, theWord );
		}*/
		return true;
		
	} else if( keyPressed == KEY_TAB && (tagscroll > -1) ) { 
	// tab, with a suggestion highlighted
		//alert( "keyPressed = "+keyPressed+", tagscroll = "+tagscroll + ", suggestions[(tagscroll)].getAttribute('onclick') = "+ suggestions[(tagscroll)].getAttribute('onclick'));
		if( tagscroll < suggestionsLength ) {
			completeTS( suggestions[(tagscroll)] );
		}
		//return true;
		
	} else if( keyPressed == KEY_ESC && (tagscroll > -1) ) { 
	// 'esc', with a suggestion highlighted
		//alert( "keyPressed = "+keyPressed+", tagscroll = "+tagscroll);
		clearActiveSelection(); 
		hideTS();
		return true;
		
	} else { // update the suggestion menu
		clearActiveSelection(); 
		
		nameTag( TagField ); // we need to make sure this element has a name so we can reference it later.
		
		var wordCount = wordArray.length;
		var wordMatch = matchWords(wordArray, alltagArray);
		var wordMatchCount = wordMatch.length;
		if( wordMatchCount > 0 ) {
			var firstWordMatch = wordMatch[0][2]; 
			buildTagMenu( wordMatch, thePopup, TagField );
			showBox( suggestionbox, TagField,  wordCount-1); // only executes if box isn't already showing
			var currentWord = wordArray.pop().toLowerCase(); // make the comparison case-insensitive
			firstWordMatch = firstWordMatch.toLowerCase();
			if( currentWord == firstWordMatch ) { // if the first suggestion is a perfect match
				makeActive( suggestions[0] );
				tagscroll =0;
				disableSubmit( TagField );
			}
		} else { // if there are no matches
			thePopup.innerHTML = ""; //clear the text
			hideTS(); // and hide that guy.
		}
		return true;
	}
	
}

		/**************
		
		support functions for tagsuggest 
		
		***************/

		if (Array.prototype.contains==null) Array.prototype.contains = function( token ) {
			for( var i=0; i<this.length; i++ ) {
				if( this[i] == token ) 
					return true;
			}
			return false;
		}
		
		
		if (Array.prototype.search==null) Array.prototype.search = function( token ) {
			for( var i=0; i<this.length; i++ ) {
				if( this[i] == token ) {
					return i;
				}
			}
			return -1;
		}
		
		if (String.prototype.replaceAll==null) String.prototype.replaceAll = function( token1, token2 ) {
			token1 = new RegExp(token1,"g")
			var str = this.replace(token1, token2)
			return str;
		}
		
		var oldFormAction = null;
		var oldForm = null;
		
		function disableSubmit( elem) { // disables the 'submit' function from the form that elem is in
			elem = byId(elem);
			var theForm = getFirstParentofType(elem, 'form' );
			if( !theForm ) return false;
			if( oldForm != theForm ) {
				oldForm = theForm
				oldFormAction = theForm.action;
			}
			theForm.action = "javascript:completeTS( globalWord )";
			global_activeField=  elem;
		}
		
		
		function enableSubmit() { // disables the 'submit' function from the form that elem is in
			if( global_activeField ) {
				if( oldForm != null ) {
					oldForm.action = oldFormAction;
				} else {
					return false;
				}
				oldForm = null;
			}
		}
		
		
		var tagscroll=-1;
		var matchCap = 8; // the number of matches that can be shown in the menu i.e. the length of the menu
		var safLockout = false; // specialized test var to deal with stupid safari double onkeyup event
		var global_activeField;
		var global_suggestionbox;
		
			
			
		var textEntities = new Array(  "&", 	"<", 	">" );	
		var htmlEntities = new Array(  "&amp;",	"&lt;",	"&gt;" );	
			
		function fromText2Entity( str ) {
			str = fromEntity2Text( str );
			var theLength = textEntities.length;
			for( var i=0; i< theLength; i++ ) {
				str = str.replaceAll( textEntities[i], htmlEntities[i] );
			}
			return str;
		}
		
		function fromEntity2Text( str ) {
			if( str == null ) return null;
			var foundAmp = str.search( '&' );
			if( foundAmp > -1 ) {
				var theLength = htmlEntities.length;
				for( var i=0; i< theLength; i++ ) {
					str = str.replaceAll( htmlEntities[i], textEntities[i] );
				}
			}
			return str;
		}
		
		
		
		var KEY_ENTER = 13,
			KEY_DOWNARROW = 40,
			KEY_UPARROW = 38,
			KEY_ESC = 27,
			KEY_SPACEBAR = 32,
			KEY_COMMA = 188, //44,
			KEY_TAB = 9;
			
		function getKeyCode(event) {
			var keyPressed = null;
			if( event && event.which ) {
				keyPressed = event.which; 
			} else { 
				event = window.event;
				keyPressed = event.keyCode;
			}
			return keyPressed;
		}
		
		
		var globalTagsField = null;
		var globalWord = null;

		function clearActiveSelection() {
		/** if the user selected a menu item with their keyboard, clear the selection **/
			var thePopup = dojo.byId( "tagsuggestbox" );
			if (!thePopup) { 	// fixed bug where an error will be thrown if thePopup === null
				return;
			} 
			var suggestions = thePopup.getElementsByTagName('a');
			var suggestionsLength = suggestions.length;
			for( var i = 0; i < suggestionsLength; i++ ) {
				if( suggestions[i] && suggestions[i]!= globalWord) {
					dojo.html.removeClass( suggestions[i], 'active' );
					dojo.html.removeClass( suggestions[i], 'selected' );
				}
			}
			//tagscroll=-1;
		}

		
		function makeActive( theElem ) {
			theElem = dojo.byId(theElem);
			globalWord = null;
			clearActiveSelection() ;
			dojo.html.addClass( theElem, 'active' );
			globalWord = theElem;
		}

		function makeSelected( theElem ) {
			theElem = dojo.byId(theElem);
			clearActiveSelection();
			dojo.html.addClass( theElem, 'selected' );
			globalWord = theElem;
		}

		function fieldValueToTagArray( allWords ) {
		/** convert the value of the input field to an array **/
			var wordArray = allWords.split(/ /); /* the space-delimited words in the text field, as an array */
			wordArray = removeEmpties( wordArray ); // take out empty entries caused by whitespaces
			return wordArray;
		}
		
		function removeEmpties( theArray ) { 
		/** takes any empty values out of an array. Good, for example, if there are several delimiters in a row **/
			var newArray = new Array();
			for( var i=0; i < theArray.length; i ++ ) {
				if( theArray[i] && (theArray[i].length > 0) ) {
					newArray.push(theArray[i]);
				}
			}
			return newArray;
		
		}
		
		function matchWords(wordArray, masterTagArray) {
		/** match words from an array of strings against a master Tag dictionary **/
			var wordArrayLen = wordArray.length;
			var currentWord = wordArray.pop().toLowerCase(); // make the comparison case-insensitive
			var wordMatch = new Array(); // wordMatch is the array of strings that I want to bring into the popup
			
			/* populating array 'wordMatch' with matches from masterTagArray 	*/
				var currentWordLength = currentWord.length;
				var dictWord = " ";
				var masterTagArrayLength = masterTagArray.length;
				for( var i=0, j=0; i< masterTagArrayLength && j < matchCap; i++ ) { 
					dictWord = masterTagArray[i][2];
					if( dictWord != null ) {
						if (  dictWord.substr(0, currentWordLength).toLowerCase() == currentWord && 
							(wordArray.contains(dictWord)==false) ) { 
							// if the word in this array slot contains what I've just typed (and hasn't already been entered)...
							wordMatch.push( masterTagArray[i] ); // ...add it to the array of matches 
							j++
						}
					}
				}
			/* end populating array 'wordmatch' 	*/
			//wordMatch =masterSortTagArray( wordMatch ); // sort the matches by my usage, count, and alpha
			wordArray.push(currentWord);
			return wordMatch;
		}
		
		function masterSortTagArray( tagArray ) { 
		/** sort by 'mytag' (primary), usage (secondary), and alpha order (tertiary) **/
			var newArray = new Array(0);
			var j=0;
			var tagArrayLength = tagArray.length
			for( var i=0; i< tagArrayLength ; i++ ) {
				var newArrayLength = newArray.length;
				for( j=0 ;  (( j < newArrayLength ) && ( Number(tagArray[i][0]) < Number(newArray[j][0]))); j++ ) {
					 /* first sort by whether or not I've used it */
					 ;
				}
				for( j=j;  (( j < newArrayLength ) && (Number(tagArray[i][0]) <= Number(newArray[j][0]))  && ( Number(tagArray[i][1]) < Number(newArray[j][1]))); j++ ) {
					 /* then, sort by usage count */
					 ;
				}
				for( j=j;  ((j < newArrayLength ) && (Number(tagArray[i][0]) <= Number(newArray[j][0]))  && (Number(tagArray[i][1]) == Number(newArray[j][1]))  && ((tagArray[i][2]) > (newArray[j][2])) ); j++ ) {
					 /* then, last sort alphabetically */
					 ;
				}
				newArray.splice( j, 0, tagArray[i]);
			}
			return newArray;
		
		}
		
		function buildTagMenu( wordMatch, thePopup, tagField) {
		/** take the array wordMatch and create html output **/
			//var newVal = "";
			var showString = "";
			var tagFieldId = nameTag(tagField);
			//alert( "tagFieldId = "+tagFieldId);
			thePopup.innerHTML = "";
			for( var i=0; (i< matchCap) && (i < wordMatch.length); i++ ) {  //build the menu from the word matches...
				var theWord = wordMatch[i][2] ;
				var theCount = wordMatch[i][1] ;
				var theClassName ="";
				var htmlWord = fromText2Entity(theWord) ;
				var theWord = fromEntity2Text(htmlWord) ;
				showString = "<span>" + htmlWord + "</span>&nbsp; ";
				if( wordMatch[i][0] == '1') {
					theClassName +=" mytag";
				}
				var newLink = document.createElement("a");	
				var newLinkID = nameTag(newLink);
				newLink.theWord = theWord;
				newLink.theWordHTML = htmlWord;
				newLink.tagscroller = i;
				newLink.tagFieldId = tagFieldId;
				newLink.onmousedown = function() {
						activeFlyout=true;
						//makeSelected(this);
					}
				newLink.onmouseover = function() {
						tagscroll = this.tagscroller;
						makeActive(this);
						disableSubmit( this.tagFieldId );
					}
				newLink.onmouseup = function() {
						//alert("mousep!");
						completeTS(this);
					}
				newLink.className = theClassName;
				newLink.setAttribute('href', 'javascript:void(0);');
				newLink.innerHTML = showString;
				thePopup.appendChild( newLink );
			}
			//thePopup.innerHTML = newVal; //...and populate the html with the menu
			return true;
		}
				
		function showBox( suggestionbox, TagField,  prevWords) {
		/** if the tagSuggestion menu is not showing, this function positions it and fades it in **/
			suggestionbox = dojo.byId(suggestionbox);
			var suggestionboxChildren = suggestionbox.getElementsByTagName( 'div' ); 
			var suggestionboxChildrenLength = suggestionboxChildren.length;
			var theTop = dojo.byId( 'taglength');
			if( theTop == null) {
				var theTopNode = document.createElement("div"); // build the pagemask HTML
				theTopNode.setAttribute('id', 'taglength');
				document.body.appendChild( theTopNode );
				theTop = dojo.byId( 'taglength' );
			}
			//alert( theTop );
			var theBox = null;
			/*for( var i=0; i < suggestionboxChildrenLength && (theBox == null || theTop == null); i ++ ) {
				if( suggestionboxChildren[i].className == 'top'  ) {
					theTop = suggestionboxChildren[i];
					//alert( "theTop found.");
				}
				if( suggestionboxChildren[i].className == 'body' ) {
					for( var j=0; j < suggestionboxChildren[i].childNodes.length; j ++ ) {
						if( suggestionboxChildren[i].childNodes[j].className == 'fade' ) {
							var theBox = suggestionboxChildren[i].childNodes[j];
							//alert( "theBox found. id = "+theBox.id);
						}
					}
				}
			}*/
			 theBox = dojo.byId( global_tagsuggestID );
			
			if( theBox.style.display != "block" ) { //if it's not already showing, let's show it.
			
				TagField = dojo.byId (TagField);
				
				var fieldHeight = getHeight( TagField ); // was originally int "24"
				var inputWidth =dojo.style.getInnerWidth( TagField );
				
			
				theBox.style.visibility = "hidden";
				theBox.style.display = "block";	 // can't detect the width of the element if it's not shown.
					var popWidth = dojo.style.getInnerWidth( theBox ); 
					var wordArray = fieldValueToTagArray( TagField.value );
					wordArray.pop();
					theTop.innerHTML = fromText2Entity( wordArray.join(" ") );
					var currentWordWidth = dojo.style.getOuterWidth( theTop );
					//alert( "getOuterWidth = "+currentWordWidth);
				theBox.style.display = "none";	 
				theBox.style.visibility = "visible";
				
				var xyPos = dojo.style.getAbsolutePosition( TagField, true );
				var fieldLeftEnd = xyPos.x;
				var fieldTopStart = xyPos.y;
				
				var xOffset = inputWidth - popWidth;
				if( popWidth > inputWidth ) { 
					 xOffset = 0;
				} else if( currentWordWidth < xOffset && popWidth < inputWidth) { 
					 xOffset = currentWordWidth;
				} 
			
				
				theBox.style.left = (fieldLeftEnd + xOffset)+"px"; //position it
				theBox.style.top = (fieldTopStart+fieldHeight)+"px";
				
				fadeShowLB( theBox, fadeInRate );
				return true;
			} else { 
				return false;
			}
		}


var activeFlyout = false; // lock mechanism to prevent flyout from closing before mousedown event is done.

function completeTS( theLink ) {
	//alert( "completing " + newString);
		theLink = dojo.byId(theLink);
		var TagField = dojo.byId( theLink.tagFieldId );
		var allWords = TagField.value;
		var wordArray = fieldValueToTagArray( allWords );
		wordArray.pop();
		//var newString = fromEntity2Text( theLink.theWord );
		wordArray.push( theLink.theWord );
		TagField.value = wordArray.join(" ") + " " ; // add an extra space at the end.
		activeFlyout = false;
		TagField.blur();
		hideTS();
		//clearActiveSelection(); 
		//enableSubmit();
		LBselectInputLastChar(TagField); // move keyboard focus to end of selection
		resetFieldFocus( TagField ); //tagscroll= -1;
		//return newString;
		enableSubmit();
}

function hideTS() {
	if( !activeFlyout ) {
		var theBox = dojo.byId( global_tagsuggestID );
		if( theBox != null ) 
			dojo.lfx.html.fadeHide(theBox, fadeInRate).play();
	}
	enableSubmit();
	clearActiveSelection(); 
	tagscroll=-1;
}

var globalField = null;

function resetFieldFocus( TagField ) {
// an attempt to deal with safari's odd highlight bug.
	if( isSaf ) {
		TagField.blur();
		globalField = TagField;
		setTimeout("globalField.focus()", fadeInRate+1 );
	}
}

var tagfieldCounter = 1;
var tagfieldCounterPrefix = "tagfield_"; // these three are used for tagsuggest

function nameTag( elem ) { // give an element an ID if one was not assigned in the HTML
	var TagField = byId( elem );
	
	if( TagField.id == null || TagField.id == ""  ) { // if this has an id name...
		TagField.id = (tagfieldCounterPrefix + tagfieldCounter);
		tagfieldCounter++;
	} else { 	
		; //do nothing
	} //otherwise, give it an ID

	return TagField.id;
}





/****************

emailsuggest

****************/

var allemailArray = new Array();

function dumpEmailData(type, data, evt ) { /* creates a data structure (2d array) out of the space-delimted text data */
	//var theBox = dojo.byId( 'texter' );
	var lineDelimiter = /[\n\r]/;
	var singleTagArray = new Array();
	allemailArray = data.split(lineDelimiter);
	allemailArray = masterSortEmailArray( allemailArray ); 
	emailsLoaded = true;
		
  //  var msg = "Data dump:\n" + data;
  //  alert( msg );
	
}
		function disableEmailSubmit( elem) { // disables the 'submit' function from the form that elem is in
			elem = byId(elem);
			var theForm = getFirstParentofType(elem, 'form' );
			if( !theForm ) return false;
			if( oldForm != theForm ) {
				oldForm = theForm
				oldFormAction = theForm.action;
			}
			theForm.action = "javascript:completeEmail( globalWord )";
		}
		
		
		function masterSortEmailArray( tagArray ) { 
		/** sort by 'mytag' (primary), usage (secondary), and alpha order (tertiary) **/
			var newArray = new Array(0);
			var j=0;
			var tagArrayLength = tagArray.length
			for( var i=0; i< tagArrayLength ; i++ ) {
				var newArrayLength = newArray.length;
				for( j=0;  ((j < newArrayLength ) && (tagArray[i] > newArray[j]) ); j++ ) {
					 /* then, last sort alphabetically */
					 ;
				}
				newArray.splice( j, 0, tagArray[i]);
			}
			return newArray;
		
		}

function completeEmail( theLink ) {
	var TagField =  dojo.byId(theLink.tagFieldId);
	var allWords = TagField.value;
	var wordArray = fieldValueToEmailArray( allWords );
	wordArray.pop();
	var newString = fromEntity2Text( theLink.theWord );
	wordArray.push( newString );
	TagField.value = wordArray.join(", ")+", " ; // add an extra space at the end.
	activeFlyout = false;
	hideTS();
	LBselectInputLastChar(TagField); // move keyboard focus to end of selection
	clearActiveSelection(); 
	tagscroll=-1;
	//return newString;
}

		
		function fieldValueToEmailArray( allWords ) {
		/** convert the value of the input field to an array **/
			var wordArray = allWords.split(/[ ,;:]/); /* the delimited words in the text field, as an array */
			wordArray = removeEmpties( wordArray ); // take out empty entries caused by whitespaces
			return wordArray;
		}
		

function emailsuggest( TagField, suggestionbox, event ) {

	TagField = byId( TagField );
	var allWords = TagField.value;
	var allWordsLength = allWords.length;
	
	var parentForm = getFirstParentofType( TagField, 'form' );

	if( tagscroll < 0  && (allWordsLength == 0 || allWords.charAt(allWordsLength-1) == " " || allWords == null ) ) { 
		// if the last char is a space or the field is empty...
		hideTS(); // hide that TA menu....
		return false; // and skip this whole function.
	} else if ( tagsLoaded == false  ) { 
		// global var to tell us if we've successfully loaded the tags file. if we haven't...	
		hideTS(); // hide that TA menu....
		return false; // and skip this whole function.
	} else {
		;
	}
	
	globalTagsField = TagField;
	/*	nameTag( parentForm );*/
	
	var thePopup = dojo.byId( "tagsuggestbox" );
	var suggestions = thePopup.getElementsByTagName('a');
	var suggestionsLength = suggestions.length;

	var keyPressed= getKeyCode(event);
	//alert('keyPressed = '+keyPressed);
	
	var wordArray = fieldValueToTagArray( allWords);
	
	//alert( "keyPressed = "+keyPressed+", tagscroll = "+tagscroll+", suggestionsLength = "+suggestionsLength);
	if( keyPressed == KEY_DOWNARROW && (suggestionsLength > 0) ) { 
	// down arrow
		if( isSaf ) { // special code to catch safari double keyup event
			if( safLockout == false ) {safLockout = true;}
			else { safLockout = false; return false;}
		}
		if( tagscroll < suggestionsLength ) {
			if( tagscroll > -1 )  dojo.html.removeClass( suggestions[(tagscroll)], 'active' );
			tagscroll++;
			if( tagscroll < suggestionsLength ) {
				makeActive( suggestions[(tagscroll)] );
				disableEmailSubmit( TagField );
			} else {
				enableSubmit();
				tagscroll = -1;
			}
		}
		return true;
	} else if( keyPressed == KEY_UPARROW && (suggestionsLength > 0) ) { 
	// up arrow
		LBselectInputLastChar(TagField); // move keyboard focus to end of selection
		if( isSaf ) { // special code to catch safari double keyup event
			if( safLockout == false ) {safLockout = true;}
			else { safLockout = false; return false;}
		}
		if( tagscroll > -1 ) {
			if( tagscroll < suggestionsLength ) dojo.html.removeClass( suggestions[(tagscroll)], 'active' );
			tagscroll--;
			if( tagscroll > -1 ) {
				makeActive( suggestions[(tagscroll)] );
				disableEmailSubmit( TagField );
			} else {
				enableSubmit();
			}
		} else {
			tagscroll = suggestionsLength-1;
			if( tagscroll > -1 ) 				
				makeActive( suggestions[(tagscroll)] );
			disableEmailSubmit( TagField );
		}
		
		LBselectInputLastChar(TagField); // move keyboard focus to end of selection
		return true;
		
	} else if( keyPressed == KEY_COMMA && (tagscroll > -1) ) { 
	// spacebar, with a suggestion highlighted
		//alert( "comma pressed! keyPressed = "+keyPressed);
		//alert( "keyPressed = "+keyPressed+", tagscroll = "+tagscroll + ", suggestions[(tagscroll)].getAttribute('onclick') = "+ suggestions[(tagscroll)].getAttribute('onclick'));
		TagField.value = wordArray.join(", "); // add an extra space at the end.
		if( tagscroll < suggestionsLength ) {
			var theWord = suggestions[(tagscroll)].innerHTML;
			completeEmail( TagField, theWord );
		}
		return true;
				
	} else if( keyPressed == KEY_SPACEBAR && (tagscroll > -1) ) { 
	// spacebar, with a suggestion highlighted
		//alert( "comma pressed! keyPressed = "+keyPressed);
		//alert( "keyPressed = "+keyPressed+", tagscroll = "+tagscroll + ", suggestions[(tagscroll)].getAttribute('onclick') = "+ suggestions[(tagscroll)].getAttribute('onclick'));
		TagField.value = wordArray.join(", "); // add an extra space at the end.
		if( tagscroll < suggestionsLength ) {
			var theWord = suggestions[(tagscroll)].innerHTML;
			completeEmail( TagField, theWord );
		}
		return true;
		
	} else if( keyPressed == KEY_ENTER && (tagscroll > -1) ) { 
	// return/enter, with a suggestion highlighted
		if( tagscroll < suggestionsLength ) {
			//var theWord = suggestions[(tagscroll)].childNodes[0].innerHTML;
			//completeTS( suggestions[(tagscroll)] );
		}
		return true;
		
	} else if( keyPressed == KEY_TAB && (tagscroll > -1) ) { 
	// tab, with a suggestion highlighted
		//alert( "keyPressed = "+keyPressed+", tagscroll = "+tagscroll + ", suggestions[(tagscroll)].getAttribute('onclick') = "+ suggestions[(tagscroll)].getAttribute('onclick'));
		if( tagscroll < suggestionsLength ) {
			var theWord = suggestions[(tagscroll)].innerHTML;
			completeEmail( TagField, theWord );
		}
		//return true;
		
	} else if( keyPressed == KEY_ESC && (tagscroll > -1) ) { 
	// 'esc', with a suggestion highlighted
		//alert( "keyPressed = "+keyPressed+", tagscroll = "+tagscroll);
		clearActiveSelection(); 
		tagscroll=-1;
		enableSubmit();
		return true;
		
	} else { // update the suggestion menu
		clearActiveSelection(); 
		
		nameTag( TagField ); // we need to make sure this element has a name so we can reference it later.
		
		var wordCount = wordArray.length;
		//alert( "allemailArray = "+allemailArray);
		var wordMatch =  matchEmails(wordArray, allemailArray);
		var wordMatchCount = wordMatch.length;
		//alert( "wordMatchCount = "+wordMatchCount);
		if( wordMatchCount > 0 ) {
			buildEmailMenu( wordMatch, thePopup, TagField );
			showBox( suggestionbox, TagField,  wordCount-1); // only executes if box isn't already showing
		} else { // if there are no matches
			thePopup.innerHTML = ""; //clear the text
			hideTS(); // and hide that guy.
		}
		return true;
	}
	
}

		function buildEmailMenu( wordMatch, thePopup, tagField) {
		/** take the array wordMatch and create html output **/
			thePopup.innerHTML = "";
			var showString = "";
			var tagFieldId = tagField.id;
			var matchCount = wordMatch.length;
			if( matchCount > 0 ) {
				for( var i=0; (i< matchCap) && (i < matchCount); i++ ) {  //build the menu from the word matches...
					//alert( "adding wordMatch["+i+"] = "+wordMatch[i]);
					var theWord = wordMatch[i] ;
					var htmlWord = fromText2Entity(theWord) ;
					//theWord = fromEntity2Text(htmlWord) ;
					showString = htmlWord;
					showString = "<span>" + htmlWord + "</span>";
					var newLink = document.createElement("a");	
					newLinkID = nameTag(newLink);
					newLink.theWord = theWord;
					newLink.theWordHTML = htmlWord;
					newLink.tagscroller = i;
					newLink.tagFieldId = tagFieldId;
					newLink.onmousedown = function() {
							activeFlyout=true;
						}
					newLink.onmouseover = function() {
							tagscroll = this.tagscroller;
							makeActive(this);
							disableSubmit( this.tagFieldId );
						}
					newLink.onmouseup = function() {
							//alert("mousep!");
							completeEmail(this);
						}
					newLink.setAttribute('href', 'javascript:void(0);');
					newLink.innerHTML = showString;
					thePopup.appendChild( newLink );
				}
			} else {
				hideTS(); 
			}
			//thePopup.innerHTML = newVal; //...and populate the html with the menu
			return true;
		}
		

		
		function matchEmails(wordArray, masterTagArray) {
		/** match words from an array of strings against a master Tag dictionary **/
			var currentWord = wordArray.pop().toLowerCase(); // make the comparison case-insensitive
			var wordMatch = new Array(); // wordMatch is the array of strings that I want to bring into the popup
			
			/* populating array 'wordMatch' with matches from masterTagArray 	*/
				var currentWordLength = currentWord.length;
				var dictWord = " ";
				var masterTagArrayLength = masterTagArray.length;
				for( var i=0, j=0; i< masterTagArrayLength && j < matchCap; i++ ) { 
					dictWord = masterTagArray[i];
					if ( ( dictWord.substr(0, currentWordLength).toLowerCase() == currentWord ) && 
						(wordArray.contains(dictWord)==false) ) { 
						// if the word in this array slot contains what I've just typed (and hasn't already been entered)...
						wordMatch.push( masterTagArray[i] ); // ...add it to the array of matches 
						// alert( "match found! masterTagArray["+i+"] = "+masterTagArray[i] );
						j++
					}
				}
			/* end populating array 'wordmatch' 	*/
			//wordMatch =masterSortTagArray( wordMatch ); // sort the matches by my usage, count, and alpha
			
			return wordMatch;
		}

		

function checkEmail_code( strng ) {
	var error = 0;
	var emailFilter=/^((([0-9a-zA-Z\-\_]+)(\.[0-9a-zA-Z\-\_]*)*)@((([0-9a-zA-Z\-]+)(\.[0-9a-zA-Z\-]*)*)(\.[a-zA-Z]{2,4})))[\s]*$|^((".+"\s*)?<)((([0-9a-zA-Z\-\_]+)(\.[0-9a-zA-Z\-\_]*)*)@((([0-9a-zA-Z\-]+)(\.[0-9a-zA-Z\-]*)*)(\.[a-zA-Z]{2,4})))>[\s]*$/; // only allows legal chars
	
	if (strng == "" ||strng == null ) {
	// no address?
	   error = 1;
	} else if (!(emailFilter.test(strng))) { 
	// correcly formatted?
		   error = 2;
	} 
	return error;    
}

		function sendEmail(theForm) {
			//theForm.style.visibility = 'hidden';
			var errMsg ='';
			theForm = dojo.byId( theForm );
			var theAddresses = theForm.elements['emails'];
			if( theAddresses != null ) {
				//alert( "theAddresses == " + theAddresses);
				theAddresses = theAddresses.value;
				theAddresses = fieldValueToEmailArray( theAddresses );
				var addCount = theAddresses.length;
				if( addCount == 0 ) {
					errMsg = checkEmail2( null );
				} else if( addCount == 1) {
					errMsg = checkEmail2( theAddresses[0] );
				} else {
					errCodes= new Array();
					for( var i=0; i< addCount; i++) {
						errCodes.push( checkEmail_code( theAddresses[i] ));
					}
					var code0 = errCodes.contains(0);
					var code1 = errCodes.contains(1);
					var code2 = errCodes.contains(2);
					var code3 = errCodes.contains(3);
					if( code2 ) {
						errMsg = "One or more addresses you entered does not appear to be valid.";
					} else if ( code3 ) {
						errMsg = "One or more addresses you entered appears to contain illegal characters.";
					} else if ( !code0 ) {
						errMsg = "You didn't enter an email address.";
					} 
				}
			}
			//alert( "errMsg == " + errMsg);
			if( errMsg == "" ) {					
				//data_send2friend( theForm['emails'], theForm['message'], window.location.href );
				//hideTS();
//				closeDialog();
				//clearError( theForm['emails'] );
				theForm.action = "";
				theForm.submit();
			} else {
				addError( theForm['emails'], errMsg);
			}	
		}


function checkEmail2( strng ) {
	var error="";
	var emailFilter=/^.+@.+\..{2,4}$/;
	if (  strng == null || strng.length == 0) {
	   error = "You didn't enter an email address.\n";
	} else if (!(emailFilter.test(strng))) { 
		   error = "Please enter a valid email address.\n";
	} else {
	//test email for illegal characters
		 var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		 if (strng.match(illegalChars)) {
			error = "The email address contains illegal characters.\n";
		  }
	}
	return error;    
}

function addError( theElement, errMsg ) {
		clearError( theElement );
		theElement = dojo.byId( theElement );
		var tempElem = getFirstParentofType( theElement, 'p' );
		if( tempElem != null ) {
			theElement = tempElem;
		}
		dojo.html.addClass( theElement, 'error' );
		var errorMsgElem = document.createElement( 'span' );
		errorMsgElem.className = "errorContent";
		errorMsgElem.innerHTML = errMsg;
		theElement.appendChild(errorMsgElem);
		
}

function clearError( theElement  ) {
		theElement = dojo.byId( theElement );
		var tempElem = getFirstParentofType( theElement, 'p' );
		if( tempElem != null ) {
			theElement = tempElem;
		}
		dojo.html.removeClass( theElement, 'error' );
		var errorMsgElem = getFirstChildwithClass( theElement, 'errorContent' );
		if( errorMsgElem ) {
			errorMsgElem.parentNode.removeChild(errorMsgElem);		
		}		
}


/***********

for tag cloud

************/

var activeCLO = null;
var activetag_over = null;
var cloud_timer = 0;
var wit_ondelay_timer = 0;
var wit_delay_timer = 0;
var waiting4fo = false;

function cloudfo( CloudLink, CloudText ) {
	clearTimeout(wit_delay_timer);
	var thePopup = dojo.byId( CloudText );
	var theLink = dojo.byId( CloudLink );
	if( (waiting4fo == false) &&  ((activeCLO != thePopup) || (activetag_over != theLink ))) {
		// showPopupper();
		hideCLO2();
		activetag_over = theLink;
		linkID = nameTag(CloudLink);
		cloud_timer = setTimeout("cloudfo1(\'"+linkID+"\',\'"+CloudText+"\')", fo_delay);
		waiting4fo = true;
	}

}

function cloudfo1( CloudLink, CloudText ) {
	var CloudLink = xGetElementById( CloudLink );
	var thePopup = xGetElementById( CloudText );
	var adjustmentX = -4;
	var adjustmentY = 0;
	if( activeCLO != thePopup ) {
		hideCLO2();
		activeCLO = thePopup;
		activeCLO = thePopup;
	}
	var fieldLeftEnd = xPageX(CloudLink) ;
	var fieldTopStart = xPageY(CloudLink);
	
	activeCLO.style.visibility = "hidden";
	activeCLO.style.display = "block";
	var adjustmentY = 0+dojo.style.getMarginBoxHeight(CloudLink);
	var popupWidth = dojo.style.getMarginBoxWidth( thePopup );
	activeCLO.style.display = "none";
	activeCLO.style.visibility = "visible";
	dojo.html.addClass(CloudLink, "tagBlowout");	
	var xyPos = dojo.style.getAbsolutePosition( CloudLink, true );
	var fieldLeftEnd = xyPos.x;
	var fieldTopStart = xyPos.y;
	//alert( "fieldLeftEnd +  = " + fieldLeftEnd + ", popupWidth = " + popupWidth);
	var totalWidth = getCanvasWidth() - (marginOfError + fieldLeftEnd + popupWidth );
	if( totalWidth < 0 ) {
		adjustmentX = totalWidth;
	}

	waiting4fo = false;
	activeCLO.style.left = fieldLeftEnd+adjustmentX+"px";
	activeCLO.style.top = fieldTopStart+adjustmentY+"px";
	fadeShowLB(activeCLO, wit_delay);
	// hidePopupper();
/*	mytimer_on_ID = setTimeout("cloudfo2", fo_delay);*/
}

function cloudfo2( ) {
	dojo.lfx.html.fadeIn(dojo.byId(activeCLO), wit_delay).play();
}

function keepCLO() {
	clearTimeout(wit_delay_timer);
}

var close_delay = 100;

function hideCLO() {
	//alert( "activeCLO is "+ activeCLO );
	// hidePopupper();
	waiting4fo = false;
	wit_delay_timer = setTimeout("hideCLO2()", close_delay);
	clearTimeout(cloud_timer);
}

function hideCLO2() {
	//alert( "activeCLO is "+ activeCLO );
	clearTimeout(wit_delay_timer);
	//activeCLO.style.display = "none";
	dojo.html.removeClass(activetag_over, "tagBlowout");	
	if( activeCLO ) {
		dojo.lfx.html.fadeHide(dojo.byId(activeCLO), fadeOutRate).play();
		activeCLO = 0;
	}
	
}




/***********

for What is this

************/

function clearEmptyNodes( theElement ) {
	if( theElement && theElement.childNodes ) {
		for( var i=0; i< theElement.childNodes.length; i ++) {
			//alert( "theElement.childNodes[i].value is "+ theElement.childNodes[i].innerHTML);
			if( theElement.childNodes[i].innerHTML == null || theElement.childNodes[i].innerHTML == 'undefined' ) {
				theElement.removeChild( theElement.childNodes[i]  );
			}
		}
		return theElement;
	}
}

var activeWIT = null;
var clickforWIT = true;

function showWhatisthis(WhatIsLink, WhatIsText) {
	mytimer_on_ID = setTimeout(("whatisthis("+WhatIsLink+","+WhatIsText+")"), fo_delay );
}

function wit_fo( WhatIsLink, WhatIsText ) {
	keepWIT();
	var thePopup = dojo.byId( WhatIsText );
	var theLink = dojo.byId( WhatIsLink );
	if( (waiting4fo == false) &&  (activeWIT != thePopup) ) {
		//alert ( "(waiting4fo == false) &&  (activeWIT != thePopup) ");
		// showPopupper();
		hideWIT2();
		activeWIT = thePopup;
		linkID = nameTag(WhatIsLink);
		clickforWIT = false;
		wit_ondelay_timer = setTimeout("whatisthis(\'"+linkID+"\',\'"+WhatIsText+"\')", fo_delay);
		waiting4fo = true;
	}

}

function positionWIT( WhatIsLink, WhatIsText ) {
	var thePopup = dojo.byId( WhatIsText );
	var WhatIsLink = dojo.byId( WhatIsLink );
	thePopup = clearEmptyNodes( thePopup );
	//alert( "thePopup.childNodes.length is "+ thePopup.childNodes.length);
	var thePopupBody = thePopup.childNodes[1];
	thePopupBody = clearEmptyNodes( thePopupBody );
	var thePopupFade = thePopupBody.childNodes[0]; 
	var thePopupBottom= thePopup.childNodes[2]; 
	
	if( activeWIT != thePopup ) {
		hideWIT2();
		activeWIT = thePopup;
	}

	thePopup.style.visibility = "hidden";
	thePopup.style.display = "block"; // I can't detect its size if diplay is 'none', but it pops up on some browsers when I check this info. So I display it hidden when I check it's stats.
		var adjustmentX = 0-dojo.style.getPaddingWidth(thePopupFade)/2;
		var adjustmentY = dojo.style.getContentBoxHeight(WhatIsLink) 
			+ dojo.style.getContentBoxHeight(thePopupBottom)
			+ dojo.style.getPaddingHeight(thePopupFade);//+ thePopupBottom.style.height + thePopupFade.style.paddingBottom;
		var divHeight = dojo.style.getBorderBoxHeight(WhatIsText);
	thePopup.style.display = "none";
	thePopup.style.visibility = "visible";
	var xyPos = dojo.style.getAbsolutePosition( WhatIsLink, true );
	var fieldLeftEnd = xyPos.x;
	var fieldTopStart = xyPos.y;
	thePopup.style.left = fieldLeftEnd+adjustmentX+"px";
	thePopup.style.top = (fieldTopStart-divHeight+adjustmentY)+"px";
}


function whatisthis( WhatIsLink, WhatIsText ){
	clearTimeout(wit_delay_timer);
	var thePopup = dojo.byId( WhatIsText );
	if( activeWIT != thePopup ) {
		hideWIT2();
		activeWIT = thePopup;
	}
	positionWIT( WhatIsLink, WhatIsText );
	
	if( clickforWIT == false ) {
		fadeShowLB(activeWIT, wit_delay);
		clickforWIT = true;
	} else {
		fadeShowLB(activeWIT, fadeInRate);
	}
}

function keepWIT() {
	clearTimeout(wit_delay_timer);
}

function hideWIT() {
	//alert( "activeWIT is "+ activeWIT );
	wit_delay_timer = setTimeout("hideWIT2()", fo_delay);
}

function hideWIT_mo() {
	//alert( "activeWIT is "+ activeWIT );
	waiting4fo = false;
	wit_delay_timer = setTimeout("hideWIT2()", close_delay);
	// hidePopupper();
}

function hideWIT2() {
	//alert( "activeWIT is "+ activeWIT );
	clearTimeout(wit_ondelay_timer);
	//activeWIT.style.display = "none";
	if( activeWIT ) {
		dojo.lfx.html.fadeHide(dojo.byId(activeWIT), fadeOutRate).play();
	}
	waiting4fo = false;
	activeWIT = 0;
}


/****************

Userflyout 

*****************/


var activeFlyout = null;
var activeUserLink = null;
var user_on_delay_timer = 0; 
var user_off_delay_timer = 0; 

function showUserFlyout( userPopup, userLink ) {
	//mytimer_on_ID = setTimeout(("userFlyout("+userLink+","+userPopup+")"), fo_delay );
	LBDebug( ('<b>showUserFlyout</b>. userLink='+userLink+", userPopup="+userPopup) );
	user_fo( userLink, userPopup ); 
}

function user_fo( userLink, userPopup ) {
		//alert( 'in user_fo!');
	//keepuser();
	clearTimeout(user_off_delay_timer);
	var thePopup = dojo.byId( userPopup );
	if( thePopup == null ) return false;
	var theLink = dojo.byId( userLink );
	if( theLink == null ) return false;
	//else alert( 'thePopup ='+thePopup+", theLink=="+theLink);
		//alert( 'thePopup ='+thePopup);
	if(  (activeUserLink != theLink || activeFlyout != thePopup ) && (mouseUnderneath(activeFlyout) == false )) {
		hideusernow(activeFlyout);
		var linkID = nameTag(userLink);
		activeFlyout = thePopup;
		activeUserLink = theLink;
		user_on_delay_timer = setTimeout("userFlyout(\'"+linkID+"\',\'"+userPopup+"\')", fo_delay);
		LBDebug( ('calling  userFlyout. linkID='+linkID+", userPopup="+userPopup) );
	} else {
		//alert( "we're already on that one."); 
	}

}

function mouseUnderneath(theElement) {
	LBDebug( 'in <b>mouseUnderneath</b>');
	if( isIE &&  theElement !=null ) {
		//theElement = dojo.byId( theElement );
		var elemHeight = dojo.style.getOuterHeight(theElement);
		var elemWidth = dojo.style.getOuterHeight(theElement);
		var xyPos = dojo.style.getAbsolutePosition( theElement, true );
		var elemTop = xyPos.y; 	
		var elemLeft = xyPos.x;
		
		var yOverlap = false;
		if(( myMouseY > elemTop) && (myMouseY < (elemTop+elemHeight ))) 
			yOverlap = true;
		LBDebug( 'yOverlap ='+yOverlap);
			
		var xOverlap = false;
		if( (myMouseX > elemLeft) && (myMouseX < (elemLeft+elemWidth ))) 
			xOverlap = true;
		LBDebug( 'xOverlap ='+xOverlap);
			
		if( xOverlap && yOverlap ) {
			//alert(' overlap! ');
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function positionUserFO( userLink, userPopup ) {
	var thePopup = dojo.byId( userPopup );
	var userLink = dojo.byId( userLink );
	thePopup = clearEmptyNodes( thePopup );
	//alert( "thePopup.childNodes.length is "+ thePopup.childNodes.length);
	var thePopupBody = thePopup.childNodes[1];
	thePopupBody = clearEmptyNodes( thePopupBody );
	var thePopupFade = thePopupBody.childNodes[0]; 
	var thePopupTop= thePopup.childNodes[0]; 
	
	var linkCenterAdjWidth = dojo.style.getMarginBoxHeight( userLink )/2 -25; //if the link img is smaller than 48x48, center the larger image over it
	var linkCenterAdjHeight = dojo.style.getMarginBoxHeight( userLink )/2 -25;
	thePopup.style.visibility = "hidden";
	thePopup.style.display = "block"; // I can't detect its size if display is 'none', but it pops up on some browsers when I check this info. So I display it hidden when I check it's stats.
		var adjustmentX = 0-dojo.style.getPaddingWidth(thePopupFade)/2 -1 + linkCenterAdjWidth ;
		var adjustmentY = 0-dojo.style.getContentBoxHeight(thePopupTop) -3 + linkCenterAdjHeight;
		var flyoutWidth = dojo.style.getOuterWidth(thePopup); 
		//var linkHeight = dojo.style.getBorderBoxHeight(userLink);
	thePopup.style.display = "none";
	thePopup.style.visibility = "visible";
	var xyPos = dojo.style.getAbsolutePosition( userLink, true );
	var fieldLeftEnd = xyPos.x;
	var fieldTopStart = xyPos.y;
	
	var viewportWidth = dojo.html.getViewportWidth();
	var theDiff = viewportWidth - (fieldLeftEnd+adjustmentX+flyoutWidth);
	//alert(viewportWidth +", "+fieldLeftEnd +", "+flyoutWidth);
	if(  theDiff < 0) { // outside the window width
		adjustmentX += theDiff-8; // 8 is a little buffer
	} 	
		thePopup.style.left = fieldLeftEnd+adjustmentX+"px";
	
	thePopup.style.top = (fieldTopStart+adjustmentY)+"px";
}


function userFlyout( userLink, userPopup ){
	//alert( 'in  userFlyout!');
	clearTimeout(user_on_delay_timer);
	clearTimeout(user_off_delay_timer);
	var thePopup = dojo.byId( userPopup );
	positionUserFO( userLink, userPopup );
	fadeShowLB(activeFlyout, fadeInRate);
		waiting4fo = true;
	LBDebug( ('userFlyout, userLink='+userLink+", userPopup="+userPopup) );
}

function keepuser() {
	if( activeFlyout ) {
		LBDebug( ('in keepuser. activeFlyout='+activeFlyout.id+", activeUserLink="+activeUserLink.id) );
		clearTimeout(user_off_delay_timer);
	}
}

var hideUser = hideuser;
function hideuser() {
	//alert( "activeFlyout is "+ activeFlyout.id );
	if( activeFlyout ) {
		LBDebug( ('in hideuser. activeFlyout='+activeFlyout.id+", activeUserLink="+activeUserLink.id) );
		user_off_delay_timer = setTimeout(("hideusernow('"+activeFlyout.id+"')"), fo_check);
	}
}


function hideusernow(flyoutID) {
	clearTimeout(user_on_delay_timer);
	flyoutID = dojo.byId(flyoutID);
	/*if( flyoutID ) {
		dojo.lfx.html.fadeHide(flyoutID, fadeOutRate).play();
		LBDebug( ("hideusernow. activeUserLink="+activeUserLink.id)+", flyoutID="+flyoutID );
	}*/
	if( activeFlyout ) {
		dojo.lfx.html.fadeHide(activeFlyout, fadeOutRate).play();
		LBDebug( ("hideusernow. activeUserLink="+activeUserLink.id)+", flyoutID="+flyoutID );
	}
	waiting4fo = false;
	activeFlyout = null;
	activeUserLink = null;
}



/****************

for navmenu

****************/

//var nav_delay = 1000;
//alert( nav_delay);
var nav_delay = fo_delay;

function positionNav( WhatIsLink, WhatIsText ) {
	var thePopup = dojo.byId( WhatIsText );
	var WhatIsLink = dojo.byId( WhatIsLink );
	var xyPos = dojo.style.getAbsolutePosition( WhatIsLink, true );
	var viewportWidth = dojo.html.getViewportWidth();
	var linkWidth = dojo.style.getBorderBoxWidth(WhatIsLink);
	var shadoWidth = 5; 
	
	thePopup.style.visibility = "hidden";
	thePopup.style.display = "block"; 
	 // I can't calculate its size if diplay is 'none', but it pops up on some browsers when I check this info. So I display it hidden when I check it's stats.
	var menuWidth = dojo.style.getBorderBoxWidth(thePopup);
	if( dojo.html.hasClass(thePopup, 'minimenu') ) {
		//minimenu goes to the right, instead of under
		var adjustmentX = linkWidth
		var adjustmentY = 1;
		
		if( xyPos.x+adjustmentX+menuWidth > viewportWidth ) { // outside the window width
			adjustmentX = -menuWidth+shadoWidth;
		}
		
	} else { 
		// regular menu goes below
		var adjustmentX = 0;
		var adjustmentY = dojo.style.getBorderBoxHeight(WhatIsLink);/*+4*/
		
		if( xyPos.x+adjustmentX+menuWidth > viewportWidth ) { // outside the window width
			adjustmentX = linkWidth - menuWidth +shadoWidth;
		}
	}
	thePopup.style.display = "none";
	thePopup.style.visibility = "visible";
	
	thePopup.style.left = (xyPos.x+adjustmentX)+"px";
	thePopup.style.top = (xyPos.y+adjustmentY)+"px";
}

var activeLink = null;

function wait_navmenu( WhatIsLink, WhatIsText ){
	keepNav();
	var thePopup = dojo.byId( WhatIsText );
	if( activeWIT != thePopup ) {
		var theLink = nameTag( WhatIsLink );
		waiting4fo = true;
		//alert( "in wait_navmenu. linkname = " +theLink );
		cloud_timer = setTimeout("show_navmenu(\'"+theLink+"\',\'"+WhatIsText+"\')", nav_delay);
		//setTimeout("waiting4fo = false;", nav_delay);
	} else {
		//alert( "in wait_navmenu. activeWIT = " +activeWIT +", and waiting4fo ==" + waiting4fo );
		//waiting4fo = false;
	}
}


function show_navmenu( WhatIsLink, WhatIsText ){
	keepNav();
	clearTimeout(cloud_timer);
	//alert( "in show_navmenu. cloud_timer = " +cloud_timer );
	//waiting4fo = false;
	var thePopup = byId( WhatIsText );
	if( activeWIT != thePopup  ) {
		hideNav_now();	
		activeWIT = thePopup;
		activeLink = byId( WhatIsLink );
		//var theLink = nameTag( WhatIsLink );
		positionNav( WhatIsLink, WhatIsText );
		fadeShowLB(activeWIT, fadeInRate);
		//alert( "in show_navmenu. WhatIsLink = " +WhatIsLink );
		dojo.html.addClass( WhatIsLink, "active" );
		activeWIT.focus();
		if (window.event) window.event.cancelBubble = true;
//		alert( 'window.event.cancelBubble='+window.event.cancelBubble);
	} else {
		//alert( "in show_navmenu. activeWIT = " +activeWIT +", and waiting4fo ==" + waiting4fo );
		return false;
	}
}

function toggle_navmenu( WhatIsLink, WhatIsText ){
	clearTimeout(wit_delay_timer);
	var thePopup = byId( WhatIsText );
	if( activeWIT == thePopup && waiting4fo == false ) {
		hideNav_now();
		activeWIT = 0;
		return false;
	} else {
		show_navmenu( WhatIsLink, WhatIsText );
	}
}

function wait_navmenu_disc( WhatIsLink, WhatIsText ){ // created for replies 
	var theMod = getFirstParentwithClass( WhatIsLink, 'mod' );
	if( dojo.html.hasClass( theMod, 'rep_collapsed') 
		|| dojo.html.hasClass( theMod, 'rep_uprated') )
		return false;
	else
		wait_navmenu( WhatIsLink, WhatIsText );
}

/*function show_navmenu_disc( WhatIsLink, WhatIsText ){
	keepNav();
	var theMod = getFirstParentwithClass( WhatIsLink, 'mod' );
	if( dojo.html.hasClass( theMod, 'rep_collapsed') 
		|| dojo.html.hasClass( theMod, 'rep_uprated') )
		return false;
	else
		show_navmenu( WhatIsLink, WhatIsText );
}*/

function toggle_navmenu_disc( WhatIsLink, WhatIsText ){
	clearTimeout(wit_delay_timer);
	var theMod = getFirstParentwithClass( WhatIsLink, 'mod' );
	if( dojo.html.hasClass( theMod, 'rep_collapsed') 
		|| dojo.html.hasClass( theMod, 'rep_uprated') )
		rateNeutral( WhatIsLink );
	else
		toggle_navmenu( WhatIsLink, WhatIsText );
}


function keepNav() {
	keepWIT();
}

function hideNav() {
	clearTimeout(wit_delay_timer);
	clearTimeout(cloud_timer);
	// Debug.write("in hideNav ");
   
	wit_delay_timer = setTimeout("hideNav_now()", fo_delay);
}

function hideNav_now() {
	clearTimeout(wit_ondelay_timer);
	if( activeWIT ) {
		activeWIT.onmouseout = function() {hideNav()};
		dojo.html.removeClass( activeLink, "active" );
		dojo.lfx.html.fadeHide(dojo.byId(activeWIT), fadeOutRate).play();
	}
	activeWIT = 0;
	waiting4fo = false;
}

function killLink( theLink ) {
	theLink = byId( theLink );
	theLink.href= "javascript:;";
}



/****************

sidebar flyout

****************/

function showSideFlyout(PostID, srcElem) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	var thePost = dojo.byId( PostID );
	var theElem = null;
	if( srcElem != null )
		theElem = dojo.byId( srcElem );
	if( activeFlyout != thePost ||  activeDiscElem != theElem ) { // skip if we're already showing*/
		clearTimeout(mytimer_on_ID);
		hideFlyout2(); 	// hide the active flyout
		activeFlyout = thePost; // make thePost the active flyout
		activeDiscElem = theElem;
		showSideFlyout2(); 	// show Post
	} else {
		return true; // do nothing;
	}
}

function showSideFlyout2() {
	// showPopupper();
	//lockOn = true;
	mytimer_on_ID = setTimeout("showSideFlyout3()", fo_delay);
}


function showSideFlyout3() {
	// showPopupper();
	clearTimeout(mytimer_on_ID);
	if( activeFlyout ) {
		positionSideFlyout();
		if( activeDiscElem ) {
			dojo.html.addClass(activeDiscElem,'active');
		}
		//var stemmer = getStemmer();
		fadeShowLB(activeFlyout, fadeInRate);
		//fadeShowLB(stemmer, fadeInRate);
		// hidePopupper();
	}
}

function positionSideFlyout() {
	if( activeFlyout && activeDiscElem ) {
		var adjustmentX = 0;//-10
		var adjustmentY = 2;//2
		
		var xyPos = dojo.style.getAbsolutePosition( activeDiscElem, true );
		var linkHeight = dojo.style.getOuterHeight( activeDiscElem, true );
		//var yCenter = linkHeight/2; // formerly calculated this on height of the link. Didn't look so good on a multi-line.
		var yCenter = 10; // beter to vertical center on the firstline/icon. this is ~ line height/2 + padding-top 
		activeFlyout.style.visibility = "hidden";
		activeFlyout.style.display = "block";
		positionStemmer( activeFlyout, 'e' );
		var flyoutWidth = dojo.style.getOuterWidth(activeFlyout); 
		var flyoutHeight = dojo.style.getOuterHeight(activeFlyout); 
		activeFlyout.style.display = "none";
		activeFlyout.style.visibility = "visible";
		
		var scrollTop = dojo.html.getScrollTop() ;
		var scrollBotom = scrollTop + dojo.html.getViewportHeight();
		var totalHeight = scrollBotom - marginOfError - (xyPos.y + flyoutHeight/2 );
		
		adjustmentX = 0-flyoutWidth+adjustmentX;
		activeFlyout.style.left = xyPos.x+ adjustmentX + "px";	
		if( totalHeight < 0 ) { // if we're going off the bottom of the viewport
			adjustmentY = 0-(flyoutHeight)+ yCenter*2;
			if( (xyPos.y +adjustmentY + flyoutHeight) > scrollBotom ) { // if we'd render outside the viewport, readjust
				activeFlyout.style.top = scrollBotom - flyoutHeight + 4+ "px" // just place it at the bottom, less some shadow height
			} else {
				activeFlyout.style.top = xyPos.y +adjustmentY+ "px"; 	
			}
			positionStemmer( activeFlyout, 'ese' );
		} else if( (xyPos.y - (flyoutHeight)/2) < scrollTop ) { // if we're going off the top of the viewport
			if( xyPos.y +adjustmentY < scrollTop ) { // if desired positioning goes out of the viewport
				activeFlyout.style.top = scrollTop+1+ "px"; //just place it at the tope	
			} else {		
				activeFlyout.style.top = xyPos.y +adjustmentY+ "px"; 	
			}
			positionStemmer( activeFlyout, 'ene' );
		} else { // position regularly
			adjustmentY = 0-(flyoutHeight)/2+ adjustmentY+ yCenter;
			activeFlyout.style.top = xyPos.y +adjustmentY+ "px"; 	
		}

	}
}


	

/****************

for dialog box

****************/

var pageMaskScreenID = "pagemask";
var activeDialog = null;
var dialog_top_offset = 50; // how far you want the dialog offset from the top of the page.
var dialogbottom_offset = 5; // min distance from bottom of page
var dialog_fadeinRate = 100;

function showDialog( popDiv, escapable ) {
	if( escapable == undefined ) escapable = true; // default value for optional param
	activeDialog = dojo.byId( popDiv );	
	if( activeDialog == null ) return false;
	activeDialog.style.visibility = "hidden";
	activeDialog.style.display = "block";	
	var Xoffset = (getCanvasWidth() - dojo.style.getOuterWidth(activeDialog))/2;
	activeDialog.style.display = "none";	
	activeDialog.style.visibility = "visible";
	activeDialog.style.top = (dialog_top_offset + getScrollTop() ) + "px";
	activeDialog.style.left = Xoffset+"px";
	fadeShowLB(activeDialog, dialog_fadeinRate);
	showPageMask();
	checkDialogYFit(); 
	window.onresize = function() {
		showPageMask();
		activeDialog.style.top = (dialog_top_offset + getScrollTop() ) + "px";
		checkDialogYFit(); 
	}
	window.onscroll = function() {
		activeDialog.style.top = (dialog_top_offset + getScrollTop() ) + "px";
	}
	if( escapable ) document.onkeypress = function(e) { // pass esacapable as false if you don't want user closing the modal with escape key
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		if( keycode == 0 ) { // mozilla returns '0' for non-ascii keycodes. If 0, try e.keyCode to ge the value.
			keycode = e.keyCode;
		}
		// alert( 'in Keypresser. keycode= '+keycode);
		if(keycode == KEY_ESC ){ 
			closeDialog();
		}
		
	}
}

function swapDialog( popDiv ) {
	/* a trick to use if you're switching from one dialog box to another, as on upload new version */
	if( activeDialog == null ) {
		showDialog( popDiv );
		return
	}
	activeDialog.style.display = "none";	

	activeDialog = dojo.byId( popDiv );	
	if( activeDialog == null ) return false;
	activeDialog.style.visibility = "hidden";
	activeDialog.style.display = "block";	
	var Xoffset = (getCanvasWidth() - dojo.style.getOuterWidth(activeDialog))/2;
	activeDialog.style.display = "none";	
	activeDialog.style.visibility = "visible";
	activeDialog.style.top = (dialog_top_offset + getScrollTop() ) + "px";
	activeDialog.style.left = Xoffset+"px";
	fadeShowLB(activeDialog, dialog_fadeinRate);
	resizePageMask();
	checkDialogYFit(); 
}

// Just for fixing the IE bug
// Note: this is just temporary - in the future we will fix it in a better way.
function showDialog2(popDiv, escapable) {
	if( escapable == undefined ) escapable = true; // default value for optional param
	activeDialog = dojo.byId( popDiv );	
	if( activeDialog == null ) return false;
	activeDialog.style.visibility = "hidden";
	activeDialog.style.display = "block";	
	var Xoffset = (getCanvasWidth() - dojo.style.getOuterWidth(activeDialog))/2;
	activeDialog.style.display = "none";	
	activeDialog.style.visibility = "visible";
	activeDialog.style.top = (dialog_top_offset + getScrollTop() ) + "px";
	activeDialog.style.left = Xoffset+"px";
	fadeShowLB(activeDialog, dialog_fadeinRate);
	showPageMask();
	checkDialogYFit2(); 
	window.onresize = function() {
		showPageMask();
		activeDialog.style.top = (dialog_top_offset + getScrollTop() ) + "px";
		checkDialogYFit2(); 
	}
	window.onscroll = function() {
		activeDialog.style.top = (dialog_top_offset + getScrollTop() ) + "px";
	}
	if( escapable ) document.onkeypress = function(e) { // pass esacapable as false if you don't want user closing the modal with escape key
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		if( keycode == 0 ) { // mozilla returns '0' for non-ascii keycodes. If 0, try e.keyCode to ge the value.
			keycode = e.keyCode;
		}
		// alert( 'in Keypresser. keycode= '+keycode);
		if(keycode == KEY_ESC ){ 
			closeDialog();
		}
		
	}
}

function checkDialogYFit2() {
	var CHROMEHEIGHT= 25;
	var theFade = getFirstChildwithClass( activeDialog, 'fade' );
	theFade.style.height = "auto";
	var viewportHeight = dojo.html.getViewportHeight();
	var fadeXheight =  dojo.style.getOuterHeight(theFade);
	var popupXheight =  dojo.style.getOuterHeight(activeDialog);
	var yDiff = viewportHeight - (popupXheight + dialogbottom_offset + dialog_top_offset + CHROMEHEIGHT); 
	if( yDiff < 0 ) {
		//if the dialog with room on top and bottom is taller than the viewport...
		theFade.style.height = (fadeXheight + yDiff) + "px";
		//alert( "yDiff = "+yDiff+", theFade.style.height = "+theFade.style.height);
	} 
}

// --- -end just for IE problem


function checkDialogYFit() {
	var CHROMEHEIGHT= 25;
	var theFade = getFirstChildwithClass( activeDialog, 'lister' );		// this recursion hangs IE7 and 8.
	if( theFade == null ) { // if there's no 'lister', we'll scroll the whole area;
		var theFade = getFirstChildwithClass( activeDialog, 'fade' );
	}
	theFade.style.height = "auto";
	var viewportHeight = dojo.html.getViewportHeight();
	var fadeXheight =  dojo.style.getOuterHeight(theFade);
	var popupXheight =  dojo.style.getOuterHeight(activeDialog);
	var yDiff = viewportHeight - (popupXheight + dialogbottom_offset + dialog_top_offset + CHROMEHEIGHT); 
	if( yDiff < 0 ) {
		//if the dialog with room on top and bottom is taller than the viewport...
		theFade.style.height = (fadeXheight + yDiff) + "px";
		//alert( "yDiff = "+yDiff+", theFade.style.height = "+theFade.style.height);
	} 
}

var pagemaskExists = true;
var MCEpagemask = false;

function showPageMask() {
	var theGray = dojo.byId( pageMaskScreenID );
	//alert( " theGray== "+theGray);
	if( theGray == null ) {
		var maskDef = document.createElement("div"); // build the pagemask HTML
		var maskDef2 = document.createElement("div");
		maskDef.setAttribute('id', pageMaskScreenID);
		maskDef2.innerHTML = "&nbsp;";
		maskDef.appendChild( maskDef2 );
		document.body.appendChild( maskDef );
		theGray = dojo.byId( pageMaskScreenID );
	}
	resizePageMask();
	theGray.style.display = 'block'; 
	resizePageMask();
	disableProblemWidgets();
	//fadeShowLB(theGray, (fadeInRate/4));
	pagemaskExists = true;
	
}


function hidePageMask() {
	var theGray = dojo.byId( pageMaskScreenID );
	if( theGray !=null ) {
		theGray.style.display = 'none'; 
		setTimeout( 'enableProblemWidgets();',fadeInRate);
		enableProblemWidgets();
	}
	// theGray.style.zIndex = '99'; 		
	pagemaskExists = 0 ;
}


function showPageMaskMCE() { 
/* for use with inlinepopups. If a mask doesn't exist, create one. 
Else change the zindex to 503, above the existing dialog box */
	var theGray = dojo.byId( pageMaskScreenID );
	//alert( " theGray== "+theGray);
	if( theGray == null ) {
		showPageMask(); 
	} else  { 
		theGray.style.zIndex = '503'; 
		MCEpagemask = true;
	}
}

function hidePageMaskMCE() {
/* for use with inlinepopups. If a mask doesn't exist, create one. 
Else change the zindex to 503, above the existing dialog box */
	if( MCEpagemask == false ) {
		hidePageMask();
	} else {
		var theGray = dojo.byId( pageMaskScreenID );
		theGray.style.zIndex = '2'; 	
		resizePageMask();
		MCEpagemask = false;
	}

}

function resizePageMask() {
	var theGray = dojo.byId( pageMaskScreenID );
	var viewportHeight = dojo.html.getViewportHeight();
	var canvasHeight = getCanvasHeight();
	var maskHeight = canvasHeight; 
	// alert( 'canvasHeight = '+canvasHeight );
	if (canvasHeight < viewportHeight) {
		maskHeight = viewportHeight;
	} 
	// alert( 'document.body.scrollHeight = '+document.body.scrollHeight );
	// alert( 'document.body.offsetHeight = '+document.body.offsetHeight );
	if( maskHeight < document.body.scrollHeight ) {
		maskHeight = document.body.scrollHeight;
	}
	theGray.style.width = getCanvasWidth()+"px";
	theGray.style.height = maskHeight+"px";
		LBDebug( ' Pagemask rezised' );
}

function closeDialog( ) {
	if( activeDialog ) {
		dojo.lfx.html.fadeHide(activeDialog, fadeOutRate).play();
		hidePageMask();
	//	dojo.lfx.html.fadeHide(theGray, fadeInRate).play();
		window.onresize = null;
		window.onscroll = null;
		document.onkeypress = null;
		
	} else {
		return false;
	}
}

function getCanvasWidth() {
	var myDoc;
	if( document.scrollWidth ) {
  		myDoc = document;
	} else if ( document.body.scrollWidth ) {
  		myDoc = document.body;
	}
	
  	return myDoc.scrollWidth;
}

function getCanvasHeight() {
	var myDoc;
	if( document.scrollHeight ) {
  		myDoc = document;
	} else if ( document.body.scrollHeight ) {
  		myDoc = document.body;
	}
  	return myDoc.scrollHeight;
}

function disableProblemWidgets() {
	var myDoc = document.body;
	dojo.html.addClass(myDoc, "ProblemWidgets");
}


function enableProblemWidgets() {
	var myDoc = document.body;
	dojo.html.removeClass(myDoc, "ProblemWidgets");
}

function getScrollTop() { // directly taken from http://www.quirksmode.org/viewport/compatibility.html
	var y=0;
	if (window.pageYOffset) // all except Explorer
	{
		y = window.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}
	 return y;
}

function setScroll( x,y ) {
	scroll(x,y);
	return true;
}

function getScrollLeft() { // directly taken from http://www.quirksmode.org/viewport/compatibility.html
	var x=0;
	if (window.pageXOffset) // all except Explorer
	{
		x = window.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft) // Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
	}
	 return x;
}


function getMouseXY(e) {
	/*setpageLayout();*/
	//if ( activeFlyout != null && activeFlyout.style != null) {
	
		//var myMouseX, myMouseY;


		var e = e || window.event;
		if (e.pageX || e.pageY){
			myMouseX = e.pageX;
			myMouseY = e.pageY;
		} else if (e.clientX || e.clientY) {
			myMouseX = event.clientX; //+ document.body.scrollLeft ;
			myMouseY = event.clientY; //+ document.body.scrollTop;
		}
		if ( isIE ) { 
				myMouseX += getScrollLeft();
				myMouseY += getScrollTop();
		}
}





function delclass ( fullStr, delStr ) {
	var doneStr = fullStr.replace( delStr, "" );
	/*if( doneStr == " " ) {
		var doneStr = "";
	}*/
	return doneStr;
}

function addclass ( fullStr, addStr ) {
	var doneStr = (fullStr + " " + addStr );
	return doneStr;
}


function addclass2 ( objID, addStr ) {
	var theObj = dojo.byId( objID );
	theObj.className = theObj.className + " " + addStr;
}


function delclass2 ( objID, delStr ) {
	var theObj = dojo.byId( objID );
	theObj.className = theObj.className.replace( delStr, "" );

}

function getHeight(id) { 
	var el=dojo.byId(id).offsetHeight; 
	return(el); 
}

function getWidth(id) { 
	var el=dojo.byId(id).offsetWidth; 
	return(el); 
}







// xGetComputedStyle, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetComputedStyle(oEle, sProp, bInt)
{
  var s, p = 'undefined';
  var dv = document.defaultView;
  if(dv && dv.getComputedStyle) {
    s = dv.getComputedStyle(oEle,'');
    if (s) p = s.getPropertyValue(sProp);
  } else if(oEle.currentStyle) {
    // convert css property name to object property name for IE
    var a = sProp.split('-');
    sProp = a[0];
    for (var i=1; i<a.length; ++i) {
      c = a[i].charAt(0);
      sProp += a[i].replace(c, c.toUpperCase());
    }   
    p = oEle.currentStyle[sProp];
  }
  else return null;
  return bInt ? (parseInt(p) || 0) : p;
}

// xPageX, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xPageX(e)
{
  if (!(e=dojo.byId(e))) return 0;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}

// xPageY, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xPageY(e)
{
  if (!(e=dojo.byId(e))) return 0;
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
//  if (xOp7Up) return y - document.body.offsetTop; // v3.14, temporary hack for opera bug 130324 (reported 1nov03)
  return y;
}

// xDef, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}


// modified dojo.html.selectInputText to move cursor to the end of the block

function LBselectInputLastChar(element){
	element = byId(element);
	if(document.selection && document.body.createTextRange){ // IE
		var range = element.createTextRange();
		range.moveStart("character", element.value.length);
		range.moveEnd("character", element.value.length);
		range.select();
//		range.setEndPoint("EndToEnd", 0);
//		range.scrollIntoView(false);
	}else if(window["getSelection"]){
		var selection = window.getSelection();
		// FIXME: does this work on Safari?
		element.setSelectionRange(element.value.length, element.value.length);
		//element.scrollIntoView();
	}
	element.focus();
}

function LBselectAll( elem ) {
	element = byId(elem);
	if(document.selection && document.body.createTextRange){ // IE
		var range = element.createTextRange();
		range.moveStart("character", 0);
		range.moveEnd("character", element.value.length);
		range.select();
//		range.setEndPoint("EndToEnd", 0);
//		range.scrollIntoView(false);
	}else if(window["getSelection"]){
		var selection = window.getSelection();
		// FIXME: does this work on Safari?
		element.setSelectionRange(0, element.value.length);
		//element.scrollIntoView();
	}
	element.focus();
}
 
function alertSize() {
  var myWidth = -1, myHeight = -1;
  htmlroot = document;
 //myWidth = dojo.html.getViewportWidth();
 // myHeight = dojo.html.getViewportHeight();
 // myHeight = dojo.style.getContentHeight(htmlroot);
  myWidth = htmlroot.scrollWidth;
  myHeight = htmlroot.scrollHeight;
 // window.alert( 'Width = ' + myWidth +', Height = ' + myHeight );
}




/********

admin pages

*********/



function getFirstParentwithClass( elem, key ) {
	elem = byId( elem );
	var elemPar = elem.parentNode;
	// key = key.toLowerCase();
	// if( elem.tagName.toLowerCase() == key ) {
	// 	return elem; 
	if( dojo.html.hasClass( elem, key )) {
		return elem; 
	} else if( elemPar == null ) {
		return false;
	} else {
		return getFirstParentwithClass( elemPar, key );
	}
}

function getFirstParentofType( elem, tagType ) {
	tagType = tagType.toLowerCase();
	elem = byId( elem );
	if( elem == null || elem.tagName == null) {
		return null;
	} 
	var elemPar = elem.parentNode;
	if( elem.tagName.toLowerCase() == tagType ) {
		return elem; 
	} else if( elemPar == null || elemPar.tagName == null) {
		return null;
	} else if( elemPar.tagName.toLowerCase() == tagType ) {
		return elemPar; 
	} else {
		return getFirstParentofType( elemPar, tagType );
	}
}

function getFirstFormElementbyType( formName, key ) {
	theForm = byId( formName );
	if( theForm.tagName.toLowerCase() != 'form' ) {
		return null;
	} else {
		key = key.toLowerCase();
		var formLength = theForm.elements.length;
		for( var i =0; i <formLength; i++ ){
			if( theForm.elements[i].type.toLowerCase()  == key ) {
				return theForm.elements[i];
			}
		}
		return false;
	}
}


function getFirstChildwithName( elem, key ) {
	elem = byId( elem );
	key = key.toLowerCase();
	var elemChildren = elem.childNodes;
	var childLength = elemChildren.length;
	for( var i =0; i <childLength; i++ ) { //first, broad,
		//var nodeName = elemChildren[i].getAttribute('name') ;
		var nodeName = elemChildren[i].name;
		if( nodeName && nodeName.toLowerCase() == key ) {
			//alert( 'elemChildren['+i+'] is a match for key '+key+'.  elemChildren['+i+'].name  == ' +nodeName ); 
			return elemChildren[i];
		} else {
			//alert( elemChildren[i] +'is no match for key '+key+'.  elemChildren['+i+'].name  == ' +nodeName +' className == ' +elemChildren[i].className + ', tagName == ' + elemChildren[i].tagName + ')'); 
		}
	}
	for( i =0; i <childLength; i++ ){ // then deep
		var tempReturn = getFirstChildwithName( elemChildren[i], key );
		if( tempReturn ) {
			return tempReturn;
		}
	}
	//alert( 'key '+key+' not found in elem ' + elem); 
	return null;
}

function getFirstChildwithTag( elem, key ) {
	elem = byId( elem );
	if( elem == null ) return null;
	key = key.toLowerCase();
	var elemChildren = elem.childNodes;
	if( elemChildren == null ) return null;
	var childLength = elemChildren.length;
	for( var i =0; i <childLength; i++ ) { //first, broad,
		//var nodeName = elemChildren[i].getAttribute('name') ;
		var nodeName = elemChildren[i].tagName;
		if( nodeName && nodeName.toLowerCase() == key ) {
			//alert( 'elemChildren['+i+'] is a match for key '+key+'.  elemChildren['+i+'].name  == ' +nodeName ); 
			return elemChildren[i];
		} else {
			//alert( elemChildren[i] +'is no match for key '+key+'.  elemChildren['+i+'].name  == ' +nodeName +' className == ' +elemChildren[i].className + ', tagName == ' + elemChildren[i].tagName + ')'); 
		}
	}
	for( i =0; i <childLength; i++ ){ // then deep
		var tempReturn = getFirstChildwithTag( elemChildren[i], key );
		if( tempReturn ) {
			return tempReturn;
		}
	}
	//alert( 'key '+key+' not found in elem ' + elem); 
	return null;
}



function getFirstChildwithClass( elem, key ) {
	//alert( 'in  getFirstChildwithClass.' ); 
	elem = byId( elem );
	if( elem == null ) return null;
	if( elem && dojo.html.hasClass(elem, key) ) {
		return elem;
	}
	var elemChildren = elem.childNodes;
	if( elemChildren == null ) return null;
	var childLength = elemChildren.length;
	for( var i =0; i <childLength; i++ ) { //first, broad,
		if( dojo.html.hasClass(elemChildren[i], key) ) {
			//alert( 'elemChildren['+i+'] is a match for key '+key+'.  elemChildren['+i+'].name  == ' +elemChildren[i] ); 
			return elemChildren[i];
		}
	}
	for( i =0; i <childLength; i++ ){ // then deep
		var tempReturn = getFirstChildwithClass( elemChildren[i], key );
		if( tempReturn ) {
			return tempReturn;
		}
	}
	//alert( 'key '+key+' not found in elem ' + elem); 
	return null;
}


function getAllChildrenwithClass( elem, key ) {
	elem = byId( elem );
	var matchArray = new Array();
	if( elem && dojo.html.hasClass(elem, key) ) {
		matchArray.push(elem);
	}
	var elemChildren = elem.childNodes;
	if( elemChildren == null ) return matchArray;
	var childLength = elemChildren.length;
	for( var i =0; i <childLength; i++ ) { 
		var tempArray = getAllChildrenwithClass( elemChildren[i], key );
		matchArray = matchArray.concat( tempArray );
		
	}
	return matchArray;
}


function getAllChildrenwithTagname( elem, key ) { //doesn't seem to work!
	elem = byId( elem );
	key = key.toLowerCase();
	var matchArray = new Array();
	//alert( "elem.tagName ="+elem.tagName);
	if( elem && elem.tagName && elem.tagName.toLowerCase() == key ) {
		matchArray.push(elem);
	}
	var elemChildren = elem.childNodes;
	if( elemChildren == null ) return matchArray;
	var childLength = elemChildren.length;
	for( var i=0; i<childLength; i++ ) { 
		var tempArray = getAllChildrenwithTagname( elemChildren[i], key );
		matchArray = matchArray.concat( tempArray );
		
	}
	return matchArray;
}

function getFirstChildwithNodeType( elem, key ) {
	elem = byId( elem );
	var elemChildren = elem.childNodes;
	if( elemChildren == null ) return null;
	var childLength = elemChildren.length;
	for( var i =0; i <childLength; i++ ) { //first, broad,
		var nodeName = elemChildren[i].nodeType;
		if( nodeName && nodeName == key ) {
			return elemChildren[i];
		}
	}
	for( i =0; i <childLength; i++ ){ // then deep
		var tempReturn = getFirstChildwithNodeType( elemChildren[i], key );
		if( tempReturn != null ) {
			return tempReturn;
		}
	}
	//alert( 'key '+key+' not found in elem ' + elem); 
}


function revealAlert( elemID ) {
	var theAlert = dojo.byId( elemID );
	dojo.html.removeClass( theAlert, "nodisplay" );

}

function removeEmail( elem ) {
	removeFromTable( elem );
	revealAlert( "hiddenSaver" ); 
}


		function removeFromTable (elem) {
			elem = getFirstParentofType(elem, 'tr');
			elem.cells[0].innerHTML = "";
			dojo.html.addClass(elem, "delete");	
			dojo.lfx.html.fadeHide(elem, fadeOutRate).play();
		}
			
			
		var rowToDelete = null;
		
		function delWithCheck (elem) {
			rowToDelete = elem;
			elem = getFirstParentofType(elem, 'tr');
			var thegroupName = node2String(elem.cells[1]);
			var group2quit = byId( 'group2quit' );
			group2quit.innerHTML = thegroupName;
			showDialog( 'deleteCheck' );
		}
			
		function quitGroup() {
			closeDialog();
			removeFromTable(rowToDelete);		
			textDecrement( 'groupCount' );
		}

		function dontQuitGroup() {
			closeDialog();
			rowToDelete=null;
		}



function removeFromTable2( elem ) {
	elem = getFirstParentofType( elem, 'tr' );
	//elem.style.display = "none";
	dojo.html.addClass(elem, "disabled");	
	dojo.lfx.html.fadeHide(elem, fadeOutRate).play();	
}

function disableInTable( elem ) {
	elem = getFirstParentofType( elem, 'tr' );
	//elem.style.display = "none";
	dojo.html.addClass(elem, "disabled");	
}

function enableInTable( elem ) {
	elem = getFirstParentofType( elem, 'tr' );
	//elem.style.display = "none";
	dojo.html.removeClass(elem, "disabled");	
}

function showhide( elem ) {
	elem = byId( elem );
	if( elem.type == "checkbox" ) {
		if( elem.checked ) {
			enableInTable( elem );
		} else {
			disableInTable( elem );
		}
	}
}

function toggleRow( elem ) {
	elem = getFirstParentofType( elem, 'tr' );
	//elem.style.display = "none";
	if( dojo.html.hasClass(elem, "toggled") ) {
		dojo.html.removeClass(elem, "toggled");	
	} else {
		dojo.html.addClass(elem, "toggled");	
	}
}

function editName( elem ) {
	elem = getFirstParentofType( elem, 'tr' );
	//elem.style.display = "none";
	if( dojo.html.hasClass(elem, "toggled") ) {
		dojo.html.removeClass(elem, "toggled");	
	} else {
		dojo.html.addClass(elem, "toggled");	
	}
}

function deselectAllRows( elem ) {
	var theTable = getFirstParentofType( elem, 'table' );
	var rowCount = theTable.rows.length;
	for( var i=0; i<rowCount; i++ ) {
		dojo.html.removeClass(theTable.rows[i], 'selected');
	}
}	

function toggleSelectRow( elem ) {
	elem = byId( elem );
	if( elem.type == "checkbox" ||  elem.type == "radio" ) {
		if( elem.checked ) {
			selectInTable( elem );
		} else {
			deselectInTable( elem );
		}
	}
}

var selectedCount = 0;

function selectInTable( elem ) {
	if( elem.type == "radio" ) {
		deselectAllRows(elem);
		//elem.checked = true;
	}
	var tr = getFirstParentofType( elem, 'tr' );
	//elem.style.display = "none";
	dojo.html.addClass(tr, "selected");	
	selectedCount++;
}

function deselectInTable( elem ) {
	elem = getFirstParentofType( elem, 'tr' );
	//elem.style.display = "none";
	dojo.html.removeClass(elem, "selected");	
	selectedCount--;
}



var EmailActivated = false;

/*function checkEmail( popupID ) {
	if( EmailActivated == false) {
		EmailActivated = true;
		showDialog(popupID);
	}
}*/




var credRowCounter = 0;
var credRowPrefix = 'cellID'

function addCredRow( destTable, sourceForm ) {
	destTable = dojo.byId( destTable );
	sourceForm = dojo.byId( sourceForm );
	//alert( "sourceForm.elements[0].value = " +sourceForm.elements[0].value  );
	//alert( "sourceForm.elements[1].value = " +sourceForm.elements[1].value  );
	//alert( "sourceForm.elements['service'].value = " +sourceForm.elements['service'].value  );
	if( sourceForm.elements['accountID'].value =="" ) {
		return false;
	} else if( sourceForm.elements['accountPassword'].value =="" ) {
		return false;
	}
	
	var newRow = destTable.insertRow(-1);
	
	var newCell = newRow.insertCell(-1);
	newCell.className ='groupwithnext';
	if( sourceForm.elements['service'].value == 'y' ) {
		newCell.innerHTML = '<img src="/include3/images/ic_yahoo.gif" alt="Yahoo! Groups" class="ic16"/>';
	} else if( sourceForm.elements['service'].value == 'g' ) {
		newCell.innerHTML += '<img src="/include3/images/ic_google.gif" alt="Google Groups" class="ic16"/> ';
	} else {
		return false;
	}
	
	var statusCellID = credRowPrefix+credRowCounter;
	credRowCounter++;

	var newCell = newRow.insertCell(-1);
	newCell.className = 'groupwithlast';
	newCell.innerHTML = '<span class="toggleA">'+(sourceForm.elements['accountID'].value)+' </span>';
	newCell.innerHTML += '<span class="fieldLabel toggleB"><input class="border1 narrowmid1" value="'+sourceForm.elements['accountID'].value+'"/> Account ID<br/> <input type="password"  class="border1 narrowmid1" autocomplete="off" value="'+sourceForm.elements['accountPassword'].value+'"/> Password <br/> <input type="button" value="submit" onclick="toggleRow(this);resetCredStatus(\''+statusCellID+'\');"/> </span>';

	var newCell = newRow.insertCell(-1);
	newCell.className ='small';
	newCell.id = statusCellID;
	newCell.innerHTML = '<span class="small toggleA"><img src="/include3/images/ajax_loader.gif" class="ic16"/> Attempting login...</span>';
	
	var newCell = newRow.insertCell(-1);
	newCell.className ='small gray';
	newCell.id = statusCellID;
	newCell.innerHTML = '<a class="" href="javascript:;" onclick="toggleRow(this);">edit</a> | <a href="javascript:;" onclick="removeFromTable(this);">remove</a>';
	
	
	//var rowCount = destTable.rows.length;
	//alert( 'newRow.id = '+newRow.id)
	//fadeShowLB( destTable.rows[rowCount] );
	
	var newRowId = nameTag( newRow );
	flashRow( newRowId );
	
	sourceForm.reset();
	failCredStatus( statusCellID ); 
}

function resolveCredStatus( statusCellID ) {
	var timer = 1600;
	var newStatus = 'byId("'+statusCellID+'").innerHTML="<span class=\'gray  toggleA \' >4 groups, all synched<span>"';
	setTimeout( newStatus, timer);
}

function resetCredStatus( statusCellID ) {
	var statusCell = byId( statusCellID );
	statusCell.innerHTML="<span class='toggleA'><img src='/include3/images/ajax_loader.gif' class='ic16'/> Attempting login... <span>";
	resolveCredStatus( statusCellID ); 
}

function failCredStatus( statusCellID ) {
	var timer = 2700;
	var newStatus = 'byId("'+statusCellID+'").innerHTML="<span class=\' error toggleA \' >problem logging in<span>"';
	setTimeout( newStatus, timer);
}

			
		//Override to modify user options
		function addEmailRow( destTable, sourceForm ) {
			destTable = byId( destTable );
			sourceForm = byId( sourceForm );
			var theField = sourceForm.elements['newEmailAddress'];
			var errorMsg = document.createElement( 'span' );
				errorMsg.innerHTML = "Please enter a valid email address";
				errorMsg.className = "error";
			var lastElem = sourceForm.lastChild;
		 	
			if( dojo.html.hasClass( lastElem, "error"  )) {
				//alert( 'error aleady applied!' );
				lastElem.parentNode.removeChild( lastElem ) ;
			}
			var newRow = destTable.insertRow(-1);
	
			var newCell = newRow.insertCell(-1);
			newCell.className ='mid1';
			newCell.innerHTML = (theField.value);
		
			var newCell = newRow.insertCell(-1);
			newCell.className ='gray small';
			newCell.innerHTML = 'pending | <a href="javascript:;" onclick="removeFromTable(this);">remove</a> ';
		
			//var rowCount = destTable.rows.length;
			var newRowId = nameTag( newRow );
			flashRow( newRowId );
			revealAlert( "hiddenSaver" ); 
			sourceForm.reset();
			
		}


		//Override to modify user options
		function addEmailRow2( destTable ) {
			destTable = byId( destTable );

			var theField = byId('newEmailAddress');
			var errorMsg = document.createElement( 'span' );
				errorMsg.innerHTML = "Please enter a valid email address";
				errorMsg.className = "error";
			var lastElem = byId('errorspan');
		 	
			if( dojo.html.hasClass( lastElem, "error"  )) {
				//alert( 'error aleady applied!' );
				lastElem.parentNode.removeChild( lastElem ) ;
			}
			var newRow = destTable.insertRow(-1);
	
			var newCell = newRow.insertCell(-1);
			newCell.className ='mid1';
			newCell.innerHTML = (theField.value);
		
			var newCell = newRow.insertCell(-1);
			newCell.className ='gray small';
			newCell.innerHTML = 'pending | <a href="javascript:;" onclick="removeFromTable(this);">remove</a> ';
		
			//var rowCount = destTable.rows.length;
			var newRowId = nameTag( newRow );
			flashRow( newRowId );
			revealAlert( "hiddenSaver" ); 
			theField.value="";			
		}


function byId( elemID ) {
	
	if( typeof elemID != 'object' ) {
		elemID= document.getElementById(elemID);
	}
	return elemID;
}

function makePrimary( elem ) {
	elem = byId( elem );
	var oldRow = getFirstParentofType( elem, 'tr' );
	var oldRowNum = oldRow.rowIndex;
	var destTable = getFirstParentofType( oldRow, 'table' );
	var newRow = moveRowXtoY( destTable, oldRowNum, 0 );
	dojo.html.addClass( newRow.cells[0],'bold' );
	newRow.cells[1].innerHTML = 'primary email';
	nameTag( newRow );
	var oldRowID = nameTag( destTable.rows[oldRowNum]  );
	dojo.html.removeClass( destTable.rows[1].cells[0],'bold' );
	destTable.rows[1].cells[1].innerHTML = '<a href="javascript:;" onclick="makePrimary(this);">make primary</a> | <a href="javascript:;" onclick="removeFromTable(this);">remove</a>';
	flashRow( newRow ) ;
	flashRow_disable( oldRowID );
	revealAlert( "hiddenSaver" ); 
}

function getFirstBodyRow(tableElem) {
	tableElem = byId( tableElem );
	var i = 0 ;
	var searchKey = 'tableheader';
	//alert( "in getFirstBodyRow. row "+i+" class name is "+ tableElem.rows[i].className);
	var foundanything = false;
	while (	!foundanything ) {
		if( tableElem.rows[i].className && tableElem.rows[i].className.search(searchKey) != -1 ) {
			foundanything = true;
			//alert( "row "+i+" contains class name 'tableheader'");
		}
		i++;
	}
	return i;
}

function moveRowUp( elem ) {
	elem = byId( elem );
	var oldRow = getFirstParentofType( elem, 'tr' );
	dojo.html.removeClass(oldRow, 'lastRow');
	var oldRowIndex = oldRow.rowIndex;
	var destTable = getFirstParentofType( oldRow, 'table' );
	var firstActiveRowIndex = getFirstBodyRow(destTable); 
	//alert( "firstActiveRowIndex = "+firstActiveRowIndex);
	if( oldRowIndex > firstActiveRowIndex ) { 
		moveRowXtoY( destTable, oldRowIndex, (oldRowIndex-1) );
		var newRowID = nameTag( destTable.rows[oldRowIndex-1] );
		var oldRowID = nameTag( destTable.rows[oldRowIndex] );
		flashRow( newRowID ) ;
		flashRow_disable( oldRowID );
		dojo.html.addClass(destTable.rows[firstActiveRowIndex].id, 'firstRow');
		dojo.html.removeClass(oldRowID, 'firstRow');
			var tableLength = destTable.rows.length;
			dojo.html.addClass(destTable.rows[tableLength-1 ].id, 'lastRow');
	}
}

function moveRowDown( elem ) {
	elem = byId( elem );
	var oldRow = getFirstParentofType( elem, 'tr' );
	dojo.html.removeClass(oldRow, 'firstRow');
	var oldRowIndex = oldRow.rowIndex;
	var destTable = getFirstParentofType( oldRow, 'table' );
	var tableLength = destTable.rows.length;
	if( oldRowIndex < (tableLength-1) ) { 
		moveRowXtoY( destTable, oldRowIndex, (oldRowIndex+1) );
		var newRowID = nameTag( destTable.rows[oldRowIndex+1] );
		var oldRowID = nameTag( destTable.rows[oldRowIndex] );
		flashRow( newRowID ) ;
		flashRow_disable( oldRowID );
		dojo.html.removeClass(oldRowID, 'lastRow');
		dojo.html.addClass(destTable.rows[tableLength-1 ].id, 'lastRow');
			var firstActiveRowIndex = getFirstBodyRow(destTable); 
			dojo.html.addClass(destTable.rows[firstActiveRowIndex].id, 'firstRow');
	}
}


function editTag( elem ) {
	elem = byId( elem );
	var theRow = getFirstParentofType( elem, 'tr' );
	nameTag( theRow );

	var currentName = getCurrentTagValue( theRow );
	var newName = getNewTagValue( theRow );
	setNewTagValue( theRow, currentName );
	
	//flashRow( theRow );
	toggleRow( theRow );
	focusNewTagValue( theRow );
	
	return true;
}

function renameTag( elem ) {
	elem = byId( elem );
	var theRow = getFirstParentofType( elem, 'tr' );
	nameTag( theRow );

	var originalName = getOriginalTagValue( theRow );
	//alert( "originalName == " + originalName ); 
	var currentName = getCurrentTagValue( theRow );
	var newName = getNewTagValue( theRow );
	if( newName == "") {
		flashRow_disable( theRow );
	} else if( currentName == newName  ) {
		flashRow_disable( theRow );
	} else if( (currentName.toLowerCase() == newName.toLowerCase())  ) {
		data_tag_rename( currentName, newName );
		setCurrentTagValue( theRow, newName);
		flashRow_disable( theRow );
	} else {
		if( originalName == null ) {
			setOriginalTagValue( theRow, currentName );
		} else if ( originalName.toLowerCase() == newName.toLowerCase() ){
			setOriginalTagValue( theRow, false );
		} 
		data_tag_rename( currentName, newName );
		setCurrentTagValue( theRow, newName);
		checkTagMerge( theRow );
		flashRow( theRow );
	} 
	blurNewTagValue( theRow );
	toggleRow( theRow );
	
	//return true;
}

function checkTagMerge( theRow ) {
	var currentName = getCurrentTagValue( theRow );
	var currentNameLC = currentName.toLowerCase();

	var currentCount = getTagCount( theRow );
	var rowNum = theRow.rowIndex;
	var theTable = getFirstParentofType( theRow, 'table' );
	var theTableLength = theTable.rows.length;
	for (var i = 0; i < theTableLength; i ++ ) {
		if( i !=rowNum ) {
			var tempRow = theTable.rows[i];
			var tempRowTag = getCurrentTagValue( tempRow );
			if( tempRowTag && (tempRowTag.toLowerCase() == currentNameLC) ) {
				var tempCount = getTagCount( tempRow );
				//alert( 'match found for word ' + currentName+'. ' +currentCount+" + "+ tempCount+" = " +(tempCount/1+currentCount/1));
				setTagCount( theRow, (tempCount/1+currentCount/1) );
				flashRow( theRow );
				removeFromTable( tempRow );	
				decrementTotalTagCount();
				return true;
			}
		}
	}
	return false;
}

function cancelRename( elem ) {
	elem = byId( elem );
	var theRow = getFirstParentofType( elem, 'tr' );
	nameTag( theRow );
	
	var currentName = getCurrentTagValue( theRow );
	setNewTagValue( theRow, currentName );
	flashRow_disable( theRow );
	toggleRow( theRow );
	
	//return true;
}

var deleteTagRow = null;

function deleteTag( elem ) {
	elem = byId( elem );
	var theRow = getFirstParentofType( elem, 'tr' );
	nameTag( theRow );

	var currentName = getCurrentTagValue( theRow );
	var tagCount = getTagCount( theRow );
	deleteTagRow = theRow;

	if (tagCount > 1 ) {
		var thePopup = byId('di_multitag');
		var tagNameVar = getFirstChildwithName( thePopup, 'tagname1' );
		tagNameVar.innerHTML = currentName;
	
		var tagCountVar = getFirstChildwithName( thePopup, 'tagcount1' );
		tagCountVar.innerHTML = tagCount;
		
		showDialog(thePopup);
		
	} else if( tagCount == 1 ) {
		//var thePopup = byId('di_1tag');
		//showDialog(thePopup);
		deleteTag2(); 
		//return true;
	} else {
		//deleteTag2( ); 
		//return true;
	}

}

function deleteTag2() {
	closeDialog();
	//alert( deleteTagRow.tagName);
	if( deleteTagRow != null ) {
		var currentName = getCurrentTagValue( deleteTagRow );
	//	alert( currentName );
		/*if( currentName != null ) 
			data_tag_delete( currentName );*/
		removeFromTable( deleteTagRow );
		decrementTotalTagCount();
	}
	//return true;
}

	function decrementTotalTagCount() {
		var elem = byId('totalTagCount');
		if( elem ) {
			var theCount = (elem.innerHTML)/1;
			theCount--;
			elem.innerHTML = theCount;
		}
	}

	function getOriginalTagValue( theRow ) {
		var destCell = theRow.cells[0];
		var originalName = getFirstChildwithName( destCell, 'originalTag' );
		if( dojo.html.hasClass( originalName, "nodisplay" ) ) {
			return null;
		} else {
			return originalName.innerHTML;
		}
	}
	
	function getCurrentTagValue( theRow ) {
		var destCell = theRow.cells[0];
		var currentName = getFirstChildwithName( destCell, 'currentTag' );
		return currentName.innerHTML;
	}
	
	function getNewTagValue( theRow ) {
		var destCell = theRow.cells[0];
		var currentName = getFirstChildwithName( destCell, 'renamefield' );
		var theValue = currentName.value;
		theValue = theValue.split( " " );
		theValue = theValue.join( "-" );
		return theValue;
	}
	
	function getTagCount( theRow ) {
		var tagCount = theRow.cells[1];
		return tagCount.innerHTML;
	}
	
	function setOriginalTagValue( theRow, newVal ) {
		var destCell = theRow.cells[0];
		var originalName = getFirstChildwithName( destCell, 'originalTag' );
		if( newVal ) {
			newVal = fromText2Entity( newVal );
			dojo.html.removeClass( originalName, "nodisplay" );
			originalName.innerHTML = newVal;
			return true;
		} else {
			dojo.html.addClass( originalName, "nodisplay" );
			originalName.innerHTML = "";
			return true;
		}
	}
	
	function setCurrentTagValue( theRow, newVal ) {
		newVal = fromText2Entity( newVal );
		var destCell = theRow.cells[0];
		var currentName = getFirstChildwithName( destCell, 'currentTag' );
		currentName.innerHTML = newVal;
		return true;
	}
	
	function setNewTagValue( theRow, newVal ){
		newVal = fromEntity2Text( newVal );
		var destCell = theRow.cells[0];
		var currentName = getFirstChildwithName( destCell, 'renamefield' );
		currentName.value =  newVal;
		return true;
	}
	
	
	function focusNewTagValue( theRow ){
		var destCell = theRow.cells[0];
		var currentName = getFirstChildwithName( destCell, 'renamefield' );
		LBselectAll(currentName);
		//currentName.focus();
		return true;
	}
	
	function blurNewTagValue( theRow ) {
		var destCell = theRow.cells[0];
		var currentName = getFirstChildwithName( destCell, 'renamefield' );
		currentName.blur();
		return true;
	}
	
	function setTagCount( theRow, newVal ) {
		var tagCount = theRow.cells[1];
		tagCount.innerHTML = newVal;
		return true;
	}
	

function moveRowXtoY( theTable, fromRow, toRow ) {
	theTable = byId( theTable );
	//alert( "moving row "+fromRow + " to row "+ toRow );
	var tableLength = theTable.length;
	if( fromRow == toRow ) { 
		return false;
	} else if( fromRow < toRow ) { 
		toRow++; 
		var oldRow = theTable.rows[fromRow];
		var newRow = theTable.insertRow(toRow);
	} else { // if( fromRow > toRow )
		var oldRow = theTable.rows[fromRow];
		var newRow = theTable.insertRow(toRow);
		fromRow++;
	}
	newRow.className = oldRow.className;
	for( var i=0; i<oldRow.cells.length; i++ ){
		newRow.insertCell(i);
		newRow.cells[i].className = oldRow.cells[i].className;
		//alert( "oldRow.cells[i].innerHTML = "+oldRow.cells[i].innerHTML );
		newRow.cells[i].innerHTML = oldRow.cells[i].innerHTML;
	}
	theTable.deleteRow(fromRow);
	return newRow;
}

var flashCounter = 0;
var flashTimer = 80;
var totalFlashes = 2;

var flashRow_timer = 0;

function flashRow( rowElem ) {
	rowElem = byId(rowElem);
	if( flashCounter == 0 ) { //init: clear existing states;
		var theTable = getFirstParentofType( rowElem, 'table' );
		clearFlash( theTable );
		dojo.html.removeClass(rowElem, "fadein"); 
		dojo.html.removeClass(rowElem, "nohover"); 
	}
	if( flashCounter < totalFlashes ) {
		dojo.html.addClass(rowElem, 'flash2');
		dojo.html.removeClass(rowElem, 'flash1');
		flashCounter++;
		flashRow_timer = setTimeout("flashRow2('"+rowElem.id +"')", flashTimer);
	} else {
		flashCounter = 0;
		dojo.html.addClass(rowElem, 'flash1');
		rowElem.onmouseover = function () {
			dojo.html.removeClass(rowElem, "flash1"); 
			rowElem.onmouseover = null;
		}
		//dojo.html.removeClass(rowElem, 'flash1');
		//dojo.html.removeClass(rowElem, 'flash2');
		return true;
	}
}

function flashRow2( rowElem ) {
	rowElem = byId(rowElem);
	dojo.html.addClass(rowElem, 'flash1');
	dojo.html.removeClass(rowElem, 'flash2');
	flashRow_timer = setTimeout("flashRow('"+rowElem.id +"')", flashTimer);
}

function clearFlash( tableElem ) {
	clearTimeout( flashRow_timer );
	clearTimeout( flashRow_disable_timer );
	tableElem = byId(tableElem);
	var rowCount = tableElem.rows.length;
	for ( var i =0; i< rowCount; i++ ) {
		dojo.html.removeClass(tableElem.rows[i], "flash1"); 
		dojo.html.removeClass(tableElem.rows[i], "flash2"); 
		//dojo.html.removeClass(tableElem.rows[i], "nohover"); 
	} // I've had problems with lingering. This clears the whole deal.
}

function flashRow_temp( rowElem ) {
	rowElem = byId(rowElem);
	if( flashCounter == 0 ) { //init: clear existing states;
		var theTable = getFirstParentofType( rowElem, 'table' );
		nameTag (rowElem );
		clearFlash( theTable );
		dojo.html.removeClass(rowElem, "fadein"); 
		dojo.html.removeClass(rowElem, "nohover"); 
	} 	
	if( flashCounter == totalFlashes ) { // done;
		var theTable = getFirstParentofType( rowElem, 'table' );
		clearFlash( theTable );
		dojo.html.removeClass(rowElem, "fadein"); 
		dojo.html.removeClass(rowElem, "nohover"); 
		flashCounter=0;	
		return;
	} else if( flashCounter < totalFlashes && (flashCounter % 2 == 0 )) {
		dojo.html.addClass(rowElem, 'flash1');
		dojo.html.removeClass(rowElem, 'flash2');
		flashCounter++;
		flashRow_timer = setTimeout("flashRow_temp('"+rowElem.id +"')", flashTimer);
	} else if( flashCounter < totalFlashes && (flashCounter % 2 == 1) ) {
		dojo.html.addClass(rowElem, 'flash2');
		dojo.html.removeClass(rowElem, 'flash1');
		flashCounter++;
		flashRow_timer = setTimeout("flashRow_temp('"+rowElem.id +"')", flashTimer);
	} 
}


var flashRow_disable_timer = 0;
function flashRow_disable( rowElemID ) {
	var rowElem = byId(rowElemID);
	dojo.html.addClass(rowElem, 'fadein');
	flashRow_disable_timer = setTimeout("flashRow_disable2('"+rowElem.id +"')", flashTimer+1);
}

function flashRow_disable2( rowElemID ) {
	clearTimeout( flashRow_disable_timer );
	var rowElem = byId(rowElemID);
	dojo.html.removeClass(rowElem, 'fadein');
	dojo.html.addClass(rowElem, 'nohover');
	rowElem.onmouseover = function () {
		rowElem.onmouseout = function () {
			dojo.html.removeClass(rowElem, "nohover"); 
			rowElem.onmouseover = null;
			rowElem.onmouseout = null;
		}
	}
}




var flashElem_timer = 0;

function flashElem( theElem ) {
	theElem = byId(theElem);
	if( flashCounter == 0 ) { //init: clear existing states;
		dojo.html.removeClass(theElem, "fadein"); 
		dojo.html.removeClass(theElem, "nohover"); 
	}
	if( flashCounter < totalFlashes ) {
		dojo.html.addClass(theElem, 'flash21');
		dojo.html.removeClass(theElem, 'flash2');
		flashCounter++;
		flashElem_timer = setTimeout("flashElem2('"+theElem.id +"')", flashTimer);
	} else {
		flashCounter = 0;
		clearTimeout( flashElem_timer );
		dojo.html.removeClass(theElem, 'flash1');
		dojo.html.removeClass(theElem, 'flash2');
		return true;
	}
}

function flashElem2( theElem ) {
	theElem = byId(theElem);
	dojo.html.addClass(theElem, 'flash2');
	dojo.html.removeClass(theElem, 'flash1');
	flashElem_timer = setTimeout("flashElem('"+theElem.id +"')", flashTimer);
}


var flashElem_disable_timer = 0;

function flashElem_disable( theElemID ) {
	var theElem = byId(theElemID);
	dojo.html.addClass(theElem, 'fadein');
	flashElem_disable_timer = setTimeout("flashElem_disable2('"+theElem.id +"')", flashTimer+1);
}

function flashElem_disable2( theElemID ) {
	clearTimeout( flashElem_disable_timer );
	var theElem = byId(theElemID);
	dojo.html.removeClass(theElem, 'fadein');
	dojo.html.removeClass(theElem, 'nohover');
}



function submitLockout_btn( submitID, optionalReplaceText ) {
	submitID = xGetElementById( submitID );
	//var txt="Id: " + submitID.id;
	//txt=txt + ", type: " + submitID.type + ", disabled: " + submitID.disabled;
	//alert(txt);
	submitID.disabled = true;
	if( optionalReplaceText ) {
		submitID.value= optionalReplaceText;
	}
}

function submitUnlock_btn( submitID, optionalReplaceText ) {
	submitID = xGetElementById( submitID );
	submitID.disabled = false;
	if( optionalReplaceText ) {
		submitID.value= optionalReplaceText;
	}
}

function submitLockout( ) {
	//alert('submit is locked out');
	if( oldForm == null ) { // i.e., if we're trying to catch the return key
		showDialog( 'submitAction' );
	} else {
		return false;
	}
}

function submitUnlock( ) {
	closeDialog( ); 
}



/****** for the Member Invitation module (email validation)  ****/


function checkInviteMsg() {
	theField = byId( 'actOnSelected');
	if( theField == null ) return false;
	if( theField.value == "invite" && activeDialog == null) { // if the selected action = invite, and no dialog is open
	// 	alert( "theField.value =" + theField.value  );
		showDialog('di_invitationMsg');
		return false;
	} else {
		return true;
	}
}


var emailDelimiter = /[,;][\s]*/;

function checkInvite(theTextArea) {
	var errCode;
	var EmailsLen = 0;
	
	theTextArea = byId( theTextArea );
	if( theTextArea != null ) {
		var Emails = theTextArea.value;
		Emails = Emails.split(emailDelimiter);
		//alert( "Emails = "+ Emails.join("|"));
		Emails = removeEmpties(Emails);
		//alert( "Emails = "+ Emails.join("-"));
		EmailsLen = Emails.length;
		
		var probTextArea = byId( 'problemEmails' );
		var problemEmails = probTextArea.value;
		problemEmails = problemEmails.split(emailDelimiter);
		problemEmails = removeEmpties(problemEmails);
		var problemCount = problemEmails.length;
	}
	
	//alert( "EmailsLen ="+ EmailsLen+", activeDialog = " +activeDialog);
	
	var	selectCount = byId( 'memCounter' );
	if(	selectCount == null)
		selectcount="0";
	else
		selectCount = selectCount.innerHTML;

	if( EmailsLen == 0) { //  no emails entered
		if( selectCount == "0" ) { // check that no members are selected, either
			showDialog('di_noEmail');
			return false; 
		}
	} 
	
	//alert( "EmailsLen ="+ EmailsLen);
	for( var i=0; i < EmailsLen; i++ ) {
		errCode = checkEmail_code( Emails[i] );
		if( errCode > 1 ) {
			problemEmails.push( Emails[i] );
			Emails[i] = "";
		}
	}
	if( theTextArea != null ) {
		problemCount = problemEmails.length;
		Emails = removeEmpties(Emails);
		
		if( problemCount > 0) { // if the selected action = invite, and no dialog is open
		// 	alert( "theField.value =" + theField.value  );
			theTextArea.value= Emails.join(", ");
			probTextArea.value= problemEmails.join(", ");
			showDialog('di_emailCheck');
			return false;
		} else {
			probTextArea.value = "";
			var successMsg = byId( 'successmsg' );
			if( successMsg != null ) {
				EmailsLen = EmailsLen + (selectCount)*1;
				if( EmailsLen == 1 ) 
					successMsg.value = "You have sent an invitation to "+EmailsLen+" person.";
				else 		
					successMsg.value = "You have sent invitations to "+EmailsLen+" people. <br/> <span class='small notbold gray'> (It may take a few hours for all the invitations to be delivered).</span>";
			}
			closeDialog();
			return true;
		}
	}
	return true;
}

function checkTransfer() {
	var errCode;
	//var emailDelimiter = /,[\s]*/;
	
	selectCount = byId( 'memCounter' );
	var ownerVal = selectCount.innerHTML; 
	if( ownerVal == "(None selected)" ) { // check that no members are selected, either
		showDialog('di_noSelection');
		return false; 
	} else {
		var successMsg = byId( 'successmsg' );
		if( successMsg != null ) {
			successMsg.value = "You have transferred ownership of this group to "+ownerVal+". <br/> <span class='small notbold gray'> (You are no longer the owner of this group site.)</span>";
		}
		return true;
	}
	return true;
}



function cancelEmailCheck(theTextArea) {
	var errCode;
	//var emailDelimiter = /,[\s]*/;

	theTextArea = byId( theTextArea );
	var Emails = theTextArea.value;
	Emails = Emails.split(emailDelimiter);
	
	var probTextArea = byId( 'problemEmails' );
	var problemEmails = probTextArea.value;
	problemEmails = problemEmails.split(emailDelimiter);
		
	//Emails = Emails.concat( problemEmails );
	//Emails = removeEmpties(Emails);
	//theTextArea.value= Emails.join(", ");
	
	probTextArea.value = "";
	closeDialog();
	//return true;
	
}


function retryEmailCheck(theTextArea) {
	var errCode;
	//var emailDelimiter = /,[\s]*/;

	theTextArea = byId( theTextArea );
	var Emails = theTextArea.value;
	Emails = Emails.split(emailDelimiter);
	
	var probTextArea = byId( 'problemEmails' );
	var problemEmails = probTextArea.value;
	problemEmails = problemEmails.split(emailDelimiter);
	probTextArea.value = "";
		
	Emails = Emails.concat( problemEmails );
	Emails = removeEmpties(Emails);
	theTextArea.value= Emails.join(", ");
	
 	var checkVal = checkInvite(theTextArea); // check it again.
	
	if( checkVal ) {
		closeDialog();
	}
	//return true;
	
}



/****** for the Member Selecter Module ****/


function memScrollTo( dest ) {
	dest = byId( dest );
	var theSelecter = byId( 'memberselecter' );
	/*alert( "dest.offsetTop = "+dest.offsetTop+", dest.offsetParent.offsetTop = "+dest.offsetParent.offsetTop+", theSelecter.offsetTop ="+theSelecter.offsetTop+", theSelecter.scrollTop ="+theSelecter.scrollTop );*/
	/*	alert( "dest.offsetParent = "+dest.offsetParent+", dest.offsetParent.offsetTop = "+dest.offsetParent.offsetTop+", dest.offsetHeight = "+dest.offsetHeight +", dest.offsetTop = "+dest.offsetTop);*/
	//alert( "scrollDiff = "+scrollDiff);
	theSelecter.scrollTop = dest.offsetTop -1;
	var firstRow = dest.rows[0];
	if( firstRow != null ) flashRow_temp( dest.rows[0] );
}


function showSelectedOnly( theElem ) {
	theElem = byId(theElem);
	dojo.html.addClass( theElem, 'selectedOnly' );
}


function showAllinTable( theElem ) {
	theElem = byId(theElem);
	//alert( 'in showAllinTable. theElem == ' + theElem );
	dojo.html.removeClass( theElem, 'selectedOnly' );
}


function toggleElem( elem ) {
	elem = byId(elem);
	//elem.style.display = "none";
	if( dojo.html.hasClass(elem, "toggled") ) {
		dojo.html.removeClass(elem, "toggled");	
	} else {
		dojo.html.addClass(elem, "toggled");	
	}
}

function selectAllMems() {
	var theTable = byId( 'memTable' );
	for( var i=0; i< theTable.rows.length; i++ ) {
		dojo.html.addClass(theTable.rows[i], 'selected');
	}
	textSet( 'memCounter', i);	
	checkAll( 'memTable' );
}	

function deselectAllMems() {
	var theTable = byId( 'memTable' );
	for( var i=0; i< theTable.rows.length; i++ ) {
		dojo.html.removeClass(theTable.rows[i], 'selected');
	}
	//alert( 'in deselectAllMems. rows == ' + i );
	uncheckAll( 'memTable' );
	textReset( 'memCounter');	
}	

var prevMemSelection = null;

var loadingMemSelect = false;

function checkSelect( tableID ) {
	//alert( "checkSelect running");
	loadingMemSelect = true;
	if( tableID ) {
		var theTable = byId( tableID );
	} else {
		var theTable = byId( 'memTable' );
	}
	var j=0;
	var tempCell;
	var totalCount = 0;
	var inputType;
	for( var i=0; i< theTable.rows.length; i++ ) {
		tempCell = theTable.rows[i];
		var elem = getFirstChildwithTag( tempCell, 'input' );
		if( elem != false ) {
			inputType = elem.type	
			totalCount += selectMem( elem ); 
		}
	}
	loadingMemSelect = false;
}


function selectMem( elem ) {
	elem = byId( elem );
	if( elem.type == "checkbox" ) {
		if( elem.checked && !elem.disabled ) {
			selectInTable( elem );
			textIncrement( 'memCounter');
			return 1;
		} else {
			prevMemSelection = null;
			deselectInTable( elem );
			textDecrement( 'memCounter');
			return 0;
		}
	} 
	if( elem.type == "radio" ) {
		if( elem.checked ) {
			if( prevMemSelection != null ) {
				deselectInTable( prevMemSelection );
			}
			var selectionName = elem.parentNode.parentNode.cells[1].innerHTML;
			selectionName = clearEndSpace(selectionName);
			textSet( 'memCounter', selectionName);
			selectInTable( elem );
			prevMemSelection = elem;
			// alert( selectionName + " is selected" );
			return 0;
		}
	}	
}

function enableChildElems( elem ) {
	elem = byId( elem );
	argLength = arguments.length;
	if( elem.type == "checkbox" ) {
		if( elem.checked ) {
		  for( var i=1; i < argLength;i++ ) {
			 enableInTable( arguments[i] );
			 textIncrement( 'memCounter');
			}
			return 1;
		} else {
			prevMemSelection = null;
              for( var i=1; i < argLength;i++ ) {
                disableInTable( arguments[i]  );
                textDecrement( 'memCounter');
              }
			return 0;
		}
	} 
}

	function enableElem( elem ){
		elem = byId( elem );
		if( elem != null ) {
			//alert('enabling  '+elem.id);;
			elem.disabled=false;
		}
	}

	function disableElem( elem ){
		elem = byId( elem );
		if( elem != null ) {
			elem.disabled=true;
		}
	}

	function textSet( elem, value ) {
		elem = byId( elem );
		if( elem ) {
			elem.innerHTML = value;
		}
	}
	
	function textReset( elem ) {
		textSet( elem, '0' ); 
		resetShow();
	}
	
	function textIncrement( elem ) {
		textAdd( elem, 1 );	
		// alert('calling  showSelected ');;
		enableElem( 'showSelected' );
	}
	
	function textDecrement( elem ) {
		if( !loadingMemSelect )  // if we're doing checkSelect, we only want to increment (i.e. count)
			textAdd( elem, -1 );
	}

	var countUpOnly = false;
	
	function textAdd( elem, adder ) {
		elem = byId( elem );
		if( elem != null ) { 
			//alert( 'elem.innerHTML = '+elem.innerHTML); 
			if( elem.innerHTML != null ) 
				var theContent = (elem.innerHTML)*1;
			else
				var theContent = 0;
			theContent = theContent+adder;
			if( theContent <= 0 ) {
				theContent = 0;
				 resetShow(); 
			}
			elem.innerHTML = theContent;
			return true;
		} else {
			//alert( 'no elem found!'); 
			return false;
		}
	}
	

function resetShow() {
	showAllinTable( 'memTable' );	
	disableElem( 'showSelected' );
	dojo.html.removeClass('selectToggle', "toggled");	
}




function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function detectText() { //deprecated
	// if we didn't specify type = text, let's assign that now
	var els = document.getElementsByTagName('input');
	for (var i=0; i <  els.length ;i++ ){
		var inputType = els[i].getAttribute('type');
		if ( inputType == null  ) {
			els[i].setAttribute('type', 'text'); 
		}
	}
}

function styleInputs() { 
	// automatically assign styles to form elements based on type.
	var els = document.getElementsByTagName('input');
	for (var i=0; i <  els.length ;i++ ){
		var inputType = els[i].getAttribute('type');
		if ( inputType == 'checkbox' || inputType == 'radio') {
			dojo.html.addClass( els[i], 'checkbox'); 
		} else if (inputType  == 'button' || inputType == 'submit' ) {
			dojo.html.addClass( els[i], 'buttonLB'); 
		} else if ( inputType == null || inputType  == 'text' || inputType == 'password' ) {
			dojo.html.addClass( els[i], 'inputLB'); 
		}		
	}
	var els = document.getElementsByTagName('textarea');
	for (var i=0; i <  els.length ;i++ ){
		dojo.html.addClass( els[i], 'inputLB'); 
	}
	var els = document.getElementsByTagName('select');
	for (var i=0; i <  els.length ;i++ ){
		dojo.html.addClass( els[i], 'inputLB'); 
	}
}

addLoadEvent(styleInputs);

function clearEndSpace( str ) { // eats up white space at the end of a string
	var strLen = str.length;
	var i = strLen -1;
	//alert(" str["+i+"] = {"+ str[i]  + "}");
	var whiteSpace = /\s/;
	while( whiteSpace.test(str[i]) ){
		//alert(" str["+i+"] = {"+ str[i]  + "}");
		i--;
	}
	i++;
	str = str.substr(0,i);
	return str;
}

function node2String( elem ) {
	var str = node2String2( elem );
	str = clearEndSpace( str );
	//alert(" newstr = {"+ str + "}");
	return str;
}

 
function node2String2( elem ) {
	elem = byId( elem );
	//alert( "elem.innerHTML == " + elem.innerHTML );
	
	var elemKids = elem.childNodes;
	var elemKidCount = elemKids.length;
	//alert( "elemKidCount == " + elemKidCount );
	var str = ""; 
	if( elemKids == null || elemKidCount == 1 ) {
		str = elem.innerHTML;
		//alert( "str == " + str );
	} else {
		for( var i=0; i< elemKidCount; i++ ) {
			str += node2String2( elemKids[i] );
		}
	}
	return str;
}



function selectThumb( elem ) {
	//elem = byId( elem );
	var elemID = nameTag( elem );
	
	if (selectedThumb != elemID ) {
		dojo.html.addClass( elem, 'selected' );
		deselectThumb( selectedThumb ); 
		selectedThumb = elemID;
		var selectSource = byId( 'selectedField_src' ); // this is for Luke's php mockups
		if( selectSource != null && selectSource.type == "hidden" ) {
			selectSource.value = elem.src;
		}
		var selectID = byId( 'selectedField' ); // this is for Erik's live bad-boy.
		if( selectID != null && selectID.type == "hidden" ) {
			selectID.value = elemID;
		}
	}
}

function selectTheme( elem ) {
	//elem = byId( elem );
	var elemID = nameTag( elem );
	
	if (selectedThumb != elemID ) {
		dojo.html.addClass( elem, 'selected' );
		deselectThumb( selectedThumb ); 
		selectedThumb = elemID;
		
		formElem = byId( 'themechoice' );
		if( formElem != null && formElem.type == "hidden" ) {
			formElem.value = elemID;
		}
	}
}

function selectTheme2( elem ) {
	//elem = byId( elem );
	var elemID = nameTag( elem );
	var targetPic = byId( 'chosenTheme' );
			
	if (selectedThumb != elemID ) {
		dojo.html.addClass( elem, 'selected' );
		deselectThumb( selectedThumb ); 
		selectedThumb = elemID;
	}
	
	targetPic.alt = elem.alt;
	targetPic.src = elem.src;


	formElem = byId( 'themechoice' );
	if( formElem != null && formElem.type == "hidden" ) {
		formElem.value = elemID;
	}
		
	closeDialog();
}

function selectCustomTheme( elem ) {
	//elem = byId( elem );
	var customeThemeName = elem.value;
	formElem = byId( 'themechoice' );
	formElem.value = customeThemeName;
	var targetPic = byId( 'chosenTheme' );
	targetPic.src = '/include3/themes/'+customeThemeName+'/thumb.gif';
	
}


function deselectThumb( elem ) {
	elem = byId( elem );
	nameTag( elem );
	dojo.html.removeClass( elem, 'selected' );
	
}



function submitAnim(elem) {
	elem = byId( elem );
	//alert( "submitAnim called!");
	//dojo.lfx.html.fadeHide(elem, 50).play();
	//var elemWidth = dojo.style.getOuterWidth( elem );
	var elemHeight = dojo.style.getOuterHeight( elem );
	//var xyPos = dojo.style.getAbsolutePosition( elem, true );
	//var fieldLeftEnd = xyPos.x;
	//var fieldTopStart = xyPos.y;
	var submitter = makeSubmitter();
	elem.parentNode.appendChild( submitter);
	submitter.style.height = elemHeight+"px";
	elem.style.display = "none";
	submitter.style.display = "block";
}

function makeSubmitter() {
	var submitter = document.createElement("div");
	submitter.innerHTML = '<p>Submitting... </p>';
	submitter.className = "submitter";
	return submitter;
}


function evalAction(elem) {
	elem = byId( elem );
	//alert('elem='+elem );
	var theForm = getFirstParentofType( elem, 'form' );
	if( selectedCount <= 0 ) { // 
		showDialog( 'di_select' );
		return false;
	} else {
		//alert(selectedCount);
		theForm.elements['checkCounter'].value = selectedCount;
		var selectedAction = theForm.elements['successmsg'];	
		
		if( selectedAction.value == 'none' ) { 
			showDialog( 'di_selectAction' );
			return false;
		} else if( selectedAction.value == 'directadd' ) {
			theForm.action = "invite_directadd.php?populate"
			theForm.submit();
		} else if( selectedAction.value == 'remove' ) { 
			showDialog( 'di_remove' );
			return false;
		} else if( selectedAction.value == 'ban' ) {
			showDialog( 'di_ban' );
			return false;
		} else if( selectedAction.value == 'resend_add' ) {
			showDialog( 'di_resend_add' );
			return false;
		} else if( selectedAction.value == 'addtogroups' ) {
			showDialog( 'di_addtogroups' );
			return false;
		} else if( selectedAction.value == 'removefromgroups' ) {
			showDialog( 'di_removefromgroups' );
			return false;
		} else if( selectedAction.value == 'invite' ) {
				showDialog( 'di_invitationMsg' );
				return false;
		} else if( selectedAction.value == 'deleteadd' ) {
				showDialog( 'di_deleteadd' );
				return false;
		} else if( selectedAction.value == 'emailsettings' ) {
				showDialog( 'di_emailsettings' );
				return false;
		} else if( selectedAction.value == 'limitmembership' ) {
				showDialog( 'di_limitmembership' );
				return false;
		} else {
			theForm.submit();
		}
	}
}



//addLoadEvent(findHiddenElems);

var hiddenImgArray = new Array();

function findHiddenElems(elem) {
	if(elem == null ) {
		elem = document.body;
		//alert( "elem = document.body!");
	}
	var tempElem, displayProp;
	var childCount = elem.childNodes.length;
	for( var i = 0; i < childCount; i ++ ) {
		tempElem = elem.childNodes[i];
		displayProp = dojo.style.getComputedStyle( tempElem, 'display' );
		if( displayProp == "none" ) { 
			//alert( "found something! a "+tempElem.tagName +" with class "+tempElem.className+" has display:"+displayProp+"!");
			loadHiddenImgs( tempElem );
		} else {
			findHiddenElems(tempElem);
		}
	}
}

function loadHiddenImgs(elem) {
	var tempElem, imgProp;	
	imgProp = dojo.style.getComputedStyle( elem, 'background-image' );
	if( elem.tagName && (elem.tagName == "img" ||  elem.tagName == "IMG" )){
		//alert( "found an image!" );
		//alert( "found an image! src=" +elem.src);
	} else if( imgProp && imgProp != "none" ) {
		//alert( "found a background image! = "+imgProp );
	}
	var childCount = elem.childNodes.length;
	for( var i = 0; i < childCount; i ++ ) {
		tempElem = elem.childNodes[i];
		loadHiddenImgs( tempElem );
	}
}

function stripURL( str ) {
}


function toggleDisableChecker( checkElem, targetElem ) {
	checkElem = byId( checkElem );
	targetElem = byId( targetElem );
	if( checkElem != null && checkElem.type == "checkbox" && targetElem != null) {
		if( checkElem.checked ) {
			dojo.html.removeClass( targetElem, 'disabled' );
			enableAll( targetElem );
		} else {
			dojo.html.addClass( targetElem, 'disabled' );
			disableAll( targetElem );
		}
	} else {
		return false;
	}
}

function toggleLimited( checkElem, targetElem ) {
	checkElem = byId( checkElem );
	targetElem = byId( targetElem );
	var autojoiners = getAllChildrenwithClass( targetElem, 'autojoin' );
	var autojoinersLen = autojoiners.length;
	if( checkElem != null && checkElem.type == "checkbox" && checkElem != null) {
		if( checkElem.checked ) {
			for( var i = 0; i< autojoinersLen; i++) {
				// dojo.html.removeClass( autojoiners[i], 'disabled' );
				autojoiners[i].disabled = false;				
			}
		} else {
			for( var i = 0; i< autojoinersLen; i++) {
				// dojo.html.removeClass( autojoiners[i], 'disabled' );
				autojoiners[i].disabled = true;				
				autojoiners[i].checked = true;				
			}
		}
	} else {
		return false;
	}
}

function mgrVsLimited( roleSelect, checkElem, checkLabel, targetElem ) {
	roleSelect = byId( roleSelect );
	checkElem = byId( checkElem );
	if( roleSelect.value == "manager") {
		checkElem.disabled = true;
		checkElem.checked = false;
		dojo.html.addClass( checkLabel, 'disabled' );
		toggleLimited(checkElem, targetElem);
	} else if( roleSelect.value == "member") {
		checkElem.disabled = false;
		toggleLimited(checkElem, targetElem);
		dojo.html.removeClass( checkLabel, 'disabled' );
	} else
	 return false;
}


/**********

For new conversation flyout

***********/
var activeTarget = null;

function showConvoFlyout(flyoutID, itemObj) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	activeTarget =  itemObj ;
	var thePost = dojo.byId( flyoutID );
	if( activeFlyout != thePost ) { // skip if we're already showing*/
		clearTimeout(mytimer_on_ID);
		hideFlyout2a(); 	// hide the active flyout
		activeFlyout = thePost; // make thePost the active flyout
		showFlyout2a(); 	// show Post
	} else {
		return true; // do nothing;
	}
}

function showFlyout2a() {
	// showPopupper();
	//lockOn = true;
	mytimer_on_ID = setTimeout("showFlyout3a()", fo_delay);
}

function hideFlyout2a(itemID) {
	//activeFlyout.style.left = '0';
	//activeFlyout.style.top = '0';
	hideFlyout2();
	activeFlyout = null; // make thePost the active flyout
	activeTarget = null;
}



function showFlyout3a() {
	// showPopupper();
	clearTimeout(mytimer_on_ID);
	var thePost = activeTarget;
	if( activeFlyout != thePost ) {
		var xyPos = dojo.style.getAbsolutePosition( thePost, true );
		var xHeight = dojo.style.getOuterHeight(thePost); 

		activeFlyout.style.left = xyPos.x + "px";		// place popup (left) at the mouse X location
		activeFlyout.style.top = xyPos.x + xHeight + "px"; 	// place popup (top) at the mouse Y location
		fadeShowLB(activeFlyout, fadeInRate);
		// hidePopupper();
	}
}


function showConvoPreview( previewID ) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	var thePreview = dojo.byId( previewID );
	if( activeFlyout != thePreview ) { // skip if we're already showing*/
		hideFlyout2(); 	// hide the active flyout
		activeFlyout = thePreview; // make thePost the active flyout
		mytimer_on_ID = setTimeout("showConvoPreview_now();", fo_delay);
	}
}

function showConvoPreview_now( ) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	clearTimeout(mytimer_on_ID); // compensates for Safari onmouseout event
	//var thePreview = dojo.byId( previewID );
	dojo.lfx.wipeIn( activeFlyout, fadeOutRate ).play();
}



function hideConvoPreview(  ) {
	mytimer_off_ID = setTimeout("hideConvoPreview_now();", 10);
}

function hideConvoPreview_now(  ) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	//hideFlyout2(); 	// hide the active flyout
	//var thePreview = dojo.byId( previewID );
	dojo.lfx.wipeOut( activeFlyout, fadeOutRate ).play();
	activeFlyout = null; // make thePost the active flyout
}


var preDetails = null;
var postDetails = null;
var  mytimer_swap_ID;
var det_delay = fo_delay *2;
var det_hide_delay = 200;

function unhideDetails( elem ) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	elem = dojo.byId( elem );
	nameTag( elem );
	if( activeFlyout == null ) { // skip if we're not showing*/
		activeFlyout = elem; // make thePost the active flyout
		mytimer_on_ID = setTimeout("unhideDetails_now();", det_delay);
	} else if( activeFlyout != elem ) { // if we're already showing , swap for another */
		preDetails = elem;
		postDetails = activeFlyout;
		clearTimeout(mytimer_swap_ID); // clear any timers
		mytimer_swap_ID = setTimeout("swapDetails();", det_delay);
	/*	clearTimeout(mytimer_on_ID); // compensates for Safari onmouseout event
		hideDetails2(); 	// hide the active flyout
		activeFlyout = elem; // make thePost the active flyout
		unhideDetails2();*/
	}
}

function showDetails( elem ) {
	elem = dojo.byId( elem );
	if( !dojo.html.hasClass( elem, 'mod' )	)
		elem = getFirstParentwithClass( elem, 'mod' );
	nameTag( elem );
	var thePreview = getFirstChildwithClass( elem, 'preview' );
	thePreview.style.display = "block";
	dojo.lfx.wipeIn( thePreview, fadeOutRate ).play();
	dojo.style.setOpacity(thePreview, 100); // immediately set opacity to 100, in case it was faded out;
}

function unshowDetails( elem ) {
	elem = dojo.byId( elem );
	if( !dojo.html.hasClass( elem, 'mod' )	)
		elem = getFirstParentwithClass( elem, 'mod' );
	nameTag( elem );
	var thePreview = getFirstChildwithClass( elem, 'preview' );
	dojo.lfx.wipeOut( thePreview, fadeOutRate ).play();
	dojo.lfx.fadeOut( thePreview, fadeOutRate ).play();
}

function hideDetails(  ) {
	//clearTimeout(mytimer_on_ID); // compensates for Safari onmouseout event
	mytimer_off_ID = setTimeout("hideDetails_now();", det_hide_delay);
}

function swapDetails()  {
	clearTimeout(mytimer_off_ID); 
	clearTimeout(mytimer_on_ID); 
	hideDetails_now();
	activeFlyout = dojo.byId(preDetails);
	unhideDetails_now();
	preDetails = null;
	postDetails = null;

}

function unhideDetails_now( ) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	//clearTimeout(mytimer_on_ID); // compensates for Safari onmouseout event
	//var thePreview = dojo.byId( previewID );
	var thePreview = getFirstChildwithClass( activeFlyout, 'preview' );
	thePreview.style.display = "block";
	dojo.lfx.wipeIn( thePreview, fadeOutRate ).play();
	dojo.style.setOpacity(thePreview, 100); // immediately set opacity to 100, in case it was faded out;
	//dojo.lfx.fadeIn( thePreview, fadeOutRate ).play();
}


function hideDetails_now(  ) {
	clearTimeout(mytimer_off_ID); // compensates for Safari onmouseout event
	if( activeFlyout ) {
		var thePreview = getFirstChildwithClass( activeFlyout, 'preview' );
		dojo.lfx.wipeOut( thePreview, (fadeOutRate) ).play();
		dojo.lfx.fadeOut( thePreview, (fadeOutRate) ).play();
		activeFlyout = null; // make thePost the active flyout
	}
}



/*****/


function toggleWipe( checkElem, targetElem ) {
	checkElem = byId( checkElem );
	targetElem = byId( targetElem );
	if( checkElem != null && checkElem.type == "checkbox" && targetElem != null) {
		if( checkElem.checked ) {
			EZwipeIn(targetElem);
		} else {
			EZwipeOut(targetElem);
		}
	} else {
		return false;
	}
}

function toggleWipe2( targetElem ) {
	targetElem = byId( targetElem );
	if( targetElem.style.display == "none" ) {
		EZwipeIn(targetElem);
	} else {
		EZwipeOut(targetElem);
	}
}

function toggleFade( checkElem, targetElem ) {
	checkElem = byId( checkElem );
	targetElem = byId( targetElem );
	if( checkElem != null && checkElem.type == "checkbox" && targetElem != null) {
		if( checkElem.checked ) {
			dojo.lfx.html.fadeShow(targetElem, 100).play();
		} else {
			dojo.lfx.html.fadeHide(targetElem, 100).play();
		}
	} else {
		return false;
	}
}


function popupOnSelect( checkElem, targetElem ) {
	checkElem = byId( checkElem );
	targetElem = byId( targetElem );
	if( checkElem != null && (checkElem.type == "checkbox" || checkElem.type == "radio" ) && targetElem != null) {
		if( checkElem.checked ) {
			showDialog(targetElem);
		} else {
			return true;
		}
	} else {
		return false;
	}
}



/*******/

function showTab( tabID ) {
	var thePane = dojo.byId( tabID );
	if( thePane == null ) 
		return false;
	if( dojo.html.hasClass( thePane, 'selected' ) ) return;
	var theTab = dojo.byId( tabID+"Tab" );

	var theTabArea = getFirstParentwithClass( thePane, 'mod' );
	var theSelectedElems = getAllChildrenwithClass( theTabArea, 'pane' ).concat(getAllChildrenwithClass( theTabArea, 'tab' ));
	var selectedCount = theSelectedElems.length;
	//alert( 'selectedCount = '+selectedCount+". theSelectedElems = "+theSelectedElems );
	for( var i=0; i< selectedCount; i++ ) {
		//alert( 'theSelectedElems[i] = '+theSelectedElems[i]+", classNAme = "+theSelectedElems[i].className);
		dojo.html.removeClass( theSelectedElems[i], 'selected' );
	}
	dojo.html.addClass( theTab, 'selected' );
	dojo.html.addClass( thePane, 'selected' );
	
}




/**********

attachments

******/


function addAttachRow( destElem ) {
	destElem = dojo.byId( destElem );
	var destRow = getFirstParentofType( destElem, 'tr' );
	if( destElem.value != '' && destRow.alreadyclicked == null ) {
//	if( destElem.alreadyclicked == null ) {
		var destTable = getFirstParentofType( destElem, 'table' );
	
		addAttachBlank( destTable );
		
		destRow.alreadyclicked = true;
		
		var trashCan = getFirstChildwithClass( destRow, 'disabled' )
		dojo.html.removeClass(trashCan, 'disabled');
	}
	toggleCheckAttacher( destElem );
}


function delMyRow( destElem ) {
	destElem = dojo.byId( destElem );
	var destRow = getFirstParentofType( destElem, 'tr' );
	var trashCan = destElem;
	if( !dojo.html.hasClass(trashCan, 'disabled' )) { // don't delete blanks
		delAttachRow( destRow ); 
	}
}

function delAttachRow( destRow ) {
	destRow = dojo.byId( destRow );
	//var destRow = getFirstParentofType( destElem, 'tr' );
	
	var rowInputs = getAllChildrenwithTagname( destRow, 'input' );
	var rowInputCount = rowInputs.length;
	for( var i =0 ; i < rowInputCount; i++ ){
		rowInputs[i].value = "";
		rowInputs[i].parentNode.removeChild(rowInputs[i]); // needed to add this to truly delete the file in Safari
	}
	removeFromTable( destRow );

}

function delVersionRow( destElem ) {
	destElem = dojo.byId( destElem );
	var destCell = getFirstParentofType( destElem, 'td' );
	var destRow = getFirstParentofType( destElem, 'tr' );
	dojo.html.addClass(destRow,'disabled');
	var fileName = getFirstChildwithClass( destRow, 'fileversion' );
	dojo.html.addClass(fileName, 'deleted');
	//fileName.className = "fileversion deleted";
	fileName.innerHTML = 'Deleted';
	destCell.innerHTML = '';

}


function clearAttachTable( destTable ) {
	var theRows = destTable.tBodies[0].rows;
	var rowCount = theRows.length;
	for( var i =0 ; i < rowCount; i++ ){
		destTable.tBodies[0].deleteRow(0);
	}

}

function addAttachFile( destTable, attachElem ) {
	//destTable = dojo.byId( destTable );
	attachElem = dojo.byId( attachElem );
	//alert( "destTable = "+destTable);
	var newRow = destTable.tBodies[1].rows[1].cloneNode(true);	// second tbody, second row is template for existing file
	destTable.tBodies[0].appendChild(newRow);
	
	newRow.className = "";
	newRow.alreadyclicked = true;
	newRow.cells[1].innerHTML = attachElem.innerHTML;
	newRow.cells[1].innerHTML += ' <span class="gray small">'+attachElem.title+'</span>';
	//alert( 'adding '+attachElem);
	//alert( "attachElem.innerHTML = "+attachElem.innerHTML);
}



function addAttachBlank( destTable ) {
	destTable = dojo.byId( destTable );
	var newRow = destTable.tBodies[1].rows[0].cloneNode(true);	
	destTable.tBodies[0].appendChild(newRow);
	newRow.className = "";
}



/*****/

function remoteSelect( checkElem ) {
	checkElem = byId( checkElem );
	if( checkElem != null && (checkElem.type == "checkbox" || checkElem.type == "radio") ) {
		checkElem.checked =true;
	} else {
		;
	}
}

function remoteDeselect( checkElem ) {
	checkElem = byId( checkElem );
	if( checkElem != null && (checkElem.type == "checkbox" || checkElem.type == "radio") ) {
		checkElem.checked =false;
	} else {
		;
	}
}

/****/

var debugging =false;

function LBDebug( dString ) {
	if( debugging ) {
		var theBox = dojo.byId( "scriptBox" );
		if(theBox !=null) {
			theBox.style.display = "block";
			var now=new Date();
			
			var timestamp = "<span class='floatright gray'>"+now.toTimeString()+"."+now.getMilliseconds()	+"</span>";
			theBox.innerHTML = "<p>"+timestamp+ " "+dString+"</p>"+theBox.innerHTML;
		}
	}
}

/****/

function positionStemmer( elem, compass )  {
	var theStemmer = getStemmer(elem);
	if( theStemmer != null ) {
		var elemHeight = dojo.style.getOuterHeight(elem); 
		var bgPostion = "0 0";
		var padInc = 14;
		var midOff = 8;
		var cenOffY = 18;
		var cenOffX = 14;
		var shadWid = 5;
		switch (compass) {
			case 'nw': 
				bgPostion = '0 0'; 
				theStemmer.style.top = "0";
				theStemmer.style.left = "0";
				theStemmer.style.margin = "0";
				elem.style.padding = "0";
				elem.style.paddingLeft = padInc+"px";
				elem.style.paddingTop = padInc+"px";
				break;
			case 'nnw': 
				bgPostion = '-50px 0 '; 
				theStemmer.style.top = "0";
				theStemmer.style.left = midOff+"px";
				theStemmer.style.margin = "0";
				elem.style.padding = "0";
				elem.style.paddingTop = padInc+"px";
				elem.style.marginLeft = "0";
				break;
			case 'n': 
				bgPostion = '-100px 0 '; 
				theStemmer.style.left = "50%";
				theStemmer.style.top = "0";
				theStemmer.style.margin = "0";
				theStemmer.style.marginLeft = -cenOffX+"px";
				theStemmer.style.marginRight = cenOffX+"px";
				elem.style.padding = "0";
				elem.style.paddingTop = padInc+"px";
				elem.style.paddingLeft = shadWid+"px";
				break;
			case 'nne': 
				bgPostion = '-150px 0 ';
				theStemmer.style.left = midOff+"px";
				theStemmer.style.top = "0";
				theStemmer.style.margin = "0";
				elem.style.padding = "0";
				elem.style.paddingTop = padInc+"px";
				break;
			case 'ne': 
				bgPostion = '-200px 0'; 
				theStemmer.style.top = "0";
				theStemmer.style.right = "0";
				theStemmer.style.margin = "0";
				elem.style.padding = "0";
				elem.style.paddingRight = padInc+"px";
				elem.style.paddingTop = padInc+"px";;
				break;
			case 'ene': 
				bgPostion = '-200px -50px '; 
				theStemmer.style.top = midOff+"px";
				theStemmer.style.right = "0";
				theStemmer.style.margin = "0";
				elem.style.padding = "0";
				elem.style.paddingRight = padInc+"px";
				elem.style.paddingTop = "0";
				break;
			case 'e': 
				bgPostion = '-200px -100px '; 
				theStemmer.style.right = "0";
				theStemmer.style.left = "";
				theStemmer.style.bottom = "";
				theStemmer.style.margin = "0";
				theStemmer.style.top = "50%";
				theStemmer.style.marginTop = "-18px";
				theStemmer.style.marginBottom = "18px"; /* may seem stupid, but it eliminates an IE render layer */
				elem.style.padding = "0";
				elem.style.paddingRight= padInc+"px";
				//alert( "elemHeight = " + elemHeight);
				//theStemmer.style.top = ( Math.ceil(elemHeight/2) -18 ) + "px";
				break;
			case 'ese': 
				bgPostion = '-200px -150px '; 
				theStemmer.style.top = "";
				theStemmer.style.left = "";
				theStemmer.style.right = "0";
				theStemmer.style.bottom = midOff+"px";
				theStemmer.style.margin = "0";
				elem.style.padding = "0";
				elem.style.paddingRight = padInc+"px";
				break;
			case 'se': 
				bgPostion = '-200px -200px '; 
				theStemmer.style.top = "";
				theStemmer.style.left = "";
				theStemmer.style.right = "0";
				theStemmer.style.bottom = "0";
				theStemmer.style.margin = "0";
				elem.style.padding = "0";
				elem.style.paddingRight = padInc+"px";
				elem.style.paddingBottom = padInc+"px";
				break;
			case 'sse': 
				bgPostion = ' -150px -200px'; 
				var xAdj = -31; /* -25 + 5 (shadow) + 1 (border) */
				var yAdj = -25;
				break;
			case 's': 
				bgPostion = '-100px -200px '; 
				theStemmer.style.top = "";
				theStemmer.style.right = "";
				theStemmer.style.bottom = "0";
				theStemmer.style.left = "50%";
				theStemmer.style.margin = "0";
				theStemmer.style.marginLeft = -cenOffX+"px";
				theStemmer.style.marginRight = cenOffX+"px";
				elem.style.padding = "0";
				elem.style.paddingBottom = padInc+"px";
				elem.style.paddingLeft = shadWid+"px";
				break;
			case 'ssw': 
				bgPostion = '-50px -200px '; 
				break;
			case 'sw': 	
				bgPostion = '0px -200px '; 
				theStemmer.style.top = "";
				theStemmer.style.right = "";
				theStemmer.style.bottom = "0";
				theStemmer.style.left = "0";
				theStemmer.style.margin = "0";
				elem.style.padding = "0";
				elem.style.paddingLeft = padInc+"px";
				elem.style.paddingBottom = padInc+"px";
				break;
			case 'wsw': 
				bgPostion = '0px -150px '; 
				break;
			case 'w': 
				bgPostion = '0px -100px '; 
				break;
			case 'wnw': 
				bgPostion = '0px -50px '; 
				break;
		}
		theStemmer.style.backgroundPosition = bgPostion;
		//theStemmer.style.top = (yPos+yAdj)+"px";
		//theStemmer.style.left = (xPos+xAdj)+"px";
	}
	return theStemmer;
}

var stemmerID = "popupstemmer";

function getStemmer( elem ) {
	elem = dojo.byId( elem );
	var testStem = getFirstChildwithClass( elem, stemmerID );
	//alert( " theStemmer== "+theStemmer);
	if( testStem == null ) {
		var theStemmer = document.createElement("div"); // build the pagemask HTML
		theStemmer.setAttribute("className", stemmerID);
		theStemmer.setAttribute("class", stemmerID);
		elem.appendChild( theStemmer );
		testStem = getFirstChildwithClass( elem, stemmerID );
	} 
	return testStem;
}

function showStemmer() {
	var theStemmer = getStemmer(); 
	if( theStemmer !=null ) {
		theStemmer.style.display = 'block'; 
	}
	return theStemmer;
}

function hideStemmer() {
	var theStemmer = getStemmer(); 
	if( theStemmer !=null ) {
		theStemmer.style.display = 'none'; 
	}
	return theStemmer;
}


/**************/

var destTagId = "machinetags";

function removeSuggestedTag( elem ) {
	elem = dojo.byId( elem );
	var theElem = getFirstParentwithClass( elem, 'deletetag' );
	if( activeFS == null )
		dojo.lfx.html.fadeHide(theElem, fadeInRate).play();
	else {
		theElem.style.display = "none";
		sizeFullScreener( activeFS ); 
	}
}

function addSuggestedTag( elem ) {
	elem = dojo.byId( elem );
	var tagHTML = elem.innerHTML;
	addSuggestedTag2( tagHTML );
	//dojo.lfx.html.fadeShow(theElem, fadeOutRate).play();
	dojo.lfx.html.fadeHide(elem, fadeOutRate).play();
	sizeFullScreener( activeFS ); 
}

function addSuggestedTag2( tagText ) {
	var theTag = document.createElement("span"); // build the pagemask HTML
	theTag.setAttribute("className", "deletetag");
	theTag.setAttribute("class", "deletetag");
	theTag.innerHTML = tagText+' <img src="/include3/images/ic12_x.gif" class="ic12" border="0" alt="X" title="" onclick="removeSuggestedTag(this);"/>'; 
	destTagList = dojo.byId( destTagId );
	destTagList.appendChild( theTag );
}

function addSuggestedTagForm( elem ) {
	elem = dojo.byId( elem );
	var tagHTML = elem.value;
	tagHTML = removeEmpties(tagHTML.split(' '));
	var tagHTMLLength = tagHTML.length;
	for( var i=0; i< tagHTMLLength; i++ ){
		addSuggestedTag2( tagHTML[i] );
	}
	elem.value = '';
}

function addSuggestedTag_simple( elem, target ) {
	elem = dojo.byId( elem );
	target = dojo.byId( target );
	var tagHTML = elem.innerHTML;
	target.value += " "+tagHTML
	dojo.lfx.html.fadeHide(elem, fadeOutRate).play();
	sizeFullScreener( activeFS ); 
}

/***********/

function editPageTitle() {
	var origH1 = dojo.byId( 'pageTitle' );
	var origText = dojo.byId( 'pageTitleContent' );
	var h1Editor = dojo.byId( 'pageTitleEditor' );
	var h1Field = dojo.byId( 'pageTitleContentReplacement' );
	//h1Field.value = origText.innerHTML;
	var newVal = origText.innerHTML;
	newVal = newVal.replace(/&nbsp;/g, ' ' );
	h1Field.value = newVal;
	origH1.style.display="none";
	h1Editor.style.display="block";
	h1Field.focus();
}
function updatePageTitle() {
	var origText = dojo.byId( 'pageTitleContent' );
	var h1Field = dojo.byId( 'pageTitleContentReplacement' );
	var newVal = h1Field.value;
	//newVal = newVal.replace(/\s*(.*)?\s/g, '$1' );
	newVal = newVal.replace(/\s+$/, '' ); // trailing whitespace
	newVal = newVal.replace(/\s\s/g, ' &nbsp;' ); // multiple spaces
	if( newVal != '' )
		origText.innerHTML = newVal;
	revertPageTitle(); 
}
function revertPageTitle() {
	var origH1 = dojo.byId( 'pageTitle' );
	var h1Editor = dojo.byId( 'pageTitleEditor' );
	h1Editor.style.display="none";
	origH1.style.display="block";
}

/*******/

function removeFromList( elem ) {
	//elem = xGetElementById( elem );
	if( elem!= null ) {
		var theLI = getFirstParentofType( elem, 'li' );
		if( theLI != null ) {
			//if( dojo.lfx.wipeOut == null ) {
				dojo.lfx.wipeOut( theLI, fadeOutRate ).play();
				dojo.lfx.fadeOut( theLI, fadeInRate ).play();
			//} else {
				//alert( theLI );
				//theLI.style.display = "none";
			//}
		} //else alert( elem.className );
	}
}

function removeFromListSlow( elem ) {
	//elem = xGetElementById( elem );
	if( elem!= null ) {
		var theLI = getFirstParentofType( elem, 'li' );
		if( theLI != null ) {
			//if( dojo.lfx.wipeOut == null ) {
				dojo.lfx.wipeOut( theLI, fadeOutRate*2 ).play();
				dojo.lfx.fadeOut( theLI, fadeOutRate*2 ).play();
			//} else {
				//alert( theLI );
				//theLI.style.display = "none";
			//}
		} //else alert( elem.className );
	}
}


function addToList( elem ) {
	//elem = xGetElementById( elem );
	if( elem!= null ) {
		var theLI = getFirstParentofType( elem, 'li' );
		if( theLI != null ) {
			//if( dojo.lfx.wipeOut == null ) {
				dojo.style.setOpacity(theLI, 0); // immediately set opacity to 100, in case it was faded out;
				dojo.lfx.wipeIn( theLI, fadeOutRate*2 ).play();
				dojo.lfx.fadeIn( theLI, fadeOutRate*4 ).play();
			//} else {
				//alert( theLI );
				//theLI.style.display = "none";
			//}
		} //else alert( elem.className );
	}
}


function showSuggestorAjax( elem ) {
	elem = xGetElementById( elem );
	// elem = byId( elem );
	if( elem!= null ) {
		elem.style.visibility="visible";
		
		dojo.style.setOpacity(elem, 0);
		dojo.lfx.fadeIn( elem, fadeOutRate*2 ).play();
	}
}

function hideSuggestorAjax( elem ) {
	elem = xGetElementById( elem );
	// elem = byId( elem );
	if( elem!= null ) {
				dojo.lfx.fadeOut( elem, fadeOutRate*2 ).play();
	}
}

/****/


function addPreferredTag( elem ) {
	elem = dojo.byId( elem );
	var tagHTML = elem.value;
	tagHTML = removeEmpties(tagHTML.split(' '));
	var tagHTMLLength = tagHTML.length;
	for( var i=0; i< tagHTMLLength; i++ ){
		addSuggestedTag2( tagHTML[i] );
	}
	elem.value = '';
	if( i > 0 ) {
		var tagName = dojo.byId( 'tagPopupDefName' );
		tagName.value = tagHTML[i-1];
		showDialog( 'di_tagtrainer');
		var tagValue = dojo.byId( 'tagPopupDefValue' );
		tagValue.focus();
		revealAlert( 'hiddenSaver1' );	
	}
}



function addTagDefinition( elem ) {
	elem = dojo.byId( elem );
	var tagHTML = elem.value;
	elem.value = '';
	if( tagHTML != '') {
		var tagName = dojo.byId( 'tagPopupDefName' );
		tagName.value = tagHTML;
		showDialog( 'di_tagtrainer');
		var tagValue = dojo.byId( 'tagPopupDefValue' );
		tagValue.focus();
	}
}

function addTagDefinition2( ) {
	var tagName = dojo.byId( 'tagPopupDefName' );
	var tagType = dojo.byId( 'tagPopupDefType' );
	var tagValue = dojo.byId( 'tagPopupDefValue' );
	if( tagType.value !="" && tagValue.value !="" ) {
		addDefinitionRow( tagName.value, tagType.value, tagValue.value ); 	
		//addDefinitionBlock( tagName.value, tagType.value, tagValue.value ); 	
		revealAlert( 'hiddenSaver2' );	
	}
	closeDialog();
	tagType.value ="";
	tagValue.value ="";
}


function addDefinitionRow( theTag, theType, theValue ) {
	var destRow = addDefinitionBlank('tagDefTable');
	
	var defTag = getFirstChildwithTag( destRow.cells[0], 'input' );
	defTag.value = theTag;
	
	var defType = getFirstChildwithTag( destRow.cells[1], 'select' );
	defType.value = theType;
	
	var defValue = getFirstChildwithTag( destRow.cells[2], 'input' );
	defValue.value = theValue;
	
}

function addNewTagDefinition( sourceInput ) {

	sourceInput = dojo.byId( sourceInput );
	if( sourceInput.value !="" ) {
		var destRow = addDefinitionBlank( 'tagDefTable' );
		var defName = getFirstChildwithTag( destRow, 'input' );
		var defVal = getFirstChildwithTag( destRow.cells[2], 'input' );
		defName.value = sourceInput.value;
		sourceInput.value = "";
		defVal.focus();
		revealAlert( 'hiddenSaver2' );	
	}
	
}



function editTagDef( elem ) {
	elem = dojo.byId( elem);
	var theDef = getFirstParentofType( elem, 'li' );
	editingDef = theDef;
	
	var oldDefTag = getFirstChildwithClass( theDef, 'defTag' ).innerHTML;
	var oldDefType = getFirstChildwithClass( theDef, 'defType' ).innerHTML;
	var oldDefValue = getFirstChildwithClass( theDef, 'defValue' ).innerHTML;
	var tagName = dojo.byId( 'tagPopupDefName2' );
	var tagType = dojo.byId( 'tagPopupDefType2' );
	var tagValue = dojo.byId( 'tagPopupDefValue2' );

	tagName.value = oldDefTag;
	tagType.value = oldDefType;
	tagValue.value = oldDefValue;

	showDialog( 'di_tagtrainer');	
}


function addDefinitionBlank( destTable ) {
	destTable = dojo.byId( destTable );
	var newRow = destTable.tBodies[1].rows[0].cloneNode(true);	
	destTable.tBodies[0].appendChild(newRow);
	newRow.className = "";
	return newRow;
}

function duplicateRow( destTable ) {
	destTable = dojo.byId( destTable );
	var prototype= dojo.byId("prototypetBody").rows[0];
	var newRow = prototype.cloneNode(true);	
	var destTBody= dojo.byId("databody");	
	destTBody.appendChild(newRow);
	newRow.className = "";
	return newRow;
}

function addTagDefinitionStr( str ) {
	var tagName = dojo.byId( 'tagPopupDefName' );
	tagName.value = str;
	showDialog( 'di_tagtrainer');
	var tagValue = dojo.byId( 'tagPopupDefValue' );
	tagValue.focus();
}


/*** unused below **/


/*var editingDef = null;

function addDefinitionBlock( theTag, theType, theValue ) {
	var dest = dojo.byId( 'tagDefs' );
	var newDef;
	newDef  = '<li class="tagdef">';
	newDef +=	 '<span class="defTag">'+theTag+'</span> <span class="defType">'+theType+'</span> <span class="defValue">'+ theValue +'</span>. ';
	newDef += 	'<span class="defActions gray"><a href="javascript:;" onclick="editTagDef(this);">edit</a> &nbsp; <a href="javascript:;" onclick="deleteTagDef(this);">delete</a></span>';
	newDef += '</li>';
	dest.innerHTML += newDef ;
}

function deleteTagDef( elem ) {
	elem = dojo.byId( elem);
	var theDef = getFirstParentofType( elem, 'li' );
	var dest = dojo.byId( 'tagDefs' );
	dest.removeChild(theDef);
	revealAlert( 'hiddenSaver2' );	
}



function editDefinitionBlock( theTag, theType, theValue ) {
	dest = dojo.byId( 'tagDefs' );
	var typeText;
	var newDef= "<div class='tagdef'><b>"+theTag+"</b> "+typeText+" "+ theValue;
	newDef += "<span class='defactions'><a href="
	dest.innerHTML += newDef ;
}


function editDefinitionBlock( theTag, theType, theValue ) {
	dest = dojo.byId( 'tagDefs' );
	var typeText;
	var newDef= "<div class='tagdef'><b>"+theTag+"</b> "+typeText+" "+ theValue;
	//newDef += "<span class='defactions'><a href=";
	dest.innerHTML += newDef ;
}
*/


/***/

var activeDefVal = null;

function check4spaces(theField ) {
	// check if it is an breviation or not
	var row= theField.parentNode.parentNode;
	var selector = getFirstChildwithName(row, "type" );
	if(selector.selectedIndex==1)
		return;
	theField = dojo.byId( theField );
	var defVal = theField.value;
	if( defVal.search( ',' ) != -1 )
		return;
	else if( defVal.search( ' ' ) != -1 ) {
		var pieces = defVal.split(' ');
		pieces = removeEmpties(pieces);
		if( pieces.length > 1 ){
			var singleConcept = dojo.byId('spaceCheckOneConcept');
			singleConcept.innerHTML = pieces.join('-');
			var multiConcept = dojo.byId('spaceCheckMultiConcepts');
			multiConcept.innerHTML = pieces.join(', ');
			showDialog( 'wit_spaces' );
			activeDefVal = theField;
		}
	}
}

function updateSpaces(theChoice) {
	activeDefVal.value = theChoice.innerHTML; 
	closeDialog();
}


/**/

var storagecost = 10.00;
function calcStorageCost(theSelect, theResult) {
	theSelect = dojo.byId( theSelect );
	theResult = dojo.byId( theResult );
    var theSelectVal = theSelect.value *1 * storagecost;
    var theSelectValDollars = Math.floor(theSelectVal);
    var theSelectValCents = (Math.ceil(theSelectVal*100))%100;
    if( theSelectValCents < 10 ) {
        theSelectValCents = "0" + theSelectValCents;
    }
    theResult.innerHTML = theSelectValDollars + "." + theSelectValCents;
    

}

/****
findPosX + findPosY from http://www.quirksmode.org/index.php?/js/findpos.php
*****/

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}



// xGetElementById, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetElementById(e)
{
  if(typeof(e)!='string') 
  	return e;
  else if(document.getElementById) 
  	e=document.getElementById(e);
  else if(document.all) 
  	e=document.all[e];
  else 
  	e=null;
  return e;
}


/*
function showstory( ) 
{
	obj = xGetElementById( 'story' );
	HideObj( 'showstory');
	obj.style.maxHeight = '2000px';
}

function hidestory( ) 
{
	obj = xGetElementById( 'story' );
	ShowObj( 'showstory');
	obj.style.maxHeight = '1px';
}
*/

function ShowObj( obj, xCoor, yCoor ) 
{
	obj = xGetElementById(obj);
	if ( xCoor )
		obj.style.left= xCoor  +'px';
	if ( yCoor )
		obj.style.top = yCoor +'px';
	/*style.top = (thisItem.offsetTop+thisItem.offsetHeight)+'px';*/
	obj.style.display = "block";
}

function HideObj( obj ) 
{
	obj = xGetElementById(obj);
	obj.style.display = "none";

}

function uprate( obj ) {
	obj = xGetElementById(obj);	
	modCont = findModContainer( obj );
	
	if( dojo.html.hasClass(modCont, 'worst1') ){
		neuterate( obj );
	} else if( dojo.html.hasClass(modCont, 'best1') ){
		neuterate( obj );
		textAdd( 'helpfulcountAll', -1 );
		textAdd( 'helpfulcountYou', -1 );
	} else {
		dojo.html.addClass( modCont, "best1" );
		/*dojo.html.addClass( modCont, "neuter" );
		unneuter_delay( obj );*/
		flashElem( modCont );
		textAdd( 'helpfulcountAll', 1 );
		textAdd( 'helpfulcountYou', 1 );
		
	}
	tapAll("comp-tools",modCont);
}

function downrate( obj ) {
	obj = xGetElementById(obj);
	modCont = findModContainer( obj );
	//var myY = findPosY(obj) + obj.offsetHeight;
	//var myX = findPosX(obj);
	//HideObj( 'plusBar' );
	//ShowObj('minusBar', myX, myY );
	
	if( dojo.html.hasClass(modCont, 'best1')) {
		neuterate( obj );
	} else if( dojo.html.hasClass(modCont, 'worst1')) {
		neuterate( obj );
	} else {
		dojo.html.addClass( modCont, "worst1" );
		/*dojo.html.addClass( modCont, "neuter" );
		unneuter_delay( obj );*/	
		textAdd( 'helpfulcountAll', 1 );
		textAdd( 'helpfulcountYou', 1 );
		flashElem_disable( modCont );
	}
	tapAll("comp-tools",modCont);
}


function spamrate( obj ) {
	obj = xGetElementById(obj);
	modCont = findModContainer( obj );
	//var myY = findPosY(obj) + obj.offsetHeight;
	//var myX = findPosX(obj);
	//HideObj( 'plusBar' );
	//ShowObj('minusBar', myX, myY );
	
	if( dojo.html.hasClass(modCont, 'best1')) {
		neuterate( obj );
		dojo.html.addClass( modCont, "worst1" );
		dojo.html.addClass( modCont, "spam1" );
		textAdd( 'helpfulcountAll', -1 );
		textAdd( 'helpfulcountYou', -1 );
	} else if( dojo.html.hasClass(modCont, 'spam1')) {
		neuterate( obj );
	} else {
		dojo.html.addClass( modCont, "worst1" );
		dojo.html.addClass( modCont, "spam1" );
		/*dojo.html.addClass( modCont, "neuter" );
		unneuter_delay( obj );*/	
		flashElem_disable( modCont );
	}
	tapAll("comp-tools",modCont);
}


var neu_delay = 1;
var mytimer_on_ID = 0;
var mytimer_off_ID = 0;

function neuterate( obj ) {
	obj = xGetElementById(obj);
	modCont = findModContainer( obj );
	
	dojo.html.addClass( modCont, "neuter" );
	dojo.html.removeClass( modCont, "selected" );
	dojo.html.removeClass( modCont, "worst1" );
	dojo.html.removeClass( modCont, "best1" );
	dojo.html.removeClass( modCont, "spam1" );
	unneuter_delay( obj );	
	flashElem_disable( modCont );
}

function tapAll( className, startWith) { 

	if( isIE ) {
		/*startWith = dojo.html.getElementsByClass( className, startWith );*/
		startWith.id = nameTag( startWith);
		var toolArray = dojo.html.getElementsByClass( className );
		var startYet = true;
		for (var i=0; i< toolArray.length; i++ ) {
			if( startYet == true ) {
				neuterate2( toolArray[i] );
			} /*else {
				if( toolArray[i].id == startWith.id ) {
					alert( "toolArray[i].id  =" +toolArray[i].id + ", startWith = " +startWith.id);
					startYet = true;
				}
			}*/
		}
	}
}

function tapAllTag( className, startWith) { 

	if( isIE ) {
		/*startWith = dojo.html.getElementsByClass( className, startWith );*/
		startWith.id = nameTag( startWith);
		var toolArray = dojo.html.getElementsByTagName( className );
		var startYet = true;
		for (var i=0; i< toolArray.length; i++ ) {
			if( startYet == true ) {
				neuterate2( toolArray[i] );
			} /*else {
				if( toolArray[i].id == startWith.id ) {
					alert( "toolArray[i].id  =" +toolArray[i].id + ", startWith = " +startWith.id);
					startYet = true;
				}
			}*/
		}
	}
}

function neuterate2( obj ) {
	var modCont = xGetElementById(obj);
	dojo.html.addClass( modCont, "neuter" );
	unneuter_delay( modCont );	
	flashElem_disable( modCont );
}

function unneuter_delay( obj ) {
	var elemID = nameTag(obj);
	var timerCommand = 'unneuterate( \"'+elemID+'\" );';
	mytimer_on_ID = setTimeout( timerCommand, neu_delay );
}

function unneuterate( obj ) {
	/*alert( "unneuterate called. obj = "+obj );*/
	obj = xGetElementById(obj);
	modCont = findModContainer( obj );
	dojo.html.removeClass( modCont, "neuter" );
}



var tagfieldCounter = 1;
var tagfieldCounterPrefix = "tagfield"; // these three are used for typeahead

function nameTag( elem ) { // give an element an ID if one was not assigned in the HTML
	var tagfield = byId( elem );
	if( tagfield != null ) {
		if( tagfield.id ) { // if this has an id name...
			return tagfield.id;
		} else { //otherwise, give it an ID
			tagfield.id = (tagfieldCounterPrefix + '_' +tagfieldCounter);
			tagfieldCounter++;
		}
		return tagfield.id
	} else {
		return null;
	}
}


function uprateBig( obj ) 
{
	obj = xGetElementById(obj);	
	
	if( obj.className.contains ('worst1') ){
		obj.className = delclass( obj.className, "best1" );
	} else if( obj.className.contains ('best1')) {
		obj.className = delclass( obj.className, "best1" );
	} else {
		obj.className = addclass( obj.className, "best1" );
	}
 	hideBar( obj );
}

function downrateBig( obj ) 
{
	obj = xGetElementById(obj);
	//var myY = findPosY(obj) + obj.offsetHeight;
	//var myX = findPosX(obj);
	//HideObj( 'plusBar' );
	//ShowObj('minusBar', myX, myY );
	
	if( obj.className.contains ('best1')) {
		obj.className = delclass( obj.className, "worst1" );
	} else if( obj.className.contains ('worst1')) {
		obj.className = delclass( obj.className, "worst1" );
	} else {
		obj.className = delclass( obj.className, "best1" );
		obj.className = addclass( obj.className, "worst1" );
	}
 	hideBar( obj );
 }



function hideBar( obj ) {
	//doesn't do anything. Why do I call it from everywhere?
}

var activetoolBar = null;

function showtoolBar (obj, toolbarID ) {
	if( obj) {
		obj = xGetElementById(obj);
		var myY = findPosY(obj);
		var myX = findPosX(obj)
	}
	myX = myX-1;
	myY = myY-2;
	
	if(activetoolBar) 
		HideObj( activetoolBar );
		
	/*var postAc = xGetChildElementByID( theToolbar, 'postActions');	
	var preAc = xGetChildElementByID( theToolbar, 'preActions');	
	theToolbar = xGetElementById(toolbarID);
	HideObj( postAc );
	ShowObj( preAc );*/
	/*HideObj( (toolbarID+'postActions') );
	ShowObj( (toolbarID+'preActions') );*/
	
	activetoolBar = toolbarID;
	var postAc = ( activetoolBar+"postActions" );
	var preAc = ( activetoolBar+"preActions" );

	HideObj( postAc );
	ShowObj( preAc );
	ShowObj( toolbarID, myX, myY );
	toolsOn = false;
}


function hidePretools( ) {
	var postAc = ( activetoolBar+"postActions" );
	var preAc = ( activetoolBar+"preActions" );
	if ( toolsOn == false ) {
		HideObj( postAc );
	} 
	HideObj( preAc );
}

function hideActions( ) {
	toolsOn = false;
	var postAc = ( activetoolBar+"postActions" );
	var preAc = ( activetoolBar+"preActions" );
	HideObj( postAc );
	HideObj( preAc );
}

var toolsOn= false;

function showActions( ) {
	toolsOn= true;
	var postAc = ( activetoolBar+"postActions" );
	var preAc = ( activetoolBar+"preActions" );
	ShowObj( postAc );
	HideObj( preAc );
}

function chill() {
}


function delclass ( fullStr, delStr ) {
	var doneStr = fullStr;
	while( doneStr.contains( delStr )  ) {	
		doneStr = doneStr.replace( delStr, "" );
	}
	doneStr = doneStr.replace( "  ", " " ); // take out extraneous spaces
	return doneStr;
}

function addclass ( fullStr, addStr ) {
	var doneStr = fullStr;
	if( !doneStr.contains( addStr ) ) {	
		doneStr = (fullStr + " " + addStr );
	}
	return doneStr;
}

function findModContainer( obj ) {
	var foo = false;
	obj = xGetElementById(obj);
	if( obj.className.contains("mod") ) {
		foo = true;
	}
	while(obj.parentNode && !foo ) {
		obj=obj.parentNode;
		if( obj.className.contains("mod") ) {
			foo = true;
		}
	}
	return obj;
}

function strContain( substr )
{
	if( this.search( substr ) == -1 ) return false;
	else return true;
}

String.prototype.contains = strContain;


function toggle( elem ) {
	if( dojo.html.hasClass(elem, "toggled") ) {
		dojo.html.removeClass(elem, "toggled");	
	} else {
		dojo.html.addClass(elem, "toggled");	
	}
}

function showquote( theElem ) {
	theElem = byId(theElem);
	theElem = getFirstParentofClass( theElem, 'quotetext' ); 
	toggle( theElem ); 
	var theBody = getFirstChildwithClass( theElem, 'quoteTextBody' ); 
	if( !isIE ) {
		dojo.lfx.wipeIn( theBody, 200 ).play();
		//dojo.lfx.fadeIn( theBody, 400 ).play();
	} else {
		theBody.style.height = 'auto';
		theBody.style.overflow = 'auto';
		theBody.style.visibility = 'visible';
		tapAll( theElem, 'mod' );
	}
}


function hidequote( theElem ) {
	theElem = byId(theElem);
	theElem = getFirstParentofClass( theElem, 'quotetext' ); 
	toggle( theElem ); 
	var theBody = getFirstChildwithClass( theElem, 'quoteTextBody' ); 
	if( !isIE ) {
		dojo.lfx.wipeOut( theBody, 200 ).play();
		//dojo.lfx.fadeOut( theBody, 400 ).play();
	} else {
		theBody.style.height = '0px';
		theBody.style.overflow = 'hidden';
		theBody.style.visibility = 'hidden';
		tapAll( theElem, 'mod' );
	}
}



function getFirstParentofClass( elem, theclassName ) {
	elem = byId( elem );
	theclassName = theclassName.toLowerCase();
	var elemClassName = elem.className.toLowerCase(); 
	if( elemClassName == theclassName ) {
		return elem; 
	} else if( elemClassName.search(theclassName) != -1 ) {
		return elem; 
	}
	var elemPar = elem.parentNode;
	if( elemPar != null ) {
		return getFirstParentofClass( elemPar, theclassName );
	} else {
	 	return false;
	}
}

var flashCounter = 0;
var flashTimer = 80;
var totalElemFlashes = 1;

var flashElem_timer = 0;

function flashElem( theElem ) {
	nameTag( theElem );
	theElem = byId(theElem);
	if( flashCounter == 0 ) { //init: clear existing states;
		dojo.html.removeClass(theElem, "fadein"); 
		dojo.html.removeClass(theElem, "nohover"); 
	}
	if( flashCounter < totalElemFlashes ) {
		dojo.html.addClass(theElem, 'flash1');
		dojo.html.removeClass(theElem, 'flash2');
		flashCounter++;
		flashElem_timer = setTimeout("flashElem2('"+theElem.id +"')", flashTimer);
	} else {
		flashCounter = 0;
		flashElem_timer = setTimeout("clearFlashElem('"+theElem.id +"')", flashTimer);
		dojo.html.addClass(theElem, 'flash1');
		dojo.html.removeClass(theElem, 'flash2');
		return true;
	}
}

function flashElem2( theElem ) {
	theElem = byId(theElem);
	dojo.html.addClass(theElem, 'flash2');
	dojo.html.removeClass(theElem, 'flash1');
	flashElem_timer = setTimeout("flashElem('"+theElem.id +"')", flashTimer);
}

function clearFlashElem( theElem ) {
	clearTimeout( flashElem_timer );
	theElem = byId(theElem);
	dojo.html.removeClass(theElem, 'flash1');
	dojo.html.removeClass(theElem, 'flash2');
}

var flashElem_disable_timer = 0;

function flashElem_disable( theElemID ) {
	var theElem = byId(theElemID);
	nameTag( theElem );
	dojo.html.addClass(theElem, 'fadein');
	flashElem_disable_timer = setTimeout("flashElem_disable2('"+theElem.id +"')", flashTimer+1);
}

function flashElem_disable2( theElemID ) {
	clearTimeout( flashElem_disable_timer );
	var theElem = byId(theElemID);
	dojo.html.removeClass(theElem, 'fadein');
	/*dojo.html.removeClass(theElem, 'nohover');*/
}













/*** new versions of the old tricks***/


function rateNeutral( obj ) {
	obj = byId(obj);
	modCont = findModContainer( obj );
	
	if(	dojo.html.hasClass( modCont, "rep_uprated")) {
		// if we're neutering from an uprate, we need to lower the score again
		
		textAdd( 'helpfulcountAll', -1 );
		textAdd( 'helpfulcountYou', -1 );

		var upBtn = getFirstChildwithClass(modCont, 'btn_uprate' ); 
		textAdd( getFirstChildwithTag(upBtn, 'span' ) , -1 );
	}
	
	if(	dojo.html.hasClass( modCont, "rep_downrated")) {
		// if we're neutering from an downrate, we need to lower the score again
		textAdd( 'unhelpfulcountAll', -1 );
		textAdd( 'unhelpfulcountYou', -1 );
		
		var upBtn = getFirstChildwithClass(modCont, 'btn_downrate' ); 
		textAdd( getFirstChildwithTag(upBtn, 'span' ) , -1 );
	}
	
	dojo.html.addClass( modCont, "rep_neutral" );
	dojo.html.removeClass( modCont, "rep_collapsed" );
	dojo.html.removeClass( modCont, "rep_downrated" );
	dojo.html.removeClass( modCont, "rep_uprated" );
	dojo.html.removeClass( modCont, "rep_spam" );
 	if ( dojo.html.hasClass( modCont, "rep_edit" ) ){
		revertEdits( obj ); 	
	}
	flashElem_disable( modCont );
}


function rateUp( obj ) {
	obj = byId(obj);	
	var modCont = findModContainer( obj );
	
 	if( dojo.html.hasClass(modCont, 'rep_deleted') ) {
 		return false; // can't undelete something the manager deleted
	} else if( !dojo.html.hasClass(modCont, 'rep_uprated')  && dojo.html.hasClass(modCont, 'rep_neutral')){
		rateNeutral( obj );
		dojo.html.addClass( modCont, "rep_uprated" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		flashElem( modCont );
		
		textAdd( 'helpfulcountAll', 1 );
		textAdd( 'helpfulcountYou', 1 );
		textAdd( getFirstChildwithTag(obj, 'span' ) , 1 );
	} else {
		rateNeutral( obj );
	}
	tapAll("comp-tools",modCont);
}

function rateDown( obj ) {
	obj = byId(obj);
	var modCont = findModContainer( obj );
	
 	if( dojo.html.hasClass(modCont, 'rep_deleted') ) {
 		return false; // can't undelete something the manager deleted
	} else if( !dojo.html.hasClass(modCont, 'rep_downrated') && dojo.html.hasClass(modCont, 'rep_neutral')) {
		rateNeutral( obj );
		dojo.html.addClass( modCont, "rep_downrated" );
		dojo.html.addClass( modCont, "rep_collapsed" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		flashElem_disable( modCont );
		
		textAdd( 'unhelpfulcountAll', 1 );
		textAdd( 'unhelpfulcountYou', 1 );
		textAdd( getFirstChildwithTag(obj, 'span' ) , 1 );

	} else {
		rateNeutral( obj );
	}
	tapAll("comp-tools",modCont);
}


function rateSpam( obj ) {
	hideNav_now();
	obj = byId(obj);
	var modCont = findModContainer( obj );
	
 	if( dojo.html.hasClass(modCont, 'rep_deleted') ) {
 		return false; // can't undelete something the manager deleted
	} else if( !dojo.html.hasClass(modCont, 'rep_spam') && dojo.html.hasClass(modCont, 'rep_neutral')) {
		rateNeutral( obj );
		dojo.html.addClass( modCont, "rep_collapsed" );
		dojo.html.addClass( modCont, "rep_spam" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		
		flashElem_disable( modCont );
	} else {
		dojo.html.removeClass( modCont, "rep_collapsed" );
		dojo.html.removeClass( modCont, "rep_spam" );
		dojo.html.addClass( modCont, "rep_neutral" );
	}
	tapAll("comp-tools",modCont);
}

function rateCommentFlag( objID ) {
	hideNav_now();
	var modCont =  byId(objID);
	//alert( objID) ;
 	if( dojo.html.hasClass(modCont, 'rep_deleted') ) {
 		return false; // can't undelete something the manager deleted
	} else if( !dojo.html.hasClass(modCont, 'rep_spam') && dojo.html.hasClass(modCont, 'rep_neutral')) {
		rateNeutral( objID );
		dojo.html.addClass( modCont, "rep_collapsed" );
		dojo.html.addClass( modCont, "rep_spam" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		flashElem_disable( modCont );
	} else { // if already marked, unmark it
		dojo.html.removeClass( modCont, "rep_collapsed" );
		dojo.html.removeClass( modCont, "rep_spam" );
		dojo.html.addClass( modCont, "rep_neutral" );
	}
	tapAll("comp-tools",modCont);
}
function rateCommentDelete( objID ) {
	hideNav_now();
	var modCont =  byId(objID);
	//alert( objID) ;
 	if( dojo.html.hasClass(modCont, 'rep_deleted') ) { // if deleted, undelete
		rateNeutral( objID );
	} else {
		// rateNeutral( objID );
		// dojo.html.addClass( modCont, "rep_collapsed" );
		 dojo.html.addClass( modCont, "temp-delete" );
		// dojo.html.removeClass( modCont, "rep_neutral" );
		// 
		// flashElem_disable( modCont );
		var doDelete = confirm('Are you sure you want to delete this comment? There is no undo for this action.');
		if( doDelete )
			EZwipeOut(objID);
		else {
		 	dojo.html.removeClass( modCont, "temp-delete" );
			return false;
		}
	}
	tapAll("comp-tools",modCont);
}

function deleteReply( objID ) {
	//var modCont = findModContainer( obj );
	hideNav_now();
	activeDel =objID;
}

function deleteReplyExec(  ) {
	closeDialog();
	obj = byId(activeDel);
	var modCont = findModContainer( obj );
	if( !dojo.html.hasClass(modCont, 'rep_deleted') && dojo.html.hasClass(modCont, 'rep_neutral')) {
		rateNeutral( modCont );
		dojo.html.addClass( modCont, "rep_collapsed" );
		dojo.html.addClass( modCont, "rep_deleted_you" );
		dojo.html.addClass( modCont, "rep_deleted" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		
		flashElem_disable( modCont );
	} else {
		rateNeutral( modCont );
	}
	tapAll("comp-tools",modCont);
}


function deleteReplyYou( obj ) {
	hideNav_now();
	obj = byId(obj);
	var modCont = findModContainer( obj );
	
 	if( dojo.html.hasClass(modCont, 'rep_deleted') ) {
 		return false; // can't undelete something the manager deleted
	} else if( !dojo.html.hasClass(modCont, 'rep_delete_you') && dojo.html.hasClass(modCont, 'rep_neutral')) {
		rateNeutral( obj );
		dojo.html.addClass( modCont, "rep_collapsed" );
		dojo.html.addClass( modCont, "rep_deleted" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		
		flashElem_disable( modCont );
	} else {
		rateNeutral( obj );
	}
	tapAll("comp-tools",modCont);
}


function deleteReplyMgr( obj ) {
	hideNav_now();
	obj = byId(obj);
	var modCont = findModContainer( obj );

	if( !dojo.html.hasClass(modCont, 'rep_deleted') && dojo.html.hasClass(modCont, 'rep_neutral')) {
		rateNeutral( obj );
		dojo.html.addClass( modCont, "rep_collapsed" );
		dojo.html.addClass( modCont, "rep_deleted" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		
		flashElem_disable( modCont );
	} else {
		rateNeutral( obj );
	}
	tapAll("comp-tools",modCont);
}

function editReply( elem ) {
	hideNav_now();
	//var elem = byId(elemID);
	var modCont = getFirstParentwithClass( elem, 'mod' );
	var theReply = getFirstChildwithClass( modCont, 'comp-content' );
	var theReplyEditor = getFirstChildwithClass( modCont, 'comp-editor' );
	var theAttachments = getFirstChildwithClass( modCont, 'comp-attachments' );
	var theContent = getFirstChildwithTag( modCont, 'textarea' );
	var contentID = theContent.id;
	//alert( "contentID="+contentID);
	//dojo.html.addClass(theReply, 'testHilight');
	if ( !dojo.html.hasClass( modCont, "rep_edit" ) && dojo.html.hasClass( modCont, "rep_neutral" )) {
		//theContent.focus();
		theContent.value = theReply.innerHTML;
		var newHeight = sizeWindow( modCont ); 
		flashElem( modCont );
		if( theAttachments != null ) {
			initAttacher( theAttachments, theReplyEditor);
		}
		if( istinyMCE() ) {
			tinyMCE.execCommand('mceAddControl', false, contentID);
		} else {
			//	alert( "!istinyMCE");
		}
		dojo.html.addClass( modCont, "rep_edit" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		//rateNeutral( elem );

	} else if ( dojo.html.hasClass( modCont, "rep_edit" ) ){
		revertEdits( elem ) 
	} else {
		rateNeutral( elem );
	}
	
}

function initAttacher( theAttachments, theReplyEditor) {
	var attacher = getFirstChildwithClass( theReplyEditor, 'attacher' );
	var fileTable = getFirstChildwithClass( attacher, 'itemtable' );
	//alert( "fileTable="+fileTable);
	//fileTable.tBodies[0].rows[2].alreadyclicked = true; //needs to be set for us to delete
	clearAttachTable(fileTable); //delete blank row... we'll add it back when we're done
	
	//var theFiles = getAllChildrenwithClass( theAttachments, 'attached_file' );
	var theFiles = getAllChildrenwithTagname( theAttachments, 'a' );
	var fileCount = theFiles.length;
	//alert( "theAttachments="+theAttachments.innerHTML);
	//alert( fileCount+" attachments found in theAttachments. (theFiles="+theFiles);
	for( var i=0; i< fileCount; i++) {
		addAttachFile( fileTable, theFiles[i] );
		//fileTable.tBodies[0].rows[i].alreadyclicked = true;
	}
	addAttachBlank(fileTable);
	dojo.html.addClass(attacher,'toggled'); //switches from offering attchment tool to showing it
}

function sizeWindow( modCont ) {
	var MINHEIGHT =130;
	var MAXHEIGHT =450;
	var Y_ADJ = 50; // the height of the tinyMCE chrome
	
	var theReply = getFirstChildwithClass( modCont, 'comp-content' );
	var theReplyEditor = getFirstChildwithClass( modCont, 'comp-editor' );
	var theContent = getFirstChildwithTag( modCont, 'textarea' );
	//alert( "theContent == " +theContent);
	var contentID = theContent.id;
	//alert( 'theReply='+ theReply );
	var elemHeight = dojo.style.getInnerHeight( theReply )+Y_ADJ;
	//alert( 'elemHeight='+ elemHeight );
	var elemWidth = dojo.style.getInnerWidth( theReply );
	if( elemHeight < MINHEIGHT )
		elemHeight = MINHEIGHT;
	else if( elemHeight > MAXHEIGHT )
		elemHeight = MAXHEIGHT;
		
	theReplyEditor.style.minHeight = (elemHeight+40)+'px';
	theContent.style.height= elemHeight+'px';
	theContent.style.width= (elemWidth-2)+'px';
	
	return elemHeight;

}

function commitEdits( elem ) {
	elem = byId(elem);
	var modCont = getFirstParentwithClass( elem, 'mod' );
	var theReply = getFirstChildwithClass( modCont, 'comp-content' );
	//var elemHeight = dojo.style.getOuterHeight( theReply );
	//var theReplyEditor = getFirstChildwithClass( modCont, 'comp-editor' );
	var theContent = getFirstChildwithTag( modCont, 'textarea' );
	addEditIcon( modCont ) ;
	var contentID = theContent.id;
	closeEdit( elem );
	//alert( ' new code == "'+theContent.value+'"');
	theReply.innerHTML = theContent.value;
	if( editBtn != null )
		theReply.appendChild(editBtn);
	editBtn = null;
}

function nowTime() {
	var nowTime = new Date();
	var now_hours= nowTime.getHours();
	var now_minutes = nowTime.getMinutes();
	var now_ampm = 'am';
	if( now_hours >= 11 )
		now_ampm = 'pm';
	if( now_hours >= 12 )
		now_hours -= 12;
	return now_hours+':'+now_minutes+now_ampm;
}

function addEditIcon( modCont ) {
	var theReplyAuthor = getFirstChildwithClass( modCont, 'comp-author' );
	var tooltipper = 'This reply was edited at '+nowTime();
	var edit_icon = ' <img src="/include3/images/ic12_edit.gif" class="ic12 fitts" alt="edit icon" title="'+tooltipper+'" />';
	var childNodeCount = theReplyAuthor.childNodes.length;
	var lastNode = theReplyAuthor.childNodes[ (childNodeCount - 1 ) ];
	if( lastNode.tagName && lastNode.tagName.toLowerCase() == 'img' ) {
		//alert( 'found another img'  );
		theReplyAuthor.removeChild( lastNode );
	}
	theReplyAuthor.innerHTML += edit_icon;
}

function closeEdit( elem ) {
	elem = byId(elem);
	var modCont = getFirstParentwithClass( elem, 'mod' );
	var theContent = getFirstChildwithTag( modCont, 'textarea' );
	var contentID = theContent.id;
	
	var modCont = getFirstParentwithClass( elem, 'mod' );
	dojo.html.addClass( modCont, "rep_neutral" );
	dojo.html.removeClass( modCont, "rep_edit" );
	if( istinyMCE() )
		tinyMCE.execCommand('mceRemoveControl', false, contentID);
}

function revertEdits( elem ) {
	elem = byId(elem);
	var modCont = getFirstParentwithClass( elem, 'mod' );
	closeEdit( elem );
	flashElem_disable( modCont );
		
	/*theReply.style.display = "block";
	theReplyEditor.style.display = "none";*/
}

function validateReplyForm( theForm) {
	var authOnly = theForm.elements['author-only'].checked;
	//alert( "authOnly = "+authOnly);
	var files = theForm.elements;
	var fileLength = files.length;
	var anyFiles = false;
	for( var i=0; i< fileLength; i++ ) {
		if ( files[i].type == "file" && files[i].value != "" ) {
			//alert( 'files['+i+'].value= '+files[i].value);
			anyFiles = true;
		}
	}
	if( authOnly && anyFiles ) { // if it's reply to author only and there are files attached...
		showDialog('di_reply2author');
		return false;
	} else {
		return true;
	}
}


function toggleCheckAttacher( elem ) {
	elem = byId( elem );
	//var myMod = getFirstParentwithClass( theElem, 'mod' );
	var parentForm = getFirstParentofType( elem, 'form' );
	validateReplyForm(parentForm);
}



function showSubmitter(theFormID){ // demo submitter element
	showDialog('di_submitter');
	var timerCommand = 'realSubmitNow( "'+theFormID+'" )';
	mytimer_on_ID = setTimeout( timerCommand, 4000 ); // 4secs
}

function realSubmitNow(theForm){
	theForm = byId(theForm);
	theForm.action = theForm.elements['realaction'].value;
	theForm.submit();
}



/*****/

function commitDescripEdits( elem ) {
	elem = byId(elem);
	var modCont = getFirstParentwithClass( elem, 'mod' );
	var theReply = getFirstChildwithClass( modCont, 'comp-description' );
	//var elemHeight = dojo.style.getOuterHeight( theReply );
	//var theReplyEditor = getFirstChildwithClass( modCont, 'comp-editor' );
	var theContent = getFirstChildwithTag( modCont, 'textarea' );
	addEditIcon( modCont ) ;
	var contentID = theContent.id;
	closeEdit( elem );
	//alert( ' new code == "'+theContent.value+'"');
	theReply.innerHTML = theContent.value;
	if( editBtn != null )
		theReply.appendChild(editBtn);
	editBtn = null;
}

var editBtn = null;
function editDescription( elem ) {
	hideNav_now();
	var elem = byId(elem);
	var modCont = getFirstParentwithClass( elem, 'mod' );
	var theReply = getFirstChildwithClass( modCont, 'comp-description' );
	var ReplyContent = theReply.cloneNode(true);
	var theEditControl = getFirstChildwithClass( ReplyContent, 'editbtn' );
	if( theEditControl != null ) {
		editBtn = theEditControl.cloneNode(true);
		theEditControl.parentNode.removeChild( theEditControl);
	}
	var editControl = getFirstChildwithClass( modCont, 'noncontent' );
	var theReplyEditor = getFirstChildwithClass( modCont, 'comp-editor' );
	var theAttachments = getFirstChildwithClass( modCont, 'comp-attachments' );
	var theContent = getFirstChildwithTag( modCont, 'textarea' );
	var contentID = theContent.id;
	//dojo.html.addClass(theReply, 'testHilight');
	if ( !dojo.html.hasClass( modCont, "rep_edit" ) && dojo.html.hasClass( modCont, "rep_neutral" )) {
		//theContent.focus();
		
		theContent.value = ReplyContent.innerHTML;
		var newHeight = sizeDescriptionEditor( modCont ); 
		flashElem( modCont );
		if( istinyMCE() ) {
			tinyMCE.execCommand('mceAddControl', false, contentID);
		}
		dojo.html.addClass( modCont, "rep_edit" );
		dojo.html.removeClass( modCont, "rep_neutral" );
		//rateNeutral( elem );

	} else if ( dojo.html.hasClass( modCont, "rep_edit" ) ){
		revertEdits( elem ) 
		editBtn = null;
	} else {
		rateNeutral( elem );
	}
	
}

function sizeDescriptionEditor( modCont ) {
	var MINHEIGHT =130;
	var MAXHEIGHT =450;
	var Y_ADJ = 0; // the height of the tinyMCE chrome
	
	var theReply = getFirstChildwithClass( modCont, 'comp-description' );
	var theReplyEditor = getFirstChildwithClass( modCont, 'comp-editor' );
	var theContent = getFirstChildwithTag( modCont, 'textarea' );
	//alert( "theContent == " +theContent);
	var contentID = theContent.id;
	//alert( 'theReply='+ theReply );
	var elemHeight = dojo.style.getInnerHeight( theReply )+Y_ADJ;
	//alert( 'elemHeight='+ elemHeight );
	var elemWidth = dojo.style.getInnerWidth( theReply );
	if( elemHeight < MINHEIGHT )
		elemHeight = MINHEIGHT;
	else if( elemHeight > MAXHEIGHT )
		elemHeight = MAXHEIGHT;
		
	theReplyEditor.style.minHeight = (elemHeight)+'px';
	theContent.style.height= elemHeight+'px';
	theContent.style.width= (elemWidth)+'px';
	
	return elemHeight;

}

var theautoSaveHold = 2500;

function autosaveRepeat() {
	autosaveOn();
	setTimeout("autosaveRepeat();", (theautoSaveHold*4) );
}

function autosaveOn() {
	//autosaver = xGetElementById();
	EZwipeIn( 'autosaver');
	setTimeout("autosaveOff();", theautoSaveHold );
}

function autosaveOff() {
	//autosaver = byId();
	EZwipeOut( 'autosaver');
}



// Pop-Up Embedder Script by David Battino, www.batmosphere.com
// Version 2006-05-31 
// OK to use if this notice is included

var mediawidth=550;
var mediabgcolor="#eeeeee";
   
function BatmoAudioPop(filepath) {
   // Get Operating System 
   var isWin = navigator.userAgent.toLowerCase().indexOf("windows") !=-1
   if (isWin) { // Use MIME type = "application/x-mplayer2"
      visitorOS="Windows";
	  var mediaheight=64;
   } 
   else { // Use MIME type = "audio/mpeg"; // or audio/x-wav or audio/x-ms-wma, etc.
      visitorOS="Other";
	  var mediaheight=22;
   }

   // Get the MIME type of the audio file from its extension (for non-Windows browsers)
   var mimeType = "audio/mpeg"; // assume MP3/M3U
   var objTypeTag = "application/x-mplayer2"; // The Windows MIME type to load the WMP plug-in in Firefox, etc.
   var theExtension = filepath.substr(filepath.lastIndexOf('.')+1, 3); // truncates .aiff to aif
   if (theExtension.toLowerCase() == "wav") { mimeType = "audio/x-wav"};
   if (theExtension.toLowerCase() == "aif") { mimeType = "audio/x-aiff"};    
   if (theExtension.toLowerCase() == "wma") { mimeType = "audio/x-ms-wma"};
   if (theExtension.toLowerCase() == "mid") { mimeType = "audio/mid"};
   // Add additional MIME types as desired
   
   if (visitorOS != "Windows") { 
  		objTypeTag = mimeType; // audio/mpeg, audio/x-wav, audio/x-ms-wma, etc.};
		document.writeln("<object width='"+mediawidth+"' height='"+mediaheight+"'>");
      	document.writeln("<param name='src' value='" + filepath + "'>");
      document.writeln("<param name='type' value='" + objTypeTag + "'>");
      document.writeln("<param name='autostart' value='1'>");
      document.writeln("<param name='showcontrols' value='1'>");    
      document.writeln("<param name='showstatusbar' value='1'>");
      document.writeln("<embed src ='" + filepath + "' type='" + objTypeTag + "' autoplay='false' width='"+mediawidth+"' height='"+mediaheight+"' controller='1' showstatusbar='1' bgcolor='"+mediabgcolor+"' kioskmode='true'>");
      document.writeln("</embed></object>");
   }
}

var tocTimer;

function showTOC() {
	toggleElem('toc_head');
	dojo.lfx.wipeIn( 'toc_body', fadeOutRate ).play();
}

function hideTOC() {
	EZwipeOut('toc_body');
	toggleElem('toc_head');
}

/****/
activeFS = null;

function goFullScreen(divID){
	var elem = byId( divID );
	if (elem == null ) return false;
	dojo.html.addClass(elem, 'fullscreen');
	activeFS = elem;
	sizeFullScreener( elem );
	setScroll(0,0); // scroll to top
	document.body.style.overflow = "hidden";
	if( isIE ) {
		var viewportHeight = dojo.html.getViewportHeight();
		document.body.style.height= (viewportHeight-10)+"px";
		//document.body.style.marginBottom = "-50px";
	}
	// document.body.style.height = "99%";
	// document.body.style.paddingBottom = "10px";
	// document.body.style.padding = "0";
	// document.body.style.margin = "-5px 10px";
	// document.body.parent.scrolling = false;
	// document.body.style.overflowY = "hidden";
	// document.body.style.overflowX = "hidden";
	window.onresize = function() {
		sizeFullScreener( activeFS ); 
	}
}

function killFullScreen(divID){
	var elem = byId( divID );
	dojo.html.removeClass(elem, 'fullscreen');
	sizeNormalScreener( elem );
	document.body.style.overflow = "auto";
	if( isIE )
		document.body.style.height= "";
	window.onresize = null;
	activeFS = null;
}

function toggleFulscreen(divID){
	var elem = byId( divID );
	if (elem == null ) return false;
	var isFull = dojo.html.hasClass(elem, 'fullscreen');
	if( !isFull ) {
		goFullScreen(divID);
	} else {
		killFullScreen(divID);
	}
}

function cancelPost() {
	if( activeFS != null)
		killFullScreen(activeFS);
	else
		history.back();
}

var oldmceHeight = null;
var oldmceResize = null;


function sizeFullScreener( elem ) {
	if( elem == null || elem =="" )
		return false;
	if( activeFS == null ) 
		return false;
	var adjustment = -1;
	if( isIE )
		adjustment -= 2;
	var fs1 = getFirstChildwithClass( elem, 'fs1' );
	var fs2 = getFirstChildwithClass( elem, 'fs2' );
	var fs3 = getFirstChildwithClass( elem, 'fs3' );
	// if( fs1 == null || fs2 == null || fs3 == null  )
	if( fs2 == null || fs3 == null  )
		return false;
	var viewportHeight = dojo.html.getViewportHeight();
	elem.style.height = viewportHeight+"px";
	if( fs1 != null )
		var fs1H = dojo.style.getBorderBoxHeight(fs1);
	else 
		var fs1H = dojo.html.getAbsoluteY(fs2);
	var fs3H = dojo.style.getBorderBoxHeight(fs3);
	//alert(fs1H);
	 
	var remainderHeight= viewportHeight - (fs1H+fs3H);
	if(fs2.style.height != remainderHeight+"px" ) {
		fs2.style.height = remainderHeight+"px";
		if( isIE ) {
			fs2.style.height = (remainderHeight-10)+"px";
		}
		fs2.style.top =  fs1H+"px";
		// fs3.style.top =  (viewportHeight-fs3H)+"px";
		var mytextarea = getFirstChildwithTag( fs2, 'textarea' );
		// alert( 'istinyMCE = ' + istinyMCE());
		if( istinyMCE() ) {
			 //if tinymce is active, resize the editor
			var mymce = mytextarea;
			if( mymce != null ){
				var mceid = mymce.id;
				if( oldmceResize == null ) {	
					oldmceHeight = getMCESetting( mceid, 'height');
					//alert(oldmceHeight );
					oldmceResize = getMCESetting( mceid, 'theme_advanced_resizing');
				}
				setMCESetting( mceid, 'theme_advanced_resizing', false);
				setMCESetting( mceid, 'height', (remainderHeight+adjustment) +"px");
				//mymce.style.height= (viewportHeight - (fs1H+fs3H)) +"px";
			} 
			var main1 = dojo.html.getElementsByClass( 'main1' );
			if( main1.length > 0 )
	 			redrawMCE( mceid );
		} else {
			//else, resize the textarea

			// alert( 'mytextarea.style.height = ' + mytextarea.style.height);
			mytextarea.style.height = (remainderHeight+adjustment) +"px";
		}
	}
	return true;
}

function sizeNormalScreener( elem ) {
	elem.style.height = "";
	var fs2 = getFirstChildwithClass( elem, 'fs2' );
	if( fs2 != null ) {
		fs2.style.height = "";
		fs2.style.top = "0";
		if( istinyMCE() ) {
			var mymce = getFirstChildwithTag( fs2, 'textarea' );
			if( mymce != null ) {	
				var mceid = mymce.id;
				if( oldmceHeight != undefined  && oldmceHeight != null)	
					setMCESetting( mceid, 'height', oldmceHeight);
				setMCESetting( mceid, 'theme_advanced_resizing', oldmceResize);
				//else alert(oldmceHeight );
			}
	 		redrawMCE( mceid );
		}
	}
	oldmceHeight = null;
	oldmceResize = null;
	return true;
}

function getMCESetting( el_id, thesetting ) {
	//works
	if( istinyMCE() ) {
		return tinyMCE.settings[thesetting];
	}
}

function setMCESetting( el_id, thesetting, val ) {
	//works
	if( istinyMCE() ) {
		tinyMCE.settings[thesetting] = val;
	}
}
function redrawMCE( el_id) {
	if( istinyMCE() ) {
       // tinyMCE.execCommand('mceRepaint', true, el_id);
        tinyMCE.execCommand('mceRemoveControl', true, el_id);
        tinyMCE.execCommand('mceAddControl', true, el_id);
	}
}

/****** for sitelinks *********/
var prevMemSelection = null;

function selectInList( elem ) {
	elem = getFirstParentofType( elem, 'li' );
	dojo.html.addClass(elem, "selected");	
}

function deselectInList( elem ) {
	elem = getFirstParentofType( elem, 'li' );
	dojo.html.removeClass(elem, "selected");	
}
function selectLink( elem ) {
	elem = byId( elem );
	if( elem.type == "radio" ) {
		if( elem.checked ) {
			if( prevMemSelection != null ) {
				deselectInList( prevMemSelection );
			}
			selectInList( elem );
			prevMemSelection = elem;
			return true;
		}
	}	
}
function selectImage( elem ) {
	elem = byId( elem );
	if( elem.tagName.toLowerCase() == "a" ) {
			if( prevMemSelection != null ) {
				deselectInList( prevMemSelection );
			}
			selectInList( elem );
			prevMemSelection = elem;
			return true;
	}	
}
function selectRadio( elem ) {
	elem = byId( elem );
	if( elem.type == "radio" ) {
		elem.checked = true;
		selectLink( elem );
	}	
}
function setLinkForm( urlVal, dispVal ){
	var theField = window.parent.document.getElementById('href');
	if(theField!=null) theField.value = urlVal;
	
	var theDescript = window.parent.document.getElementById('description');
	if (theDescript !== null && theDescript.tagName === "META") {	// fix bug #287 
																	// Interestingly,
		theDescript = null;											// IE gets this element <META name="description"/> which sucks!
	}
	var theLinkName = window.parent.document.getElementById('sitelinkname');
	if( (theDescript !== null && theLinkName !== null) && theDescript.value == theLinkName.value ) { // only change the 
		theDescript.value = dispVal;
	}
	if( theLinkName!=null )theLinkName.value = dispVal;
}
function setImageForm( urlVal, idVal ){
	var theField = window.parent.document.getElementById('src_site');
	theField.value = urlVal;
	if( idVal != null ) {
		var theId = window.parent.document.getElementById('id');
		theId.value = idVal;
	}
	window.parent.showPreviewImage( urlVal); 
}

function initPickView( selectElem ) {
	var selectElem = byId( selectElem );
	var selIndex = selectElem.selectedIndex;
	var theVal =selectElem.options[selIndex].value;
	if( theVal == "search") {
		document.getElementById('searchbox').style.display = "";
		document.getElementById('links').style.display = "none";
	} 
}
function pickView( selectElem ) {
	var selectElem = byId( selectElem );
	var selIndex = selectElem.selectedIndex;
	var theVal =selectElem.options[selIndex].value;
	if( theVal == "search") {
		document.getElementById('searchbox').style.display = "";
		document.getElementById('links').style.display = "none";
	} else if( theVal!="" ) { 
		location.href = theVal;
	}
}
var progTimer = 0;
function fakeProgressBar( fakebarID, fakeTotal, hideMe, showMe ) {
	if(hideMe == null || hideMe == undefined ) {
		hideMe = '';	
	}
	if(showMe == null || showMe == undefined ) {
		showMe = '';	
	}
	//	alert( ' fakeProgressBar. elem='+fakebarID);
	fakeTotal = fakeTotal*1
	//alert(fakeTotal);
	var elem = byId( fakebarID );
	var par = elem.parentNode;
	var uploadAmount = getFirstChildwithClass( par, 'amountuploaded');
	//alert(uploadAmount);
	var theWidth = elem.style.width; /*"95%" "95px" "95pt" "95em" */
	if (theWidth =="") /* no style set */
		theWidth = 0;
	//alert( ' fakeProgressBar. theWidth='+theWidth);
	var theWidthRe = new RegExp(theWidth); /* numbers only */
	//alert( ' fakeProgressBar. theWidthRe='+theWidthRe);
	var re = /\d+/; /* numbers only */
	var numWidth = re.exec(theWidth);
	numWidth = numWidth*1;
	//alert( ' fakeProgressBar. numWidth='+numWidth);
	if( numWidth >= 100 ) {
		if( hideMe!= "" ) {
		//	alert( hideMe );
			hideElem(hideMe);
			if( showMe!= "" )
				showElem(showMe);
			elem.style.width = '0';
			uploadAmount.innerHTML = "0.0";
		}
		return true;
	} else {
		numWidth++;
		elem.style.width = (numWidth) + "%";
		uploadAmount.innerHTML = " "+(Math.floor((fakeTotal)*(numWidth/100)))+"."+(Math.floor((fakeTotal*10)*(numWidth/100))%10);
		progTimer = setTimeout("fakeProgressBar('"+fakebarID+"',"+fakeTotal+",'"+hideMe+"','"+showMe+"')", 8 );
	}
}
function fakeProgressBarF( fakebarID, fakeTotal, thefunction ) {
	if(thefunction == null || thefunction == undefined ) {
		thefunction = '';	
	}
	//	alert( ' fakeProgressBar. elem='+fakebarID);
	fakeTotal = fakeTotal*1
	//alert(fakeTotal);
	var elem = byId( fakebarID );
	var par = elem.parentNode;
	var uploadAmount = getFirstChildwithClass( par, 'amountuploaded');
	//alert(uploadAmount);
	var theWidth = elem.style.width; /*"95%" "95px" "95pt" "95em" */
	if (theWidth =="") /* no style set */
		theWidth = 0;
	//alert( ' fakeProgressBar. theWidth='+theWidth);
	var theWidthRe = new RegExp(theWidth); /* numbers only */
	//alert( ' fakeProgressBar. theWidthRe='+theWidthRe);
	var re = /\d+/; /* numbers only */
	var numWidth = re.exec(theWidth);
	numWidth = numWidth*1;
	//alert( ' fakeProgressBar. numWidth='+numWidth);
	if( numWidth >= 100 ) {
		//	alert( hideMe );
		eval(thefunction);
		elem.style.width = '0';
		uploadAmount.innerHTML = "0.0";
		return true;
	} else {
		numWidth++;
		elem.style.width = (numWidth) + "%";
		uploadAmount.innerHTML = " "+(Math.floor((fakeTotal)*(numWidth/100)))+"."+(Math.floor((fakeTotal*10)*(numWidth/100))%10);
		progTimer = setTimeout("fakeProgressBarF('"+fakebarID+"',"+fakeTotal+",'"+thefunction+"')", 8 );
	}
}

function stopProgBar( fakebarID, hideMe, showMe ) {
	clearTimeout( progTimer );
	var elem = byId( fakebarID );
	elem.style.width = '0';
	hideElem(hideMe);
	showElem(showMe);
}

function toggleComments( elemID ) {
	var elem = byId( elemID );
	var displayProp  = dojo.style.getComputedStyle( elem, 'display' );
	if( displayProp == "none" ) {
		EZwipeIn(elem);
	} else {
		EZwipeOut(elem);
	}
}		

function showComments( elemID ) {
	var elem = byId( elemID );
	EZwipeIn(elem);
}


function showSelecter( elem, popup ) {
	popup = byId(popup);
	activeFlyout = popup;
	popup.style.display = "block";
	popup.style.left = (dojo.style.getOuterWidth(elem) + dojo.html.getAbsoluteX(elem) -1)+"px";
	popup.style.top = (dojo.html.getAbsoluteY(elem) + dojo.style.getOuterHeight(elem) +dojo.html.getScrollTop() - dojo.style.getOuterHeight(popup)) +"px";
	makeClickMask(hideSelecter);
	document.onkeypress = function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		if( keycode == 0 ) { // mozilla returns '0' for non-ascii keycodes. If 0, try e.keyCode to ge the value.
			keycode = e.keyCode;
		}
		// alert( 'in Keypresser. keycode= '+keycode);
		if(keycode == KEY_ESC ){ 
			hideSelecter();
		}
		
	}
	
}


function hideSelecter( ) {
	if( activeFlyout!= null )
		activeFlyout.style.display= "none";
	activeFlyout = null;
	document.onkeypress = null;
	hideClickMask();
}

var clickMaskScreenID = "clickmask";

function makeClickMask(f) {
	var theGray = byId( clickMaskScreenID );
	//alert( " theGray== "+theGray);
	if( theGray == null ) {
		var maskDef = document.createElement("div"); // build the pagemask HTML
		maskDef.setAttribute('id', clickMaskScreenID);
		document.body.appendChild( maskDef );
		theGray = byId( clickMaskScreenID );
	}
	theGray.style.display = 'block'; 
	theGray.onclick = f;
}

function hideClickMask() {
	var theGray = byId( clickMaskScreenID );
	if( theGray == null ) 
		return false;
	theGray.style.display = "none";
	return true;
}


function makeMouseOverMask(f) {
	var theGray = byId( clickMaskScreenID );
	//alert( " theGray== "+theGray);
	if( theGray == null ) {
		var maskDef = document.createElement("div"); // build the pagemask HTML
		maskDef.setAttribute('id', clickMaskScreenID);
		document.body.appendChild( maskDef );
		theGray = byId( clickMaskScreenID );
	}
	theGray.style.display = 'block'; 
//	theGray.onmouseover = alert('mouseover!'s);
	theGray.onmouseover = function() {
		//alert('hi');
		LBDebug('mouseover MouseMask');
	 	f;
		hideClickMask();
	}
}

function resetForm(formID) {
	var theForm = byId( formID );
	if( theForm == null ) 
		return false;
	theForm.reset();		
	return true;
	
}

function countDownFromLimit(inp, countid, limit) {
	inp = byId(inp);
	var countelem = byId(countid);
	var count = inp.value.length;
	//var limit = inp.maxlength;
	//alert( "count ="+ count+" limit=" + limit );
	var diff = limit-count;
	if( diff < 0) {
		dojo.html.addClass(countelem, 'overcharlimit');
		dojo.html.removeClass(countelem, 'nearcharlimit');
		// dojo.html.addClass(inp.parentNode, 'error');
		dojo.html.addClass(inp, 'overcharlimitfield');
		countelem.innerHTML = diff;
		return false;
	} else if( diff <25 ) {
			dojo.html.addClass(countelem, 'nearcharlimit');
			// dojo.html.addClass(inp.parentNode, 'error');
			dojo.html.removeClass(countelem, 'overcharlimit');
			dojo.html.removeClass(inp, 'overcharlimitfield');
			countelem.innerHTML = diff;
			return false;
		} else {
		dojo.html.removeClass(countelem, 'nearcharlimit');
		dojo.html.removeClass(countelem, 'overcharlimit');
		dojo.html.removeClass(inp, 'overcharlimitfield');
		// dojo.html.removeClass(inp.parentNode, 'error');
		countelem.innerHTML = limit-count;
		return true;
	}
}
