var undefined="undefined";
var isNetscape=false;
var isMicrosoft=false;
var isOpera=false;
var isWebTV=false;
var browserVersion=0.00;

if (navigator.appName=="Netscape")
	isNetscape=true;
else if (navigator.appName=="Microsoft Internet Explorer")
	isMicrosoft=true;

browserVersion=parseInt(navigator.appVersion.substring(0,navigator.appVersion.indexOf(" ")) * 100);

if (navigator.appVersion.indexOf("MSIE 5") > -1)
	browserVersion=500;
	
//debugger;
//Correction Version 6.0
if (navigator.appVersion.indexOf("MSIE 6") > -1)
	browserVersion=600;

if (navigator.appVersion.indexOf("MSIE 7") > -1)
	browserVersion=600;

if (navigator.appVersion.indexOf("MSIE 8") > -1)
	browserVersion=600;
	
var isNS4=false;
var isIE4=false;
var isNew=false;

var browser_name=((navigator.appName) + (parseInt(navigator.appVersion)));

if (parseInt(navigator.appVersion >=5 ))
	isNew=true;
else if (browser_name=="Netscape4")
	isNS4=true;
else if	 (browser_name=="Microsoft Internet Explorer4")
	isIE4=true;

var docObj;
var styleObj;

if (isNS4 || isIE4 || isNew)
{
	docObj=(isNS4) ? 'document.' : 'document.all.';
	styleObj=(isNS4) ? '' : '.style';
}

function addButton(button)
{
	var array_size=this.buttons.length;
	this.buttons[array_size]=button;
}

function getButton(button_name)
{
	var i=0;
	var array_size=this.buttons.length;
	var button_object=WIC_Button();

	for (i=0; i < array_size; i++)
	{
		if (this.buttons[i].name==button_name)
			return this.buttons[i];
	}

	for (i=0; i < array_size; i++)
	{
		button_object=this.buttons[i].getButton(button_name);
		if (button_object != null)
		{
			return button_object;
		}
	}

	alert("ERROR:\n\nButton: " + button_name + " has not been defined");
	return null;
}

function getMenu(menu_name)
{
	var i=0;
	var array_size=this.buttons.length;
	var menu_object=WIC_Menu();

	for (i=0; i < array_size; i++)
	{
		if (this.buttons[i].popup_menu.valid==true)
		{
			menu_object=this.buttons[i].getMenu(menu_name);
			if (menu_object != null)
			{
				return menu_object;
			}
		}
	}

	alert("ERROR:\n\nMenu :" + menu_name + " has not be defined");
	return null;
}

function _onMouseClick(button_name)
{
	this.showButtonEnter(button_name);
}

function _onMouseExit(button_name,sub_button)
{
	if (this.clickedButton != button_name)
	{
		this.showButtonExit(button_name);
		this.showMenu(this.showButtonEnter(this.clickedButton));
	}
}

function _onMouseEnter(button_name)
{
	if (this.clickedButton != "") 
		this.hideMenu(this.showButtonExit(this.clickedButton));

	var menu_name=this.showButtonEnter(button_name);
	this.showMenu(menu_name);

	this.clickedButton=button_name;
	this.showButtonClick(button_name);
	this.showMenu(this.showButtonEnter(button_name));
}

function _showButtonEnter(button_name)
{
	var i=0;
	var array_size=this.buttons.length;

	for (i=0; i < array_size; i++)
	{
		var menu_name=this.buttons[i].onMouseEnter(button_name);

		if (button_name==this.buttons[i].name)
			this.buttons[i].displayImage(this.buttons[i].image_enter);

		if (menu_name!="")
			break;
	}

	return menu_name;
}

function _showButtonExit(button_name)
{
	var i=0;
	var array_size=this.buttons.length;

	for (i=0; i < array_size; i++)
	{
		var menu_name=this.buttons[i].onMouseExit(button_name);

		if (button_name==this.buttons[i].name)
			this.buttons[i].displayImage(this.buttons[i].image_exit);

		if (menu_name!="")
			break;
	}

	return menu_name;
}

function _showButtonClick(button_name)
{
	var i=0;
	var array_size=this.buttons.length;

	for (i=0; i < array_size; i++)
	{
		var menu_name=this.buttons[i].onMouseClick(button_name);

		if (menu_name!="")
			break;
	}

	return menu_name;
}

function hideMenu(popup_name,force)
{
	if (force==false)
		return;

	var array_size=this.buttons.length;
    
	for (var i=0; i < array_size; i++)
	{
		if (this.buttons[i].hideMenu(popup_name)==1)
		{
			this.activeCount=this.activeCount - 1;
			break;
		}
	}
}

function showMenu(popup_name)
{
	var i=0;
	var array_size=this.buttons.length;

	for (i=0; i < array_size; i++)
	{
		if (this.buttons[i].showMenu(popup_name)==1)
		{
			if (popup_name != this.activeMenu)
				this.activeCount=this.activeCount + 1;

			return;
		}
	}
}

function keepPopupOpen(flag)
{
	this.keepOpen=flag;
}

function setDelay(delay)
{
	this.delay=delay;
}

function WIC_Container()
{
	this.activeMenu="";
	this.clickedButton="";
	this.clickedMenu="";
	this.keepOpen=false;
	this.delay=5;
	this.timeoutID=-1;
	this.activeCount=0;

	this.buttons=new Array();

	this.addButton=addButton;
	this.getMenu=getMenu;
	this.getButton=getButton;
	this.onMouseEnter=_onMouseEnter;
	this.onMouseExit=_onMouseExit;
	this.onMouseClick=_onMouseClick;
	this.hideMenu=hideMenu;
	this.showMenu=showMenu;
	this.keepPopupOpen=keepPopupOpen;
	this.setDelay=setDelay;
	this.showButtonEnter=_showButtonEnter;
	this.showButtonExit=_showButtonExit;
	this.showButtonClick=_showButtonClick;

	return this;
}

function setURL(url_link,target)
{
	this.url_link=url_link;
	this.target=target;
}

function setPopupMenu(popup_menu)
{
	this.popup_menu=popup_menu;
	this.popup_menu.parentButton=this;
}

function setSecondPopupMenu(popup_menu)
{
	this.popup_menu_2=popup_menu;
	this.popup_menu_2.parentButton=this;
}

function setThirdPopupMenu(popup_menu)
{
	this.popup_menu_3=popup_menu;
	this.popup_menu_3.parentButton=this;
}

function _buttonOnMouseEnter(button_name)
{
	if (this.name==button_name)
	{
		if (this.popup_menu.valid==true)
			return this.popup_menu.name;
		else
		{
			this.displayImage(this.image_enter);

			if (this.parent_menu != null)
				return this.parent_menu.name;
			else
				return "";
		}
	}
	else if (this.popup_menu.valid==true)
		return this.popup_menu.onMouseEnter(button_name);

	return "";
}

function _buttonOnMouseExit(button_name)
{
	if (this.name==button_name)
	{
		if (this.popup_menu.valid==true)
			return this.popup_menu.name;
		else
		{
			this.displayImage(this.image_exit);
		    
			if (this.parent_menu != null)
				return this.parent_menu.name;
			else
				return "";
		}
	}
	else if (this.popup_menu.valid==true)
		return this.popup_menu.onMouseExit(button_name);

	return "";
}

function _buttonOnMouseClick(button_name)
{
	if (this.name==button_name)
	{
		this.displayImage(this.image_click);
		return 1;
	}
	else if (this.popup_menu.valid==true)
		return this.popup_menu.onMouseClick(button_name);

	return 0;
}

function _buttonHideMenu(popup_name)
{
	if (this.popup_menu.valid==true)
	{
		var return_value=this.popup_menu.hideMenu(popup_name);

		if (return_value==1)
			this.displayImage(this.image_exit);
	}
	return return_value;
}

function _buttonShowMenu(popup_name)
{
	if (this.popup_menu.valid==true)
		if (this.popup_menu.showMenu(popup_name)==1)
		{
			this.displayImage(this.image_enter);
			return 1;
		}

	return 0;
}

function _buttonGetButton(button_name)
{
	var i=0;
	var array_size=this.buttons.length;
	var button_object=new WIC_Menu();

	for (i=0; i < array_size; i++)
	{
		if (this.buttons[i].name==button_name)
			return this.buttons[i];

		button_object=this.buttons[i].getMenu(button_name);
	}

	return button_object;
}

function _buttonGetMenu(menu_name)
{
	if (this.popup_menu.valid==false)
		return null;

	if (this.popup_menu.name==menu_name)
		return this.popup_menu;

	if (this.popup_menu_2.name==menu_name)
	   return this.popup_menu_2;    

	if (this.popup_menu_3.name==menu_name)
	   return this.popup_menu_3;    

	return menu_object=this.popup_menu.getMenu(menu_name);
}

function _showImage(image)
{
	if (isNS4)
		eval(docObj + this.name + styleObj + ".src=\"" + image.src + "\"");
	else if (isIE4)
		document.images[this.name].src=image.src;
}

function displayButtonHTML(sub_button)
{
	if (this.url_link=="javascript:void(0);" && this.popup_menu.valid==false && (sub_button==false || (this.parent_menu.buttons.length < 2 && sub_button==true)))
		document.write("<img name=\"" + this.name + "\" SRC=\"" + this.image_exit.src + "\" BORDER=0>");
	else
	{
		if (sub_button != true && sub_button != false)
			sub_button=false;

		document.write("<a href=\"" + this.url_link + "\"" +
					   " onMouseOver=\"container.onMouseEnter('" + this.name + "');\"" +
					   " onMouseOut=\"container.onMouseExit('" + this.name + "'," + sub_button + ");\"" +
					   " onClick=\"container.onMouseClick('" + this.name + "');\">" +
					   "<img name=\"" + this.name + "\" SRC=\"" + this.image_exit.src + "\" BORDER=0>" +
					   "</a>");
	}
}

function WIC_Button(name,image_enter,image_exit,image_click)
{
	this.name=name;
	this.image_enter=new Image();
	this.image_enter.src=image_enter;
	this.image_exit=new Image();
	this.image_exit.src=image_exit;
	this.image_click=new Image();
	this.image_click.src=image_click;
	this.parent_menu=null;

	this.url_link="javascript:void(0);";
	this.target="_top";
	this.popup_menu=new WIC_Menu();
	this.popup_menu_2=new WIC_Menu();
	this.popup_menu_3=new WIC_Menu();
	this.popup_menu_valid=false;

	this.setURL=setURL;
	this.setPopupMenu=setPopupMenu;
	this.setSecondPopupMenu=setSecondPopupMenu;
	this.setThirdPopupMenu=setThirdPopupMenu;
	this.onMouseEnter=_buttonOnMouseEnter;
	this.onMouseExit=_buttonOnMouseExit;
	this.onMouseClick=_buttonOnMouseClick;
	this.getMenu=_buttonGetMenu;
	this.getButton=_buttonGetButton;
	this.displayImage=_showImage;
	this.displayHTML=displayButtonHTML;
	this.hideMenu=_buttonHideMenu;
	this.showMenu=_buttonShowMenu;

	return this;
}

function _menuAddButton(button)
{
	var array_size=this.buttons.length;
	button.parent_menu=this;
	this.buttons[array_size]=button;
	this.parent_button=this;
}

function popupOnMouseEnter(button_name)
{
	var i=0;
	var array_size=this.buttons.length;
    
	for (i=0; i < array_size; i++)
	{
		var menu_name=this.buttons[i].onMouseEnter(button_name);

		if (menu_name != "")
			return menu_name;
	}

	return "";
}

function popupOnMouseExit(button_name)
{
	var i=0;
	var array_size=this.buttons.length;

	for (i=0; i < array_size; i++)
	{
		var menu_name=this.buttons[i].onMouseExit(button_name);

		if (menu_name != "")
			return menu_name;
	}

	return "";
}

function popupOnMouseClick(button_name)
{
	var i=0;
	var array_size=this.buttons.length;
    
	for (i=0; i < array_size; i++)
	{
		if (this.buttons[i].onMouseClick(button_name)==1)
			return 1;
	}

	return 0;
}

function popupShow()
{
	var dom=eval(docObj + this.name + styleObj);
	dom.visibility="visible";

	if (this.parentButton != null)
	{
		if (this.parentButton.popup_menu_2.valid==true)
		{
			var dom=eval(docObj + this.parentButton.popup_menu_2.name + styleObj);
				dom.visibility="visible";
		}
	    
		if (this.parentButton.popup_menu_3.valid==true)
		{
			var dom=eval(docObj + this.parentButton.popup_menu_3.name + styleObj);
				dom.visibility="visible";
		}
	}
	return 1;
}

function popupHide()
{
	var dom=eval(docObj + this.name + styleObj);
	dom.visibility="hidden";

	this.parentButton.displayImage(this.parentButton.image_exit);

	if (this.parentButton != null)
	{
		if (this.parentButton.popup_menu_2.valid==true)
		{
			var dom=eval(docObj + this.parentButton.popup_menu_2.name + styleObj);
				dom.visibility="hidden";
		}
	    
		if (this.parentButton.popup_menu_3.valid==true)
		{
			var dom=eval(docObj + this.parentButton.popup_menu_3.name + styleObj);
				dom.visibility="hidden";
		}
	}
	return 0;
}

function _menuGetButton(menu_name)
{
	var i=0;
	var array_size=this.buttons.length;
	var button_object=null;

	for (i=0; i < array_size; i++)
	{
		button_object=this.buttons[i].getMenu(name);
	}

	return button_object;
}

function _menuGetMenu(menu_name)
{
	var i=0;
	var array_size=this.buttons.length;
	var menu_object=new WIC_Menu();

	for (i=0; i < array_size; i++)
	{
		if (this.buttons[i].popup_menu.valid==true)
		{
			menu_object=this.buttons[i].getMenu(name);		  
			if (menu_object.name==menu_name)
				return menu_object;
		}
	}
	 return null;
}


function displayMenuStyle()
{
	document.write ("\n<style type=\"text/css\">\n");
	document.write ("." + this.name + "{position: absolute;\n");
	document.write ("top: " + this.loc_y + "px;\n");
	document.write ("left: " +	this.loc_x + "px;\n");
	document.write ("width: " + this.width + "px;\n");
	document.write ("height: " + this.height + "px;\n");
	document.write ("visibility: hidden;\n");
	document.write ("background-color: " + this.bgcolor + ";}\n");
	document.write ("</style>\n");
}

function displayMenuHTML()
{
	var event_code;

	if (this.buttons.length > 1)
	{
		event_code= "onMouseOver=\"container.showMenu('" + this.name + "')\" " +
					"onMouseOut=\"container.hideMenu('" + this.name + "',false)\"";
	}
	else
		event_code="";
    
	if (browserVersion < 500 && browserVersion > 400 && isNetscape)
	{
		document.write ("<layer name=\"" + this.name + "\"" +
						" top=\"" + this.loc_y + "\"" +
						" left=\"" + this.loc_x + "\"" +
						" width=\"" + this.width + "\"" +
						" height=\"" + this.height + "\"" +
						/*" bgcolor=\"" + this.bground + "\"" +*/
						" visibility=\"hide\"" + event_code + " >");
	}
	else if ((isMicrosoft && browserVersion > 400) || (browserVersion >= 500 && !isNetscape))
		document.write ("<div class=\"" + this.name+ "\" ID=\"" + this.name + "\" name=\"" + this.name +"\"" + event_code + ">");
	else if (isNetscape && browserVersion >= 500)
		document.write ("<span class=\"" + this.name+ "\" ID=\"" + this.name + "\" name=\"" + this.name +"\"" + event_code + ">");
    
	if (this.buttons.length > 1)
		document.write("<table border=0 cellspacing=0 cellpadding=10><tr><td>");

	var button_count=this.buttons.length;

	for (var i=0; i<button_count; i++)
	{
		this.buttons[i].displayHTML(true);
	}

	if (this.buttons.length > 1)
		document.write("</td></tr></table>");

	if (browserVersion < 500 && browserVersion > 400 && isNetscape)
		document.write ("</layer>\n");

	else if ((isMicrosoft && browserVersion > 400) || (browserVersion >= 500 && !isNetscape))
		document.write ("</div>\n");

	else if (isNetscape && browserVersion >= 500)
	{
		document.write ("</span>\n");
		this.hide();
	}
}

function _menuHideMenu(popup_name)
{
	var i=0;
	var array_size=this.buttons.length;

	if (this.name==popup_name)
	{
		this.hide();
		return 1;
	}

	for (i=0; i < array_size; i++)
	{
		if (this.buttons[i].hideMenu(popup_name)==1)
			return 1;
	}
	return 0;
}

function _menuShowMenu(popup_name)
{
	if (this.name==popup_name)
	{
		this.show();
		return 1;
	}

	var i=0;
	var array_size=this.buttons.length;

	for (i=0; i < array_size; i++)
	{
		if (this.buttons[i].showMenu(popup_name) != 0)
		{
			this.show();
			return 1;
		}
	}
	return 0;
}

function WIC_Menu(name,loc_x,loc_y,width,height,bgcolor)
{
	this.valid=false;

	var name_value="" + name;

	if (name_value != "undefined" && name_value != null) 
		this.valid=true;

	this.buttons=new Array();
	this.name=name;
	this.loc_x=loc_x;
	this.loc_y=loc_y;
	this.width=width;
	this.height=height;
	this.bgcolor=bgcolor;
	this.parentButton=null;

	this.addButton=_menuAddButton;
	this.setDelay=setDelay;
	this.onMouseEnter=popupOnMouseEnter;
	this.onMouseExit=popupOnMouseExit;
	this.onMouseClick=popupOnMouseClick;
	this.show=popupShow;
	this.hide=popupHide;
	this.displayStyle=displayMenuStyle;
	this.displayHTML=displayMenuHTML;
	this.getMenu=_menuGetMenu;
	this.getButton=_menuGetButton;
	this.hideMenu=_menuHideMenu;
	this.showMenu=_menuShowMenu;

	return this;
}
