function selectNextItemByShopp(id) {
	var id = id;
	var select = document.getElementById(id);
	var sel = select.value;
	if (sel == 1) {
		if (select.selectedIndex + 1 < select.options.length) {
			select.options[select.selectedIndex + 1].selected = true;
		} else {
			select.options[0].selected = true;
		}
	}
}

function checkname() {
	if (sendorderfrm.name.value == "") {
		alert("请输入收货人名称！")
		sendorderfrm.name.focus();
		return false;
	}
	return true;
}

function checkaddress() {
	if (sendorderfrm.address.value == "") {
		alert("请输入送货地址！")
		sendorderfrm.address.focus();
		return false;
	}
	return true;
}

function checkphone() {
	if (sendorderfrm.phone.value == "") {
		alert("请输入联系电话！")
		sendorderfrm.phone.focus();
		return false;
	}
	return true;
}

function checksenddate() {
	if (sendorderfrm.senddate.value == "") {
		alert("请输入送货时间！")
		sendorderfrm.senddate.focus();
		return false;
	}
	return true;
}

function checkdatabyshop() {
	return checkname() && checkaddress() && checkphone() && checksenddate();
}

function buyamount(str1, str2, labelId, dataId, userId, imgId) {
	var str1 = str1;
	var str2 = str2;
	var labelId = labelId;
	var dataId = dataId;
	var userId = userId;
	var imgId = imgId;
	var buyamount = document.getElementById(dataId).value;

	if (isNaN(buyamount)) {
		alert("购买数量必须是数字！");
		document.getElementById(dataId).value = "";
		// document.getElementById(dataId).focus();
		return;
	}
	if (buyamount > 0) {
		if (buyamount > 100) {
			alert("凡购买100件以上商品，请电话联系客服人员！");
			document.getElementById(dataId).value = "";
			// document.getElementById(dataId).focus();
			return;
		}
	} else {
		alert("至少购买一件商品！");
		document.getElementById(dataId).value = "";
		// document.getElementById(dataId).focus();
		return;
	}

	window.open("AddToCar.do?frm=" + str1 + "&by=" + str2 + "&labelId="
			+ labelId + "&dataId=" + dataId + "&userId=" + userId + "&imgId="
			+ imgId + "&buyamount=" + buyamount + "", target = "_parent");
}

function isbuy() {
	var total = document.getElementById("total").value;
	if (total == "0") {
		alert("您还没有购买商品，请购买！");
		return false;
	}
	return true;
}

var divid;
var ismyshop = false;
function gettotal(str1, str2, labelId, dataId, userId, imgId) {
	var str1 = str1;
	var str2 = str2;
	var labelId = labelId;
	var dataId = dataId;
	var userId = userId;
	var imgId = imgId;
	divid = dataId;
	if (str1 == 'b' && str2 == 'b') {
		ismyshop = true;
	}
	//send_request_addtocar('http://localhost:8080/wikiex/shopping/AddToCar.do?frm=' + str1 + '&by=' + str2 + '&labelId=' + labelId + '&dataId=' + dataId + '&userId=' + userId + '&imgId=' + imgId + '&show=alt');
	send_request_addtocar('http://www.pptiger.com/shopping/AddToCar.do?frm='+str1+'&by='+str2+'&labelId='+labelId+'&dataId='+dataId+'&userId='+userId+'&imgId='+imgId+'&show=alt');

}

var http_request_addtocar;
function send_request_addtocar(url) {
	http_request_addtocar = false;
	if (window.ActiveXObject) {
		try {
			http_request_addtocar = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request_addtocar = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	} else if (window.XMLHttpRequest) {
		http_request_addtocar = new XMLHttpRequest();
		if (http_request_addtocar.overrideMimeType) {
			http_request_addtocar.overrideMimeType('text/xml');
		}
	}

	if (!http_request_addtocar) {
		window.alert("不能创建XMLHttpRequest对象实例");
		return false;
	}

	http_request_addtocar.onreadystatechange = proRequestrand;
	http_request_addtocar.open("GET", url, false);
	http_request_addtocar.send(null);
}
function proRequestrand() {
	if (http_request_addtocar.readystate == 4) {

		if (http_request_addtocar.status == 200) {
			// redraw();
			displaycar(divid);
			var str = http_request_addtocar.responseText;
			dateArray = str.split("@");
			// document.getElementById('car').innerHTML =
			// http_request_addtocar.responseText;
			if (ismyshop) {
				parent.document.getElementById('shownum1').innerHTML = "("
						+ dateArray[0] + ")";
			} else {
				document.getElementById('shownum1').innerHTML = "("
						+ dateArray[0] + ")";
			}
			document.getElementById('shownum2' + divid).innerHTML = dateArray[0];
			document.getElementById('showmoney' + divid).innerHTML = dateArray[1];

		} else {
			alert("您所请求的页面有异常");
		}
	}
}

// function redraw(){

// var CarTable = "<div style='height:32px; width:328px;
// background-color:#dcedf6;'>"
// +" <div style='margin-left:10px; margin-top:7px; float:left;'>"
// +" <img src='image/shopping/right.gif' />"
// +" <span style='font-size:12px; color:#377fa4;'>商品已添加到购物车</span>"
// +" </div>"
// +" <div style='float:right; margin-right:5px; margin-top:3px;'>"
// +" <a onClick='hide()'>"
// +" <img border='0' src='image/shopping/mismark.gif' />"
// +" </a>"
// +" </div>"
// +"</div>"
// +"<div>"
// +" <div id='car' style='margin-top:30px; margin-left:40px; font-size:12px;
// color:#666666;'></div>"
// +" <div style='margin-left:60px; margin-top:20px;'>"
// +" <div style='float:left;'><a target='_parent'
// href='http://localhost:8080/wikiex/shopping/ShowCarInDetail.do'><img
// border='0' src='image/shopping/checkcar.png' /></a></div>"
// +" <div style='float:left; margin-left:8px;'><a href='#'><img border='0'
// src='image/shopping/goonshop.png' /></a></div>"
// +" </div>"
// +"</div>";
// document.getElementById('showcar').innerHTML = CarTable;
// }

function displaycar(divid) {
	if (document.getElementById(divid).style.display == "none") {
		document.getElementById(divid).style.display = "";
	}
	if (isbuyqg) {

	} else {
		if (document.getElementById("showbtn" + divid).style.display == "") {
			document.getElementById("showbtn" + divid).style.display = "none";
		}
	}

}

function hidecar(divid) {
	if (document.getElementById(divid).style.display == "") {
		document.getElementById(divid).style.display = "none";
	}
	if (isbuyqg) {

	} else {
		if (document.getElementById("showbtn" + divid).style.display == "none") {
			document.getElementById("showbtn" + divid).style.display = "";
		}
	}
}

var isdefault = false;
function getqgnum() {
	isdefault = true;
	var d = new Date();
	var today = d.getYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
	var createtime = today+' 00:00:00';
	var endtime = today+' 23:59:59';
	//send_request_isbuy('http://localhost:8080/wikiex/shopping/AddToCar.do?isbuy=1&ctime=' + createtime + '&etime=' + endtime + '&qgnum=1');
	send_request_isbuy('http://www.pptiger.com/shopping/AddToCar.do?isbuy=1&ctime=' + createtime + '&etime=' + endtime + '&qgnum=1');
}

var isbuyqg = false;
function getqg(str1, str2, labelId, dataId, userId, imgId, price) {
	isdefault = false;
	var str1 = str1;
	var str2 = str2;
	var labelId = labelId;
	var dataId = dataId;
	var userId = userId;
	var imgId = imgId;
	var price = price;
	divid = dataId;
	var d = new Date();
	var today = d.getYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
	var createtime = today+' 00:00:00';
	var endtime = today+' 23:59:59';
	//send_request_isbuy('http://localhost:8080/wikiex/shopping/AddToCar.do?isbuy=1&pid=' + dataId + '&ctime=' + createtime + '&etime=' + endtime);
	send_request_isbuy('http://www.pptiger.com/shopping/AddToCar.do?isbuy=1&pid=' + dataId + '&ctime=' + createtime + '&etime=' + endtime);
	if (isbuyqg) {
		//send_request_addxsqg('http://localhost:8080/wikiex/shopping/AddToCar.do?frm=' + str1 + '&by=' + str2 + '&labelId=' + labelId + '&dataId=' + dataId + '&userId=' + userId + '&imgId=' + imgId + '&price=' + price + '&show=alt');
		send_request_addxsqg('http://www.pptiger.com/shopping/AddToCar.do?frm=' + str1 + '&by=' + str2 + '&labelId=' + labelId + '&dataId=' + dataId + '&userId=' + userId + '&imgId=' + imgId + '&price=' + price + '&show=alt');
	}
}

var http_request_addxsqg;
function send_request_addxsqg(url) {
	http_request_addxsqg = false;
	if (window.ActiveXObject) {
		try {
			http_request_addxsqg = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request_addxsqg = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	} else if (window.XMLHttpRequest) {
		http_request_addxsqg = new XMLHttpRequest();
		if (http_request_addxsqg.overrideMimeType) {
			http_request_addxsqg.overrideMimeType('text/xml');
		}
	}

	if (!http_request_addxsqg) {
		window.alert("不能创建XMLHttpRequest对象实例");
		return false;
	}

	http_request_addxsqg.onreadystatechange = xsqgRequestrand;
	http_request_addxsqg.open("GET", url, false);
	http_request_addxsqg.send(null);
}
function xsqgRequestrand() {
	if (http_request_addxsqg.readystate == 4) {

		if (http_request_addxsqg.status == 200) {
			if (isbuyqg) {
				//window.open("http://localhost:8080/wikiex/shopping/ShowCarInDetail.do", target = "_parent");
				window.open("http://www.pptiger.com/shopping/ShowCarInDetail.do", target = "_parent");
			} else {
				// redraw();
				displaycar(divid);
				var str = http_request_addxsqg.responseText;
				dateArray = str.split("@");
				// document.getElementById('car').innerHTML =
				// http_request_addtocar.responseText;
				if (ismyshop) {
					parent.document.getElementById('shownum1').innerHTML = "("
							+ dateArray[0] + ")";
				} else {
					document.getElementById('shownum1').innerHTML = "("
							+ dateArray[0] + ")";
				}
				document.getElementById('shownum2' + divid).innerHTML = dateArray[0];
				document.getElementById('showmoney' + divid).innerHTML = dateArray[1];
			}
		} else {
			alert("您所请求的页面有异常");
		}
	}
}

var http_request_isbuy;
function send_request_isbuy(url) {
	http_request_isbuy = false;
	if (window.ActiveXObject) {
		try {
			http_request_isbuy = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request_isbuy = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	} else if (window.XMLHttpRequest) {
		http_request_isbuy = new XMLHttpRequest();
		if (http_request_isbuy.overrideMimeType) {
			http_request_isbuy.overrideMimeType('text/xml');
		}
	}

	if (!http_request_isbuy) {
		window.alert("不能创建XMLHttpRequest对象实例");
		return false;
	}

	http_request_isbuy.onreadystatechange = isbuyRequestrand;
	http_request_isbuy.open("GET", url, false);
	http_request_isbuy.send(null);
}

function isbuyRequestrand() {
	if (http_request_isbuy.readystate == 4) {

		if (http_request_isbuy.status == 200) {
			if (isdefault) {
				var t = http_request_isbuy.responseText;
				dateArray = t.split("@");

				var i = 0;
				for (i = 0; i <= 5; i++) {
					document.getElementById("num" + (parseInt(i) + parseInt(1))	+ "").innerHTML = dateArray[i];
					if (dateArray[i] == "此商品已抢购完！") {
						document.getElementById("showbtn" + (parseInt(i) + parseInt(1))).style.display = "none";
						document.getElementById("nonebtn" + (parseInt(i) + parseInt(1))).style.display = "";
					}
				}
			} else {
				// displaycar(divid);
				
				if (http_request_isbuy.responseText == "") {
					isbuyqg = true;
				} else {
					isbuyqg = false;
					if (http_request_isbuy.responseText == "很抱歉，每人每天只能抢购一件商品！"){
						document.getElementById('shownum2').innerHTML = http_request_isbuy.responseText;	
						document.getElementById('showalt').style.display = "";
					}else if (http_request_isbuy.responseText == "请登录！"){
						document.getElementById('shownum1').style.display = "";
					}					
				}
			}
		} else {			
			alert("您所请求的页面有异常");
		}
	}
}


function cancel(id){
	var id = id;
	document.getElementById(id).style.display = "none";
}








