﻿
var appShop=new Object();

dcs.init.loadRes("codes");


appShop.toProductDiscountPrice=function(strPrice,strDiscount)
{
	if (!dcs.common.isNumber(strDiscount)) strDiscount=100;
	var re=strPrice*strDiscount/100;
	re=dcs.codes.toPrice(re);
	return re;
}

appShop.toProductDiscount=function(strDiscount)
{
	if (!dcs.common.isNumber(strDiscount)) strDiscount=100;
	strDiscount=strDiscount/10;
	var re="";
	if (strDiscount<10) re="<font class=\"mark\">"+strDiscount+"折</font>";
	else re="不打折";
	return re;
}

appShop.toProductAmount=function(strAmount,strUnit)
{
	if (!dcs.common.isNumber(strAmount)) strAmount=0;
	var re="";
	if (strAmount<1) re="缺货";
	else if (strAmount==999999999) re="不限";
	else re=strAmount+strUnit;
	return re;
}

appShop.toProductEmoney=function(intEmoney,strUnit)
{
	var re="不可以使用金币购买";
	if (intEmoney > 0) re="<font class=\"emoney\">"+intEmoney+"</font> "+strUnit;
	return re;
}

appShop.toButtonBuyEmoney=function(intEmoney,intID)
{
	var re="";
	if (isNum(intEmoney) && toNum(intEmoney)>0) re="<a href=\""+dcs.config.getURL()+"shop/cart.asp?eid="+intID+"\"><img class=\"icon\" src=\""+dcs.config.getURL("skin")+"images/common/ico_emoney.gif\" alt=\"金币("+intEmoney+")购买\"></a>";
	return re;
}


appShop.toCartStatus=function(strNum)
{
	var re='';
	if (strNum>0) re='<font class=\"gray\">您已订购 <font class=\"total\">'+strNum+'</font> 件商品</font>';
	else re='<font class=\"gray\">您还没有订购商品</font>';
	return re;
}

appShop.toOrderPayable=function(strOrdernum,strPayable)
{
	var re='';
	if (strPayable==1)
	{
		tmpURL=dcs.config.getURL("common")+"payment.asp?channel=shop&ordernum="+strOrdernum;
		re=' <a href="'+tmpURL+'" title="点击重新在线支付订单 '+strOrdernum+'">支付</a>';
	}
	return re;
}


appShop.doCartCheck=function(strfrm)
{
	dcs.init.loadUtil("error");
	var err=new VDCS.utilError();
	if (strfrm.o_realname.value.length==0)
	{
		err.addItem("请输入收货人姓名！");
		strfrm.o_realname.focus();
	}
	if (strfrm.o_address.value.length==0)
	{
		err.addItem("请输入收货人具体地址！");
		strfrm.o_address.focus();
	}
	if (strfrm.o_postcode.value.length==0)
	{
		err.addItem("请输入邮政编码！");
		strfrm.o_postcode.focus();
	}
	if (strfrm.o_phone.value.length==0)
	{
		err.addItem("请输入联系电话！");
		strfrm.o_phone.focus();
	}
	if (strfrm.o_email.value.length==0)
	{
		err.addItem("请输入电子邮件！");
		strfrm.o_email.focus();
	}
	err.doPop();
	var re=err.isCheck();
	if (re)
	{
		re=window.confirm("您确定填写的收货信息准确无误吗？\n\n提交生成订单后将不可更改！");
	}
	return re;
}


// hold code for old version
appShop.getProductPrice=function(strPrice,strDiscount) { return this.toProductDiscountPrice(strPrice,strDiscount); }
appShop.getProductDiscount=function(strDiscount) { return this.toProductDiscount(strDiscount); }
appShop.getProductAmount=function(strAmount,strUnit) { return this.toProductAmount(strAmount,strUnit); }
appShop.getOrderPayable=function(strOrdernum,strPayable) { return this.toOrderPayable(strOrdernum,strPayable); }
appShop.getProductEmoney=function(intEmoney,strUnit) { return this.toProductEmoney(intEmoney,strUnit); }
appShop.getEmoneyBuyBtn=function(intEmoney,intID) { return this.toButtonBuyEmoney(intEmoney,intID); }

