﻿function Products()
{
    this.key="p_items";
    this.Set = function(id,count,size)
    {
        var cookie = new Cookie(this.key + id);  
        //cookie.title=title;          
        cookie.size=size;
        cookie.count=count;
        cookie.id=id;
        cookie.store(1);        
    }
    this.Remove = function(id)
    {
        var cookie = new Cookie(this.key + id);
        if(cookie!=null)
            cookie.remove();
    } 
    this.items=null;
    this.count=0;
    this.GetProducts = function(){
        this.items=new Array();
        this.count=0;
        var allcookies = document.cookie;
        if (allcookies == "") return;
        var cookies = allcookies.split(';');
        var cookie = null;
        for(var i = 0; i < cookies.length; i++) {
            if (cookies[i].trim().indexOf(this.key)==0) { 
                cookie = new Cookie(cookies[i].substring(0, cookies[i].indexOf("=")))
                if(cookie!=null && cookie['id']){
                    this.items[this.count++]=cookie;
                }
            }
        }
    }
    this.Get=function(id)
    {
        this.GetProducts();
        for(var i=0;i<this.count;i++)
        {
            if(this.items[i]["id"]==id)
                return this.items[i]
        }
        return null;
    }
}
var list=new Products();
list.GetProducts();

function OneMore(id,size)
{
    var item=list.Get(id);
    if(item==null)
    {
        list.Set(id,1,size);        
    }
    else
    {
        list.Set(id,parseInt(item["count"])+1,size);
    }   
}
