function hideLoadingIndicator()
{
	if (document.getElementById ('loadingIndicator') != null)
	{
		changeClass ('loadingIndicator', 'hide');
	}
	if (document.getElementById ('loadingIndicator2') != null)
	{
		changeClass ('loadingIndicator2', 'show');
	}
}

function showLoadingIndicator ()
{
	if (document.getElementById ('loadingIndicator') != null)
	{
		changeClass ('loadingIndicator', 'show');
	}
	if (document.getElementById ('loadingIndicator2') != null)
	{
		changeClass ('loadingIndicator2', 'hide');
	}
}

 
function loadPage(page, idIn, runAfter)
{
	showLoadingIndicator ();
	AjaxRequest.get({
		'url':page
		,'onSuccess':function(req){ if (idIn != null) document.getElementById(idIn).innerHTML = req.responseText; if (runAfter != null) eval (runAfter); hideLoadingIndicator (); return req.responseText; }
		,'onError':function(req){ showErrorMessage(req.responseText); hideLoadingIndicator (); }
  	});
}


function evalPage(page, runAfter)
{
	showLoadingIndicator ();
	AjaxRequest.get({
		'url':page
		,'onSuccess':function(req){ eval(req.responseText); if (runAfter != null) eval (runAfter); hideLoadingIndicator (); return req.responseText; }
		,'onError':function(req){ alert(req.responseText);  hideLoadingIndicator (); }
  	});
}


function getFormWithSessionBind(sessionBind)
{
	var forms = document.getElementsByTagName('form');
	for(i = 0;i < forms.length; i++)
	{
		var formSessionBind = forms[i].getAttribute ('session-bind');
		if (formSessionBind != null)
		{
			if (formSessionBind == sessionBind)
			{
				return forms[i];
			}
		}
	}
}

function setFocus ()
{
	var inputs = document.getElementsByTagName('input');
	for(i = 0;i < inputs.length; i++)
	{
		var focusAttribute = inputs[i].getAttribute ('setfocushere');
		if (focusAttribute != null)
		{

			// This line is added as a fix to an IE bug. Do not remove.
			inputs[i].onFocus = inputs[i].setActive();
			
			inputs[i].focus();			
			break;
		}
	}
}

function setFieldClassName (sessionBind, fieldName, className)
{
	var form = getFormWithSessionBind (sessionBind);
	if (form != null)
	{
		var field = form.elements[fieldName];
		if (field != null)
		{
			field.className = className;
		}
	}
}

function setFieldValue (sessionBind, fieldName, value)
{
	var forms = document.getElementsByTagName ('form');
	for(i = 0; i < forms.length; i++)
	{
		var formSessionBind = forms[i].getAttribute ('session-bind');
		if (formSessionBind != null)
		{
			if (formSessionBind == sessionBind)
			{
				var field = forms[i].elements[fieldName];
				if (field != null)
				{
					field.value = value;
				}
			}
		}
	}
}

function disableField (sessionBind, fieldName)
{
	var forms = document.getElementsByTagName ('form');
	for(i = 0; i < forms.length; i++)
	{
		var formSessionBind = forms[i].getAttribute ('session-bind');
		if (formSessionBind != null)
		{
			if (formSessionBind == sessionBind)
			{
				var field = forms[i].elements[fieldName];
				if (field != null)
				{
					field.disabled = true;
				}
			}
		}
	}
}

function enableField (sessionBind, fieldName)
{
	var forms = document.getElementsByTagName ('form');
	for(i = 0; i < forms.length; i++)
	{
		var formSessionBind = forms[i].getAttribute ('session-bind');
		if (formSessionBind != null)
		{
			if (formSessionBind == sessionBind)
			{
				var field = forms[i].elements[fieldName];
				if (field != null)
				{
					field.disabled = false;
				}
			}
		}
	}
}

function showErrorMessage (error)
{
	var errorMessage = document.getElementById ("errorMessage");
	if (errorMessage != null)
	{
		errorMessage.innerHTML = error;
	}
	var errorMessageBox = document.getElementById ("errorMessageBox");
	if (errorMessageBox != null)
	{
		errorMessageBox.className = "show";
	}
}

function closeErrorMessage()
{
	var errorMessage = document.getElementById ("errorMessage");
	if (errorMessage != null)
	{
		errorMessage.innerHTML = "";
	}
	var errorMessageBox = document.getElementById ("errorMessageBox");
	if (errorMessageBox != null)
	{
		errorMessageBox.className = "hide";
	}
}

function showAjaxBox (url)
{
	Element.hide('ajaxBox');
	loadPage(url, 'ajaxBox', null);
	setWindowSize();
	setScroll();
	var messageTable = null;
	var ajaxBox = window.parent.document.getElementById("ajaxBox");
	if (ajaxBox != null) {
		var tables = ajaxBox.getElementsByTagName("table");
		if (tables != null) {
			messageTable = tables[0];
		}
	}
	var boxWidth = window.parent.document.getElementById("ajaxBox").style.width;
	var boxHeight = window.parent.document.getElementById("ajaxBox").style.height;
	var middleWidth = (myWidth / 2) - (boxWidth.substring(0, boxWidth.length - 2) / 2) + scrOfX;
	var middleHeight = (myHeight / 2) - (boxHeight.substring(0, boxHeight.length - 2) / 2) + scrOfY;

	if (messageTable != null) {
		if (messageTable.width && messageTable.width.indexOf("%") == -1) {
			boxWidth = messageTable.width;
			middleWidth = (myWidth / 2) - (boxWidth.substring(0, boxWidth - 2) / 2) + scrOfX;
		}
		if (messageTable.height && messageTable.height.indexOf("%") == -1) {
			boxHeight = messageTable.height;
			middleHeight = (myHeight / 2) - (boxHeight.substring(0, boxHeight - 2) / 2) + scrOfY;
		}
	}
	window.parent.document.getElementById("ajaxDimmer").style.width = "100%";
	window.parent.document.getElementById("ajaxDimmer").style.height = myHeight + scrOfY;
	window.parent.document.getElementById("ajaxDimmer").className = 'opacity65';
	window.parent.document.getElementById("ajaxBox").style.left = middleWidth;
	window.parent.document.getElementById("ajaxBox").style.top = middleHeight - 100;
	Effect.Appear('ajaxBox');
}

function hide (id)
{
  var element = window.parent.document.getElementById (id);
  if (element != null)
  {
    element.className = 'hide';
  }
}

function show (id)
{
  var element = window.parent.document.getElementById (id);
  if (element != null)
  {
    element.className = 'show';
  }
}

function dim (id)
{
  var element = window.parent.document.getElementById (id);
  if (element != null)
  {
    element.className = 'hide';
  }
}

function unDim (id)
{
  var element = window.parent.document.getElementById (id);
  if (element != null)
  {
    element.className = 'show';
  }
}

function closeAjaxBox()
{
	Element.hide('ajaxBox');
	window.parent.document.getElementById("ajaxDimmer").className = 'hide';
}


var myHeight = 0, myWidth = 0;
function setWindowSize() {
  myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( window.parent.document.documentElement &&
      ( window.parent.document.documentElement.clientWidth || window.parent.document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = window.parent.document.documentElement.clientWidth;
    myHeight = window.parent.document.documentElement.clientHeight;
  } else if( window.parent.document.body && ( window.parent.document.body.clientWidth || window.parent.document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = window.parent.document.body.clientWidth;
    myHeight = window.parent.document.body.clientHeight;
  }
}

var scrOfX = 0, scrOfY = 0;
function setScroll() {
  scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( window.parent.document.body && ( window.parent.document.body.scrollLeft || window.parent.document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = window.parent.document.body.scrollTop;
    scrOfX = window.parent.document.body.scrollLeft;
  } else if( window.parent.document.documentElement &&
      ( window.parent.document.documentElement.scrollLeft || window.parent.document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = window.parent.document.documentElement.scrollTop;
    scrOfX = window.parent.document.documentElement.scrollLeft;
  }
}












