﻿// JScript File

nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
function nereidFade(object, destOp, rate, delta){
if (!document.all)
return
    if (object != "[object]"){  //do this so I can take a string too
        setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
        return;
    }
    clearTimeout(nereidFadeTimers[object.sourceIndex]);
    diff = destOp-object.filters.alpha.opacity;
    direction = 1;
    if (object.filters.alpha.opacity > destOp){
        direction = -1;
    }
    delta=Math.min(direction*diff,delta);
    object.filters.alpha.opacity+=direction*delta;
    if (object.filters.alpha.opacity != destOp){
        nereidFadeObjects[object.sourceIndex]=object;
        nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
    }
}


function setVisible(divID)
{
  
var allDivs = document.getElementsByTagName("div");
var len = allDivs.length;
for(var i = 1; i < allDivs.length; i++)
{
    var objDiv = document.getElementById("Menu"+i);
    if (objDiv!=null)
       objDiv.style.display = "none";
}
    var objDiv = document.getElementById(divID);
    if (objDiv.style.display == "none")
        objDiv.style.display = "block";
    else
        objDiv.style.display = "none";
}

function changeStyleMainItem(obj, flag)
{
    if (flag == 0)
        obj.style.backgroundColor = "#D0CEC7";
    else
        obj.style.backgroundColor = "#F7F6F2";
}

function changeStyleSubItem(obj, flag)
{
    if (flag == 0)
        obj.style.backgroundColor = "#F3F2EE";
    else
        obj.style.backgroundColor = "#F9F8F4";
}

function getProductListInSubCatalog(subCatalogID)
{
    document.getElementById("colProduct").style.visibility = "hidden";
    document.getElementById("layerLoading").style.visibility = "visible";
    Anthem_InvokePageMethod("GetProductListInSubCatalog", [subCatalogID, 0], getProductListInSubCatalog_Callback);
    window.location.replace("default.aspx#TOP");
}

function getProductListInSubCatalog_Callback(result)
{
 

    document.getElementById("layerLoading").style.visibility = "hidden";
    document.getElementById("colProduct").style.visibility = "visible";



}

function searchProducts()
{
    document.getElementById("colProduct").style.visibility = "hidden";
    document.getElementById("layerLoading").style.visibility = "visible";
    Anthem_InvokePageMethod("SearchProducts", null, searchProducts_Callback);
}


function searchProducts_Callback(result)
{
    document.getElementById("layerLoading").style.visibility = "hidden";
    document.getElementById("colProduct").style.visibility = "visible";
}

function addToCart(productID)
{
    Anthem_InvokePageMethod("AddToCart", [productID], null);
    alert("This product is added to your shopping cart.");
}

function redirectProductList(subCatalogID)
{
    window.location = "Default.aspx?flag=0&subid=" + subCatalogID;
}

function redirectSearch()
{
    var text = document.getElementById("txtSearch").value;
    var allwords = document.getElementById("chkSearch").checked;
    
    window.location = "Default.aspx?flag=1&text=" + text + "&allwords=" + allwords;
}

function buyProduct(productID)
{
    var quantity = document.getElementById("txtQuantity").value;
    if (isNaN(quantity) == true)
        alert("Please input Quantity correctly.");
    else
    {
        Anthem_InvokePageMethod("BuyProduct", [productID, quantity], null);
        alert("This product is added to your shopping cart.");
    }
}

function buyProductV2(productID)
{
    Anthem_InvokePageMethod("BuyProduct", [productID, 1], null);
    alert("This product is added to your shopping cart.");
}

function getService(flag)
{
    document.getElementById("colContent").style.visibility = "hidden";
    document.getElementById("colFeedback").style.visibility = "hidden";    
    document.getElementById("layerLoading").style.visibility = "visible";
    
    Anthem_InvokePageMethod("GetService", [flag], getService_Callback);
}

function getService_Callback(result)
{
    document.getElementById("layerLoading").style.visibility = "hidden";
    document.getElementById("colContent").style.visibility = "visible";
    document.getElementById("colFeedback").style.visibility = "visible";
}

function validateEmail(email)
{
    var reEx = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (email.match(reEx))
        return true;
    return false;
}

function redirect(link)
{
    window.location = link;
}

function getProductDetail(productID)
{
    Anthem_InvokePageMethod("GetProductDetail", [productID], null);
    window.location.replace("ProductDetail.aspx?id="+productID+"#TOP");
}

function shoppingCartAddProduct(productID)
{
    Anthem_InvokePageMethod("ShoppingCartAddProduct", [productID], null);
    alert("This product is added to your shopping cart.");
}

function downloadPriceList(fileName)
{
    if (fileName == "")
        alert("No price list available.");
    else
        window.location = "Download/" + fileName;
}
