
//
// Tab management
// copyright Mircea LUTIC 2000
// email mircealutic@mail.com
//
// Developed for the Council of Europe by Mircea LUTIC
// Reproduction is not permitted without written permission from the author
//

//
// helper functions
//
var TAB_JS=1; // not frames but js code

function TabPage(name,url,icon){this.name = name; this.url = url; this.icon = icon;return this;}

function TabSet(name, tabFrame, pageFrame, flgs) 
{	
	this.name = name; 
	this.length = 0; 
	this.flgs=flgs;

	this.selTab=-1;	// index of selected tab

	this.tophtml="";	// text above the tabs
	this.prefix ="";	// text to the left of tabs

	this.clrBgnd="9999CC";//"325498";//"406080";
	this.clrPage="ffffff";
	this.clrNsel="013366";
	this.selTop ="013366";
	this.nslTop ="013366";
	this.clrEdge="013366";
	this.clrText0="FFCC00";
	this.clrText1="013366";

	this.pthIcon="img/";
	this.dimText ="9pt";
	this.MinHeight=30;

	this.tabFrame=tabFrame;
	this.pageFrame=pageFrame;

	return this;
}

TabSet.prototype.setClrBgnd=function (val)  {this.clrBgnd =val;}
TabSet.prototype.setClrPage=function (val)  {this.clrPage =val;}
TabSet.prototype.setClrNsel=function (val)  {this.nslTop  =val;}
TabSet.prototype.setClrEdge=function (val)  {this.clrEdge =val;}
TabSet.prototype.setClrTxt0=function (val)  {this.clrText0=val;}
TabSet.prototype.setClrTxt1=function (val)  {this.clrText1=val;}
TabSet.prototype.setClrTop0=function (val)  {this.nslTop  =val;}
TabSet.prototype.setClrTop1=function (val)  {this.selTop  =val;}

TabSet.prototype.setHtmlTop=function (val)  {this.tophtml =val;}
TabSet.prototype.setHtmlPfx=function (val)  {this.prefix  =val;}
TabSet.prototype.setPthIcon=function (val)  {this.pthIcon =val;}

TabSet.prototype.add =function (object)  
{	
	this.length++; 	
	this[this.length] = object; 
	return this.length; 
}

//
//	Drawing function
//
TabSet.prototype.drawTabs=function (ctype)
{
    var clrtop;

	if (ctype==null)
	{
		ctype = "text/html";
	}
	var outputFrame = this.tabFrame.window.document;
	outputFrame.open(ctype);
	outputFrame.write("<HTML>\n<HEAD>\n");
	outputFrame.write("<meta http-equiv='Content-Type' content='"+ctype+"'>");
	outputFrame.write("\n<style>\n<!--\n");
	outputFrame.write("A {text-decoration:none; font-weight:bold; color:"+this.clrText0+"; font-size:"+this.dimText+"; font-family:Verdana, Arial, Helvetica, sans-serif}\n");
	outputFrame.write("td {text-decoration:none; font-weight:bold; color:"+this.clrText1+"; font-size:"+this.dimText+"; font-family:Verdana, Arial, Helvetica, sans-serif}\n");
	outputFrame.write("\n-->\n</style>\n</HEAD>");

	outputFrame.write("<BODY  topmargin=0 leftmargin=0 Bgcolor="+this.clrBgnd+">\n"); //

	if (this.tophtml && this.tophtml!="")
	    outputFrame.write(this.tophtml);
	outputFrame.write("<table border=0 cellspacing=0 cellpadding=0 width=100%><tr>\n");
	outputFrame.write("<td nowrap valign=bottom width=100% bgcolor="+this.clrBgnd+">");

	if (this.prefix && this.prefix!="")
	    outputFrame.write(this.prefix);
	
	outputFrame.write("<img border=0 width=1  height=1 src="+this.pthIcon+"px.gif></td>\n");

	outputFrame.write("<td align=right valign=bottom rowspan=2>"
			 +"\n<table border=0 cellspacing=0 cellpadding=0>\n");
	outputFrame.write("<tr><td colspan="+(this.length*4+1)+ " bgcolor="+this.clrBgnd
			  +"><img border=0 width=1 height=1 src="+this.pthIcon
			  +"px.gif></td></tr>\n<tr>\n");
	var i=1;
        var s,z;
	while (i<=this.length)
	{
	    if (this.selTab ==i)
	    {
			s = this.pthIcon + "tab1s.gif";
			z = this.pthIcon + "tab1z.gif";
			clrtop=this.selTop;
	    }
	    else
	    {
			s = this.pthIcon+"tab0s.gif";
			z = this.pthIcon+"tab0z.gif";
			clrtop=this.nslTop;
	    }
	    outputFrame.write("<td nowrap valign=top rowspan=2 bgcolor="+this.clrBgnd
				+"><img border=0 width=20 height=1 src="+this.pthIcon+"px.gif></td>\n");
	    outputFrame.write("<td nowrap valign=top rowspan=2 bgcolor="+this.clrBgnd
				+"><img border=0 src="+s+"></td>\n");
	

	    outputFrame.write("<td nowrap bgcolor="+clrtop
				+"><img border=0 width=1 height=1 src="+this.pthIcon+"px.gif></td>\n");
	    outputFrame.write("<td nowrap valign=top rowspan=2 bgcolor="+this.clrBgnd
				+"><img border=0 src="+z+"></td>\n");
	    i++;
	}

	outputFrame.write("<td nowrap valign=top rowspan=2 bgcolor="+this.clrBgnd
			+"><img border=0 width=20 height=1 src="+this.pthIcon+"px.gif></td></tr>\n<tr>");

	i=1;
	while (i<=this.length)
	{
	    var ico = "";
	    if (this[i].icon.length>0)
		ico="<img border=0 width=16 height=16 src='"
			+this[i].icon
			+"'>&nbsp;";
		
	    if (i==this.selTab)
		outputFrame.write("<td bgcolor="+this.clrPage
			+"><nobr>&nbsp;<b>"+ico+this[i].name+"</b>&nbsp;</nobr></td>\n");
	    else
		outputFrame.write("<td bgcolor="+this.clrNsel
			+"><nobr>&nbsp;"+ico+"<a href='javascript:parent."+this.name+".setTab("+i+")'>"
			+this[i].name+"</a>&nbsp;</nobr></td>\n");
	    i++;
	}
	if (this.selTab >0 && this.selTab <=this.length)
	{
		outputFrame.write("</tr><tr><td colspan="+(4*this.selTab-3)+" nowrap bgcolor="+this.clrEdge
			+"><img border=0 width=20 height=1 src="+this.pthIcon+"px.gif></td>\n");
		outputFrame.write("<td colspan=3 nowrap bgcolor="+this.clrPage
			+"><img border=0 width=20 height=1 src="+this.pthIcon+"px.gif></td>\n");
		outputFrame.write("<td colspan="+(4*(this.length-this.selTab)+1)+" nowrap bgcolor="+this.clrEdge
			+"><img border=0 width=20 height=1 src="+this.pthIcon+"px.gif></td>\n");
	}
	else
		outputFrame.write("</tr><tr><td colspan="+(4*this.length+1)+" nowrap bgcolor="+this.clrEdge
			+"><img border=0 width=20 height=1 src="+this.pthIcon+"px.gif></td>\n");

	outputFrame.write("</tr></table></td>");

	outputFrame.write("<td width=50% bgcolor="+this.clrBgnd
			+"><img border=0 width=1 height="+this.MinHeight+" src="+this.pthIcon+"px.gif>\n");
	outputFrame.write("</td></tr><tr>");
	outputFrame.write("<td valign=bottom nowrap bgcolor="+this.clrEdge
			+"><img border=0 width=1 height=1 src="+this.pthIcon+"px.gif></td>\n");
	outputFrame.write("<td valign=bottom nowrap bgcolor="+this.clrEdge
			+"><img border=0 width=1 height=1 src="+this.pthIcon+"px.gif></td>\n");
	outputFrame.write("</tr></table>");
	outputFrame.write("<table border=0 cellspacing=0 cellpadding=0 width=100% height=100 bgcolor="
			+this.clrPage+"><tr><td bgcolor="+this.clrPage+">&nbsp;</td></tr></table>\n");
	outputFrame.write("</BODY>\n</HTML>");
	outputFrame.close();
}

//
// set tab
//
TabSet.prototype.setTab=function (n)
{
    if (this.selTab!=n)
    {
	   this.selTab=n;
	   if (this.flgs & TAB_JS)
            this.pageFrame.execScript(this[n].url);
	    else
            this.pageFrame.location=this[n].url;
	   this.drawTabs();
    }
}

//
// change URL for tab (after password)
//
TabSet.prototype.setUrl=function (n,path,gothere)
{
    this[n].url = path;
    if (gothere)
        this.setTab(n);
}


