
//初始化
$(document).ready(function() { 

		//$.get("ip.aspx",function(aboard){if(aboard) location.href('en_index.asp');}); 	//登陆初始化
		$(".sp").css("display","none"); //略所图初始化
		$(".pro li").css("height","140px"); //略所图初始化
		//$(".price_normal").css("display","none"); //略所图初始化

		//$("#top_login").load("login.aspx?action=chkLogin"); 	//登陆初始化
		//$("#leftindex").html('Products'); //Left标题初始化
		$(".thumb").LoadImage(true,110,100); //略所图初始化
		$(".big").LoadImage(true,640,480);  //大图略所初始化
		
}); 	


function register()
{
	$(document).ready(function() { 
		$("#register").html("加载中...");
		$("#register").load("register.aspx"); 
		$('#register').jqm();
 		$('#register').jqmShow(); 		
 	}); 
}


function registerok()
{
	$(document).ready(function() { 
		$('#register').jqm();
 		$('#register').jqmHide(); 		
 	}); 	
}

function chkexist(str)
{
	var str;
	
}
function login()
{
	$(document).ready(function() { 
		$("#login").html("加载中...");
		$("#login").load("login.aspx"); 
		$('#login').jqm();
 		$('#login').jqmShow(); 		
 	}); 		
}
function loginok()
{
	$(document).ready(function() { 
		$('#login').jqm();
 		$('#login').jqmHide(); 		
 	}); 	
}

function offlogin()
{
	$.get("Login.aspx?action=offLogin");
	$("#top_login").load("login.aspx?action=chkLogin"); 	
}

function passUpdate()
{
	$(document).ready(function() { 
		$("#loading").html("加载中...");
		$("#loading").load("member_password.aspx"); 
		$('#loading').jqm();
 		$('#loading').jqmShow(); 		
 	}); 
}

function sendComment()
{
		if($("#gbooktitle").attr("value")=="") {alert('评论标题不能为空');return};
		if($("#gbookcontent").attr("value")=="") {alert('评论内容不能为空');return};

			$.post("gbook.aspx", { 
				gbooktitle:$("#gbooktitle").attr("value"),
				gbookcontent:$("#gbookcontent").attr("value"),
				product_id:$("#product_id").attr("value")
				},
			  function(_re){
					//document.write(_re);		
					getComment();
		   }
			); 		
}

function getComment()
{
//加载评论
	$(document).ready(function() { 	
			$("#comment").html('加载评论信息...'); 
			//验证会员中心登陆
			$.get(
	     "gbook.aspx?product_id="+$("#product_id").attr("value"),
		     function(data){
		       $("#comment").html(data);
		     }   
		  );  
	}); 	
}

function passUpdateok()
{
	$(document).ready(function() { 
		$('#loading').jqm();
 		$('#loading').jqmHide(); 		
 	}); 	
}

function passSave()
{
		$(document).ready(function() { 
		if($("#newpassword").attr("value")==""||$("#oldpassword").attr("value")=="") {alert('密码不能为空');return};
			if($("#newpassword").attr("value")!=$("#confirmnewpassword").attr("value")) {alert('两次密码输入不一致');return}

			$.post("member_password.aspx", { oldpassword:$("#oldpassword").attr("value"),newpassword:$("#newpassword").attr("value") },
			  function(_pass){
			  		if(_pass=='ok')
			  		{
							alert('密码修改成功,请牢记您的新密码');
							passUpdateok();
			  		}
				 		else
			  		{
			  			alert('请输入正确的旧密码');	
			  		}	
			   }
			); 
		
		});	
}

function checklogin()
{
		$(document).ready(function() { 
			if(!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test($("#loginemail").attr("value"))) {alert('请输入合法Email地址');return};

			$.post("Login.aspx", { loginemail:$("#loginemail").attr("value"),loginpassword:$("#loginpassword").attr("value") },
			  function(_login){
			  		if(_login=='ok')
			  		{
			  			//alert('登陆成功');	
			  			$.cookie('memberemail',$("#loginemail").attr("value"),{expires:30});  
			  			loginok();
			  			$("#top_login").load("login.aspx?action=chkLogin"); 
			  		}
				 		else
			  		{
			  			alert('Email或密码错误');	
			  		}	
			   }
			); 
		
		});

}

function checkItemCount()
{
		$(document).ready(function() {
			var totalprice=0;
			var totalcount=0;
			var _productids="";
			var itemproce;
			$(".cartlist .ItemCount").each(function(i){
				if(isNaN($(this).attr("value"))||$(this).attr("value")>100) $(this).attr("value",1);
				totalprice+=$(this).attr("sprice")*$(this).attr("value");
				totalcount = parseInt(totalcount)+parseInt($(this).attr("value"));
				$("#itemprice"+$(this).attr("sproduct_id")).text(parseInt($(this).attr("sprice")*$(this).attr("value")).toFixed(2));
				
				//_productids = $.cookie('product_ids_cart');
				for(i=0;i<parseInt($(this).attr("value"));i++){			
				_productids +="-"+$(this).attr("sproduct_id");
				$.cookie('product_ids_cart',_productids,{expires:30}); 
					//alert($(this).attr("sproduct_id"));				
				}
			});
			$("#CartCount").text(totalcount);
			$("#CartPrice").text(totalprice.toFixed(2));
		});
}


	function input_hover(obj, color) {
		obj.style.border = '1px solid ' + color;
	}	
	function checkemail(str)
	{
		return true;
		var str;
		var r = $.ajax({ 
									type:"GET",
								  url: "Login.aspx", 
								  data:"action=chkExist&email="+str+"",
								  async: false
									}).responseText; 
		if(r=='exist') 
		{
			alert('该Email已经被注册');
			return false;
		}
	
		if(!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(str))
		{
			alert('请输入合法Email地址');
			return false;
		}
	}

	function registerSave()
	{
		$(document).ready(function() { 
		if(!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test($("#registeremail").attr("value")))
		{
			alert('请输入合法Email地址');
			return;
		}			
		if($("#registerpassword").attr("value")=="") {alert('密码不能为空');return};
			if($("#registerpassword").attr("value")!=$("#confirmpassword").attr("value")) {alert('两次密码输入不一致');return}
			if(checkemail($("#registeremail").attr("value")))
			{
				$.post("register.aspx", { registeremail:$("#registeremail").attr("value"),registerpassword:$("#registerpassword").attr("value") },
				  function(data){
				  		if(data=='ok')
				  		{
				  			alert('感谢您的注册,请牢记您的密码');
				  			registerok();
				  			$("#top_login").load("login.aspx?action=chkLogin"); 
				  			$.cookie('memberemail',$("#registeremail").attr("value"),{expires:30});  		
				  		}
				  		else
				  		{
				  			alert('内部错误，请联系工作人员');	
				  		}	
				  }
			   )
			}; 
		});	
	}
function login()
{
	$(document).ready(function() { 
		$("#login").html("加载中...");
		$("#login").load("login.aspx"); 
		$('#login').jqm();
 		$('#login').jqmShow(); 		
 	}); 
}

function productSearch()
{
		if($("#keywords").attr("value")==""||$("#keywords").attr("value")=="input keywords")
		{
			alert('plear input your keywords');
			return false;
		}
		else
		{
			var at = document.getElementById("search").action;
			at += "-"+ $("#keywords").attr("value")+".html";	
			document.getElementById("search").action = at;
			return true;
		}	
}

function Loading()
{
	$(document).ready(function() { 
		  $('#loading').jqm();
		  $('#loading').jqmShow();		
	});	
}
function Loaded()
{
	$(document).ready(function() { 
		  $('#loading').jqm();
		  $('#loading').jqmHide();		
	});	
}

function addToCart(_productid)
{
	var _productid;
	var _productids="";	
	$(document).ready(function() { 
		$.cookie('product_ids_cart')==null? _productids=_productid:_productids = $.cookie('product_ids_cart')+"-"+_productid;
		$.cookie('product_ids_cart',_productids,{expires:30}); 
			$("#cart").html("购物车加载中...");
			$("#cart").load("cart.aspx?Product_ID="+_productid+""); 
		  $('#cart').jqm();
		  $('#cart').jqmShow();
	}); 
}
function delFromCart(_productid)
{
	var _productid;
	var _productids="";
	$(document).ready(function() { 
		$.cookie("product_ids_cart").indexOf("-")!=-1? _productids=$.cookie('product_ids_cart').replace("-"+_productid,""):_productids=$.cookie('product_ids_cart').replace(_productid,"");	
		$.cookie('product_ids_cart',_productids,{expires:30}); 
		$("#cartindex"+_productid).remove(); 
	}); 
}

function ClearCart()
{
	$.cookie('product_ids_cart',null,{expires:30}); 
	$('.cartlist').hide(); 
}
function CloseCart()
{
 	$('#cart').jqmHide(); 
}
function OpenCart()
{
	$(document).ready(function() { 
		try{CloseOrder()}catch(e){};
		$("#cart").html("购物车加载中...");
		$("#cart").load("cart.aspx"); 
		$('#cart').jqm();
 		$('#cart').jqmShow(); 		
 	}); 
}

function CloseOrder()
{
 	$('#order').jqmHide(); 
}
function OpenOrder()
{
	$(document).ready(function() { 
	 	CloseCart();
		$("#order").html("订单表加载中...");
		$("#order").load("order.aspx"); 	 	
		$('#order').jqm();
 		$('#order').jqmShow();
	
 	}); 
}

function SubmitOrder()
{
	$(document).ready(function() { 	
		if($("#orderaddress").attr("value")==""){alert('请输入送货地址');return};
		if($("#ordercontactname").attr("value")==""){alert('请输入收件人');return};
		
		if($("#ordermobile").attr("value")==""){alert('手机号码必须填写');return};
		if($("#orderpostcode").attr("value")==""){alert('请输入邮政编码');return};
		//if($("#orderemail").attr("value")==""){alert('Email地址必须填写');return};
		if(!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test($("#orderemail").attr("value"))) {alert('请输入合法Email地址');return};
	
		$.post("order.aspx", { 
				//contentType: "charset=gb2312",
				orderaddress:$("#orderaddress").attr("value"),
				ordercontactname:$("#ordercontactname").attr("value"),
				ordertel:$("#ordertel").attr("value"),
				ordermobile:$("#ordermobile").attr("value"),
				orderpostcode:$("#orderpostcode").attr("value"),
				orderemail:$("#orderemail").attr("value")
			},
		  function(data){
		    //alert(data);
				$("#loading").html(data);
				$('#loading').jqm();
		 		$('#loading').jqmShow();
		 		$("#top_login").load("login.aspx?action=chkLogin"); 	//登陆初始化
		    CloseOrder();   
		   }
		);
	});
}
function CloseWin()
{
	$(document).ready(function() { 	
	$('#loading').jqm();	
	$('#loading').jqmHide();
	});
}
