﻿// © Copyright Strategy Builders Inc. 2000-2009. All rights reserved.
//   
// The entire contents of this file is protected by International and
// U.S.Copyright Laws. Unauthorized reproduction, distribution, 
// redistribution and reverse engineering of any or all portion of the code 
// contained in this file is strictly prohibited and may
// result in severe civil and criminal penalties and will be
// prosecuted to the maximum extent possible under the law.
//  
// RESTRICTIONS 
//  
// THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES  
// ARE CONFIDENTIAL AND PROPRIETARY TRADE  
// SECRETS OF Strategy Builders Inc. 
//  
// THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED
// FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE  
// COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE 
// AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  
// AND PERMISSION FROM Strategy Builders Inc. 
//  
// CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON 
// ADDITIONAL RESTRICTIONS.
//  

function RepeaterControl(id, itemName, collection) {
    this._Collection = collection;
    this._ItemName = itemName;
    this._start = 0;
    if (collection != null) {
        this._end = collection.length;
    }
    else {
        this._end = 0;
    }
    this._callback = null;
    ContainerControl.call(this, id);
}

RepeaterControl.prototype = new ContainerControl();


RepeaterControl.prototype.setCollection = function(collection) {
    this._Collection = collection;
    if (collection != null) {
        this._end = collection.length;
    }
    else {
        this._end = 0;
    }
}

RepeaterControl.prototype.getCollection = function() {
    return this._Collection;
}

RepeaterControl.prototype.appendCollection = function(collection) {
    //this._Collection.join(collection);
    if (this._Collection == null) {
        this._Collection = collection;
    }
    else {
        this._Collection = this._Collection.concat(collection);
    }
    if (this._Collection != null) {
        this._end = this._Collection.length;
    }
    else {
        this._end = 0;
    }
}

RepeaterControl.prototype.setCallbackFunction = function(cb) {
    this._callback = cb;
}

RepeaterControl.prototype.setStart = function(st) {
    this._start = st;
}

RepeaterControl.prototype.setEnd = function(en) {
    this._end = en;
}

RepeaterControl.prototype.getCount = function() {
    return this._Collection.length;
}

RepeaterControl.prototype.getHTML = function() {

    var outHtml = '';
    var last = this._end;
    if (last > this.getCount()) {
        last = this.getCount();
    }

    //for (var i in this._Collection) {
    for (var i = this._start; i < last; i++) {
        if ((i >= this._start) && (i < this._end)) {
            var id = this._ItemName;
            var myControl = new Control(id);
            myControl.setParent(this);
            myControl.setTemplate(this._template);
            myControl.setAttribute(id, this._Collection[i]);
            myControl.setAttribute('RowNumber', i);
            outHtml += myControl.getHTML();
        }
        if ((this._end - i) > 1) {
            if (this._callback != null) {
                this._callback(this);
                return outHtml;
            }
        }
    }

    return outHtml;
}


