// BRD 2009-09-09 D00005-S00003 - Mods made to get this to work in dietrich's vault.

//	Use this function from a form submissiom
//	You can modify this function to take the form as a parameter (either id or object reference)
function showProcessingContainer(searchFormID) {
//debugger;
	var processingContainer = null;
	var positioningContainerID = null;
	if(searchFormID == "topsearchform")
	{
		processingContainer = "topProcessingContainer";
		positioningContainerID = "apDiv8";
	}
	else 
	{
		if(searchFormID == "AdvSearchForm")
		{
				processingContainer = "AdvProcessingContainer";
				positioningContainerID = "AdvPositionContainer";
		}
	}
		
	
	if (searchFormID) {
		popProcessing(positioningContainerID,processingContainer);
		//searchform.submit();
	}
	return true;
}

var processingText = "";
var processingTimer = null;

//	The positioning container is used to determine the positioning of the processing container.
//       The lower left hand corner of the positioning container is the anchor point for the processing container.
//        The left and top offsets may be used to adjust the position of the processing container.
//BRD 2009-09-11 D00005-S00002: - start
//var positioningContainerID = "headercontainer";
//var positioningContainerID = "apDiv1";
//BRD 2009-09-11 D00005-S00002: - end
var processingContainerLeftOffset = 300;
var processingContainerTopOffset = -10;

//	Use this function from an onclick event
function popProcessing(positioningContainerID,processingContainer) {
	clearProcessingTimer();
	var positioningContainer = document.getElementById(positioningContainerID);
	var processingContainer = document.getElementById(processingContainer);
	//var processingContainer = document.getElementById("processingcontainer");
	if (positioningContainer) {
		if (processingContainer) {
			var x = processingContainerLeftOffset;
			var y = processingContainerTopOffset;
			x += getElementLeft(positioningContainer);
			y += getElementBottom(positioningContainer);
			var oDocumentElement = document.documentElement;
			if (oDocumentElement) {
				x += oDocumentElement.scrollLeft;
				y += oDocumentElement.scrollTop;
			}
			processingContainer.innerHTML = processingText;
			setElementProperty(processingContainer, 'left', x + "px");
			setElementProperty(processingContainer, 'top', y + "px");
			setElementProperty(processingContainer, 'display', 'inline');
			processingTimer = window.setTimeout("updateProcessingHtml()", 1000);
		}
	}
}
function clearProcessingTimer(){
	if (processingTimer != null)
		window.clearTimeout(processingTimer);
}
function updateProcessingHtml(){
	clearProcessingTimer();
//	var processingContainer = document.getElementById("processingcontainer");
//	if (processingContainer.innerHTML == processingText + "..........")
//		processingContainer.innerHTML = processingText;
//	else
//		processingContainer.innerHTML += ".";
	processingTimer = window.setTimeout("updateProcessingHtml()", 1000);	
}

/** Return the px distance from left border of the element to left border of the window **/
function getElementLeft(p_elm) {
	var x = 0;
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	while (elm != null) {
		x+= elm.offsetLeft;
		elm = elm.offsetParent;
	}
	return parseInt(x);
}

/** Return the px width of the element **/
function getElementWidth(p_elm){
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	return parseInt(elm.offsetWidth);
}

/** Return the px distances from right border of the element to left border of window **/
function getElementRight(p_elm){
	return getElementLeft(p_elm) + getElementWidth(p_elm);
}

/** Return the px distances from top border of the element to top border of the window **/
function getElementTop(p_elm) {
	var y = 0;
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	while (elm != null) {
		y+= elm.offsetTop;
		elm = elm.offsetParent;
	}
	return parseInt(y);
}

/** Return the px heght of the element **/
function getElementHeight(p_elm){
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	return parseInt(elm.offsetHeight);
}

/** Return the px distances from bottom border of the element to border top of the window **/
function getElementBottom(p_elm){
	return getElementTop(p_elm) + getElementHeight(p_elm);
}

/** Return a style property of the elemnt , it return null if does not exist **/
function getElementProperty(p_elm, p_property){
	var elm = null;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	if (elm != null){
		if(elm.style){
			elm = elm.style;
			if(elm[p_property]){
				return elm[p_property];
			} else {
				return null;
			}
		} else {
			return null;
		}
	}
}

/** Set a property of style type of the element **/
function setElementProperty(p_elm, p_property, p_value){
	var elm = null;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	if((elm != null) && (elm.style != null)){
		elm = elm.style;
		elm[ p_property ] = p_value;
	}
}
