/*
 * © 2001-2005 Compuware Corporation.  All rights reserved.
 * Unpublished - rights reserved under the Copyright
 * Laws of the United States.
 *
 * U.S. GOVERNMENT RIGHTS-Use, duplication, or
 * disclosure by the U.S. Government is subject to
 * restrictions as set forth in Compuware Corporation
 * license agreement and as provided in DFARS
 * 227.7202-1(a) and 227.7202-3(a) (1995), DFARS
 * 252.227-7013(c)(1)(ii)(OCT 1988), FAR 12.212(a)
 * (1995), FAR 52.227-19, or FAR 52.227-14 (ALT III), as
 * applicable.  Compuware Corporation.
 *
 * This product contains confidential information and
 * trade secrets of Compuware Corporation.  Use,
 * disclosure, or reproduction is prohibited without the
 * prior express written permission of Compuware
 * Corporation.
 */

/**
 * Find the next element (siblings and not children) with a specific tag name
 *
 * a_elt: the element to start searching from
 * a_eltTag: the tag of the element to find
 */
function getNextElement ( a_elt,a_eltTag )
{
    var node = a_elt.nextSibling;

    while (node!=null)
    {
        if (node.nodeName.toLowerCase()==a_eltTag.toLowerCase())
        {
            return node;
        }
        else
        {
            node = node.nextSibling;
        }
    }
    return null;
}

/**
 * Find a parent element with a specific tag name
 *
 * a_elt: the element to start searching from
 * a_eltTag: the tag of the element to find
 */
function getParentElement ( a_elt,a_eltTag )
{
    var node = a_elt;

    while (node!=null)
    {
        if (node.nodeName.toLowerCase()==a_eltTag.toLowerCase())
        {
            return node;
        }
        else
        {
            node = node.parentNode;
        }
    }
    return null;
}

/**
 * Link to the value of href of the next link
 *
 * a_elt: the hyperlink that is clicked
 */
function doLink ( a_elt )
{
	var linkElt = getNextElement ( a_elt,"a" );
	if (linkElt!=null)
	{
		window.location.href = linkElt.href;
	}
}

/**
 * Set form action
 *
 * a_elt: the element that is part of the form of which the action needs to be changed
 * a_action: the new action
 */
function setFormAction ( a_elt,a_action )
{
	var form = getParentElement ( a_elt,"form" );
	if (form==null)
	{
		return;
	}

	form.action = a_action;
}
/**
 * Set form action to the value of href of the next link
 *
 * a_elt: the element that is part of the form of which the action needs to be changed
 */
function setFormLinkAction ( a_elt )
{
	var linkElt = getNextElement ( a_elt,"a" );
	if (linkElt!=null)
	{
		setFormAction ( a_elt,linkElt.href );
	}
}


/**
 * Submit the form of which the specified element is a child
 *
 * a_elt: the element that is part of the form that needs to be submitted
 */
function submitForm ( a_elt )
{
    var form = getParentElement ( a_elt,"form" );
    if (form!=null)
    {
        form.submit();
    }
}

/**
 * Cancel the form of which the specified element is a child
 *
 * a_elt: the element that is part of the form that needs to be submitted
 */
function cancelForm ( a_elt )
{
    var cancelButton = getNextElement ( a_elt,"input" );
    if (cancelButton!=null)
    {
        cancelButton.click();
    }
}
