﻿	var BuyType="";
	var NowDate="";
jQuery(function ($) {
	if (NowDate>2010) {$("#FavInfo").hide();}
	
	$("#TblList :checkbox").each(function () {
	   if (!$(this).attr("checked")) {$(this).parent().parent().find(":text").attr("disabled",true);}
	   else{$(this).parent().parent().find(":text").attr("disabled",false);}
	})		

	$("#TblList :checkbox").live("click",function () {				
		if (!$(this).attr("checked")) {
		
		  $(this).parent().parent().find(":text").attr("disabled",true);
		  $(this).parent().parent().find(":text").val("");  
	   }
	   else{$(this).parent().parent().find(":text").attr("disabled",false);}
	   var amount=0;
	   var GBNum=0;
	   var GBNumZS=0;
		  $("#TblList :checkbox").each(function () {
				var mun=parseInt($(this).parent().parent().find(":text").val());
				if (isNaN(mun)) {
					mun=0;
				}
				var id=$(this).prev().text();								
				if ($(this).attr("checked")&&mun!=""&&mun!="0") {	
					if (NowDate<2010) {
						if (id==2009091602||id==2009091603) {
							GBNumZS=GBNumZS+mun;						
						}
						if (id==2009091601) {
							 GBNum=mun;
						}	
					}	
				    						
					$.ajax({
						type: "POST",
						url: "onlinebuy.aspx/ReturnPrice",
						data: "{'id':"+id+",BuyType:"+BuyType+"}",
						contentType: "application/json; charset=utf-8",
						async: false,
						dataType: "json",
						beforeSend:function () {
							
						},
						success:function (msg) {					
							amount=amount+msg*mun;													
						},
						error:function (msg) {
							alert(msg);
						},
						complete:function () {					
						}
					})
				}
		  })

//		  alert(order_onlinebuy.aa().value);
		  $("#GBNumZS").text(GBNumZS);
		  $("#GBNumAll").text(GBNumZS+GBNum);
		  $("#LblAomunt").text(amount);		  
	})
	$("#TblList :text").live("keyup",function () {
	   var amount=0;
	   var GBNum=0;
	   var GBNumZS=0;
		  $("#TblList :checkbox").each(function () {
				var mun=parseInt($(this).parent().parent().find(":text").val());
				if (isNaN(mun)) {
					mun=0;
				}
				var id=$(this).prev().text();								
				if ($(this).attr("checked")&&mun!=""&&mun!="0") {	
					if (NowDate<2010) {
						if (id==2009091602||id==2009091603) {
							GBNumZS=GBNumZS+mun;
							
						}
						if (id==2009091601) {
							 GBNum=mun;
						}	
					}							
					$.ajax({
						type: "POST",
						url: "onlinebuy.aspx/ReturnPrice",
						data: "{'id':"+id+",BuyType:"+BuyType+"}",
						contentType: "application/json; charset=utf-8",
						async: false,
						dataType: "json",
						beforeSend:function () {
							
						},
						success:function (msg) {					
							amount=amount+msg*mun;															
						},
						error:function (msg) {
							alert(msg);
						},
						complete:function () {					
						}
					})
				}
		  })
		  $("#GBNumZS").text(GBNumZS);
		  $("#GBNumAll").text(GBNumZS+GBNum);
		  $("#LblAomunt").text(amount);	
	})
	$("#BtnLogin").live("click",function () {
		
		
		location.href="http://www.3dsource.cn/login-"+url+".html";
		tb_remove();
	})
	
	$("#BtnSubmit").live("click",function () {
		var istrue=false;
		var istrue1=true;
		$("#TblList :checkbox").each(function () {
			if ($(this).attr("checked")==true) {
			
				if ($(this).parent().parent().find(":text").val()!=""&&$(this).parent().parent().find(":text").val()!="0") {
					istrue=true;
				}
				else{istrue1=false;}				
			}
		})
		if (istrue1==false) {
			alert("请在选择购买的对应产品里，输入购买数量！");
			return false;
		}	
		if (istrue==false) {
			alert("请选择一个产品，并输入购买数量！");
			return false;
		}	
	})
	
	
		$("#TblList :text").live("keypress",function () {
		 value=$(this).val();
		 var reg=new RegExp();
		 reg=/^[0-9]*[1-9][0-9]*$/;  
		 if (!$.browser.mozilla) 
		 {                   
			  if (event.keyCode==0) 
			  {	                   
				 return true;
			  }
			  var str=value+String.fromCharCode(event.keyCode)
			  return reg.test(str);
		 }
		 else
		 {                 
			  if (window.event.charCode==0) 
			  {
				 return true;
			  }
			  var str=value+String.fromCharCode(window.event.charCode)
			  return reg.test(str);                    
		 }
	})
	$("#TblList :text").css("ime-mode","disabled");
//	$("#BtnSubmit").live("click",function () {
//		var islogin;
//		if ($("#TblList :checkbox").attr("checked")==false||$.trim($("#TblList :text").val())=="") {
//			alert("至少选择一样产品");
//			return false;
//		}
//		else
//		{
//			$.ajax({
//					type: "POST",
//					url: "onlinebuy.aspx/IsLogin",
//					data: "{}",
//					contentType: "application/json; charset=utf-8",
//					async: false,
//					dataType: "json",
//					beforeSend:function () {
//						
//					},
//					success:function (msg) {
//							islogin=msg;
//							if (!msg) {
//									
//								tb_show('登录', '#TB_inline?height=155&width=300&inlineId=popup', ''); 
//							}	
//								
//					}
//			})
//		}
//		if (!islogin) {
//			return false;
//		}	
//	})
	
})

function showpopup()
{
tb_show('登录', '#TB_inline?height=100&width=150&inlineId=popup', ''); 
}