function GetProductToolbarArguments()
{
    var argArray = { "ProductNumbers" : GetProductNumbers(), "ProductQuantities" : GetProductQuantities() };    
    return "{jsonArgs:" + JSON.stringify(argArray) + "}"; 
}

function GetProductNumbers()
{
    alert("This method must be overridden in the Javascript of your .aspx page.   This method should return an array of strings with product numbers.");
} 

function GetProductQuantities()
{
    alert("This method must be overridden in the Javascript of your .aspx page.   This method should return an array of strings with product quantities.");
}

function ProductToolbar_Success(textResponse, validationType)
{
    // Here are the properties of objResponse:    
    //      objResponse.products[x].partNumber 
    //      objResponse.products[x].quantity 
    //      objResponse.products[x].errorMessage 
    //      objResponse.products[x].isValid 
    //      objResponse.validationStatus 
    //      objResponse.errorMessageSummary    
    //      objResponse.productCount
    //      objResponse.validProductCount
    //      objResponse.invalidProductNumberCount
    //      objResponse.invalidProductQuantityCount
    //      objResponse.redirectUrl    

    var objResponse = eval("(" + textResponse + ")");

    var winArgs = new Array();

    var settings = "titlebar=no,toolbar=no,location=no,directories=no," +
				"status=no,menubar=no,scrollbars=no," +
				"resizable=yes,width=650,height=500,modal=yes";

    var settingsFireFox = "titlebar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=530,height=550,modal=yes";
  
    
    var name = "ProductDisplay";
    switch (objResponse.validationStatus) {
    
        case "NoValid":
            alert("Price must be assigned for online purchase.  \nPlease call for price and availability.");
            break;

        case "SomeValid":
            var agree = confirm("Warning: Some products do not have a price assigned and will not be added to your " + validationType + ".  Click OK to have the valid products added to your " + validationType + ".");
            if (agree) {
          
                window.location = objResponse.redirectUrl;
//                if (objResponse.redirectUrl.indexOf("ProductDisplay.aspx") < 1)
//                    window.location = objResponse.redirectUrl;
//                else {
//                        var winArgs;
//                        if (typeof window.showModalDialog == 'object')
//                            winArgs = window.showModalDialog(objResponse.redirectUrl, '_blank', settings);
//                        else {
//                            winArgs = window.open(objResponse.redirectUrl, '_blank', settingsFireFox);
//                            winArgs.focus();
//                        }

//                        if (winArgs != null) {
//                            if (winArgs[0] == "true")
//                                window.location = "/order/cart.aspx";
//                        }
//                  
//                }
            }
            break;

        case "AllValid":
            window.location = objResponse.redirectUrl;      

//            if (objResponse.redirectUrl.indexOf("ProductDisplay.aspx") < 1)
//                window.location = objResponse.redirectUrl;
//            else {

//                var winArgs;
//                if (typeof window.showModalDialog == 'object')
//                    winArgs = window.showModalDialog(objResponse.redirectUrl, '_blank', settings);
//                else {
//                    winArgs = window.open(objResponse.redirectUrl, '_blank', settingsFireFox);
//                    winArgs.focus();
//                    }
//                    if (winArgs != null) {
//                        if (winArgs[0] == "true")
//                            window.location = "/order/cart.aspx";
//                    }
//            }
            break;
           
        case "NoneSelected":
            alert("You have no products selected.  Please selected some products and try again.");
            break;    
            
        default:
            alert("Error receiving data from the server.  Please try again.  If you continue to receive this error, please contact your Airgas Representative.");
    }
}

function popupAvail(url) {
 
    var winArgs = new Array();

    var settings = "titlebar=no,toolbar=no,location=no,directories=no," +
				"status=no,menubar=no,scrollbars=no," +
				"resizable=yes,width=650,height=500,modal=yes";

    var name = "ProductDisplay";
    if (typeof window.showModalDialog != 'undefined')
        winArgs = window.showModalDialog(url, name, settings);
    else
        var winArgs = window.open(url, name, settings);


   
    


}
function ProductToolbar_Failure(textResponse)
{
    if (textResponse == null)
    {
        textResponse = "";
    }
    alert("Error communicating with the server.  Please try again.  If you continue to receive this error, please contact your Airgas Representative.  Error message: " + textResponse);
}

function AddToTemplate_Success(textResponse)
{
    ProductToolbar_Success(textResponse, "Template");
}

function AddToTemplate()
{      
    var args = GetProductToolbarArguments();
    ProductToolbar.AddToTemplate(args, AddToTemplate_Success, ProductToolbar_Failure, this);
}

function AddToShoppingCart_Success(textResponse)
{
    ProductToolbar_Success(textResponse, "Shopping Cart");
}


function AddToShoppingCartProductDisplay() {
    var args = GetProductToolbarArguments();
    ProductToolbar.AddToShoppingCartProductDisplay(args, AddToShoppingCart_Success, ProductToolbar_Failure, this);
}

function AddToShoppingCart()
{      
    var args = GetProductToolbarArguments(); 
    ProductToolbar.AddToShoppingCart(args, AddToShoppingCart_Success, ProductToolbar_Failure, this);
}

function ValidateProducts_Success(textResponse)
{
    alert("ValidateProducts_Success");
    /// Write code here!   This is not finished yet.  --brandon 2010-02-12
}

function ValidateProducts()
{      
    var args = GetProductToolbarArguments();
    ProductToolbar.AddToShoppingCart(args, AddToShoppingCart_Success, ProductToolbar_Failure, this);
}
