/**
 * author	liqiu
 * lastmodified		2010-08-25
 */
function def_song_photo(obj)
{
	//obj.src='/images/nopic.jpg';
	obj.src='http://www.lianxi123.com/images/nopic.jpg';
	obj.style.width='100px';
	obj.style.height='100px';
}
function def_shop_photo(obj,width,height)
{
	//obj.src='/images/nopic.jpg';
	obj.src='http://www.lianxi123.com/images/nopic.jpg';
	obj.style.width=width+'px';
	obj.style.height=height+'px';
}
function def_user_photo(obj,width,height)
{
	obj.src='http://www.lianxi123.com/images/nopiclogo'+width+height+'.jpg';
	obj.style.width=width+'px';
	obj.style.height=height+'px';
}
/*************用户注册************/
function checkRegForm()
{
	//说明修改密码
	if ($('#password').val() == "")
	{
		alert("密码不合法");
		$('#password')[0].focus();
		return false;
	}
	else
	{
		if ($('#password').val().length < 6)
		{
			alert("密码个数不能小于六个");
			$('#password')[0].focus();
			return false;
		}
	}
	
	
	//用户昵称
	if ($('#nickname').val() == "")
	{
		alert("会员姓名不可以为空");
		$('#nickname')[0].focus();
		return false;
	}
	
	//地址
	if ($('#address').val() == "")
	{
		alert("通信地址不可以是空");
		$('#address')[0].focus();
		return false;
	}
	
	//email
	pattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	var oEmail = document.getElementById("loginname");
	if (!pattern.test(oEmail.value))
	{
		alert("您的email不合法");
		$('#loginname')[0].focus();
		return false;
	}
	
	//电话
	pattern = /^\d+([-\d])\d+$/;
	if (!pattern.test($('#phone').val()))
	{
		alert("您的电话号码不合法");
		$('#phone')[0].focus();
		return false;
	}
	return true;
}
var loginname;
//检查用户名
function checkloginname(flag)
{
	loginname = $('#loginname').val();
	if (loginname=='')
	{
		return ;
	}
	$.get("/user/checkloginname/", { loginname: loginname, rad: Math.random() }, function(data)
	{
		if (data == -14)
		{
			if (flag)
			{
				alert('恭喜：email名可以使用！')
			}
			return true;
		}
		else
		{
			alert('对不起，email已经被占用'+data);
		}
	});
}
/******************订单页面*************/
//计算总价格
function sumPrice()
{
	var sumprice=0;
	$(".cart_price").each(function(){
		sumprice = sumprice + parseFloat($(this).html());
	});
	$("#sumprice").html(sumprice);
	
	if (document.URL.indexOf('cart')!=-1)
	{
		if (shop_price>sumprice)
		{
			$("#price_ci").html('<a href="/" style="color:red;">对不起，本店商品起送价格是'+shop_price+'元,点击返回首页修改<br />	</a>');
			$('#next_startorder').hide();//隐藏下一步
			return false;
		}
		else
		{
			$("#price_ci").html('<a href="/">请确认以上商品准确无误，如果您需要修改所购商品,请返回首页<br />	</a>');
		}
		$('#next_startorder').show();//显示下一步
	}
	else
	{
		
		if (shop_price>sumprice)
		{
			$("#price_ci").html('<a href="/order/cart" style="color:red;">对不起，本店商品起送价格是'+shop_price+'元,点击返回购物车修改<br />	</a>');
			$('#startorder_submit').slideUp();//隐藏提交
			return false;
		}
		else
		{
			$("#price_ci").html('<a href="/order/cart/">请确认以上商品准确无误，如果您需要修改所购商品,请返回购物车<br />	</a>');
		}
		$('#startorder_submit').slideDown();//显示提交
	}
	return true;
}


//计算总积分
function sumScore()
{
	var sumscore=0;
	$(".cart_score").each(function(){
		sumscore = sumscore + parseFloat($(this).html());
	});
	$("#sumscore").html(sumscore);
	
	var sumprice=0;
	$(".cart_price").each(function(){
		sumprice = sumprice + parseFloat($(this).html());
	});
	$("#sumprice").html(sumprice);
	
	if (jifen <= sumscore)
	{
		if (document.URL.indexOf('cart')!=-1)
		{
			if (jifen<sumscore)
			{
				$("#price_ci").html('<a href="/" style="color:red;">对不起，您的积分不足！点击返回首页修改<br />	</a>');
				$('#next_startorder').hide();//隐藏下一步
				return false;
			}
			$('#next_startorder').show();//显示下一步
		}
		else
		{
			if (jifen<sumscore)
			{
				$("#price_ci").html('<a href="/order/cart" style="color:red;">对不起，您的积分不足！点击返回购物车修改<br />	</a>');
				$('#startorder_submit').slideUp();//隐藏提交
				return false;
			}
			$('#startorder_submit').slideDown();//显示提交
		}
		return true;
	}
}



//删除商品
function delCart(pids)
{
	//alert(pids);
	
	$.get("/order/delcart/?pids="+pids);
}

//修改商品数量
function changenum(pid,num,price)
{
	if (parseInt(num)<0)
	{
		num=0;
		$("#num_"+pid).val(0);
	}
	$.get("/order/ajaxchangeproductnum/", { pid: pid, num: num, rand:Math.random() },
	function(data){
//	alert("Data Loaded: " + data);
	});
	$("#price_"+pid).html(price*num);
	sumPrice();
	sumScore();
	return false;
}

//修改商品数量
function changezpnum(pid,num,price)
{
	if (parseInt(num)<0)
	{
		num=0;
		$("#num_"+pid).val(0);
	}
	$("#price_"+pid).html(price*num);
	sumPrice();
	return false;
}

//清空购物车
function delallcart()
{
	pids="";
	$(".productid").each(function(){
		pid=$(this).html();
		pids = pids + "," + pid;
		$("#cart_"+pid).slideUp();
	});
	$.get("/order/clearcart/");
	$("#sumprice").html(0);
	$("#sumscore").html(0);
}

var LianxiHead = {
   bookmarksite: function(){
   var sTitle=document.title;
   var sURL=window.location.href;
   try {   
        window.external.addFavorite(sURL, sTitle);   
    } catch (e) {   
        try {   
            window.sidebar.addPanel(sTitle, sURL, "");   
        } catch (e) {   
            alert("加入收藏失败，请使用Ctrl+D进行添加");   
        }   
    }   
   }
}
window.onerror=function(){return true;}
function ShowHide(tabName,tabId,tabNumber){
	for(i=0;i<tabNumber;i++){
		document.getElementById(tabName+"_con"+i).style.display = "none";
		document.getElementById(tabName+"_tab"+i).className = "";
	}
	document.getElementById(tabName+"_con"+tabId).style.display = "block";
	document.getElementById(tabName+"_tab"+tabId).className = "cur";	
}
