﻿function initxmlhttp() {
	var xmlhttp;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefiend') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

// 收藏
function shoucang(pid) {
	xmlhttp = initxmlhttp();
	var url = 'isonline.aspx';
	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var ss= xmlhttp.responseText;				
		if(ss!=""){
		favorite(pid);		
		}else{
		 alert('请登录');
		}
	 }		
	}
	xmlhttp.send(null);
}
//先判断 库存是否为空
function isonline(id) {
	xmlhttp = initxmlhttp();
	var url = 'kucun.aspx?pid=' +id;
	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var ss= xmlhttp.responseText;		
			if(ss== 0){
			alert('该商品库存不足，请稍后再购！');
			}else
			{
			isonline2(id);
			}
		}		
	}
	xmlhttp.send(null);
}
// 添加到购物车
function isonline2(id) {
	xmlhttp = initxmlhttp();
	var url = 'orderconfirm.aspx?pid=' +id;
	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var ss= xmlhttp.responseText;		
		alert('已放入购物车');
		}		
	}
	xmlhttp.send(null);
}
// 添加到收藏
function favorite(id) {
	xmlhttp = initxmlhttp();
	var url = 'favorite.aspx?pid=' +id;
	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var ss= xmlhttp.responseText;
		alert('已收藏');
		}		
	}
	xmlhttp.send(null);
}


