
ProductForm.prototype.getSliceHandler = ProductForm_getSliceHandler;
ProductForm.prototype.getLayoutHandler = ProductForm_getLayoutHandler;
ProductForm.prototype.addToCart = ProductForm_addToCart;
ProductForm.prototype.loadAvailMsg = ProductForm_loadAvailMsg;
ProductForm.prototype.addToWishList = ProductForm_addToWishList;
ProductForm.prototype.setSkuId = ProductForm_setSkuId;
ProductForm.prototype.findMatchingSku = ProductForm_findMatchingSku;
ProductForm.prototype.showEnhanced = ProductForm_showEnhanced;
ProductForm.prototype.emailAFriend = ProductForm_emailAFriend;
ProductForm.prototype.printView = ProductForm_printView;
ProductForm.prototype.moreDetails = ProductForm_moreDetails;
ProductForm.prototype.filterSlices = ProductForm_filterSlices;
ProductForm.prototype.submitForm = ProductForm_submitForm;
ProductForm.prototype.setWishListName = ProductForm_setWishListName;
ProductForm.prototype.setWishListAction = ProductForm_setWishListAction;
ProductForm.prototype.validate = ProductForm_validate;

function ProductForm()
{
    this.sliceHandler = null;
    this.layoutHandler = null;
}

function ProductForm_getSliceHandler()
{
    if(this.sliceHandler == null)
    {
        this.sliceHandler = new SliceHandler();
    }
    return this.sliceHandler;
}

function ProductForm_getLayoutHandler()
{
    if(this.layoutHandler == null)
    {
        this.layoutHandler = new LayoutHandler();
    }
    return this.layoutHandler;
}

function ProductForm_addToCart()
{
    var sku = this.findMatchingSku();
    if(sku != null)
    {
        if(this.getLayoutHandler().validate())
        {
            hideErrorMessage();
            this.setSkuId(sku);
            this.submitForm();
        }
    }
}
function ProductForm_loadAvailMsg()
{
	var sh = this.getSliceHandler();
	sh.filterSlices();
}

function ProductForm_addToWishList()
{
    var sku = this.findMatchingSku();
    if(sku != null)
    {
        if(this.getLayoutHandler().validate())
        {
            this.setSkuId(sku);
            this.setWishListName("default");
            this.setWishListAction("Add");
            this.submitForm();
        }
    }
}

function ProductForm_setSkuId(skuId)
{
    var el = document.getElementById("skuId");
    el.value = skuId;
}

function ProductForm_findMatchingSku()
{
    var sh = this.getSliceHandler();
    sh.clearErrors();
    var sku = null;
    if(sh)
    {
        if(sh.validate())
        {
            sku = sh.getSku();
            if(sku == null)
            {
                alert("An available product does not match your current selections!");
            }
        }
    }
    return sku;
}

function ProductForm_showEnhanced(pid)
{
    window.open("zoom/index.jsp?productId=" + pid, "zoom", "width=835,height=871,top=0,left=0,resizable=yes,scrollbars=yes");
}

function ProductForm_emailAFriend(url)
{
    window.open(url, "email_a_friend", "width=480,height=598,top=0,left=0,resizable=no,scrollbars=yes");
}

function ProductForm_printView(url, w, h)
{
    if (!w) w = 600;
    if (!h) h = 700;
    window.open(url, "print", "width=" + w + ",height=" + h + ",top=0,left=0,resizable=no,scrollbars=yes");
}

function ProductForm_moreDetails(url)
{
    window.open(url, "more_details", "width=480,height=482,top=0,left=0,resizable=no,scrollbars=no");
}

function ProductForm_filterSlices(pid, sliceId)
{
    this.getSliceHandler().filterSlices(pid, sliceId);
}

function ProductForm_submitForm()
{
    var el = document.getElementById("productForm");
    if(this.validate())
	el.submit();
}

function ProductForm_setWishListName(name)
{
    var el = document.getElementById("wlName");
    el.value = name;
}

function ProductForm_setWishListAction(sa)
{
    var el = document.getElementById("wlAction");
    el.value = sa;
}

function ProductForm_validate()
{
var el = document.getElementById("qty_0");
    if(el)
    {
        var errorElementId = "qty_0_Error";
        if(el.value > 999)
        {
            showErrorMessage("Please complete the selections marked below.");
            showElement(errorElementId);
            return false;
        }
    }
    return true;

}
