/* CTTable.js */

var isMinNS4=(navigator.appName.indexOf("Netscape")>=0&&parseFloat(navigator.appVersion)>=4)?1:0;
var isMinIE4=(document.all)?1:0;
var CTTables=new Array();
var BASERESOLUTION=1004;
var afterCmds='';

function getWindowWidth(){
 if(isMinNS4) return window.innerWidth;
 if(isMinIE4) return document.body.clientWidth;
 return-1;
}

function adjust (size)
{
//    var w=getWindowWidth();
//    if (w<780) w=780;
//    return (Math.floor (size * w/BASERESOLUTION));
  
  return (Math.floor (size * getWindowWidth()/BASERESOLUTION));
}

function CTTableItem(type,item,width){
 this.created=false;
 this.type=type;
 this.item=item;
 this.width=width;
 this.handlers="";
 this.link="";
 this.bgColor="";
 this.colSpan=1;
 this.rowSpan=1;
 this.caption=""
 this.align="left";
 this.valign="middle";
 this.name="";
 this.imgWidth=0;
 this.imgHeight=0;
 this.imgBorder=0;
 this.FontColor="#000000";
 this.FontFamily="Verdana";
 this.FontStyle="plain";
 this.FontWeight="bold";
 this.FontSize="8";
 this.setHandlers=CTTableItemSetHandlers;
 this.setLink=CTTableItemSetLink;
 this.setLayout=CTTableItemSetLayout;
 this.setImage=CTTableItemSetImage;
 this.setName=CTTableItemSetName;
 this.setFont=CTTableItemSetFont;
 this.create=CTTableItemCreate;
 this.createStr=CTTableItemCreateStr;
}


function CTTableItemSetHandlers (handlers){
 if(!this.created){
  this.handlers=handlers;
 }
}

function CTTableItemSetLink (link){
 if(!this.created){
  this.link=link;
 }
}

function CTTableItemSetLayout (bgColor, align, valign, colSpan, rowSpan){
 if(!this.created){
  this.bgColor=bgColor;
  this.align=align;
  this.valign=valign;
  this.colSpan=colSpan;
  this.rowSpan=rowSpan;
 }
}

function CTTableItemSetImage (name, width, height, caption, border){
 if(!this.created){
  this.name=name;
  this.imgWidth=width;
  this.imgHeight=height;
  this.caption=caption;
  this.imgBorder=border;
 }
}

function CTTableItemSetName (name){
 if(!this.created){
  this.name=name;
 }
}

function CTTableItemSetFont (color, family, style, weight, size){
 if(!this.created){
  this.FontColor=color;
  this.FontFamily=family;
  this.FontStyle=style;
  this.FontWeight=weight;
  this.FontSize=size; }
}


function CTTableItemCreate (curTable){
 var str;

 if (this.created) return ('');

 str='<td'+(this.width>0? ' width='+adjust(this.width):'')+' align='+this.align+' valign='+this.valign+(this.bgColor==""?'':' bgcolor='+this.bgColor)+' colspan='+this.colSpan+' rowspan='+this.rowSpan+'>';
 str+=this.createStr (curTable);
 str+='</td>\n'
 this.created=true;
 return (str);
}

function CTTableItemCreateStr (curTable){
 var str='';

 switch (this.type.toLowerCase ()) {
  case 'text':
   if (this.link != "" || this.handlers != "") str += '<A '+(this.link != ""? 'HREF="'+this.link+'"': '')+this.handlers+'>';
   str+='<SPAN STYLE="color:'+this.FontColor+';font-family:'+this.FontFamily+';font-size:'+adjust(this.FontSize)+'pt;font-style:'+this.FontStyle+';font-weight:'+this.FontWeight+';">'
   str+=this.item;
   str+='</SPAN>'
   if (this.link != "" || this.handlers != "") str += '</A>';
   break;
  case 'image':
   if (this.link != "" || this.handlers != "") str += '<A HREF="'+this.link+'"'+this.handlers+'>';
   str+='<img src='+this.item+' border='+adjust(this.imgBorder)+' width='+adjust(this.imgWidth)+' height='+adjust(this.imgHeight)+' alt="'+this.caption+'"'+(this.name!=""? ' name='+this.name:'')+'>';
   if (this.link != "" || this.handlers != "") str += '</A>';
   break;
  case 'table':
   str+=this.item.createSubTable(curTable);
   break;
  case 'empty':
   break;
 }
 return (str);
}


function CTTableRow(){
 this.items=new Array();
 this.created=false;
 this.addItem=CTTableRowAddItem;
 this.create=CTTableRowCreate;
}

function CTTableRowAddItem(item){
 if (!this.created) {
   this.items[this.items.length]=item;
 }
}

function CTTableRowCreate(curTable){
 var str,i;

 if(this.created) return;
 str='<tr>\n';
 for(i=0;i<this.items.length;i++){
    str+=this.items[i].create(curTable);
 }
 str+='</tr>\n';
 this.created=true;
 return (str);
}

function CTTable (width){
 this.created=false;
 this.father=-1;
 this.rows=new Array();
 this.x=-1;
 this.y=-1;
 this.realY=0;
 this.z=0;
 this.width=width;
 this.bgColor="";
 this.bgImage="";
 this.align="left";
 this.padding=4;
 this.spacing=1;
 this.border=0;
 this.borderColor="#000000";
 this.visible=true;
 this.handlers="";
 this.layer=null;
 this.setPosition=CTTableSetPosition;
 this.setRealY=CTTableSetRealY;
 this.setZIndex=CTTableSetZIndex;
 this.setWidth=CTTableSetWidth;
 this.setLayout=CTTableSetLayout;
 this.setBorder=CTTableSetBorder;
 this.setVisibility=CTTableSetVisibility;
 this.setHandlers=CTTableSetHandlers;
 this.getLayerLeft=CTTableGetLayerLeft;
 this.getLayerTop=CTTableGetLayerTop;
 this.getLayerWidth=CTTableGetLayerWidth;
 this.getLayerHeight=CTTableGetLayerHeight;
 this.getLayer=CTTableGetLayer;
 this.IEResizeWidth=CTTableIEResizeWidth;
 this.IESetLayerHeight=CTTableIESetLayerHeight;
 this.NSSetLayerHeight=CTTableNSSetLayerHeight;
 this.addRow=CTTableAddRow;
 this.create=CTTableCreate;
 this.createSubTable=CTTableCreateSubTable;
 this.index=CTTables.length;
 CTTables[this.index]=this;
}


function CTTableSetPosition(x, y){

 this.x=x;
 this.y=y;
 this.realY=0;

 if (this.created && this.father == -1) {
  if(isMinNS4) {
   document['CTTable'+this.index].left=adjust(x);
   document['CTTable'+this.index].top=adjust(y);
  }
  else if(isMinIE4) {
   eval('document.all.CTTable'+this.index).style.left=' '+adjust(x)+'px';
   eval('document.all.CTTable'+this.index).style.top=' '+adjust(y)+'px';
  }
 }
}

function CTTableSetRealY(y){

 this.y=y;
 this.realY=1;

 if (this.created && this.father == -1) {
  if(isMinNS4) {
   document['CTTable'+this.index].left=adjust(x);
   document['CTTable'+this.index].top=y;
  }
  else if(isMinIE4) {
   eval('document.all.CTTable'+this.index).style.left=' '+adjust(x)+'px';
   eval('document.all.CTTable'+this.index).style.top=' '+y+'px';
  }
 }
}

function CTTableSetZIndex(z){

 this.z=z;

 if (this.created && this.father == -1) {
  if(isMinNS4) {
   document['CTTable'+this.index].zIndex=z;
  }
  else if(isMinIE4) {
   eval('document.all.CTTable'+this.index).style.zIndex=z;
  }
 }
}

function CTTableSetWidth(width){
 if(!this.created){
  this.width=width;
 }
}

function CTTableSetLayout (bgcolor,bgImage,align,padding,spacing){
 if(!this.created){
  this.bgColor=bgcolor;
  this.bgImage=bgImage
  this.align=align;
  this.padding=padding;
  this.spacing=spacing;
 }
}

function CTTableSetBorder (border, borderColor){
 if(!this.created){
  this.border=border;
  this.borderColor=borderColor;
 }
}

function CTTableSetVisibility(visible){

 this.visible=visible;

 if (this.created && this.father == -1) {
  if(isMinNS4) {
   document['CTTable'+this.index].visibility=(this.visible? 'show': 'hide');
  }
  else if(isMinIE4) {
   eval('document.all.CTTable'+this.index).style.visibility=(this.visible? 'visible': 'hidden');
  }
 }
}

function CTTableSetHandlers (handlers){
 if(!this.created){
  this.handlers=handlers;
 }
}

function CTTableGetLayerWidth(){
 if (this.layer == null) this.getLayer ();
 if(isMinNS4){
  if(this.layer.document.width) return this.layer.document.width;
  else return this.layer.clip.right-this.layer.clip.left;
 }
 if(isMinIE4){
  if(this.layer.style.pixelWidth) return this.layer.style.pixelWidth;
  else return this.layer.clientWidth;
 }
 return-1;
}

function CTTableGetLayerHeight(){
 if (this.layer == null) this.getLayer ();
 if(isMinNS4){
  if(this.layer.document.height) return this.layer.document.height;
  else return this.layer.clip.bottom-this.layer.clip.top;
 }
 if(isMinIE4){
  if(this.layer.style.pixelHeight) return this.layer.style.pixelHeight;
  else return this.layer.clientHeight;
 }
 return-1;
}

function CTTableGetLayerLeft(){
 if (this.layer == null) this.getLayer ();
 if(isMinNS4) return this.layer.left;
 if(isMinIE4) return this.layer.style.pixelLeft;
 return-1;
}

function CTTableGetLayerTop(){
 if (this.layer == null) this.getLayer ();
 if(isMinNS4) return this.layer.top;
 if(isMinIE4) return this.layer.style.pixelTop;
 return-1;
}

function CTTableGetLayer(){
 if(this.father != -1) return null;
 if(isMinNS4) this.layer=eval('document.CTTable'+this.index);
 if(isMinIE4) this.layer=eval('document.all.CTTable'+this.index);
 return (this.layer);
}

function CTTableIEResizeWidth (width){
 if (this.layer == null) this.getLayer ();
 this.layer.style.pixelWidth=adjust(width);
 this.width=width;
}

function CTTableIESetLayerHeight (height){
 if (this.layer == null) this.getLayer ();
 this.layer.style.pixelHeight=height;
}

function CTTableNSSetLayerHeight (height){
 if (this.layer == null) this.getLayer ();
 this.layer.clip.height=height;
}

function CTTableAddRow(row){
 if(!this.created)
  this.rows[this.rows.length]=row;
}

function CTTableCreate(){
 var str='';

 if(this.created) return;

 afterCmds='';
 if(isMinNS4) str+='<layer name="CTTable'+this.index+'">\n';
 if(isMinIE4) str+='<div id="CTTable'+this.index+'" style="position:absolute;">\n';
 str+=this.createSubTable(-1); //top-level CTTable
 if(isMinNS4) str+='</layer>\n';
 if(isMinIE4) str+='</div>\n';

 document.write (str);
 document.write ('<script language="JavaScript">'+afterCmds+'</script>\n');

 
}

function CTTableCreateSubTable(father){
 var str;
 var i;

 if(this.created) return;
 this.father=father;
 str=''
 str='<table '+(isMinNS4?'name':'id')+'="CTTable'+this.index+'tbl" width='+adjust(this.width)+' border='+this.border+' bordercolor='+this.borderColor+(this.bgColor==""?'':' bgcolor='+this.bgColor)+' cellpadding='+adjust(this.padding)+' cellspacing='+adjust(this.spacing)+'>\n';

 // Set position, background image, visibility and handlers only for top-level tables.

 if (father == -1 && this.x>=0){
   if(isMinNS4) afterCmds+='document.CTTable'+this.index+'.left='+adjust(this.x)+';\n';
   if(isMinIE4) afterCmds+='document.all.CTTable'+this.index+'.style.left="'+adjust(this.x)+'px";\n';
 }
 if (father == -1 && this.y>=0){
   if(isMinNS4) afterCmds+='document.CTTable'+this.index+'.top='+(this.realY?this.y:adjust(this.y))+';\n';
   if(isMinIE4) afterCmds+='document.all.CTTable'+this.index+'.style.top="'+(this.realY?this.y:adjust(this.y))+'px";\n';
 }
 if (father == -1){
   if(isMinNS4) afterCmds+='document.CTTable'+this.index+'.zIndex='+this.z+';\n';
   if(isMinIE4) afterCmds+='document.all.CTTable'+this.index+'.style.zIndex='+this.z+';\n';
 }
 if (father == -1 && this.bgImage != ""){
   if (isMinNS4) afterCmds+='document.CTTable'+this.index+".background.src='"+this.bgImage+"';\n";
   if (isMinIE4) afterCmds+='document.all.CTTable'+this.index+'tbl.style.backgroundImage="url('+this.bgImage+')";\n';
 }
 if (father == -1 && this.handlers != ""){
   e = this.handlers.split ('###');
   for (i=0; e[i] != null; i++)
   {
     if (isMinNS4)
     {
       if(e[i].indexOf("onmouseup")==0) afterCmds+='document.CTTable'+this.index+'.captureEvents(Event.MOUSEUP);\n';
       afterCmds+='document.CTTable'+this.index+'.'+e[i]+';\n';
     }
     if (isMinIE4) afterCmds+='document.all.CTTable'+this.index+'.'+e[i]+';\n';
   }
 }
 if (father == -1){
   if (isMinNS4) afterCmds+='document.CTTable'+this.index+'.visibility='+(this.visible? '"show";\n': '"hide";\n');
   if (isMinIE4) afterCmds+='document.all.CTTable'+this.index+'.style.visibility='+(this.visible? '"visible";\n': '"hidden";\n');
 }

 for(i=0;i<this.rows.length;i++){
   str+=this.rows[i].create(this.index);
 }
 str+='</table>'
 this.created=true;

 return (str);


}

