  
var ALL_DIVISION_CODE="1";var SELLER=0;var ORDINARY=1;var FAST=2;var EMS=7;var VIRTUAL=3;var CORPFAST=4;var POSTFAST=5;var ordPrefix='ord';var corpFastPrefix='corpFast';var postFastPrefix='postFast';var emsPrefix='ems';function PostageItem(){this.id=0;this.postageid=0;this.mode=0;this.destination="";this.fee=0.0;this.increment=0.0;}
PostageItem.prototype.isDefault=function(){return(ALL_DIVISION_CODE==this.destination);}
PostageItem.prototype.isContains=function(destCode){return(-1!=this.destination.indexOf(destCode));}
function Postage(){this.id=0;this.userid="";this.name="";this.memo="";this.postageItemsMap={};this.postageItems=[];this.ordItems=[];this.corpFastItems=[];this.postFastItems=[];this.emsItems=[];}
Postage.prototype.getDefaultOrdItem=function(){for(var i=0;i<this.ordItems.length;i++){var postageItem=this.ordItems[i];if(postageItem.isDefault()){return postageItem;}}
return null;}
Postage.prototype.getDefaultCorpFastItem=function(){for(var i=0;i<this.corpFastItems.length;i++){var postageItem=this.corpFastItems[i];if(postageItem.isDefault()){return postageItem;}}
return null;}
Postage.prototype.getDefaultPostFastItem=function(){for(var i=0;i<this.postFastItems.length;i++){var postageItem=this.postFastItems[i];if(postageItem.isDefault()){return postageItem;}}
return null;}
Postage.prototype.getDefaultEmsItem=function(){for(var i=0;i<this.emsItems.length;i++){var postageItem=this.emsItems[i];if(postageItem.isDefault()){return postageItem;}}
return null;}
Postage.prototype.hasOtherPostageItem=function(modeEnum){if(null==modeEnum||0>=modeEnum){return false;}
var list=this.getPostageItemsByModeEnum(modeEnum);return(null!=list&&1<list.length)?true:false;}
Postage.prototype.hasOrdinary=function(){return(null!=this.ordItems&&0<this.ordItems.length)?true:false;}
Postage.prototype.hasOtherOrdItem=function(){return(null!=this.ordItems&&1<this.ordItems.length)?true:false;}
Postage.prototype.hasCorpFast=function(){return(null!=this.corpFastItems&&0<this.corpFastItems.length)?true:false;}
Postage.prototype.hasOtherCorpFastItem=function(){return(null!=this.corpFastItems&&1<this.corpFastItems.length)?true:false;}
Postage.prototype.hasPostFast=function(){return(null!=this.postFastItems&&0<this.postFastItems.length)?true:false;}
Postage.prototype.hasOtherPostFastItem=function(){return(null!=this.postFastItems&&1<this.postFastItems.length)?true:false;}
Postage.prototype.hasEms=function(){return(null!=this.emsItems&&0<this.emsItems.length)?true:false;}
Postage.prototype.hasOtherEmsItem=function(){return(null!=this.emsItems&&1<this.emsItems.length)?true:false;}
Postage.prototype.getPostageItemsByModeEnum=function(modeEnum){if(null==modeEnum||0>=modeEnum){return this.postageItems;}
switch(modeEnum){case ORDINARY:return this.ordItems;case CORPFAST:return this.corpFastItems;case POSTFAST:return this.postFastItems;case EMS:return this.emsItems;default:return this.postageItems;}}
Postage.prototype.getPostageItemsByDestCode=function(destCode){if(null==destCode||0==destCode.length){return null;}
var list=[];var ordItem=this.getPostageItemByDestCode(destCode,ORDINARY);var corpFastItem=this.getPostageItemByDestCode(destCode,CORPFAST);var postFastItem=this.getPostageItemByDestCode(destCode,POSTFAST);var emsItem=this.getPostageItemByDestCode(destCode,EMS);if(null!=ordItem){list.push(ordItem);}
if(null!=corpFastItem){list.push(corpFastItem);}
if(null!=postFastItem){list.push(postFastItem);}
if(null!=emsItem){list.push(emsItem);}
return list;}
Postage.prototype.getPostageItemByDestCode=function(destCode,modeEnum){if(null==destCode||0==destCode.length||null==modeEnum||0>=modeEnum){return null;}
var postageItems=this.getPostageItemsByModeEnum(modeEnum);var defaultPostageItem=null;for(var i=0;i<postageItems.length;i++){var postageItem=postageItems[i];if(postageItem.isContains(destCode)){return postageItem;}
if(postageItem.isDefault()){defaultPostageItem=postageItem;}}
return defaultPostageItem;}
Postage.prototype.getPostageItemById=function(postageid){if(null==postageid||0>=postageid){return null;}
return this.postageItemsMap[postageid];}
Postage.prototype.isSinglePostageMode=function(){var modeCount=0;if(this.hasOrdinary()){modeCount++;}
if(this.hasCorpFast()){modeCount++;}
if(this.hasPostFast()){modeCount++;}
if(this.hasEms()){modeCount++;}
if(1==modeCount){return true;}else{return false;}}
function buildPostageItem(id,postageid,mode,destination,fee,increment){var postageItem=new PostageItem();postageItem.id=id;postageItem.postageid=postageid;postageItem.mode=mode;postageItem.destination=destination;postageItem.fee=fee;postageItem.increment=increment;postage.postageItems.push(postageItem);postage.postageItemsMap[id]=postageItem;switch(postageItem.mode){case ORDINARY:postage.ordItems.push(postageItem);break;case CORPFAST:postage.corpFastItems.push(postageItem);break;case POSTFAST:postage.postFastItems.push(postageItem);break;case EMS:postage.emsItems.push(postageItem);break;default:break;}}
function Postagefees(){this.ordFee=-1;this.corpFastFee=-1;this.postFastFee=-1;this.emsFee=-1;this.fastFee=-1;}
function calculatePostfees(postage,destCode,count){if(null==postage||null==destCode||0==destCode.length||0>count){return null;}
var postfees={};var postageItems=postage.getPostageItemsByDestCode(destCode);for(var i=0;i<postageItems.length;i++){var postageItem=postageItems[i];var postfee=0.0;if(0<count){postfee=(postageItem.fee*100+postageItem.increment*(count-1)*100)/100;}
postfees[postageItem.mode]=postfee;}
return postfees;}
