var http_request = false;
function send_request(url)
{//初始化、指定处理函数、发送请求的函数
	http_request = false;
	//开始初始化XMLHttpRequest对象
	if(window.XMLHttpRequest) { //Mozilla 浏览器
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {//设置MiME类别
			http_request.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) { // IE浏览器
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) { // 异常，创建对象实例失败
		//window.alert("不能创建XMLHttpRequest对象实例.");
		window.alert("您所请求的页面异常。");
		return false;
	}
	http_request.onreadystatechange = processRequest;
	// 确定发送请求的方式和URL以及是否同步执行下段代码
	http_request.open("GET", url, true);
	http_request.send(null);
}
// 处理返回信息的函数
function processRequest()
{
	if (http_request.readyState == 4) { // 判断对象状态
           if (http_request.status == 200) { // 信息已经成功返回，开始处理信息
               //alert(http_request.responseText);
			   var tmp = http_request.responseText;
			   if (fucCheckNUM(tmp)==1)
			   {
				  alert("订阅成功!");
				  return false;
			   }
			   alert(tmp);
			   /*
			   if (tmp=="already")
			   {
				   alert("已经收藏!");
				   return false;
			   }
			   else if(tmp=="ok")
			   {
				   alert("收藏成功!");
				   return false;
			   }
			   else
			   {  
				   alert("服务器忙,请稍后...!");
				   return false;
			   }
			   */
           } else { //页面不正常
               alert("服务器忙,请稍后...!");
           }
       }
}
/////////////////////////////////////////
//我要收藏
function detailFavorite(parm_to_paste)
{
	var i = parm_to_paste.indexOf("=");
	var magID = parm_to_paste.substring(i+1 );
	if (GetCookie("xplus_inst")==null)
	{
		window.location="http://www.xplus.com.cn/inc/download_note.php";	
	}
	else
	{
		if ((GetCookie("c_userid")==null)||(GetCookie("c_pwd")==null))
		{
			window.location="http://www.xplus.com.cn/inc/download_note.php";
		}
		else
		{
			//alert(GetCookie("userid"));
			//window.location="http://www.xplus.com.cn/inc/subscribe_xin.php?uid="+GetCookie("c_userid")+"&pwd="+GetCookie("c_pwd")+"&magID="+magID;
			var subURL = "http://www.xplus.com.cn/inc/favorite.php?userid="+GetCookie("c_userid")+"&pwd="+GetCookie("c_pwd")+"&magid="+magID;
			//alert(subURL);
			send_request(subURL);
		}
	}
	return false;		//this prevent link runs
}

//我要订阅
function detailSub(parm_to_paste)
{
	var i = parm_to_paste.indexOf("=");
	var magID = parm_to_paste.substring(i+1 );
	
	try
	{
      var xplus_Obj40 = new ActiveXObject("XplusAgent.XplusActiveX.1");
      var userinfo=xplus_Obj40.UserInfo;
	  //alert(userinfo);
	  user_arr=userinfo.split(" ");
	  //alert(user_arr.length);
	  //alert(user_arr[0]);
	  //alert(user_arr[1]);
	  //alert(user_arr[2]);
	  if(user_arr[0]!="" && user_arr[2]=="3")
	   {
	     //alert("y");
	     send_request("../www/sub_xin.php?magid="+magID+"&userid="+user_arr[0]);
	   }
	   else
	   {
		     alert("请先启动客户端");
		     //window.location="http://www.xplus.com";
		      //window.location="../inc/download_note.php";
	   }
	}
	catch(e)
	  {
	    if ((GetCookie("c_userid")==null)||(GetCookie("c_pwd")==null))
   	     {
		   //alert("2");
		   window.location="http://www.xplus.com.cn/inc/download_note.php";
	     }
	    else
	     {
		//订阅电子杂志/每本
		     send_request("../www/sub_xin.php?magid="+magID+"&userid="+GetCookie("c_userid"));
	     }
	  }
		
	
	return false;		//this prevent link runs
}




function GetCookie (name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	
	while(i < clen)
	{
		var j = i + alen;
		
		if (document.cookie.substring(i, j) == arg)
		{
			return getCookieVal (j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
		{
			break;
		}
	}
	return null;
}


function SetCookie (name, value)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;

	var expires = (argc > 2) ? argv[2] : null;

	var path = "/";
	//var domain = ".xplus.com.cn";
	var domain = ".xplus.com";
	var secure = false;
	
	document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function getCookieVal (offset)
{
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1)
        {
                endstr = document.cookie.length;
        }
        return unescape(document.cookie.substring(offset, endstr));
}
function fucCheckNUM(NUM)
{
 var i,j,strTemp;
 strTemp="0123456789";
 if ( NUM.length== 0)
  return 0
 for (i=0;i<NUM.length;i++)
 {
  j=strTemp.indexOf(NUM.charAt(i)); 
  if (j==-1)
  {
  //说明有字符不是数字
   return 0;
  }
 }
 //说明是数字
 return 1;
}
