
StandardPage.prototype = ProductPage.prototype;

StandardPage.prototype.selectDetailView = StandardPage_selectDetailView;
StandardPage.prototype.detailZoom = StandardPage_detailZoom;

StandardPage.prototype.showProductColor = StandardPage_showProductColor;
StandardPage.prototype.hideProductColor = StandardPage_hideProductColor;

StandardPage.prototype.selectProductColor = StandardPage_selectProductColor;

StandardPage.prototype.sizeChange = StandardPage_sizeChange;
StandardPage.prototype.updateAvailability = StandardPage_updateAvailability;

StandardPage.prototype.addToCart = StandardPage_addToCart;

StandardPage.prototype.addToWishlist = StandardPage_addToWishlist;

StandardPage.prototype.validate = StandardPage_validate;
StandardPage.prototype.showError = StandardPage_showError;
StandardPage.prototype.hideErrors = StandardPage_hideErrors;


function StandardPage()
{
    this.setupPage();
}

function StandardPage_selectDetailView(productId, detailId)
{
    var detailImageId = detailId;
    var detail = this.getDetail(detailId);
    if(detail && detail.isFront)
    {
        var product = this.getProduct(productId);
        detailImageId = productId + product.getSliceId();
    }
    swapElements(
            this.getDetailImageId() + "Main", 
            detailImageId + "Main"
        );
    swapClass(
            this.getDetailId() + "Thumb",
            detailId + "Thumb",
            "on"
        );
    this.setDetailId(detailId);
    this.setDetailImageId(detailImageId);
}

function StandardPage_detailZoom(productId)
{
    var detail = this.getSelectedDetail();
    if(detail && detail.isFront)
    {
        var product = this.getProduct(productId);
        detail = product.getSlice();
    }
    this.zoom(detail);
}

function StandardPage_showProductColor(pid, sid)
{
    this.showDetailView(pid + sid);
}

function StandardPage_hideProductColor(pid, sid)
{
    this.hideDetailView(pid + sid);
}

function StandardPage_selectProductColor(pid, sid)
{
    var product = this.getProduct(pid);
    this.showProductColor(pid, sid);
    swapClass(
            pid + product.getSliceId() + "Thumb",
            pid + sid + "Thumb",
            "on"
        );
    swapClass(
            this.getDetailId() + "Thumb",
            "detail0Thumb",
            "on"
        );
    product.setSliceId(sid);
    this.setDetailId("detail0");
    this.setDetailImageId(pid + sid);
    product.updateSizes();
    this.updateAvailability(pid);
}

function StandardPage_sizeChange(pid)
{
    var product = this.getProduct(pid);
    product.sizeChange();
    this.updateAvailability(pid);
}

function StandardPage_updateAvailability(pid)
{
    var product = this.getProduct(pid);
    var availFlag = product.getAvailFlag();
	var shipWindow = product.getShipWindow();
    if(availFlag)
    {
        var availMsg = "In Stock";
        if(availFlag == 'IN_STOCK')
        {
            availMsg = availMsg + ", leaves warehouse in " +shipWindow;
        }
        else
        {
            availMsg = "Pre-Order";
        }
        var el = document.getElementById("product-avail-msg");
        el.innerHTML = availMsg;
        showElement("product-avail");
    }
    else
    {
        hideElement("product-avail");
    }
}

function StandardPage_addToCart()
{
    if(this.validate("cart"))
    {
        document.getElementById("productForm").submit();
    }
}

function StandardPage_addToWishlist()
{
    if(this.validate("wishlist"))
    {
        var el = document.getElementById("wlName");
        el.value = "default";
        document.getElementById("productForm").submit();
    }
}

function StandardPage_validate(source)
{
    this.hideErrors();
    for(var pid in productMap)
    {
        var prod = productMap[pid];
        if(!prod.isValid())
        {
            this.showError("error-"+source+"-size");
            return false;
        }
    }
    return true;
}

function StandardPage_showError(id)
{   
    showElement("error");
    showElement(id);
}

function StandardPage_hideErrors()
{   
    hideElement("error-cart-size");
    hideElement("error-wishlist-size");
    hideElement("error");
}
