function PriceListTable()
{
if(typeof PriceListTable._initialized == 'undefined')
{
PriceListTable.prototype.load = function()
{
this.getTableReference();
if(this.table)
{
this.reset();
this.attachHead();
}
};
PriceListTable.prototype.getTableReference = function()
{
var table = document.getElementsByClassName('table','priceList');
if(table.length == 1)this.table = table[0];
};
PriceListTable.prototype.reset = function()
{
var tableBody = this.table.getElementsByTagName('tbody')[0];
//reset table tag attributes
this.table.setAttribute('border','0');
this.table.setAttribute('width','605');
//remove width from
var oTD = this.table.getElementsByTagName('td');
for(var i = 0; i < oTD.length; i++)
{
oTD[i].removeAttribute('width');
}
//set TD colspan + set title classes + set link classes
var bodyTR = tableBody.getElementsByTagName('tr');
for(var i = 0; i < bodyTR.length; i ++)
{
var oTD = bodyTR[i].getElementsByTagName('td');
/*
oTD[0].setAttribute('colspan','2');
oTD[1].setAttribute('colspan','1');
oTD[2].setAttribute('colspan','1');
oTD[3].setAttribute('colspan','1');
*/
oTD[0].setAttribute('width','185');
oTD[1].setAttribute('width','140');
oTD[2].setAttribute('width','140');
oTD[3].setAttribute('width','140');
if(this.isTitleRow(oTD[1],oTD[2],oTD[3]))
{
oTD[0].className = 'title';
oTD[0].setAttribute('width','605');
} else {
this.setViewLinkClass(oTD[1],'pdf');
this.setViewLinkClass(oTD[2],'excel');
this.setViewLinkClass(oTD[3],'pdf');
}
}
};
PriceListTable.prototype.isTitleRow = function(TD1,TD2,TD3)
{
var link1 = TD1.getElementsByTagName('a');
var link2 = TD2.getElementsByTagName('a');
var link3 = TD3.getElementsByTagName('a');
if(link1.length == 0 && link2.length == 0 && link3.length == 0)return true;
return false;
};
PriceListTable.prototype.setViewLinkClass = function(oTD,sClass)
{
var oLink = oTD.getElementsByTagName('a');
if(oLink.length == 1)oLink[0].className = sClass;
};
PriceListTable.prototype.attachHead = function()
{
var oTR = document.createElement('tr');
for(var i = 0; i < 4; i++)
{
var oTD = document.createElement('td');
/*
if(i == 0)oTD.setAttribute('colspan','2');
if(i == 1)oTD.appendChild(document.createTextNode('Brochure (PDF)'));
if(i == 2)oTD.appendChild(document.createTextNode('Price list (Excel)'));
if(i == 3) oTD.appendChild(document.createTextNode('Price list (PDF)'));
*/
if(i == 0)
{
oTD.setAttribute('width','185');
} else {
oTD.setAttribute('width','140');
}
if(i == 1) oTD.appendChild(document.createTextNode('Brochure (PDF)'));
if(i == 2)oTD.appendChild(document.createTextNode('Price list (Excel)'));
if(i == 3) oTD.appendChild(document.createTextNode('Price list (PDF)'));
oTR.appendChild(oTD);
}
var oHead = document.createElement('thead');
oHead.appendChild(oTR);
var oTBody = this.table.getElementsByTagName('tbody')[0];
this.table.insertBefore(oHead,oTBody);
};
}
PriceListTable._initialized = true;
this.load();
}
var priceListTable = new PriceListTable();
|