//创建ajax对象
var name_re = false; 
   function name_xml()
   {
   try { 
     name_re = new XMLHttpRequest(); 
   } catch (trymicrosoft) { 
     try { 
       name_re = new ActiveXObject("Msxml2.XMLHTTP"); 
     } catch (othermicrosoft) { 
       try { 
         name_re = new ActiveXObject("Microsoft.XMLHTTP"); 
       } catch (failed) { 
         name_re = false; 
       }   
     } 
   } 
   if (!name_re) 
     alert("Error initializing XMLHttpRequest!"); 
}

var name_use;
var mail_use;



//加入购物车


function addCart(id,actionid,bookid,bookcount){
	

	
	var userid = document.getElementById('userid').value;
	var thisurl = document.getElementById('thisurl').value;
	var id = id;
	var actionid = actionid ;
	var bookid = bookid;
	var bookcount = bookcount;
	
	//alert(thisurl)
	//alert(bookid)
	//alert(bookcount)
	

if (userid==""){
alert("请先登录!")
return false;
}

else{
cart_ajax(id,actionid,bookid,bookcount,thisurl)
}


//加入购物车


function cart_ajax(id,actionid,bookid,bookcount,thisurl){

var url="buy.asp?action=add&id="+escape(id)+"&actionid="+escape(actionid)+"&bookid="+escape(bookid)+"&bookcount="+escape(bookcount)+""

//alert(url);

     name_xml();
     name_re.open("GET", url, true); 
     name_re.setRequestHeader("content-type","text/xml");
     name_re.onreadystatechange = name_requst; 
name_re.setRequestHeader("If-Modified-Since","0");
     name_re.send(null); 
}

function name_requst(){
if(name_re.readyState==4 && name_re.status==200)//返回完成
{
var msg=name_re.responseText;



if (msg=="yes"){

alert("加入失败！")

return false;
}
else{

//alert("加入成功！")
//alert("加入成功！);location='index.asp'")
alert('加入成功');window.location=thisurl
//alert('加入成！);location='index.asp'
//window.location.reload(); //刷新页面
//window.location.reload(); //刷新页面


return true;
}
}
}

}




//删除购物车数据




function delCart(order_id){
	

	


	var order_id = order_id;

	
	//alert(actionid)
	//alert(bookid)
	//alert(bookcount)
	


delcart_ajax(order_id)






function delcart_ajax(order_id){


var url="shop-delcart.asp?order_id="+escape(order_id)+""

 //alert(url);

     name_xml();
     name_re.open("GET", url, true); 
     name_re.setRequestHeader("content-type","text/xml");
     name_re.onreadystatechange = name_requst; 
name_re.setRequestHeader("If-Modified-Since","0");
     name_re.send(null); 
}

function name_requst(){
if(name_re.readyState==4 && name_re.status==200)//返回完成
{
var msg=name_re.responseText;



if (msg=="yes"){

alert("删除失败！")

return false;
}
else{

alert("删除成功！")
window.location.reload(); //刷新页面


return true;
}
}
}

}











//修改购物车数量


function modifyCart(actionid,bookid,bookcount){
	

	


	var actionid = actionid;
	var bookid = bookid;
	var bookcount = bookcount;
	
	//alert(actionid)
	//alert(bookid)
	//alert(bookcount)
	


modifycart_ajax(actionid,bookid,bookcount)






function modifycart_ajax(actionid,bookid,bookcount){


var url="chcount.asp?bookid="+escape(bookid)+"&actionid="+escape(actionid)+"&bookcount="+escape(bookcount)+""

 //alert(url);

     name_xml();
     name_re.open("GET", url, true); 
     name_re.setRequestHeader("content-type","text/xml");
     name_re.onreadystatechange = name_requst; 
name_re.setRequestHeader("If-Modified-Since","0");
     name_re.send(null); 
}

function name_requst(){
if(name_re.readyState==4 && name_re.status==200)//返回完成
{
var msg=name_re.responseText;



if (msg=="yes"){

alert("修改失败！")

return false;
}
else{

//alert("修改成功！")
window.location.reload(); //刷新页面


return true;
}
}
}

}









