﻿$(function(){
	//圆角
	//$("#searchdiv").corner();

	//装载默认关键字
	var keywords=$.cookie("keywords");
	if (keywords!=null){$("#keywords").val(keywords)};

var hotkeywords = ' 热门关键字：';
	hotkeywords +=' <a title="合作办公" href="/list.asp?k=%E5%90%88%E4%BD%9C%E5%8A%9E%E5%85%AC" target="searchwin">合作办公</a>';
	hotkeywords +=' <a title="合作办公复印纸" href="/list.asp?k=%E5%90%88%E4%BD%9C%E5%8A%9E%E5%85%AC+%E5%A4%8D%E5%8D%B0%E7%BA%B8" target="searchwin">合作办公 复印纸</a>';
	hotkeywords +=' | <a title="最新商品" href="/list.asp?new=30" target="searchwin">最新商品</a>';

	$('#hotkeywords').html(hotkeywords);
	
	
	//显示购物车信息
	$.loadcartinfo();
	$.loadclientinfo();

	//输入状态的检查
	$("input[@name=qty]").click(function(){
		$(this).removeClass().addClass("inp");
	}).blur(function(){
		if (new RegExp('^[1-9]\\d*$', 'gi').test($(this).val())==false){
			$(this).removeClass().addClass("err");
		}else{
			$(this).removeClass().addClass("okk");
		}
	});
	
	
	//点击购买
	$(".buybtn a").click(function(){
		var obj = $(this).prev();
		//获取商品数量
		var qty = $.trim(obj.val());
		if (new RegExp('^[1-9]\\d*$', 'gi').test(qty)==false){
			alert("请输入一个大于0的整数");
			obj.select().removeClass().addClass("err");
		}else{
			obj.removeClass().addClass("okk");
		}
		//获取货号
		var gid = String(obj.attr("id")).match(/\d{7}/gi)[0];
			gid = (String(gid).length==7)?gid:0;
		
		if (gid>0 && qty>0){//递交购买操作
			$.get($.siteconfig.api, { act: "cartadd", id:gid, qty:qty }, function(data){
				//alert(data);//返回0表示成功，不为零表示有错误
				if (parseInt(data)==0){
					var str='商品添加成功！';
						str+='<ul>';
						str+='<li>当前购物车商品数量<span class="total_qty">0</span>个</li>';
						str+='<li>当前购物车商品总金额：<span class="total_amount">0.00</span>元</li>';
						str+='</ul>';
						
					$.prompt(str,{
						  buttons:{"查看购物车":true,"继续购物":false}, 
						  prefix:'cleanblue',
						  callback:function(v){if (v==true){window.location='/cart.html';}}
					}); 
					//window.location='/cart.html';
				}else if (parseInt(data)==1){
					var str='该商品不在网上销售！';
						str+='<ul>';
						str+='<li>当前购物车商品数量<span class="total_qty">0</span>个</li>';
						str+='<li>当前购物车商品总金额：<span class="total_amount">0.00</span>元</li>';
						str+='</ul>';
					$.prompt(str,{
						  buttons:{"返回":false}, 
						  prefix:'cleanblue'
					});
				}else{
					$.prompt('服务器响应失败，请刷新重试！',{
						  buttons:{"刷新":true,"返回":false}, 
						  prefix:'cleanblue',
						  callback:function(v){if (v==true){window.location.reload();}}
					});
				}
				$.loadcartinfo();
			})
		}
	});

	//加载页面广告
	//alert($.pagesadsxml(window.document.location.pathname))
	$.loadpagesads($.pagesadsxml(window.document.location.pathname));
	
	//加载在线客服
	//$("#livechat").html($.siteconfig.livechatstr);
	
	//图片放大
	$(".jqzoom").jqueryzoom();
	
	//输入用户账号的事件
	var AccountStr = '输入会员卡号或email';
	var Account = $("#loginform input[@name=account]");
		Account
		.focus(function(){ if(Account.val()==AccountStr){Account.val('')};})
		.blur(function(){if(Account.val()==''){Account.val(AccountStr)};});

});


/*加载FLASH导航*/
var params = {};
    params.wmode = "transparent";
    swfobject.embedSWF("/style/nav/oo.swf", "topmenus", "480", "80", "9.0.0", "/flash/expressInstall.swf", false ,params);
