﻿
/* 将产品添加到用户收藏夹中 */
function AddCollection(productId,productName)
{
    var member = Collection.GetCurrentUserId().value;
    if(member>0)
    {
        if(Collection.IsExist(member,productId).value)
        {
            alert('您已收藏了商品 '+productName+' ！');
            return;
        }
        if(Collection.Add(member,productId).value)
            alert('商品 '+productName+' 已成功添加到您的收藏夹中！');
        else
            alert('收藏商品 '+productName+' 失败，请稍候再试！');
    }
    else
    {
        alert('请您先登录本网站，再收藏您喜欢的商品');
    }
}

/* 将产品添加到购物车中 用积分购买 */
function AddCart0(productId,productName)
{
    //跳转到购物车
    ShoppingCart.Add(2,productId,productName,1);
    if(ShoppingCart.IsLogined().value==true)
        window.location.href = "/member/shoppingcart.aspx";
    else
        window.location.href = "/sale/shoppingcart.aspx";
}

/* 将产品添加到购物车中 */
function AddCart(productId,productName)
{
    //跳转到购物车
    ShoppingCart.Add(1,productId,productName,1);
    if(ShoppingCart.IsLogined().value==true)
        window.location.href = "/member/shoppingcart.aspx";
    else
        window.location.href = "/sale/shoppingcart.aspx";
}

/* 将产品添加到购物车中 记录用户选中的特性 */
function AddCate2(productId,productName,properties)
{
    var temp = "";
    for(var i=0;i<properties;i++)
    {
        var ddl = $('ctl00_Content_rptProperies2_ctl0'+i+'_ddlPropertyValues');
        if(ddl.options[ddl.selectedIndex].value!="-1")
            temp = temp + "/"  + ddl.options[ddl.selectedIndex].text;
    }
    if(temp!="")
	{
		temp = temp.substring(1,temp.length);
        temp = " <b>(" +temp + ")</b>";//<font color='red'></font>
	}
    else
        temp = "";
    var qty = $E('selectQty').options[$E('selectQty').selectedIndex].text;
    //跳转到购物车
    ShoppingCart.Add(1,productId,productName+temp,qty);
    if(ShoppingCart.IsLogined().value==true)
        window.location.href = "/member/shoppingcart.aspx";
    else
        window.location.href = "/sale/shoppingcart.aspx";
}

/* 将产品添加到购物车中 用积分购买 并 记录用户选中的特性 */
function AddCate3(productId,productName,properties)
{
    var temp = "";
    for(var i=0;i<properties;i++)
    {
        var ddl = $('ctl00_Content_rptProperies2_ctl0'+i+'_ddlPropertyValues');
        if(ddl.options[ddl.selectedIndex].value!="-1")
            temp = temp + "/" + ddl.options[ddl.selectedIndex].text;
    }
    if(temp!="")
	{
		temp = temp.substring(1,temp.length);
        temp = " <b>(" +temp + ")</b>";//<font color='red'></font>
	}
    else
        temp = "";
    var qty = $('selectQty').options[$('selectQty').selectedIndex].text;
    //跳转到购物车
    ShoppingCart.Add(2,productId,productName+temp,qty);
    if(ShoppingCart.IsLogined().value==true)
        window.location.href = "/member/shoppingcart.aspx";
    else
        window.location.href = "/sale/shoppingcart.aspx";
}

/* 搜索产品 */
function Search(event)
{
    var e;
    e = Edward.Web.FixEvent(event);
    if(e.keyCode==0 || e.keyCode==13)
    {
        var key = $('txtSearchKey').value.Trim();
        if(key=="")
        {
            alert('请输入搜索内容！');
            $('txtSearchKey').focus();
             return false;
        }
        else
        {
            window.location = "/search/result.aspx?key="+encodeURI(key);
        }
    }
}

/* 搜索产品 */
function SearchForIndex(event)
{
    var e;
    e = Edward.Web.FixEvent(event);
    if(e.keyCode==0 || e.keyCode==13)
    {
        var key = $('txtSearchKey').value.Trim();
        if(key=="")
        {
            alert('请输入搜索内容！');
            $('txtSearchKey').focus();
             return false;
       }
        else
        {
            window.location = "search/result.aspx?key="+encodeURI(key);
        }
    }
}

function ShowCate(id)
{
    $('liFCate').className="";
    $('liBCate').className="";
    $('li'+id).className="nonce";
    $('ulBCate').style.display = "none";
    $('ulFCate').style.display = "none";
    $('ul'+id).style.display="block";
}

function showUserInfo()
{
    var html = "";
    if(ShoppingCart.IsLogined().value==true)
    {
        var user = ShoppingCart.LoginedUser().value;
        html='<font color="#084093">欢迎您，<b>'+user+'</font></b> /<font color="#fe7c26">（<a class="loginlink" href="/member/logout.aspx">退出</a>）</font>&nbsp;<img src="http://img.meheme.com/icon/meb_01.gif" align="absmiddle" /> <a href="/member/index.aspx"><b>MyMeheme</b></a>';
        html+=' <img src="http://img.meheme.com/icon/buycar.gif" align="absmiddle" /> <a class="color666" href="/member/shoppingcart.aspx"><b>我的购物车</b></a> ';
    }
    else
    {
        html='<a class="loginlink" href="/member/login.aspx">会员登录</a>';
        html+=' <a class="reglink" href="/member/register.aspx">注册</a>';
        html+=' <img src="http://img.meheme.com/icon/buycar.gif" align="absmiddle" />';
        html+=' <a class="color666" href="/sale/shoppingcart.aspx"><b>我的购物车</b></a> ';
    }
    $('spanLogin').innerHTML = html;
}
