/**
 * Microsoft's IE has a very obnoxious "feature" that makes SELECT boxes
 * ignore zIndex settings and therefore float above all other elements. This
 * is problematic for popups (i.e. Menus/Calendars) because they  will float
 * behind these elements. IE does however allow IFRAME elements to hover above
 * these windowed elements. This method tricks IE into displaying the popups
 * correctly. It does so by creating a "shield" iframe immediately below the
 * popup element that will obscure the underlying SELECT boxes. The shield is
 * owned by the object and therefore when the popup is made invisible the
 * shield is as well.
 *
 * @param obj The object to create the shield behind
 */
function shieldPopup(obj)
{
	// Short circuit if not necessary
	if (!document.all)
        return;
	else
		shieldIt(obj);
}

function shieldIt(obj)
{
	// Embed a IFRAME inside the object
	var name = obj.id + "Shield";

	// Verify that shield has not previously been created
	var iFrame = document.getElementById(name);
	if (iFrame == null)
	{
		iFrame = document.createElement("IFRAME");
		iFrame.id = name;
		iFrame.style.position = "absolute";
		iFrame.style.visibility = "inherit";
		iFrame.style.zIndex = obj.style.zIndex - 2;
		iFrame.style.margin = -1;
		iFrame.scrolling = "no";
		iFrame.frameBorder = 0;

		// in order to prevent errors in https
		// we need to point iframe to a page
		// and this page must exist.
		iFrame.src = "javascript:''";

		// Set zIndex just below parent
		iFrame.style.zIndex = obj.style.zIndex - 1;

		// Position at top left of parent
		iFrame.style.top = "0px";
		iFrame.style.left = "0px";

		// Size iFrame to match parent's size
		iFrame.style.width = obj.offsetWidth;
		iFrame.style.height = obj.offsetHeight;

		// Append to object
		obj.appendChild(iFrame);
	}
	// If frame already exists - make certain position is correct
	else
	{
            // Set zIndex just below parent
            iFrame.style.zIndex = obj.style.zIndex - 1;

            // Position at top left of parent
            iFrame.style.top = "0px";
            iFrame.style.left = "0px";

            // Size iFrame to match parent's size
            iFrame.style.width = obj.offsetWidth;
            iFrame.style.height = obj.offsetHeight;
	}
}

function ShuttleRight(all, elementID)
{
    var available = document.getElementById(elementID + "Available");
    var selected = document.getElementById(elementID);

    for (var i=available.options.length-1;i>=0;i--)
    {
        if (all || available.options[i].selected)
        {
            available.options[i].selected = false;
            selected.appendChild(available.options[i]);
        }
    }
}

function ShuttleLeft(all, elementID)
{
    var available = document.getElementById(elementID + "Available");
    var selected = document.getElementById(elementID);

    for (var i=selected.options.length-1;i>=0;i--)
    {
        if (all || selected.options[i].selected)
        {
            selected.options[i].selected = false;
            available.appendChild(selected.options[i]);
        }
    }
}

 function onPageSizeChange(size)
 {
 	var href = window.location.href;
 	param = "psNew=" + size;
 	
	if (href.indexOf("psNew=") > -1){
	 		href = href.replace(/psNew=\d*/, param);
	 		param = "";
	}
	else if (href.indexOf("?") > -1)
		param = "&" + param;			
	else
		param = "?" + param;
	
    document.location.href = href + param;
 }
 
 /**
 * This method functions as a base method for validating a form. The user
 * must supply the onSuccess evaluation mentod in order to deal with th results of 
 * validation.
 * input frm - the form being submitted.
 */
 function baseFormValidate(frm)
 {
 	var url = frm.action;

	if (window.beforeValidate)
		beforeValidate();

	var e = $(frm).serialize();
	frm.validateForm.value = true;
	new Ajax.Request(url, {parameters: e, 
		onSuccess: function(t) {
			if (!window.validationResponse)
			{
		    	alert("The calling page must implement the java script function \n" +
		    		"validationResponse(response) in order to continue.\n"
		    		+ "This function is responsible for handling the form validation messages or submitting the "
		    		+ "form itself on success.");
			}
			else
			{
				validationResponse(t);
			}
		}, 
		onFailure:function(t) {
	    alert('Error ' + t.status + ' -- ' + t.statusText);}
	    });
	
	return false;
}