/**
 * cookie命名空间
 */
var cookieSpace = 'AirShop';
var cartItemCount=0;
var cartItemAmount=0;
var cartItemTotal=0;
/**
 * 获取省市区
 * @param parentId
 * @param type
 * @return
 */
function getOption(parentId, type){
	
	if(parentId !=""){
		if(type==0){
			id = 'city';
			document.getElementById('county').length=0;
			document.getElementById('county').options[0] = new Option('请选择...', '');
		}
		else{
			id='county';
		}
		document.getElementById(id).options[0] = new Option('正在载入...', '');
		
		Ajax.call('/user/getregion', 'parentId=' + parentId,
			function (result){
				//alert(result);
				//if(result.error==0){
					//alert(result.content.length);
					document.getElementById(id).length=0;
					document.getElementById(id).options[0] = new Option('请选择...', '');
					for(i=0;i<result.length;i++){
						//alert(result[i]['RegionName']);
						
						getObjectId(id).options[i+1] = new Option(result[i]['RegionName'], result[i].Id);
					}
				//}
				
				
			}, 'POST', 'JSON', true, true);
	}
}
/**
 * 
 * @return
 */
function getMiniCart(){
	$("#cartContent").html("<img src='/Assets/Images/lightbox-ico-loading.gif'/>");
	Ajax.call('/user/minicart', '', function (result){
											  
		$('#cartCount').text(getCartItemTotal());
		if(result==''){
			$("#cartContent").html("<div style='padding:10px;color:red'>您的购物车为空。</div>");
			/*$('#cartContent').css({
					width:100,
					height:100
			          }
					);*/
		}
		else{
			var itemTotal=0;
			var totalMoney=0;
			var htmls ='<table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding:5px;float:left">';
			for(i=0;i<result.length;i++){
				itemTotal += parseInt(result[i].GoodsNumber);
				totalMoney += parseInt(result[i].GoodsNumber)*result[i].GoodsPrice;
				htmls +='<tr><td style="border-bottom:#D2D2D2 1px dashed;" width="20%" height="60"><img src="http://www.buy78.com/Data/'+result[i].Thumb+'" width="48" height="48"/></td><td width="55%" style="border-bottom:#D2D2D2 1px dashed;">'+result[i].Name+'&nbsp;￥<span class="shopPrice" name="shopPrice">'+result[i].GoodsPrice+'</span>&nbsp;&nbsp;<img src="/Assets/Images/x.jpg" style="cursor:pointer" onclick="miniRemove('+result[i].CartId+')"/></td><td width="25%" style="border-bottom:#D2D2D2 1px dashed;"><img src="/Assets/Images/jian.gif" style="cursor:pointer" onclick="changeCartNum('+result[i].CartId+', 0, '+result[i].GoodsId+')"/>&nbsp;<input type="text"  readonly value="'+result[i].GoodsNumber+'" id="buyNumber'+result[i].CartId+'" name="buyNumber"  style="width:20px;text-align:center"/>&nbsp;<img src="/Assets/Images/jia.gif" style="cursor:pointer" onclick="changeCartNum('+result[i].CartId+', 1, '+result[i].GoodsId+')"/><input type="hidden" id="original_'+result[i].CartId+'" value="'+result[i].GoodsNumber+'"/></td></tr>';
			}
			htmls +='<tr><td height="20" colspan="3" style="padding-top:5px;">&nbsp;商品数量：<span class="price" id="miniTotal">'+itemTotal+'</span>&nbsp;总价：￥<span class="price" id="miniTotalMoney">'+numberFormat(totalMoney, 2)+'</span>元<br/>&nbsp;<a href="/cart.html"><img src="/Assets/Images/viewCart.gif" border="0" align="absmiddle"/></a>&nbsp;<a href="/userZone/checkoutStep1"><img src="/Assets/Images/toCheck.jpg" border="0" align="absmiddle"/></a></td></tr><tr><td colspan="3" id="miniMsg"></td></tr> </table>';
			$("#cartContent").html(htmls);
			
		}
	}, 'POST', 'JSON', true, true
	);
}
/**
 * 删除购物车中物品
 * @param cartId
 * @return
 */
function miniRemove(cartId){
	Ajax.call('/user/removecartitem', 'cartId=' + cartId, function (result){
	     if(result.error == 1){
			 alert(result.message);
		 }
		 else{
			 getMiniCart();
		 }
																	 }
	, "POST", "JSON");
}
function changeCartNum(cartId, type, goodsId){
	var number = parseInt($("#buyNumber"+cartId).val());
	if(type==0){
		if(number<=1){
           return;
		}
		number = number -1;
		
	}
	else if (type==1){
		number = number+1;
	}
	else{
		
	}
	
	Ajax.call('/user/changecartnumber', 'cartId=' + cartId+"&number="+number+"&goodsId="+goodsId, function (result){
	     if(result.error == 1){
			 //alert(result.message);
	    	 $('#miniMsg').html('<font color="red">提示信息：'+result.message+'</font>');
			 $("#buyNumber"+cartId).val($('#original_'+cartId).val());
		 }
		 else{
			 $("#buyNumber"+cartId).val(number);
			 reCalculateMiniCart();
			 
		 }
																	 }
	, "POST", "JSON");
	
	
}
function reCalculateMiniCart(){
	var totalItem=0;
	var totalMoney=0;
	//alert($("[name=shopPrice]"));
	var i=0;
	$("[name=shopPrice]").each(function() { 
		  // alert($(this).html());
		   price = parseFloat($(this).html());
		   number = parseInt($("[name=buyNumber]").eq(i).val());
		   totalItem += number;
		   totalMoney += number*price;
		   i++;
	}); 
	$('#miniTotal').html(totalItem);
	$('#miniTotalMoney').html(numberFormat(totalMoney, 2));
}
/**
 * 查看列表
 * @param obj
 * @return
 */
function shiftListItem(obj)
{
    if(obj)
    {
        var childnodes = obj.parentNode.childNodes;
        for(var i=0; i < childnodes.length;i++)
        {
            if(childnodes[i].nodeName.toLowerCase() == "dl")
            {
                childnodes[i].style.display = 'none';
            }
            else if(childnodes[i].nodeName.toLowerCase() == "ul")
            {
                childnodes[i].style.display = '';
            }
        }
        obj.style.display = 'none';
        if(document.all)
        {
            obj.nextSibling.style.display='block';//不把持FF
        }
        else
        {
            obj.nextSibling.nextSibling.style.display='block';
        }
    }
}
/**
 * 返回二位小数
 * @param src
 * @param pos
 * @return
 */
function formatFloat(src, pos)
{
    return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}
/**
 * 截取小数位数
 * @param value
 * @param num
 * @return
 */
function numberFormat(value, num) // 四舍五入
{
  var a_str = formatNumber(value, num);
  var a_int = parseFloat(a_str);
  if (value.toString().length > a_str.length)
  {
    var b_str = value.toString().substring(a_str.length, a_str.length + 1);
    var b_int = parseFloat(b_str);
    if (b_int < 5)
    {
      return a_str;
    }
    else
    {
      var bonus_str, bonus_int;
      if (num == 0)
      {
        bonus_int = 1;
      }
      else
      {
        bonus_str = "0."
        for (var i = 1; i < num; i ++ )
        bonus_str += "0";
        bonus_str += "1";
        bonus_int = parseFloat(bonus_str);
      }
      a_str = formatNumber(a_int + bonus_int, num)
    }
  }
  return a_str;
}
/**
 * 
 * @param value
 * @param num
 * @return
 */
function formatNumber(value, num) // 直接去尾
{
  var a, b, c, i;
  a = value.toString();
  b = a.indexOf('.');
  c = a.length;
  if (num == 0)
  {
    if (b != - 1)
    {
      a = a.substring(0, b);
    }
  }
  else
  {
    if (b == - 1)
    {
      a = a + ".";
      for (i = 1; i <= num; i ++ )
      {
        a = a + "0";
      }
    }
    else
    {
      a = a.substring(0, b + num + 1);
      for (i = c; i <= b + num; i ++ )
      {
        a = a + "0";
      }
    }
  }
  return a;
}
function cartToolTip(title, thisObj){
	if(typeof(thisObj)=="undefined"){
		var button = $('#cartBtn');
	}
	else{
		var button = $(thisObj);
	}
	getCartItemTotal();
	$('#cartToolTip').remove();
	//按钮的高
	var btnHeight=button.height();
	//按钮的宽
	var btnWidth=button.width();
	//按钮的offset
	var offset=button.offset();
	var html='<div id="cartToolTip">';
	html +='    <div class="cartContent">';
	html +='	    <div class="cartTitle">';
	html += '		  <table width="100%" border="0" cellspacing="0" cellpadding="0">';
	html +='            <tr>';
	html +='              <td width="90%">&nbsp;'+title+'</td>';
	html +='              <td width="10%"><img src="/Assets/Images/dialog-close.png" alt="关闭窗口" onclick="closeCartDialog();" align="absmiddle" style="cursor:pointer"/>&nbsp;</td>';
	html +='            </tr>';
	html +='          </table>';
	html +='';
	html +='		</div>';
	html +='		<div class="cartBody">';
	html +='		<p style="font-size:12px;"><img src="/assets/images/shopCart.png" align="absmiddle"/>购物车共<strong>'+cartItemTotal+'</strong>种商品<br/>总数量：<strong>'+cartItemCount+'</strong>,总金额：<strong>'+cartItemAmount+'</strong>元<br>';
	html +='';
	html +='		  <input type="button" name="Submit" value="查看购物车" onclick="window.location.href=\'/cart.html\'" />&nbsp';
	html +='		  <input type="button" name="Submit2" value="继续购物" onclick="closeCartDialog();" />';
	html +='		</p>';
	html +='	  </div>';
	html +='	</div>';
	html +='</div>';
	$(document.body).prepend(html);
	
	var width = $('#cartToolTip').width();
	var height = $('#cartToolTip').height();
    $('#cartToolTip').css({
			top:offset.top+btnHeight+5+"px",
			left:offset.left+"px",
			height:height+"px",
			width:width+"px"
    }
    );
	//alert(html);
	$('#cartToolTip').fadeIn('slow');
	$('#cartCount').html(cartItemTotal);
}
/**
 * tooltip
 * @param obj
 * @param title
 * @param content
 * @param width
 * @param height
 * @return
 */
function toolTipi(obj, title, content, width, height){
	$('#toolTip').remove();
	var button =$('#'+obj);
	//按钮的高
	var btnHeight=button.height();
	//按钮的宽
	var btnWidth=button.width();
	//按钮的offset
	var offset=button.offset();
	var html='<div id="toolTip">';
	html +='    <div class="toolTipContent">';
	html +='	    <div class="tipTitle">';
	html += '		  <table width="100%" border="0" cellspacing="0" cellpadding="0">';
	html +='            <tr>';
	html +='              <td width="90%">&nbsp;'+title+'</td>';
	html +='              <td width="10%"><img src="/Assets/Images/dialog-close.png" alt="关闭窗口" onclick="closeTip();" align="absmiddle" style="cursor:pointer"/>&nbsp;</td>';
	html +='            </tr>';
	html +='          </table>';
	html +='';
	html +='		</div>';
	html +='		<div class="tipBody">';
	html +=          content;
	html +='	  </div>';
	html +='	</div>';
	html +='</div>';
	$(document.body).prepend(html);
    $('#toolTip').css({
			top:offset.top+btnHeight+5+"px",
			left:offset.left+"px",
			height:height+"px",
			width:width+"px"
    }
    );
	//alert(html);
	$('#toolTip').fadeIn('slow');
}
function closeTip(){
	$('#toolTip').hide().fadeIn('slow').remove();
}
/**
 * 关闭对话框
 * @return
 */
function closeCartDialog(){
	$('#cartToolTip').hide().fadeIn('slow').remove();
}
/**
 * 购物车总数
 * @return
 */
function getCartItemTotal(){
	cartItemTotal= getCookie(cookieSpace+'_cartItemTotal');
	cartItemCount= getCookie(cookieSpace+'_cartItemCount');
	cartItemAmount= getCookie(cookieSpace+'_cartItemAmount');
	
}
function isLogin(){
	var userId=getCookie(cookieSpace+'[UserId]');
	if(userId==null || userId==''){
		return false;
	}
	return true;
}
// JavaScript Document
function getCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  {
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    {	
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function setCookie(cookieName,cookieValue,DayValue)
{
	var expire = "";
	var day_value=1;
	if(DayValue!=null)
	{
		day_value=DayValue;
	}
    expire = new Date((new Date()).getTime() + day_value * 86400000);
    expire = "; expires=" + expire.toGMTString();
	document.cookie = cookieName + "=" + escape(cookieValue) +";path=/"+ expire;
}

function delCookie(cookieName)
{
	var expire = "";
    expire = new Date((new Date()).getTime() - 1 );
    expire = "; expires=" + expire.toGMTString();
	document.cookie = cookieName + "=" + escape("") +";path=/"+ expire;
	//path=/
}


/**
 * 删除cookie
 * @param sName
 * @param sValue
 * @return
 */
function removeCookie(sName,sValue)
{
  return delCookie(sName);
}

function getObjectId(id){
	return document.getElementById(id);
}
function getSelectedValues(){
	var ids='';
	$("input[name='ids[]']").each(function(){
	 if($(this).attr("checked")==true){
		 ids += $(this).attr("value")+",";
	   }
	})
	ids = ids.substring(0,ids.length-1);//去掉最后一个多余的逗号
	return ids;
}

$(function() { 
$("#checkAll").click(function() { 
if ($(this).attr("checked") == true) { // 全选 
   $("input[name='ids[]']").each(function() { 
   $(this).attr("checked", true); 
  }); 
} else { // 取消全选 
   $("input[name='ids[]']").each(function() { 
   $(this).attr("checked", false); 
  }); 
} 
}); 
});
/**
 * 快速浏览
 * @param gId
 * @return
 */
function miniView(gId){
	var html ='<div id="fastPreview"><div class="fastBar"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="94%">&nbsp;</td><td width="6%" align="center"><img src="/Assets/Images/dialog-close.png" width="16" height="16" style="cursor:pointer" alt="关闭"  onclick="closeBlockUI()" /></td></tr></table></div><div class="fastBody" id="fastContent">&nbsp;&nbsp;<img src="/Assets/Images/loadding_1.gif" align="absmiddle"/></div></div>';
	$.blockUI({ message: html,css: {
        padding:        0,
        margin:         0,
        top:  ($(window).height()-555) /2 + 'px', 
        left: ($(window).width()-470) /2 + 'px',
        width: '470px',height: '555px' ,
        cursor: 'normal',
        textAlign:      'left',
        color:          '#000',
        border:         '3px solid #aaa',
        backgroundColor:'#fff'
    }}); 
	//加载内容
	$.ajax({ //一个Ajax过程    
		type: 'post',  //以post方式与后台沟通   
		url : '/goods/fastPreview', //与此php页面沟通   
		dataType:'text',//从php返回的值以 JSON方式 解释   
		data: 'goodsId='+gId, //发给php的数据有两项，分别是上面传来的u和p   
		success: function (res){
		    $('#fastContent').html(res);
	    }
	});
}
function closeBlockUI(){
	$.unblockUI();
}
function setStep(type){
	if(type==0){
		if(parseInt($("#buyNumber").val())<=1){
           return;
		}
		$("#buyNumber").val(parseInt($("#buyNumber").val())-1);
	}
	else{
		$("#buyNumber").val(parseInt($("#buyNumber").val())+1);
	}
}
function setPreview(src, thumb){
       var _self = $('#preview');
	   
		_self.hide();
		var img = new Image();
		$(img).load(function(){
			$('#preHref').attr('href', src);				 
			_self.attr("src", thumb);
			_self.fadeIn("slow");
		}).attr("src", thumb); 
   
}
/**
 * 按价格搜索
 * @return
 */
function searchByPrice(){
	var minPrice = parseInt($('#minPrice').val());
	var maxPrice = parseInt($('#maxPrice').val());
	if(minPrice==""){
		minPrice='-';
	}
	if(maxPrice==""){
		maxPrice='-';
	}
	
	if((minPrice !="-" && maxPrice!="-" ) && (minPrice>=maxPrice)){
		alert('起始价不能大于结束价！');
		return;
	}
	var urlPrefix = $('#pricePrefixUrl').val();
	urlPrefix = urlPrefix.replace('%min', minPrice);
	urlPrefix = urlPrefix.replace('%max', maxPrice);
	window.location.href=urlPrefix;
}

function changeCaptcha(obj){
	obj.src="/user/captcha/"+Math.random();  
}
function changeStock(obj, goodsId){
	obj.src="/api/stock/goodsId/"+goodsId+"/r/"+Math.random(); 
}
function cleanHistory(){
	$('#historyList').block({ 
			message: "&nbsp;&nbsp;<img src='/Assets/Images/loadding_1.gif' align='absmiddle'/>loading...", 
			css: { backgroundColor:'#ffffff',border: '3px solid #a00'} , 
			overlayCSS:  {
				   backgroundColor: '#333',
				   opacity:         '0.4'
			}
            });
	$.ajax({ //一个Ajax过程    
		type: 'post',  //以post方式与后台沟通   
		url : '/goods/cleanHistory', //与此php页面沟通   
		dataType:'json',//从php返回的值以 JSON方式 解释   
		data: '', //发给php的数据有两项，分别是上面传来的u和p   
		success: function (res){
		if(res.error==0){
			$('#historyList').html('已清空历史记录。');
			$.unblockUI();
			return;
		}
		
		  
	    }
	});
}
var ff5 = navigator.appName == 'Netscape' ? true : false; //mozilla firefox
var ns4 = document.layers ? true : false; //Netscape
var ie4 = document.all ? true : false; //Microsoft Internet Explorer
function BrowserDetect() {
	doc=window.document;
	navVersion=navigator.appVersion.toLowerCase();
	this.ie4=(!doc.getElementById&&doc.all)?true:false;
	this.ie5=(navVersion.indexOf("msie 5.0")!=-1)?true:false;
	this.ie55=(navVersion.indexOf("msie 5.5")!=-1)?true:false;
	this.ie6=(navVersion.indexOf("msie 6.0")!=-1)?true:false;
	this.ie7=(navVersion.indexOf("msie 7.0")!=-1)?true:false;
	this.isIE=(this.ie5||this.ie55||this.ie6||this.ie7)?true:false;
	this.ff5 = navigator.appName == 'Netscape' ? true : false; //mozilla firefox
	this.ns4 = document.layers ? true : false; //Netscape
	this.isGecko=!this.isIE;
};
/**
 * @classDescription 获取滚动条上边距
 * @author ice deng
 * @return (Array)
 */
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
};
/**
 * @classDescription 判断字符串是否为空
 * @author ice deng
 * @return (Boolean)
 */
function isNull(){
	var value = arguments[0];
	if(value == undefined || value == "undefined" || value == "" || value.length < 1)
		return true;
	return false;
};
Browser = new BrowserDetect();
/**
 * @classDescription 获取窗口大小
 * @author ice deng
 * @return (Array)
 */
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
};
var Ajax ={
	 call : function (url, params, callback, transferMode, responseType, asyn, quiet){
		 transferMode = transferMode.toLowerCase();
		 responseType = responseType.toLowerCase();
		 return $.ajax({ //一个Ajax过程    
					type: transferMode,  //以post方式与后台沟通   
					url : url, //与此php页面沟通   
					dataType:responseType,//从php返回的值以 JSON方式 解释   
					data: params, //发给php的数据有两项，分别是上面传来的u和p   
					success: callback
	  })
	}
}
function setShoppingUrl()
{
    setCookie("ShoppingBackUrl",location.href, 300);//设置返回页面
}
function backShoppingUrl()
{
    var Url=getCookie("ShoppingBackUrl");
    if(Url=="" || Url==undefined)Url="/index.html";
    location.href=Url;
}
function chat(){
	$.get('/index/liveChat', function(data) {
        $.blockUI({ message: data,css: {
        padding:        0,
        margin:         0,
        top:  ($(window).height()-355) /2 + 'px', 
        left: ($(window).width()-205) /2 + 'px',
        width: '355px',height: '205px' ,
        cursor: 'normal',
		float:'left',
        textAlign:      'left',
        color:          '#000'
    }}); 
    });
	
	
}
function changeOrderType(obj)
{
    url = $(obj).val();
	var minPrice = '';
	var maxPrice = '';
	url = url.replace('%min', minPrice);
	url = url.replace('%max', maxPrice);
	//alert(url);
	location.href=url;
}
function toolTip(obj,msg){var button=$(obj);$('#my_tool_tip').remove();var btnHeight=button.height();var btnWidth=button.width();var offset=button.offset();var html='<div id="my_tool_tip"><p>'+msg+'</p></div>';$(document.body).prepend(html);var width=$('#my_tool_tip').width();var height=$('#my_tool_tip').height();$('#my_tool_tip').css({top:offset.top-40+"px",left:offset.left-width/2-30+"px",height:height+"px",width:width+"px"});$('#my_tool_tip').fadeIn('slow');setTimeout(removeToolTip,3500);}
function removeToolTip(){$('#my_tool_tip').fadeOut('slow');}

var currentPage=1;function viewNext(){if(currentPage>=100){return;}
currentPage++;$('#pageNo').html(currentPage+'/100');$('#latestPro').block({message:"&nbsp;&nbsp;<img src='/assets/Images/loadding_1.gif' align='absmiddle'/>",css:{backgroundColor:'',border:'0px solid #a00'},overlayCSS:{backgroundColor:'#333',opacity:'0.3',cursor:''}});$.post('/goods/getLatestProducts',{'page':currentPage},function(result){if(result.error){$('#latestPro').unblock();}
else{$('#latestPro').unblock();$('#latestPro').html(result.content);}},"json");}
function viewPre(){if(currentPage<=1){return;}
currentPage--;$('#pageNo').html(currentPage+'/100');$('#latestPro').block({message:"&nbsp;&nbsp;<img src='/public/Images/loadding_1.gif' align='absmiddle'/>",css:{backgroundColor:'',border:'0px solid #a00'},overlayCSS:{backgroundColor:'#333',opacity:'0.3',cursor:''}});$.post('/goods/getLatestProducts',{'page':currentPage},function(result){if(result.error){$('#latestPro').unblock();}
else{$('#latestPro').unblock();$('#latestPro').html(result.content);}},"json");}

function actionContent(n){
	var proDetailControl=document.getElementById("proDetailControl");
	var proDetailList=proDetailControl.getElementsByTagName("span");
	for(var i=0,j=proDetailList.length;i<j;i++){
		(function(i,j){
			proDetailList[i].onclick=function(){
				for(var m=0;m<j;m++){
					proDetailList[m].className=m==i?"on":"";
				}
				document.getElementById("showProductDetail").innerHTML=document.getElementById("content"+i).innerHTML;
			}
		})(i,j);
	};

}
function fastBuy(obj, goodsId, number){
	    //是否登录了会员中心
		 if(!isLogin()){
			 showLoginDialog();
			 return;
		 }
		 Ajax.call('/user/addcart', 'goodsId=' +goodsId+'&number='+number, function(result){
			if(result.error==0){
		 value = result.content;
		 if(value==-2){
			 cartToolTip('订购数大于库存数', obj);
		 }
		 else if(value==-1){
			 cartToolTip('购物车中已存在此商品', obj);
			  $(obj).replaceWith("<a href='/cart.html' style='color:#FF0000' title='查看购物车'><img src='/assets/images/gous.gif' align='absmiddle' alt='查看购物车'>已订购</a>");
			
		 }
		 else if(value==-3){
			  cartToolTip('购物车已满', obj);
		 }
		 else if(value==-4){
			 cartToolTip('订购数量不能小于最小起订量。', obj);
		 }
		 else if(value==-5){
			  alert('订购数量不能大于最大订购量,此商品设置了最大订购数量！');
		 }
		 else if (value>0){
			  cartToolTip('商品已放入购物车', obj);
			  $(obj).replaceWith("<a href='/cart.html' style='color:#FF0000' title='查看购物车'><img src='/assets/images/gous.gif' align='absmiddle' alt='查看购物车'>已订购</a>");
			 /*if(confirm('商品已放入购物车\n点击确认查看购物车，点击取消停留在本页。')){
				 window.location.href='/user/cart'
			 }*/
		 }
		 else{
			 alert('oh ho出错啦!');
		 }}
		}, "POST", "JSON");
}
/**
 * 加入购物车
 * @param gId
 * @return
 */
function addFav(gId, obj){
	
	//没有登录
	if(false == isLogin()){
		//弹出登录窗口
		showLoginDialog();
	}
	else{
		//加入收藏
	    Ajax.call('/userZone/addfav', 'gId=' + gId, function (result){
	    toolTip(obj, '已放入收藏夹！');}, "POST", "JSON");
	}
}
function showLoginDialog(){
	var html='<div class="dialog"><div class="dialog_title_bar"><div class="dialog_t_1">登录会员中心：</div><div class="dialog_t_2"><img src="/assets/images/x.png" onclick="closeLoginDialog()" align="absmiddle"/></div></div><div class="dialog_body"><table width="100%" border="0" style="float:left;"><tr><td width="8%" height="23" align="right">用 户 名：</td><td width="8%" ><input type="text" name="username" id="username"><a href="/fastreg.html">注册新会员</a></td></tr><tr><td align="right">登录密码：</td><td><input type="password" id="password" name="password">&nbsp;<a href="/forget.html">忘记密码？</a></td></tr><tr><td colspan="2" align="center"><img  src="/assets/images/loginBtn.gif" onclick="miniLogin()" id="dialog_sub_btn" style="cursor:pointer"></td></tr></table></div></div>';
	
	var width=350;var height=200;$.blockUI({message:html,css:{padding:0,margin:0,top:($(window).height()-width)/2+'px',left:($(window).width()-height)/2+'px',width:width+'px',height:height+'px',cursor:'normal',textAlign:'left',color:'#000'},overlayCSS:{backgroundColor:'#000',opacity:0.6}});$('#password').bind('keyup',function(event){if(event.keyCode==13){miniLogin()}});
}
function closeLoginDialog(){
	$.unblockUI();
}
function miniLogin(){
	var username = $("#username").val();
	var password = $("#password").val();
	
	var validCode = '';
	
	var msg = '';

    if (username.length == 0)
   {
      msg += '用户名不能为空。\n';
	  $('#username').focus();
   }

   if (password.length == 0)
   {
      msg +=   '密码不能为空。\n';
	  $('#password').focus();
   }
  
   if (msg.length > 0)
   {
      alert(msg);
      return false;
  }
  else
  {
	//登录
	Ajax.call('/user/signin', 'username=' + username + '&password=' + encodeURIComponent(password) + '&captcha=' + validCode, signinResponsei, "POST", "JSON");
    return false;
  }
}
function signinResponsei(result){
	if(result.error>0){
		alert(result.message);
	}
	else{
		$.unblockUI();
		$.growlUI('登录提示：', '<img src="/Assets/Images/yes.png" align="absmiddle">&nbsp;登录成功!'); 
	}
	
}
function chooseThisSize(obj, name, store, indexId){
	  $("#attributes li").each(function (index, domEle) {
		 if(domEle.className!='nocm'){
			 domEle.className='cm';
		 }
	     
	  });
	  $('#IndexId').val(indexId);
	  obj.className = 'cm2';
	 $('#selectedSize').html(name);
}

