﻿var process_request = '正在处理您的请求…';
jQuery.noConflict();
/**
 * 添加商品到收藏夹
 */
function collect(goodsId) {
    jQuery.ajax({
        type: "GET",
        url: "assistant/flow.ashx?Act=collect&ID=" + goodsId,
        success: function(data, textStatus) {
        alert(data);
        }
    });
}

/**
 * 添加商品到购物车
 */
function addToCart(goodsId, isOneStep, spec) {
    var num = Math.round(Math.random() * 10000);
    jQuery.ajax({
    type: "post",
        url: "assistant/flow.ashx?Act=add_to_cart&ID=" + goodsId + "&IsOneStep=" + isOneStep+"&Spec="+escape(spec)+"&a="+num,
        success: function(data, textStatus) {
            addToCartResponse(data);
        },
        dataType: "json"
    });
}

/* *
 * 处理添加商品到购物车的反馈信息
 */
function addToCartResponse(result) 
{
  if (result.error > 0)
  {
    // 如果需要缺货登记，跳转
    if (result.error == 2)
    {
        if (confirm(result.message))
        {
            location.href = 'userbooking.aspx?act=add&id=' + result.goods_id;
        }
    }
    else
    {
        alert(result.message);
    }
  }
  else
  {
    var cart_url = 'flow.aspx';

    if (result.one_step_buy == '1')
    {
      location.href = cart_url;
    }
    else
    {
      switch(result.confirm_type)
      {
        case '1' :
          if (confirm(result.message)) location.href = cart_url;
          break;
        case '2' :
          if (!confirm(result.message)) location.href = cart_url;
          break;
        case '3' :
          location.href = cart_url;
          break;
        default :
          break;
      }
    }
}
}

/*******************************************************************************************************/

// 添加积分商品到购物车
function addExchangeGoodsToCart(goodsID, userID)
{
    if (userID >0)
    {
        Ajax.call('Assistant/Flow.ashx?Act=add_exchangegoods_to_cart', 'ID=' + goodsID, addExchangeGoodsToCartResponse, 'POST', 'JSON');
    }
    else
    {
        alert('对不起，您没有登录，不能参加兑换，请您先登录！');
    }
}

function addExchangeGoodsToCartResponse(result)
{
    if (result.error == 0)
    {
          location.href = "flow.aspx?step=consignee";
    }
    else
    {
        alert(result.message);
    }
}

/*******************************************************************************************************/

function getNewsClick(newsid)
{
     jQuery.ajax({
            type:"get",
            url:"assistant/flow.ashx?act=click&newsid=" + newsid,
            success:function(result, textStatus){
                document.getElementById("span_news_clicks").innerHTML = result;
            },
		    dataType:"html"
    });
}

/*******************************************************************************************************/

function getCartGoodsNum()
{
         jQuery.ajax({
                type:"get",
                url:"assistant/flow.ashx?act=get_cart_goods_num",
                success:function(result, textStatus){
                    document.getElementById("spanCartGoodsNum").innerHTML = result;
                },
		        dataType:"html"
        });
   
}

function getCartGoodsNumResponse(result)
{
    document.getElementById("spanCartGoodsNum").innerHTML = result;
}

/*******************************************************************************************************/

function changeTab(currIndex, count, tabname, conname, overcss, outcss)
{
    for (var i=1; i<=count; i++)
    {
        if (currIndex == i)
        {
            document.getElementById(tabname+i).className = overcss;
            document.getElementById(conname+i).style.display="";
        }
        else
        {
            document.getElementById(tabname+i).className = outcss;
            document.getElementById(conname+i).style.display="none";
        }
    }
}

/**
*复制代码
*/
function copyData(text){
var clipBoardContent,clip,trans,str,len,str,copytext,clipid;
clipBoardContent = text;
if(window.clipboardData){
   window.clipboardData.clearData();
   window.clipboardData.setData("Text", clipBoardContent);
}
else if(navigator.userAgent.indexOf("Opera") != -1){
   window.location = clipBoardContent;
}
else if (window.netscape){
   try{
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   }catch (e){
    alert("您的当前浏览器设置已关闭此功能！请按以下步骤开启此功能！\n新开一个浏览器，在浏览器地址栏输入'about:config'并回车。\n然后找到'signed.applets.codebase_principal_support'项，双击后设置为'true'。\n声明：本功能不会危极您计算机或数据的安全！");
   }
   clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   trans.addDataFlavor('text/unicode');
   str = new Object();
   len = new Object();
   str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
   copytext = clipBoardContent;
   str.data = copytext;
   trans.setTransferData("text/unicode",str,copytext.length*2);
   clipid = Components.interfaces.nsIClipboard;
   if (!clip) return false;
   clip.setData(trans,null,clipid.kGlobalClipboard);
}
return true;
}

