
$(document).ready(function() {
					   	
	$("#ajaxstart").ajaxStart(function(){ 	 	
 	 	$("#ajaxstart").animate({opacity: 'show'}, 'slow');		
	});

});


function addtocart(pid){

	var idmsg = "color_"+pid;
	//var selectcolor = "select[@id="+idmsg+"] option[@selected]").val();
	var selectcolor = $("#"+idmsg).val();
	
			$.post("/cart.php",
				{m:"addtocart", pid: pid, pcolor: selectcolor},
				function(data){
					data = Trim(data);
					if(data.length < 5){

						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html('加入成功了！您目前共有 '+data+' 件战利品。点击右面的购物车按钮可以 <a href=/cart/>快速结帐</a> ...');
						$("#allertid").animate({opacity: 'show'}, 'slow');
						
						carths(data);

						window.setTimeout("hideshow('allertid')",20000);
					}else{
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html(data);
						$("#allertid").animate({opacity: 'show'}, 'slow');
					}
				}			
			);
}

function removecart(kid){

			$.post("/cart.php",
				{m:"removecart", kid: kid},
				function(data){
					data = Trim(data);
					if(data.length < 5){
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#linegoods_"+kid).animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html('移除成功！');
						$("#allertid").animate({opacity: 'show'}, 'slow');

						carths(data);
						
						window.setTimeout("hideshow('allertid')",10000);
					}else{
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html(data);
						$("#allertid").animate({opacity: 'show'}, 'slow');
					}
				}			
			);
}

function addtowishlist(pid){


			$.post("/my.php",
				{m:"addtowishlist", pid: pid},
				function(data){
					data = Trim(data);
					if(data == "ok"){

						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html('加入成功！点此可以 <a href="/wishlist/">查看</a> 我的常用商品...');
						$("#allertid").animate({opacity: 'show'}, 'slow');
						
						window.setTimeout("hideshow('allertid')",20000);
					}else{
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html(data);
						$("#allertid").animate({opacity: 'show'}, 'slow');
					}
				}			
			);
}

function removewishlist(pid){
	
	if(confirm("您确定要移除该商品吗?"))
	{	
			$.post("/my.php",
				{m:"removewishlist", pid: pid},
				function(data){
					data = Trim(data);
					if(data == "ok"){
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#linegoods_"+pid).animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html('移除成功！');
						$("#allertid").animate({opacity: 'show'}, 'slow');
					
						window.setTimeout("hideshow('allertid')",10000);
					}else{
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html(data);
						$("#allertid").animate({opacity: 'show'}, 'slow');
					}
				}			
			);
	}
}


function cancelorder(oid){

	if(confirm("您确定要作废此订单吗?"))
	{	
			$.post("/my.php",
				{m:"cancelorder", oid: oid},
				function(data){
					data = Trim(data);
					if(data == "ok"){
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#statustext_"+oid).html('客户作废');
						$("#allertidtext").html('操作成功...');
						$("#allertid").animate({opacity: 'show'}, 'slow');
					
						window.setTimeout("hideshow('allertid')",10000);
					}else{
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html(data);
						$("#allertid").animate({opacity: 'show'}, 'slow');
					}
				}			
			);
	}
}



function Trim(str)
{ 
	return str.replace(/^\s*|\s*$/g,""); 
}

function hideshow(divid)
{
	$("#"+divid).animate({opacity: 'hide'}, 'slow');
}

function carths(numgoods)
{

	$("#cart_picture").attr("src","/template/img/cart_over.jpg");
	$("#cart_text").html('您的购物车中有&nbsp;<span class="font12">'+numgoods+'</span>&nbsp;件战利品！');
	
}

function guestorderadd(){
	
	var sendtype = $('input[@name=sendtype][@checked]').val();

	if($("#AddressContact").val()=="" || $("#AddressPhone").val()=="" || $("#AddressAddress").val()=="")
	{
		$("#allertidtext").html('收货人 / 联系电话 / 详细地址 不能为空,为保证物品能及时快捷的到达，请填写完整您的收货信息!');
		$("#allertid").animate({opacity: 'show'}, 'slow');	
		window.setTimeout("hideshow('allertid')",20000);
	}else{
			$.post("/order.php",
				{m:"guestadd", sendtype: sendtype, AddressCompany: $("#AddressCompany").val(), AddressContact: $("#AddressContact").val(), AddressPhone: $("#AddressPhone").val(), AddressAddress: $("#AddressAddress").val(), remark: $("#remark").val(), addorder: $("#addorder").val()},
				function(data){

					data = Trim(data);
					
					if(data.length < 10){
						
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
	
						var jumpurl = 'order.php?id='+data;
						document.location = jumpurl;

					}else{
						$("#ajaxstart").animate({opacity: 'hide'}, 'slow');
						$("#allertidtext").html(data);
						$("#allertid").animate({opacity: 'show'}, 'slow');
					}
				}			
			);
	}
}


