var curved_tabs_objs = new Array();
var curved_tabs_obj_count = 0;

function curved_tabs(obj_id_name, name_array, func_name1, font_color, select_background_color)
{
this.obj = document.getElementById(obj_id_name);
if(this.obj == null)
	return null;
//this.doc = document;
this.func_name = func_name1;
this.count = name_array.length;
this.font_color = font_color;
this.background_color = select_background_color;
this.hide_tab = hide_curved_tab;
this.select_tab = select_curved_tab;
this.set_tab_name = set_curved_tab_name;
this.disabled = false;
this.selected_index = -1;
this.hide = hide_curved_tabs;
index = set_curved_tabs_obj(this);
var width = '100%';
var str = '';
var i;
str += '<table border="0" id="curved_'+this.func_name+'_table" cellspacing="0" cellpadding="0" width1="'+width+'" height="100%">\n';
str += '	<tr>\n';

for(i = 0; i < name_array.length; ++i)
	{
	str += '		<td width="200"  valign="bottom" align="center">\n';
	str += '			<span value="0" id="curved_tab_'+this.func_name+'_'+i+'_t1" style="display: block; background: transparent;">\n';
	str += '			<b id="curved_'+this.func_name+'_'+i+'_b1" style="display:block;  overflow:hidden;  height:1px;  font-size:1px; margin:0 5px; background: gray;"></b>\n';
	str += '			<b id="curved_'+this.func_name+'_'+i+'_b2" style="display:block;  overflow:hidden;  height:1px;  font-size:1px; margin:0 3px; border-left:2px solid gray;  border-right:2px solid gray;"></b>\n';
	str += '			<b id="curved_'+this.func_name+'_'+i+'_b3" style="display:block;  overflow:hidden;  height:1px;  font-size:1px; margin:0 2px; border-left:1px solid gray;  border-right:1px solid gray;"></b>\n';
	str += '			<b id="curved_'+this.func_name+'_'+i+'_b4" style="display:block;  overflow:hidden;  height:2px;  font-size:1px; margin:0 1px; border-left:1px solid gray;  border-right:1px solid gray;"></b>\n';
	str += '			<div onmousedown="handle_curved_tab_select('+i+','+index+',true)" id="curved_'+this.func_name+'_'+i+'_s1" style="cursor: pointer; cursor: hand; width: 105px; height: 25px; display: block; text-align: center; vertical-align: top; border: 0px solid gray;  border-width: 0 1px 0 1px;">';
	str += '				<table style="text-align: center; vertical-align: top;" border="0" cellspacing="0" cellpadding="0">\n';
	str += '					<tr>\n';
	str += '						<td style="font-size: 6pt;">\n';
	str += '							&nbsp;';
	str += '						</td>\n';

	if(name_array[i][2] != null)
		{
		str += '						<td>\n';
		str += '							<img  id="curved_'+this.func_name+'_'+i+'_s3" src="'+name_array[i][2]+'" height="25">\n';
		str += '						</td>\n';

		str += '						<td style="font-size: 6pt;">\n';
		str += '							&nbsp;';
		str += '						</td>\n';
		str += '						<td valign="middle" align="left">\n';
		}
	else
		{
		str += '						<td valign="middle" align="center">\n';
		}

	str += '							<span href1="javascript:handle_curved_tab_select('+i+','+index+',true)" id="curved_'+this.func_name+'_'+i+'_s2" style="font-family: arial; color: gray; text-align: center; font-size: 10pt; cursor: pointer; cursor: hand" title="'+name_array[i][1]+'">'+name_array[i][0]+'</span>';
	//str += name_array[i][1];
	str += '						</td>\n';
	str += '					</tr>\n';
	str += '				</table>\n';
	str += '			</div>\n';
	str += '				</span>\n';
	str += '		</td>\n';
	str += '<td style="font-size: 6pt; border-bottom: 1px solid black;">&nbsp;</td>';
	}
str += '<td style="border-bottom: 1px solid black" width="100%">&nbsp;</td>';
str += '	</tr>\n';
str += '</table>\n';
this.obj.innerHTML = str;
this.obj.style.visibility = 'visible';
//setTimeout('handle_curved_tab_select(0,'+index+')',10);
}

function set_curved_tabs_obj(obj)
{
var index = curved_tabs_obj_count;
curved_tabs_objs[curved_tabs_obj_count++] = obj;
return index;
}

function get_curved_tabs_obj(index)
{
	return curved_tabs_objs[index];
}

function get_curved_tabs_obj_index(obj)
{
	var i;
	for(i = 0; i < curved_tabs_obj_count; ++i)
		{
		if(curved_tabs_objs[i] == obj)
			{
			return i;
			}
		}
return -1;
}

function handle_curved_tab_select(index, obj_index, fire_function)
{
var obj = get_curved_tabs_obj(obj_index);
if(obj == null)
	{
	//alert('NULL');
	return;
	}
var elem;
var i;
var id;
var border_color;
var font_color1;
var background_color;
var font_weight;
var border_type;
var bottom_border_type;
var show_type;
var filter_type;
if(obj.disabled == true && obj.selected_index != -1)
	{
	//	alert(obj.disabled + "," + obj.selected_index);
	return;
	}
obj.selected_index = index;
for (i = 0; i < obj.count; ++i)
	{
	id='curved_tab_'+obj.func_name+'_'+i+'_t1';
	elem = document.getElementById(id);
	if(elem == null)
		continue;
	show_type = elem.value*1;
	if(show_type != 2)
		{
		if(i == index)
			{
			//this is the selected tab
			elem.value = 1;
			show_type = 1;
			}
		else
			{
			//this is a visible non selected tab
			elem.value = 0;
			show_type = 0;
			}
		}
	else
		{
		if(i == index)
			{
			fire_function = false;
			}
		}
	switch(show_type)
		{
		case 0:	//non selected tab
			font_color1 				= '#666666';
			border_color 				= font_color1;
			background_color 		= '';
			font_weight 				= 'normal';
			border_type 				= 'solid';
			bottom_border_type 	= '1px solid black';
			side_border 				= '0 1px 0 1px';
			filter_type					= 'gray';
			break;

		case 1:	//selected tab
			font_color1 				= obj.font_color;
			border_color 				= 'black';
			background_color 		= obj.background_color;
			font_weight 				= 'bold';
			border_type 				= 'solid';
			bottom_border_type 	= '0px';
			side_border 				= '0 1px 0 1px';
			filter_type					= '';
			break;

		case 2:	//hidden tab
			font_color1 				= '';
			border_color 				= '';
			background_color 		= '';
			font_weight 				= 'normal';
			border_type 				= '';
			bottom_border_type 	= '1px solid black';
			side_border 				= '0px';
			filter_type					= '';
			break;

		}

	id='curved_'+obj.func_name+'_'+i+'_b1';
	elem = document.getElementById(id);
	if(elem != null)
		{
		elem.style.background = border_color;
		}
	for (j = 2; j <= 4; ++j)
		{
		id='curved_'+obj.func_name+'_'+i+'_b'+j;
		elem = document.getElementById(id);
		if(elem != null)
			{
			elem.style.background = background_color;
			if(j != 2)
				{
				elem.style.borderLeft  = '1px '+border_type+' '+border_color;
				elem.style.borderRight = '1px '+border_type+' '+border_color;
				}
			else
				{
				elem.style.borderLeft  = '2px '+border_type+' '+border_color;
				elem.style.borderRight = '2px '+border_type+' '+border_color;
				}
			}
		}
	id='curved_'+obj.func_name+'_'+i+'_s1';
	elem = document.getElementById(id);
	if(elem != null)
		{
		elem.style.background = background_color;
		elem.style.border= '0px '+border_type+' ' + border_color;
		elem.style.borderWidth = side_border;
		elem.style.borderBottom = bottom_border_type;
		}
	id='curved_'+obj.func_name+'_'+i+'_s2';
	elem = document.getElementById(id);
	if(elem != null)
		{
		if(show_type == 2)
			{
			elem.style.visibility = 'hidden';
			}
		else
			{
			elem.style.visibility = 'visible';
			elem.style.fontWeight=font_weight;
			elem.style.background = background_color;
			elem.style.color= font_color1;

			}
		}
	id='curved_'+obj.func_name+'_'+i+'_s3';
	elem = document.getElementById(id);
	if(elem != null)
		{
		elem.style.filter = filter_type;
		}
	}
if(fire_function == true)
	{
	setTimeout(obj.func_name+"("+index+")",10);
	}
}

function hide_curved_tab(index, hide)
{
var id;
var elem;
var i;
id='curved_tab_'+this.func_name+'_'+index+'_t1';
elem = document.getElementById(id);
if(elem == null)
	{
	return;
	}

i = get_curved_tabs_obj_index(this);
if(i == -1)
	return;

if(hide == true)
	{
	if(index > 0 && elem.value == 1)
		{
		//alert(index);
		id = index - 1;
		elem.value = 2; //hide this tab
		handle_curved_tab_select(id,i,true);
		}
	else
		{
		elem.value = 2;
		handle_curved_tab_select(this.selected_index,i,false);
		}
	}
else
	{
	elem.value = 0; //make this tab visible
	handle_curved_tab_select(this.selected_index,i,false);
	}


/*
for(i = 1; i <=4; ++i)
	{
	id='curved_'+this.func_name+'_'+index+'_b'+i;
	elem = document.getElementById(id);
	if(elem != null)
		elem.style.visibility = (hide == false)?('visible'):('hidden');
	}
id='curved_'+this.func_name+'_'+index+'_s2';
elem = document.getElementById(id);
if(elem != null)
	{
	elem.style.visibility = (hide == false)?('visible'):('hidden');
	}
id='curved_'+this.func_name+'_'+index+'_s1';
elem = document.getElementById(id);
if(elem != null)
	{
	if(hide == true)
		{
		elem.style.borderWidth = '0 0 1px 0';
		}
	else
		{
		elem.style.borderWidth = '0 1px 1px 1px';
		}
	}
*/
}

function select_curved_tab(index, fire_function)
{
var i;
i = get_curved_tabs_obj_index(this);
if(i == -1)
	return;
handle_curved_tab_select(index, i, fire_function);
//setTimeout('handle_curved_tab_select('+index+','+i+','+fire_function+')',10);
}

function set_curved_tab_name(index, name)
{
var id='curved_'+this.func_name+'_'+index+'_s2';
var elem = document.getElementById(id);
if(elem != null)
	{
	elem.innerHTML = name;
	}
}

function hide_curved_tabs(hide)
{
var count;
var i;
var id = 'curved_'+this.func_name+'_table';
var elem = document.getElementById(id);
if(elem != null)
	{
	elem.style.visibility = hide?("hidden"):("visible");
	}
count = this.count;
for(i = 0; i < count; ++i)
	{
	id='curved_'+this.func_name+'_'+i+'_s2';
	elem = document.getElementById(id);
	if(elem != null)
		{
		if(hide == true)
			{
			elem.style.visibility = 'hidden';
			}
		else
			{
			if(elem.value != 2)
				{
				elem.style.visibility = 'visible';
				}
			}
		}
	}
}
