function ScrollToElement(theElement){

  var selectedPosX = 0;
  var selectedPosY = 0;
              
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }                        		      
  window.scrollTo(selectedPosX,selectedPosY);
}


function URLDecode(url) //function decode URL
{
// Replace + with ' '
// Replace %xx with equivalent character
// Put [ERROR] in output if %xx is invalid.
var HEXCHARS = "0123456789ABCDEFabcdef";
var encoded = url;
var plaintext = "";
var i = 0;
while (i < encoded.length) {
var ch = encoded.charAt(i);
if (ch == "+") {
plaintext += " ";
i++;
} else if (ch == "%") {
if (i < (encoded.length-2)
&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
plaintext += unescape( encoded.substr(i,3) );
i += 3;
} else {
alert( 'Bad escape combination near ...' + encoded.substr(i) );
plaintext += "%[ERROR]";
i++;
}
} else {
plaintext += ch;
i++;
}
} // while

return plaintext;
};

  



function flashMsg(msg) {
	if (msg) {
		//scroll to the flash screen
		ScrollToElement('flash_shell');
		//put the message in the flash box (nl2br) and show it
		var flashContainer = document.getElementById('flash_container');
		msg = URLDecode(msg);
		flashContainer.innerHTML = msg.replace(/\n/g,'<br />');
		showMe('flash_shell');
	}
}

function flashClear() {
	var flashContainer = document.getElementById('flash_container');
	flashContainer.innerHTML = '';
	hideMe('flash_shell');
}




function callHeaderSubmenu (url,tabID, focusOn) {
	var submenu = document.getElementById('header_submenu_container');	
	
	//create a unique title for the submenu, based on the url & tab, so we can identify it later
	var tabTitle = tabID + "**+**" + url;
	
	//if the submenu title matches this title, then close it
	if (submenu.title==tabTitle) {
		submenu.title = '';
		headerSubmenuClear();
		
		//if tabID was provided, change the tab color to "off"
		if (tabID) {
			document.getElementById(tabID).setAttribute("class", "");
		}
		
	//otherwise, proceed
	} else {
		
		//check if the current title specifies a tab id -- if so, turn that tab id off before turning this new one on
		var tabTitle_parts = submenu.title.split("**+**");
		if (tabTitle_parts[0]) {
			document.getElementById(tabTitle_parts[0]).setAttribute("class", "");
		}
		//turn on new tab
		if (tabID) {
			document.getElementById(tabID).setAttribute("class", "submenuOn");
		}		
		//set hte new title
		submenu.title = tabTitle;
		//ajax request
		postAjax("",url,"submenuResultsVar");
		callHeaderSubmenuResults(focusOn);
	}	
}

function callHeaderSubmenuResults(focusOn) {
	if (window.submenuResultsVar) {
		headerSubmenu(window.submenuResultsVar,focusOn);
	} else {
		setTimeout("callHeaderSubmenuResults('"+focusOn+"');",200);
	}
}


function headerSubmenu(contents,focusOn) {
	//test if it's already on.  if it is, then close it
	if (contents) {
		//put the contents into the box
		var container = document.getElementById('header_submenu_contents');
		container.innerHTML = contents;
		//flashContainer.innerHTML = msg.replace(/\n/g,'<br />');
		showMe('header_submenu_container');
		//focus on the field, if requested
		if (focusOn) {
			document.getElementById(focusOn).focus();
		}
	}
}

function headerSubmenuClear() {
	hideMe('header_submenu_container');
	var container = document.getElementById('header_submenu_contents');
	container.innerHTML = '';
}