﻿/*
 * JAM 02/27/2008 - Added getProductTabContent Function
 *
 * Function: getProductTabContent(iPackageID, oElement)
 * Parameters:
 *		iPackageID  = CES Package ID of Product Tab
 *		oElement	= HTML element that was clicked
 * Returns:
 *		void
 * Purpose:
 *		Gets Product Tab content and put the content in the productContent div
 */
function getProductTabContent(iPackageID, sTabClickedID)
{
    var oContext = new Object();
    oContext.Function = "GETPRODUCTTABCONTENT";
    oContext.PackageID = iPackageID;
    oContext.TabClickedID = sTabClickedID;
    Services.AJAX.getProductTabContent(iPackageID, OnAJAXSucceeded, OnAJAXFailed, oContext);
}

/**********************************************************************************************************************
    AJAX Return Functions
***********************************************************************************************************************/
/*
 * JAM 02/27/2008 - Added OnAJAXSucceeded Function
 *
 * Function: OnAJAXSucceeded(result, userContext, methodName)
 * Parameters:
 *		result      = Return value of ajax server call
 *		userContext	= Context object created during the calling function
 *      methodName  = Method name called
 * Returns:
 *		void
 * Purpose:
 *		Processes successful server calls for tree
 */
function OnAJAXSucceeded(result, userContext, methodName) 
{
    switch(userContext.Function.toUpperCase())
    {
        case "GETPRODUCTTABCONTENT":
            //HIDE CURRENT TAB and SHOW CLICKED TAB
            var aClicked = document.getElementById(userContext.TabClickedID);
            //Replace the class on all of the tabs
            var ulProductTabs = aClicked.parentNode.parentNode;
            for(ili = 0; ili < ulProductTabs.childNodes.length; ili++)
            {
                var li = ulProductTabs.childNodes[ili];
                if (li.nodeName.toLowerCase() == "li")
                {
                    li.className = "";
                }
            }
            //Change the class on the selected tab to selected
            aClicked.parentNode.className = "selected";            
            //Replace the HTML in the Tab Div with returned content
            document.getElementById("productDetailContent").innerHTML = result;
            break;
        default:
            break;
    }
}

/*
 * JAM 02/27/2008 - Added OnAJAXFailed Function
 *
 * Function: OnAJAXFailed(error, userContext, methodName)
 * Parameters:
 *		error       = error message of ajax server call
 *		userContext	= Context object created during the calling function
 *      methodName  = Method name called
 * Returns:
 *		void
 * Purpose:
 *		Processes failed server calls for tree
 */
function OnAJAXFailed(error, userContext, methodName) 
{
    var sMessage = "";
    switch(userContext.Function.toUpperCase())
    {
        case "GETPRODUCTTABCONTENT":
            sMessage = "Error retrieving tab content.";
            break;
        default:
            break;
    }
    
    alert(sMessage);    
}