				
function callExecuted( callingFunction, useHtml )
{
	switch ( callingFunction )
	{	
		case "getCategories":
		    document.getElementById("divCategory").innerHTML = useHtml;
		    populateCategories();
            document.getElementById("viewGetProductsButton").style.display = "block";
		    break;
		case "getProducts":
		    document.getElementById("divProducts").innerHTML = useHtml;
		    break;
	    case "removeFromCart":
	        document.getElementById("leftNavPublicControl_divCart").innerHTML = useHtml;
	        break;	
	}
}

function clearDropDown( selectList )
{selectList.options.length = 0;}

function getCategories()
{
    if ( document.getElementById("divStore" + gCurrentStoreId) )
    {document.getElementById("divStore" + gCurrentStoreId).style.display = "none";}
    
    gCurrentStoreId = document.getElementById("lstStores").value;
    
    document.getElementById("viewCategory").style.display = "none";
    document.getElementById("viewSubCategory").style.display = "none";
	document.getElementById("divCategory").innerHTML = "";
    if ( gCurrentStoreId == "" )
    {document.getElementById("viewGetProductsButton").style.display = "none";}
    else
    {
	    document.getElementById("divCategory").innerHTML = "<h2 class=\"title_sm\">Loading Categories...</h2>";
        document.getElementById("divStore" + gCurrentStoreId).style.display = "block";
        gCallingFunction = "getCategories";
        postData = "action=get&dataElement=categories&storeId=" + gCurrentStoreId + "&country=" + gCurrentCountry;
        getData("/servers/integration/marketamerica.aspx", postData);
    }
}

function getProducts()
{
    document.location.href = "/shopproducts.aspx?storeId=" + gCurrentStoreId + "&categoryId=" + gCurrentCategoryId + "&subCategoryId=" + gCurrentSubCategoryId;
}

function populateCategory(categoryId)
{
    if ( document.getElementById("divCategory" + gCurrentCategoryId) )
    {document.getElementById("divCategory" + gCurrentCategoryId).style.display = "none";}
    gCurrentCategoryId = categoryId;
    document.getElementById("divCategory" + gCurrentCategoryId).style.display = "block";
}

function populateCategories()
{
    categoryDropDownList = document.getElementById("lstCategories");
    clearDropDown(categoryDropDownList);
    
    categoryIndex = 0;
    arrCategories = document.getElementById("txaCategories").value.split(":~:");
    for( i = 0; i < arrCategories.length; i++ )
    {
        arrCategory = arrCategories[i].split(":*:");
        if ( arrCategory[1] != undefined )
        {
            if ( gCurrentCategoryId == arrCategory[0] )
            {categoryIndex = i;}
            addOption(categoryDropDownList, arrCategory[0], arrCategory[1]);
        }
    }
    categoryDropDownList.options[categoryIndex].selected = true;
    arrCategory = arrCategories[categoryIndex].split(":*:");
    gCurrentCategoryId = arrCategory[0];
    populateCategory(gCurrentCategoryId);
    populateSubCategories( categoryIndex );
    document.getElementById("viewCategory").style.display = "block";
    document.getElementById("viewSubCategory").style.display = "block";    
}

function populateSubCategories( categoryIndex )
{
    subCategoryDropDownList = document.getElementById("lstSubCategories");
    clearDropDown( subCategoryDropDownList );
    
    subCategoryIndex = 0;
    arrCategories = document.getElementById("txaCategories").value.split(":~:");
    arrCategory = arrCategories[categoryIndex].split(":*:");
    arrSubCategories = arrCategory[2].split(":#:");
    for( i = 0; i < arrSubCategories.length; i++ )
    {
        arrSubCategory = arrSubCategories[i].split(":%:");
        if ( arrSubCategory[1] != undefined )
        {
            if ( gCurrentSubCategoryId == arrSubCategory[0] )
            {subCategoryIndex = i;}
            addOption(subCategoryDropDownList, arrSubCategory[0], arrSubCategory[1]);
        }
    }
    subCategoryDropDownList.options[subCategoryIndex].selected = true;
    arrSubCategory = arrSubCategories[subCategoryIndex].split(":%:");
    gCurrentSubCategoryId = arrSubCategory[0];
}

function removeFromCart( productId )
{
    gProductId = productId;
	gCallingFunction = "removeFromCart";
	postData = "action=delete&dataElement=cartProduct&productId=" + gProductId;
	getData("/servers/integration/marketamerica.aspx", postData);    
}

function setCountry(country)
{
    setOpacity(document.getElementById("imgIcon" + gCurrentCountry), 30);
    gCurrentCountry = country;
    setOpacity(document.getElementById("imgIcon" + gCurrentCountry), 100);
    getCategories();
}
