function _g(id){return document.getElementById(id)};
function confirms(mess,url){
	if(confirm(mess))location.replace(url)
}

var xmlHttp;
function createXMLHttpRequest() {
   if (window.ActiveXObject) {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   } 
   else if (window.XMLHttpRequest) {
       xmlHttp = new XMLHttpRequest();
   }
}
function getRequestBackText( url ) {
	createXMLHttpRequest();
	var queryString = url+'&timestamp='+Math.random();
	xmlHttp.open("GET", queryString, false);
	try{
		xmlHttp.send();
	}catch( e ){
		return;
	}
	return xmlHttp.responseText;
}
function buynow(id){
	var pcount = _g("buynum").value;
	if(pcount==""){alert("请输入您要购买的数量.");return;}
	getRequestBackText("ajax.asp?act=buynow&id="+id+"&pcount="+pcount);
	location.href="cart.asp";
}
function buynow2(id){
	getRequestBackText("ajax.asp?act=buynow&id="+id+"&pcount=1");
	location.href="cart.asp";
}
function buycart(id){
	var pcount = _g("buynum").value;
	if(pcount==""){alert("请输入您要购买的数量.");return;}
	getRequestBackText("ajax.asp?act=buynow&id="+id+"&pcount="+pcount);
	confirms("商品已经加入购物车内\n\n现在进入购物车请点“确定”,继续购物请点“取消”","cart.asp");
}
function addcoll(id){
	var islogin = getRequestBackText("ajax.asp?act=checklogin");
	if(islogin==0){
		alert("请登录后再收藏本商品");
		return;
	}else{
		var isok = getRequestBackText("ajax.asp?act=addcoll&id="+id);
		if(isok==1){
			alert("收藏成功!");
		}else{
			alert("您已经收藏过该商品!");
		}
	}
}
