<!--
//######################
//#Vector object
//######################
function Vector()
{
    this.V_LIMIT = 25;
    this.V_LIMIT_CNT = 0;
    this.V_SIZE = 0;
    this.vectorArray = new Array( this.V_LIMIT );
    this.add=add;  
    this.size=size;
    this.show=show;
    this.remove=remove;   
    this.get=get;   
}
Vector.prototype.toString=vectorobjToString;
function vectorobjToString()
{
	return "Vector.toString():\nV_LIMIT=" + this.V_LIMIT + "\nV_LIMIT_CNT=" + this.V_LIMIT_CNT + "\nV_SIZE=" + this.V_SIZE;
}

function size()
{
	return this.V_SIZE;
}

function add( theobject )
{
    if ( this.V_LIMIT_CNT >= this.V_LIMIT-1 )
    {
        this.V_LIMIT_CNT = 0;
        this.V_SIZE = 0;
            //Increase the vector size
        var tmparray = new Array( this.vectorArray.length + this.V_LIMIT );
        for (y=0; y<this.vectorArray.length; y++)
        {
            if ( this.vectorArray[ y ] != null )
            {
                tmparray[ this.V_SIZE ] = this.vectorArray[ y ];
                this.V_SIZE++;
            }
        }
            //Create new array, increase its size
        this.vectorArray = tmparray;
        tmparray = null;
    }

        //Add the object
    this.vectorArray[ this.V_SIZE ] = theobject;
    //document.write( '<br>' + this.vectorArray[0].id + " " + this.vectorArray[0].desc + " " + this.vectorArray[0].price );
		//Increace the vector size and counter
    this.V_LIMIT_CNT++;
    this.V_SIZE++;
}

function show()
{
	document.write( '<br>Vector size: ' + this.size() );
	for (y=0; y<this.vectorArray.length; y++)
	{
	    if ( this.vectorArray[ y ] != null )
	    {
	        document.write( '<br>[' + y + '] ' + this.vectorArray[ y ] );
	    }
	}
}

	/*
	 * Position start from 0 to this.V_LIMIT
	 */
function remove( pos )
{
    var tmparray = new Array( this.V_LIMIT );
    var tmp_size = 0;
    var tmp_cnt = 0;
    var deleted = false;
    
	for (y=0; y<this.vectorArray.length; y++)
	{
	    if ( this.vectorArray[ y ] != null )
	    {
	    		//Don't include the desired position
	    	if ( pos != y )
	    	{
                tmparray[ tmp_size ] = this.vectorArray[ y ];
                tmp_size++;
                tmp_cnt++;
                if ( tmp_cnt > this.V_LIMIT )
                	tmp_cnt = 0;
	    	} else deleted = true;
	    }
	}
	
	if ( deleted )
	{
			//We deleted someting
	    this.vectorArray = tmparray;
	    this.V_LIMIT_CNT = tmp_cnt;
	    this.V_SIZE = tmp_size;
	}	
}

function get( pos )
{
	var obj = null;
	for (y=0; y<this.vectorArray.length; y++)
	{
	    if ( this.vectorArray[ y ] != null )
	    {
				//Don't include the desired position
	    	if ( pos == y )
	    	{
	    		obj = this.vectorArray[ y ];
	    		break;
	    	}
	    }
	}
	
	return obj;
}
-->
