function ReleaseTable(options)
{
    ReleaseTable.prototype = Table.call(this, options); //calling the base constructor
    this.m_useHeader = true;

 //   this.m_banks = new Array();


    this.getRowId = function( rowInfo )
    {
        if(rowInfo.release_id==0)
        {
            rowInfo.release_id="new_"+this.m_nextWidgetId++;
        }

        return rowInfo.release_id;
    }

    this.configureBank = function(widgetBank, rowInfo)
    {
            widgetBank.m_autoSave = false;
            widgetBank.m_collapsible = false;

           widgetBank.addWidget({  name:"release_country_code",
                                    label:"Country:",
                                    type:"select",
                                    width:130,
                                    showAlt:true,
                                    nullOption:{val:'',label:'Select'},
                                    values:[rowInfo.release_country_code],
                                    valueMap:genCountryMap( rowInfo.release_country_code ) });

            widgetBank.addWidget({  name:"release_date",
                                    label:"Release Date:",
                                    width:180,
                                    upcoming:true,
                                    help:"If a release date for this toy has not yet been announced, you can check the \"upcoming\" box. For toys that have already been released, fill in as much of the date as you can. You can leave day and month unselected if you're unsure of them, but you have to specify a year.",
                                    values:[rowInfo.release_date_m, rowInfo.release_date_d, rowInfo.release_date_y, rowInfo.release_date_upcoming],
                                    type:"date_select" });

            widgetBank.addWidget({  name:"release_price",
                                    label:"Retail Price:",
                                    width:60,
                                    type:"float",
                                    length:128,
                                    values:[rowInfo.release_price]});
    }
}

function FormTable(options)
{
    FormTable.prototype = Table.call(this, options); //calling the base constructor

    this.m_image_list = options.image_list;
    this.m_useHeader = true;

    this.onNeighborChange = function( action, options )
    {
        if(action=="add")
        {
            this.m_image_list.push(options);
        }
        for( var i = 0; i < this.m_banks.length; i++ )
        {
            this.m_banks[i].onNeighborChange( action, options );
        }
    }

    this.postAdd = function( widget )
    {
        if(widget.m_type=="image")
        {
            widget.m_imageList = this.m_image_list;
        }
    }

    this.configureBank = function(widgetBank, rowInfo)
    {
        widgetBank.m_autoSave = false;
        widgetBank.m_collapsible = false;

        widgetBank.addWidget({  name:"part_form_form",
                                label:"Form:",
                                type:"category",
                                width:150,
                                help:"Browse your way to the proper form, or shape, of this part. If you know the number of the form you want already, you can type it into the text box.",
                                showAlt:true,
                                path:rowInfo.path,
                                data:rowInfo.data,
                                values:[rowInfo.part_form_form]
                            });

        widgetBank.addWidget({  name:"part_form_override",
                                label:"Override:",
                                width:90,
                                help:"You can refine the default form name with a little extra information, here. For example, if the default name is <b>Chevrolet</b>, you can enter <b>\"Battle Mode\" Chevrolet</b>, and from here on out that is the name that will be displayed for this form when viewing this part.",
                                values:[rowInfo.part_form_override],
                                type:"text" });

        widgetBank.addWidget({  name:"part_form_photo",
                                label:"Image:",
                                width:70,
                                help:"Choose a photo from the list. Choose the \"No photo needed\" option for forms that don't require a transformation (for dual-purpose parts, like tail/clubs).",
                                imageList:rowInfo.imageList,
                                values:[rowInfo.part_form_photo],
                                type:"image" });

        if(!rowInfo.instant_remove)
        {
            widgetBank.addWidget({  name:"part_form_delete",
                                label:"Delete:",
                                type:"checkbox",
                                width:45,
                                help:"Check this box to remove this form from this part.",
                                values:[rowInfo.part_form_delete]
                            });
        }
    }
}

function PhotoTable(options)
{
    PhotoTable.prototype = Table.call(this, options); //calling the base constructor

    this.m_useHeader = true;

    this.getRowId = function( rowInfo )
    {
        if(rowInfo.photo_id==1)
        {

            rowInfo.photo_id="new_"+this.m_nextWidgetId++;
        }

        return rowInfo.photo_id;
    }

    this.configureBank = function(widgetBank, rowInfo)
    {
        widgetBank.m_autoSave = false;
        widgetBank.m_collapsible = false;

        widgetBank.addWidget({  name:"photo_id",
                                label:"Photo:",
                                width:120,
                                pathSmall:rowInfo.path_small,
                                pathLarge:rowInfo.path_large,
                                initialized:rowInfo.initialized,
                                sizeSmall:rowInfo.size_small,
                                sizeLarge:rowInfo.size_large,
                                fileSize:rowInfo.file_size,
                                recordType:rowInfo.record_type,
                                canUpload:rowInfo.can_upload,
                                help:"Choose an image from your computer to upload.",
                                values:[rowInfo.photo_id],
                                type:"imageUpload" });

        widgetBank.addWidget({  name:"photo_submitter",
                                label:"Submitted by:",
                                type:"select",
                                width:90,
                                valueMap:rowInfo.credit_list,
                                help:"who done took this photo?",
                                showAlt:true,
                                path:rowInfo.path,
                                values:[rowInfo.photo_submitter]
                            });
        widgetBank.addWidget({  name:"photo_caption",
                                label:"Caption:",
                                type:"text",
                                width:90,
                                help:"You can enter some text here, and it will be displayed when viewing this image in the gallery.",
                                values:[rowInfo.photo_caption]
                            });

        if(!rowInfo.instant_remove)
        {
           var photoDelete = widgetBank.addWidget({  name:"photo_delete",
                                label:"Delete:",
                                type:"checkbox",
                                width:45,
                                help:"Check this box to remove this photo from the system forever!",
                                values:[rowInfo.photo_delete]
                            });

            photoDelete.onLoad = function()
            {
                photoDelete.customChange();
            }

            photoDelete.customChange = function()
            {
                var name = this.m_widgetBank.m_id;
                var enabled = true;
                enabled = this.m_element.is(':checked');
                this.m_widgetBank.m_table.m_tableMgr.onNeighborChange( "enable", {"photo_id":name, "enabled":!enabled});
            }

        }
    }
}
PhotoTable.prototype = new Table();
PhotoTable.prototype.constructor = PhotoTable;


function CollectTable(options)
{
    CollectTable.prototype = Table.call(this, options); //calling the base constructor
    this.getTitle = function( rowInfo )
    {
        var title =  "#"  + rowInfo.collect_id + " - "
                    + rowInfo.collect_current_condition_str + ", ";

        if(rowInfo.price_paid >= 0)
        {
   	        var price = formatCurrency( rowInfo.price_paid, rowInfo.price_paid_currency_symbol );
            title += price + ", ";
        }
        title += rowInfo.date_bought_str;
        return title;
    };

    this.configureBank = function(widgetBank, rowInfo)
    {
        widgetBank.m_autoSave = true;

        var currentConditionWidget = widgetBank.addWidget({  name:"collect_current_condition",
                                label:"Current Condition:",
                                type:"select",
                                help:"What condition is your toy currently in? Is it graded (AFA), sealed (MISB), opened (MIB), or loose?",
                                width:80,
                                values:[rowInfo.collect_current_condition],
                                valueMap:genCondMap( rowInfo.package_type_id.toString(10) ) });

       var boughtConditionWidget = widgetBank.addWidget({  name:"collect_bought_condition",
                                label:"Purchased Condition:",
                                type:"select",
                                help:"What condition was the toy in when you bought it? This information, combined with the price you paid, is used to supplement the appraisal system, so try to be precise!",
                                width:80,
                                nullOption:{val:'-1',label:'Select'},
                                values:[rowInfo.collect_bought_condition],
                                valueMap:genCondMap( rowInfo.package_type_id.toString(10) ) });

       var priceWidget = widgetBank.addWidget({  name:"price_paid",
                                label:"Price Paid:",
                                type:"price",
                                width:80,
                                help:"How much did you pay for this toy? The currency you used should already be selected, but if it isn't, select it from the drop-down list. You can only set this value once you've chosen an option for 'Purchased Condition:'",
                         //       valueMap:genCurrencyMap(),
                                values:[rowInfo.price_paid, rowInfo.price_paid_currency] });

        widgetBank.addWidget({  name:"collect_market",
                                label:"From:",
                                type:"select",
                                width:140,
                                values:[rowInfo.collect_market],
                                valueMap:genMarketMap() });

       widgetBank.addWidget({  name:"date_bought",
                                label:"Date Bought:",
                                width:190,
                                values:[rowInfo.date_bought_m, rowInfo.date_bought_d, rowInfo.date_bought_y],
                                type:"date_select" });

        widgetBank.addWidget({  name:"collect_comment",
                                label:"Comment:",
                                help:"Enter anything you like in this field, such as details about the condition of the toy, who you bought it from, girls you have crushes on, whatever you like.",
                                width:250,
                                type:"text_area",
                                length:128,
                                values:[rowInfo.collect_comment]});

        var listWidget = widgetBank.addWidget({  name:"collect_checklist",
                                label:"Checklist:",
                                width:250,
                                type:"checklist",
                                length:128,
                                values:rowInfo.parts});

        currentConditionWidget.m_targetWidgets['bought_condition'] = boughtConditionWidget;
        currentConditionWidget.customChange = function()
        {
            var currentCondition = this.value();
            var myBoughtConditionWidget = this.m_targetWidgets['bought_condition'];
            var boughtCondition = myBoughtConditionWidget.value();
            if ( currentCondition==0 || currentCondition==1 )
            {
                listWidget.enable(false);
                listWidget.checkAll(true);
            }
            else
            {
                listWidget.enable(true);
            };

            if(boughtCondition>=0)
            {
                if(boughtCondition>currentCondition)
                {
                    myBoughtConditionWidget.setValue(currentCondition);
                }
            }
        };

        boughtConditionWidget.m_targetWidgets.current_condition = currentConditionWidget;
        boughtConditionWidget.m_targetWidgets.price_paid = priceWidget;
        boughtConditionWidget.customChange = function()
        {
            var currentConditionWidget = this.m_targetWidgets['current_condition'];
            var myPriceWidget = this.m_targetWidgets.price_paid;
            var boughtCondition = this.value();


            if ( boughtCondition==-1 ) // "SELECT" option, ie. no decision made
            {
                myPriceWidget.enable(false);
                myPriceWidget.setValue(-1);
            }
            else
            {
                var currentCondition = currentConditionWidget.value();
                if(currentCondition < boughtCondition)
                {
                    currentConditionWidget.setValue(boughtCondition);
                    currentConditionWidget.customChange();
                }
                myPriceWidget.enable(true);
            };
        };
    }

    this.getRowId = function(rowInfo)
    {
        return rowInfo.collect_id;
    }
}
CollectTable.prototype = new Table();
CollectTable.prototype.constructor = CollectTable;

