﻿function Ajax(url)
{
	var m_xmlReq=false;
	var m_OnSucceed=function(){};
	var m_OnReading=function(){};
	var m_timer=null;

	this.Url=url;

	if(window.XMLHttpRequest)
	{
		m_xmlReq = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{ 
	   try {m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP'); }catch(e)
	   {
		  try { m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
		}
	}

	this.OnReading=function(reading)
	{
		m_OnReading=reading;
	}

	this.OnSucceed=function(succeed)
	{
		m_OnSucceed=succeed;
	}

	this.OnTimeout=function(timeout)
	{
		m_timer=window.setTimeout(timeout,10000);
	}

	this.invokeServer=function(send_data,method)
	{
		if(!m_xmlReq)  return;
		m_xmlReq.open(method,this.Url,true);
		if(method=='POST') 
		m_xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');  
		m_xmlReq.onreadystatechange=function()
		{
					if(m_xmlReq.readyState == 1)
					{
						m_OnReading();
					}
					else if(m_xmlReq.readyState == 4 && m_xmlReq.status==200)
					{
						var result=null;
						eval("result="+m_xmlReq.responseText);
						m_OnSucceed(result);
						if(m_timer!=null) window.clearTimeout(m_timer);
					}    
		}
		m_xmlReq.send(send_data.toString());
	}
}

function setFavorite(o)
{
    var setFavorite_Ajax=new Ajax("/UserCenter/ajaxurl/SetFavorite_Wish.aspx");
    setFavorite_Ajax.OnReading
    (
        function()
        {
            
        }
    );
    setFavorite_Ajax.OnSucceed
    (
	    function(result)
	    {		    
		    if(result!=null && result["errorCode"]==0 )
            {  
                alert("聚齐乐购物网提醒您：商品收藏成功！")
            }
            else
            {
                alert("您可能没有登录，或者其它原因，商品收藏失败！")     
            }
	    }
    );
	setFavorite_Ajax.OnTimeout
    (
	    function()
	    {
	        alert("网络链接超时")    
	    }
    );
	setFavorite_Ajax.invokeServer("proid="+o.toString()+"&opttype=1",'POST');	
}

function setWishList(o)
{
    var setWishList_Ajax=new Ajax("/UserCenter/ajaxurl/SetFavorite_Wish.aspx");
    setWishList_Ajax.OnReading
    (
        function()
        {
            
        }
    );
    setWishList_Ajax.OnSucceed
    (
	    function(result)
	    {		    
		    if(result!=null && result["errorCode"]==0 )
            {  
                alert("聚齐乐购物网提醒您：放入暂存架成功！")
            }
            else
            {
                alert("您可能没有登录，或者其它原因，放入暂存架失败！")     
            }
	    }
    );
	setWishList_Ajax.OnTimeout
    (
	    function()
	    {
	        alert("网络链接超时")    
	    }
    );
	setWishList_Ajax.invokeServer("proid="+o.toString()+"&opttype=2",'POST');	
}