// ++=========================================================================++
// || DTO ShowCase v2.0.0 - 213
// || Copyright © 2008-2010 Drive Thru Online, Inc. All Rights Reserved.
// || This file may not be redistributed in whole or significant part, or
// || used on web site without licensing of the enclosed code,
// || and software features.
// || http://www.drivethruonline.com | info@drivethruonline.com
// || Downloaded 19:12, Fri Jul 16th 2010
// || 623790213_604952770317
// ++ ========================================================================++

function DTO_ShowcaseMainView()                            {}

function DTO_ShowcaseMainView_new(viewIDP)
{
    var obj = new DTO_ShowcaseMainView();
    DTO_View_init(obj, viewIDP);
    DTO_ShowcaseMainView_init(obj);
    return obj;
}

function DTO_ShowcaseMainView_init(obj)
{
    obj.searchView = null;
    obj.resultView = null;
    
    obj.drawSelfPre = function(frag)
    {
        var contents, leftcol, rightcol;
        
        this.clear();
       
        table = document.createElement("table");
        table.border = 0;
        tbody = document.createElement("tbody");
        tr = document.createElement("tr");
        
        td = document.createElement("td");
        td.id = 'showcaseSearch';
        td.align = 'left';
        td.width='340';
        td.vAlign = 'top';
        td.style.paddingRight = "6px";
        tr.appendChild(td);
        
        td = document.createElement("td");
        td.id = 'showcaseResults';
        td.width='100%';
        td.align = 'left';
        td.vAlign = 'top';
        
        tr.appendChild(td);
        
        
        tbody.appendChild(tr);                
        table.appendChild(tbody);     
        frag.appendChild(table);    
        
            
    }
    
    obj.createSubviews = function()
    {   
        this.searchView = DTO_ShowcaseSearchView_new("showcaseSearch"); 
        this.resultView = DTO_ShowcaseResultView_new("showcaseResults"); 

        this.addSubview(this.searchView);
        this.addSubview(this.resultView);
        
        this.searchView.createSubviews();
        this.resultView.createSubviews();
    }
}

/*--------------------------------------------------------------*/

function DTO_ShowcaseSearchView()                        {}

function DTO_ShowcaseSearchView_new(viewIDP)
{
    var obj = new DTO_ShowcaseSearchView();
    DTO_View_init(obj, viewIDP);
    DTO_ShowcaseSearchView_init(obj);
    return obj;
}

function DTO_ShowcaseSearchView_init(obj)
{
    obj.showcaseTypeView = null;
    obj.usernameView = null;
    obj.submitButton = null;
    obj.optionViews = [];
    
    obj.drawSelfPre = function(frag)
    {
        var h2, div, section, row;
        
        this.clear();
        h2 = document.createElement('h2');
        h2.appendChild(document.createTextNode(DTO_Phrase_cachedWithID('dto_showcase_js_search_criteria').phrase));
        h2.className = "blockhead";        
        frag.appendChild(h2);        
                
        div = document.createElement("div");
        div.className = 'blockbody formcontrols settings_form_border';  // formcontrols
        div.style.width = '340px';
        section = document.createElement("div");
        section.className = 'section';   
        
        row = document.createElement("div");
        row.id = 'showcaseType';
        row.className = 'blockrow';
        row.style.width = "325px";
        section.appendChild(row);
        
        row = document.createElement("div");
        row.id = 'username';
        row.className = 'blockrow';
        row.style.width = "325px";
        section.appendChild(row);            

        var i, count = this.optionViews.length;

        for(i=0; i<count; i++)
        {
            var view = this.optionViews[i];
            var row = document.createElement("div");
            row.className = "blockrow";
            row.style.width = "325px";
            row.id = view.getViewID();
            
            section.appendChild(row);    
        }

        row = document.createElement("div");
        row.id = 'submit';
        row.className = "";
        row.style.paddingTop = "6px";
        

        div.appendChild(section);
        frag.appendChild(div);
        
        frag.appendChild(row);
    }
    
    obj.createSubviews = function()
    {
        this.showcaseTypeView = DTO_Table2PopupView_new("showcaseType", DTO_Phrase_cachedWithID('dto_showcase_js_type').phrase);
        this.usernameView = DTO_Table2FieldView_new("username", DTO_Phrase_cachedWithID('dto_showcase_js_username').phrase);
        this.submitButton = DTO_Table2ButtonView_new("submit", DTO_Phrase_cachedWithID('search').phrase);
        
        this.addStdSubviews();
    }
    
    obj.addStdSubviews = function()
    {
        this.addSubview(this.showcaseTypeView);
        this.addSubview(this.usernameView);
        this.addSubview(this.submitButton);
    }
    
    obj.makeIntCallback = function(view, attr)
    {
        view.setOnChange(function(view){var self = attr; self.doIntRange(view);});
    }
    
    obj.makeCheckboxCallback = function(view, attr)
    {
        view.setOnChange(function(view){var self = attr; self.doCheckbox(view);});
    }
    
    obj.makePopupCallback = function(view, attr)
    {
        view.setOnChange(function(view){var self = attr; self.doPopup(view);});
    }
    
    obj.makeStringCallback = function(view, attr)
    {
        view.setOnChange(function(view){var self = attr; self.doString(view);});
    }
    
    obj.makeDecimalCallback = function(view, attr)
    {
        view.setOnChange(function(view){var self = attr; self.doDecimalRange(view);});
    }
    
    obj.setOptionsArray = function(array)
    {
        var i, ii;
        var count = (array ? array.length : 0);
        var breakClassID = -1;

        Array_clear(this.optionViews);
        this.clearSubviews();
        this.addStdSubviews();
            
        for(i=0; i<count; i++)
        {
            var attr = array[i];    //this is really a DTO_SearchAttribute
            var subview = null;
            var classID = attr.classAttributes[0].classID;    //somewhat dangerous, relies on no name collisions
                        
            if(classID != breakClassID)
            {
                var theClass = DTO_ClassInheritance_cachedWithID(classID);
                var label = DTO_Table2LabelView_new('label_'+classID, theClass.className);
                this.addSubview(label);
                this.optionViews.push(label);
                breakClassID = classID;
            }

            switch(attr.attributeType)
            {
                case 10:        //int  
                    subview = DTO_Table2RangeView_new('attr_'+attr.attributeID, attr.displayName);
                    subview.setStyle('smallfont');
                    this.makeIntCallback(subview, attr);
                    subview.setLowValue(attr.getValue());
                    subview.setHighValue(attr.getValue());
                    this.addSubview(subview);
                    this.optionViews.push(subview);
                    break;
                case 11:        //boolean
                    subview = DTO_Table2CheckboxView_new('attr_'+attr.attributeID, attr.displayName);
                    subview.setStyle('smallfont');
                    this.makeCheckboxCallback(subview, attr);
                    subview.setSelected(attr.getValue());
                    this.addSubview(subview);
                    this.optionViews.push(subview);
                    break;
                case 12:        //popup
                    subview = DTO_Table2PopupView_new('attr_'+attr.attributeID, attr.displayName);
                    subview.setStyle('smallfont');
                    this.makePopupCallback(subview, attr);
                    subview.setSelected(attr.getValue());
                    subview.setFormatter(DTO_SearchPopupFormatter_new(attr.popupOptions));
                    this.addSubview(subview);
                    this.optionViews.push(subview);
                    break;
                case 14:        //string
                case 15:        //text
                    subview = DTO_Table2FieldView_new('attr_'+attr.attributeID, attr.displayName);
                    subview.setStyle('smallfont');
                    this.makeStringCallback(subview, attr);
                    subview.setValue(attr.getValue());
                    this.addSubview(subview);
                    this.optionViews.push(subview);
                    break;
                case 16:        //currency
                case 17:        //decimal
                    subview = DTO_Table2RangeView_new('attr_'+attr.attributeID, attr.displayName);
                    subview.setStyle('smallfont');
                    this.makeDecimalCallback(subview, attr);
                    subview.setLowValue(attr.getValue());
                    subview.setHighValue(attr.getValue());
                    this.addSubview(subview);
                    this.optionViews.push(subview);
                    break;
            }
        }
    }
}

/*--------------------------------------------------------------*/

function DTO_ShowcaseResultView()                              {}

function DTO_ShowcaseResultView_new(viewIDP)
{
    var obj = new DTO_ShowcaseResultView();
    DTO_View_init(obj, viewIDP);
    DTO_ShowcaseResultView_init(obj);
    return obj;
}

function DTO_ShowcaseResultView_init(obj)
{
    obj.rowData = null;
    obj.resultView = null;
    
    obj.drawSelfPre = function(frag)
    {
        //var table, tbody;
        var div, divblock, h2, ul;
        this.clear();
        
        divblock = document.createElement("div");
        divblock.className = 'block';
        
        h2 = document.createElement("h2");
        h2.className = 'blockhead';
        h2.appendChild(document.createTextNode(DTO_Phrase_cachedWithID('dto_showcase_js_search_results').phrase));
        divblock.appendChild(h2);

        div = document.createElement("div");
        div.className = 'blockbody settings_form_border floatcontainer';
        divblock.appendChild(div);       

        ul = document.createElement("ul");
        ul.id = "dtophotocontainer";
   
        div.appendChild(ul);
        frag.appendChild(divblock);        
    }
    
    obj.createSubviews = function()
    {
        var column;

        this.resultView = DTO_BodyFloatView_new('dtophotocontainer', DTO_ShowcaseCellFormatter_new()); 
        this.resultView.setEmptyMessage("No showcases found.");
        this.addSubview(this.resultView);
    }
    
    obj.setArray = function(array)                  
    {
        this.rowData = array;
        this.resultView.setRowData(array);
        this.resultView.draw();
    }

    obj.sort = function(tag)
    {
        switch(tag)
        {
            case 'showcaseName':    this.rowData.sort(DTO_ShowcaseResultView_sortByShowcaseName);             break;
            case 'showcaseType':    this.rowData.sort(DTO_ShowcaseResultView_sortByShowcaseType);             break;
            case 'username':        this.rowData.sort(DTO_ShowcaseResultView_sortByUsername);                 break;
        }
        this.resultView.draw();
    }
}

function DTO_ShowcaseResultView_sortByShowcaseName(a, b)
{
    if(a.showcaseName == b.showcaseName)
        return DTO_ShowcaseResultView_sortByUsername(a, b);
    else
        return (a.showcaseName > b.showcaseName ? 1 : -1);
}

function DTO_ShowcaseResultView_sortByShowcaseType(a, b)
{
    var objA = DTO_ShowcaseType_cachedWithID(a.showcaseTypeID);
    var objB = DTO_ShowcaseType_cachedWithID(b.showcaseTypeID);
    if(objA.name == objB.name)
        return DTO_ShowcaseResultView_sortByShowcaseName(a, b);
    else
        return (objA.name > objB.name ? 1 : -1);
}

function DTO_ShowcaseResultView_sortByUsername(a, b)
{
    if(a.username == b.username)
        return 0;
    else
        return (a.username > b.username ? 1 : -1);
}

/*--------------------------------------------------------------*/

function DTO_ShowcaseBrowseMainView()                              {}

function DTO_ShowcaseBrowseMainView_new(viewIDP)
{
    var obj = new DTO_ShowcaseBrowseMainView();
    DTO_View_init(obj, viewIDP);
    DTO_ShowcaseBrowseMainView_init(obj);
    return obj;
}

function DTO_ShowcaseBrowseMainView_init(obj)
{
    obj.rowData = null;
    obj.resultView = null;
    
    obj.drawSelfPre = function(frag)
    {
        var table, tbody;
        this.clear();
        
        table = document.createElement("table");
        table.id = this.getViewID() + '_table';
        table.border = 0;  
        table.width = '100%';
        
        tbody = document.createElement("tbody");
        tbody.id = this.getViewID() + '_table_tbody';
        tbody.className = 'alt1';       
        
        table.appendChild(tbody);
        frag.appendChild(table);
    }
    
    obj.createSubviews = function()
    {
        var column;
        
        this.resultView = DTO_TableBodyGridView_new(this.getViewID() + '_table_tbody',
                            DTO_ShowcaseGridFormatter_new(), showcaseSearchApp.gridWidth());  
        this.resultView.setStyle('alt1');
        this.resultView.setAltStyle('alt2');
        this.resultView.setEmptyMessage("No showcases found.");
                
        this.addSubview(this.resultView);
    }
    
    obj.setArray = function(array)                  
    {
        this.rowData = array;
        this.resultView.setRowData(array);
        this.resultView.draw();
    }
}

/*--------------------------------------------------------------*/

function DTO_ShowcaseGridFormatter()                  {}

function DTO_ShowcaseGridFormatter_new()
{
    var obj = new DTO_ShowcaseGridFormatter();
    DTO_TableBodyGridFormatterAbstract_init(obj);
    DTO_ShowcaseGridFormatter_init(obj);
    return obj;
}

function DTO_ShowcaseGridFormatter_init(obj)
{
    obj.drawCell = function(frag, obj)
    {
        var table = document.createElement("table");
        var tbody = document.createElement("tbody");
        var tr1 = document.createElement("tr");
        var tr2 = document.createElement("tr");
        var td0 = document.createElement("td");
        var td1 = document.createElement("td");
        var td2 = document.createElement("td");
        var a1 = document.createElement("a");
        var txt = document.createTextNode(obj.showcaseName);
        var thumb = obj.thumbImage;
        
        table.style.border = '1px solid rgb(136, 136, 136)'; 
        table.style.margin = '5px'; 
        table.style.padding = '5px'; 
        table.style.width = '120px'; 
        table.style.height = '120px';
        
        td0.align = 'center';
        td0.vAlign = 'middle'; 
        td0.className = 'smallfont';  
        
        td1.align = 'center';
        td1.vAlign = 'top';
        td1.className = 'smallfont'; 
                
        td2.align = 'center';
        td2.vAlign = 'bottom'; 
        td2.className = 'smallfont'; 
                        
        a1.href = showcaseSearchApp.baseURL() + '/dto_showcase.php?do=preview&g=' + obj.id;
        a1.target = "showcase_" + obj.id;
        a1.style.textDecoration = 'none';
        
        if(thumb)
        {
            var img = document.createElement("img");
            img.border = 0;
            img.src = thumb.url;
            a1.appendChild(img);
        }
        
        a1.appendChild(document.createElement("br"));
        a1.appendChild(txt);
        td2.appendChild(a1);
        tr1.appendChild(td1);
        tr2.appendChild(td2);
        tbody.appendChild(tr1);
        tbody.appendChild(tr2);
        table.appendChild(tbody);
        td0.appendChild(table);
        frag.appendChild(td0);
    }
}

