function MyPrettyTable(){
    this.makeTableTop = makeTableTop;
    this.makeTableBottom = makeTableBottom;
    this.makeRow = makeRow;
    this.endSub = endSub;
    this.makeSub = makeSub;
    this.count = 0;
    this.stuff = "";
    this.wholetable = new Array();
    this.wholetable_index = 0;
    this.applyitems = new Array();
    this.addapply = false;
    this.applyhtml = "<a href=\"javascript:openLink('https://www.loanliner.com/LoanRequest/CLPPresenter/LoanList.aspx?CUID=00800271&LoanListId=665&ChannelId=4287292306019170451&LocationId=3627749000168185736&IsFramed=F');\">apply online</a>";
    this.checkApply = checkApply;
}

function checkApply(rates){
    if(this.applyhtml == ""){
        return false;
    }
   // needed only the first child of 'Fixed Rate Second Trust Mortgage, Terms to 240 Months (Maximum $250,000)'
    for(var i = 0; i < this.applyitems.length; i++){
    //alert(rates[0] + "\t" + (rates[0].indexOf(this.applyitems[i]) != -1)+"\t" + this.applyitems[i]);
        if(rates[0].indexOf(this.applyitems[i]) != -1){
            return !this.addapply;
        }		
    }
    return this.addapply;
}

//added for 201-51128
function makeSub(){
	this.wholetable[this.wholetable_index++]='<tr><td class="tableheader" style="background-color: #ffffff;" colspan="3">';
this.wholetable[this.wholetable_index++]='<table width="100%" border="0" cellspacing="0" cellpadding="0">';
this.wholetable[this.wholetable_index++]='<tr>';
this.wholetable[this.wholetable_index++]='<td class="tableheader">';
this.wholetable[this.wholetable_index++]='<table width="100%" cellspacing="1" cellpadding="3" border="0">';
}

function endSub(){
	this.wholetable[this.wholetable_index++]='</table></td></tr></table>';
}
// end add

function makeRow(data,style,stuff,td_edit,edit){
    if(!style){
        this.count%2 == 0 ? style = "tablecontent1" : style = "tablecontent2";
        this.count++;
    }
    if(stuff){ 
        this.stuff = stuff;   
    }
  
    this.wholetable[this.wholetable_index++] = "<tr>";  
    for(i=0;i<data.length;i++){
       if(data[i] == ""){
            data[i] = "<br>";
       }
	   // added 3/23/05, do not add 'apply now' after Second Trust Loans
        if(data.length > 1 && this.addapply && i == 0 && data[i] !="Second Trust Loans (maximum $50,000)"){
            data[i] += "<img src='../images/clearpix.gif' width='15' height='1' alt='' border='0'>";
            data[i] += this.applyhtml;
            //alert(this.applyhtml+"\t"+data[i]);
       }
        if(i == td_edit){
           this.wholetable[this.wholetable_index++]="<td class='"+style+"' "+edit+">"+data[i]+"</td>";
        }
        else{
           this.wholetable[this.wholetable_index++]="<td class='"+style+"' "+this.stuff+">"+data[i];
		   if(data[i] == "Terms to 240 months" || data[i] == "Home Equity Line of Credit (maximum $250,000)**" || data[i] == "Home Equity Products"){
				this.wholetable[this.wholetable_index++]= "&nbsp;&nbsp;" + this.applyhtml;
		   }
			this.wholetable[this.wholetable_index++]="</td>";
		   // alert("<td class="+style+" "+this.stuff+">"+data[i]+"</td>")
        }
    }
    this.wholetable[this.wholetable_index++]= "</tr>";
    //reset this.stuff
    this.stuff = "";      
    return;  
}

function makeTableTop(attributes){
if(!attributes){
    attributes = 'width="100%" cellspacing="1" cellpadding="3" border="0"';
}

this.wholetable[this.wholetable_index++]='<table width="100%" border="0" cellspacing="0" cellpadding="0">';
this.wholetable[this.wholetable_index++]='<tr>    ';
this.wholetable[this.wholetable_index++]='<td class="tableheader">';
this.wholetable[this.wholetable_index++]='<table '+attributes+'>';
return;
}

function makeTableBottom(header){
    this.wholetable[this.wholetable_index++]='</table></td></tr></table>';
    document.open('text/html',"replace");
    document.write(this.wholetable.join(""));
    document.close();
    return;
}

// end of file
