function Product(){this.m_id=null;this.m_name=null;this.m_presText="";this.m_module=null;this.m_desc=null;this.m_ttp=null;this.m_previews=[];this.m_priceRange=null;this.m_modelCount=null}
Product.getById=function(id){return Product._getProductById(id)}
Product.createFromXML=function(dom,node){var prod=new Product();if(!prod._readFromXML(dom,node))
return null;return prod}
Product.prototype._readFromXML=function(dom,node){this.m_id=parseInt(node.getAttribute("id"));this.m_name=node.getAttribute("name");this.m_presText=XMLUtils.getChildText(node,"description");this.m_module=node.getAttribute("module");this.m_ttp=parseInt(XMLUtils.getChildText(node,"ttp"));var types=new Array("small","normal","large");this.m_previews=[];for(var i=0,n=types.length;i<n;++i){var previewType=types[i];for(var j=0;j<42;++j){var previewNode=XMLUtils.selectSingle
(node,"preview[@type='"+previewType+"' and @index='"+j+"']");if(previewNode==null)
break;if(!this.m_previews[j])
this.m_previews[j]=[];this.m_previews[j][previewType]=Product.Preview.createFromXML(previewNode)}}
var homeNode=XMLUtils.getChildByTagName(node,"home");this.m_desc=ProductDescription.createFromXML(dom,homeNode);var prNode=XMLUtils.getChildByTagName(node,"price-range");this.m_priceRange=Product.PriceRange.createFromXML(prNode);var modelsNode=XMLUtils.getChildByTagName(node,"models");this.m_modelCount=parseInt(modelsNode.getAttribute("count"));return true}
Product.prototype.getId=function(){return this.m_id}
Product.prototype.getName=function(){return this.m_name}
Product.prototype.getPresText=function(){return this.m_presText}
Product.prototype.getDescription=function(){return this.m_desc}
Product.prototype.getPriceRange=function(){return this.m_priceRange}
Product.prototype.getTTP=function(){return this.m_ttp}
Product.prototype.getModule=function(){return this.m_module}
Product.prototype.getModelCount=function(){return this.m_modelCount}
Product.prototype.getPreviewCount=function(){return this.m_previews.length}
Product.prototype.getPreview=function(index,type){if(index<0||index>=this.m_previews.length)
return null;var preview=this.m_previews[index];return(preview[type]?preview[type]:null)}
Product._getProductById=function(id){if(Product.s_productById==null)
Product._getProducts();if(Product.s_productById[id])
return Product.s_productById[id];return null}
Product.s_productById=null;Product.s_products=null;Product._getProducts=function(){Product.s_productById=[];Product.s_products=new ArrayList();var webs=new IDM.WebService
(new URL("/shop/enum-products.php").addParam("shop",g_shopId));webs.call();if(!webs.isSuccess()){if(JSUtils.isDebug())
alert(webs.getError())}
var doc=webs.getResult();var root=XMLUtils.getRootElement(doc);var prodNodes=XMLUtils.getChildrenByTagName(root,"product");var products=new ArrayList();for(var i=0,n=prodNodes.length;i<n;++i){var prodNode=prodNodes[i];var prod=Product.createFromXML(doc,prodNode);if(prod==null)
continue;Product.s_products.add(prod);Product.s_productById[prod.getId()]=prod}}
Product.Preview=function(src,width,height,border){this.m_src=src;this.m_width=width;this.m_height=height;this.m_border=border}
Product.Preview.createFromXML=function(node){return new Product.Preview(node.getAttribute("url"),parseInt(node.getAttribute("width")),parseInt(node.getAttribute("height")),node.getAttribute("border")==="true")}
Product.Preview.prototype.getSource=function(){return this.m_src}
Product.Preview.prototype.getWidth=function(){return this.m_width}
Product.Preview.prototype.getHeight=function(){return this.m_height}
Product.Preview.prototype.getSize=function(){return new Size(this.getWidth(),this.getHeight())}
Product.Preview.prototype.hasBorder=function(){return this.m_border}
function ProductDescription(){this.m_homeType=0;this.m_homeText=""}
ProductDescription.prototype.getHomeType=function(){return this.m_homeType}
ProductDescription.prototype.getHomeText=function(){return this.m_homeText}
ProductDescription.createFromXML=function(dom,node){var desc=new ProductDescription();if(!desc._readFromXML(dom,node))
return null;return desc}
ProductDescription.prototype._readFromXML=function(dom,node){this.m_homeType=parseInt(node.getAttribute("type"));this.m_homeText=XMLUtils.getElementText(node);return true}
Product.PriceRange=function(){this.m_minPrice=null;this.m_maxPrice=null}
Product.PriceRange.prototype.getMinPrice=function(){return this.m_minPrice}
Product.PriceRange.prototype.getMaxPrice=function(){return this.m_maxPrice}
Product.PriceRange.createFromXML=function(node){var pr=new Product.PriceRange();if(!pr._readFromXML(node))
return null;return pr}
Product.PriceRange.prototype._readFromXML=function(node){this.m_minPrice=node.getAttribute("min");this.m_maxPrice=node.getAttribute("max");return true}