/*---------------------------------------------------  
 *  RepeterControl for AJAX
 *  (c) 2005 Jigar Desai <desaijm@hotmail.com>
 *  Date Change: 12/31/2005
 *  requires: prototype.js http://prototype.conio.net/
/*--------------------------------------------------*/

function RepeaterControl(){
    
    this.HeaderTemplate = "";
    this.ItemTemplate = "";
    this.SelectedItemTemplate = "";
    this.FooterTemplate = "";
    this.AlternatingItemTemplate = "";
    this.SeparatorTemplate = "";
    this.HostControlID = null;
    
    this.DataSource = null;
}

RepeaterControl.prototype.DataBind = function(){
    var htmlString = "";
    htmlString += this.HeaderTemplate;
    
    
    for(var count=0;count<this.DataSource.length;count++){
        var node = this.DataSource[count];
        var row = this.ItemTemplate
        
        if(this.AlternatingItemTemplate != "" && (count+1)% 2 == 0 ){
            row = this.AlternatingItemTemplate;
        }
       
        for (var i = 0; i < node.attributes.length; i++){
			var re = new RegExp("{@" + node.attributes[i].nodeName + "}","g");
			row = row.replace(re,node.attributes[i].nodeValue);
		}
		
		for (var i = 0; i < node.childNodes.length; i++){
		    if(node.nodeType != 3 && node.childNodes[i].firstChild != null){
			    var re = new RegExp("{\\$" + node.childNodes[i].nodeName + "}","g");
			    row = row.replace(re,node.childNodes[i].firstChild.nodeValue);
			}
		}
		
		// eval javascript
		evalRe = new RegExp("{Eval(.*?)}","g");
		
		myArray = row.match(evalRe);
		
		if(myArray != null){
		    for(var i=0;i<myArray.length;i++){
		        var result = eval(myArray[i].replace(evalRe,"$1"));
		        row = row.replace(myArray[i],result);
		    }
		}
        
		row = row.replace("<span class=\"green\">{$PaperType} #{$PaperNumber}</span><br><br>","");
        htmlString += row;
        
        if(this.SeparatorTemplate != "" && count + 1 != this.DataSource.length){
            htmlString += this.SeparatorTemplate;
        }
        
        
    }
    
    htmlString += this.FooterTemplate;
    
    $(this.HostControlID).innerHTML = htmlString;
}


