<!--

// ----------------------------------------------------------------------------
//
// TrolleyBox - Copyright (C) 1999-2006 Spanner Sofware Ltd. All rights reserved.
// 
// This code is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2.0 as published by the Free Software Foundation. See
// http://www.gnu.org/copyleft/gpl.html for full details.
// 
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// Please notify us of any improvements by sending them to
// dev@spannersoftware.com
// 
// Filename:  menu.js
// Version:   1.01
// Purpose:   Dropdown menu functions
// 
// Version  Date        Author  Action
// 1.00     06-03-2002  VJS     Created
// 1.01     04-12-2003  VJS     Customised for DomainNameShop.co.uk
// 
// ----------------------------------------------------------------------------

x = 0;
dx = 0;
hspace = 0;
num_menu_layers = 0;
Menu = new Array();

function MenuItem(type, url, itemtext, width, height, menucss) {
  this.type = type;
  this.url = url;
  this.itemtext = itemtext;
  this.width = width;
  this.height = height;
  this.menucss = menucss;
}

function GetMaxHeight() {
  max_height = 0;

  for (i = 0; i < Menu.length; i++) {
    if (Menu[i].height > max_height) {
      max_height = Menu[i].height;
    }
  }
  
  return max_height;
}

function GetNoMenus() {
  num_menus = 0;

  for (i = 0; i < Menu.length; i++) {
    if (Menu[i].type == "main") {
      num_menus++;
    }
  }
  
  return num_menus;
}

function add_menu(start_x, y, spacing, current_url, bg_color, hl_color, menu_height, item_height, hide_first_form, x_adjust, new_win_url, use_dropdown) {
  var layer_vis = "visible";
  var curr_item = 0;
  var in_layer = false;
  var menu_layer_no = 0;
	
	hspace = spacing;
	x = start_x;
	dx = x_adjust;

  if (use_dropdown == "Y") {
		// do mask layer to hide menu layers when not required
		document.writeln('<div id="mask" style="position:absolute; left:0px; top:' + y + 'px; width:' + (WindowWidth() - 30) + 'px; height:' + GetMaxHeight() + 'px; z-index:1; visibility: hidden">');
		document.writeln('<a href="javascript:;" onMouseOver="HideAll(' + hide_first_form + ')"><img src="/pics/t.gif" width="100%" height="100%" border="0"></a>');
		document.writeln('</div>');
	}
  
  // do main menu buttons first
  curr_item = 0;
  menu_layer_no = 0;
  num_menus = GetNoMenus();
  total_width = (num_menus * hspace);

//  document.writeln('<table bgcolor="' + bg_color + '" width="' + total_width + '" cellspacing="0" cellpadding="2">');
  document.writeln('<table width="' + total_width + '" cellspacing="0" cellpadding="0">');
	document.writeln('<tr><td width="' + start_x + '">');
	document.writeln('<img src="/pics/t.gif" width="' + start_x + '" height="' + menu_height + '" border="0"></td>');
  
  while (curr_item < Menu.length) {
    if (Menu[curr_item].type == "main") {
      if (Menu[curr_item].height > 0) {
        menu_layer_no++;
      }
      
			if (use_dropdown == "Y") {
        add_main(hspace, Menu[curr_item].height, Menu[curr_item].url, Menu[curr_item].itemtext, Menu[curr_item].menucss, menu_layer_no, bg_color, hl_color, hide_first_form);
			} else {
        add_main_only(hspace, Menu[curr_item].height, Menu[curr_item].url, Menu[curr_item].itemtext, Menu[curr_item].menucss, bg_color, hl_color, hide_first_form);
			}
    }
      
    curr_item++;
  }

  document.writeln('</tr></table>');

  if (use_dropdown == "Y") {
		// now create submenus as layers
		curr_item = 0;
		menu_layer_no = 0;
		curr_x = x;
		in_layer = false;
		
		while (curr_item < Menu.length) {
			if (Menu[curr_item].type == "main") {
				if (in_layer) {
					close_menu_layer();
					in_layer = false;
				}
	
				if (Menu[curr_item].height > 0) {
					menu_layer_no++;
	
					if ((dx > 0) && (WindowWidth() > dx)){
						open_menu_layer("menu" + menu_layer_no, "hidden", bg_color, curr_x + ((WindowWidth() - dx) / 2), y - 3, Menu[curr_item].width,
							Menu[curr_item].height);
					} else {
						open_menu_layer("menu" + menu_layer_no, "hidden", bg_color, curr_x, y - 3, Menu[curr_item].width,
							Menu[curr_item].height);
					}
	
					in_layer = true;
				}
	
				curr_x += hspace;
			} else if (Menu[curr_item].type == "item") {
				add_item_button(Menu[curr_item].url, Menu[curr_item].itemtext, Menu[curr_item].menucss, item_height, bg_color, hl_color);
			}
				
			curr_item++;
		}
			
		if (in_layer) {
			close_menu_layer();
		}
	
		num_menu_layers = menu_layer_no;
	}
}

function DoResize() {
  if (dx > 0) {
		curr_item = 0;
		menu_layer_no = 0;
		curr_x = x;
		in_layer = false;
		
		while (curr_item < Menu.length) {
			if (Menu[curr_item].type == "main") {
				if (Menu[curr_item].height > 0) {
					menu_layer_no++;
					
					if (WindowWidth() > dx) {
  					new_x = curr_x + ((WindowWidth() - dx) / 2);
					} else {
					  new_x = curr_x;
					}
	
					if (document.layers) {
						layer = document.layers['menu' + menu_layer_no].left = new_x;
					} else if (document.all) {
						layer = document.all('menu' + menu_layer_no).style.left = new_x;
					} else {
						layer = document.getElementById('menu' + menu_layer_no).style.left = new_x;
					}
				}
	
				curr_x += hspace;
			}
				
			curr_item++;
		}
	}
}

function WindowWidth() {
  if (window.innerWidth) {
	  return window.innerWidth;
	} else {
	  return document.body.offsetWidth;
	}
}

function ShowMenu(menu_layer_no, hide_first_form) {
  if (document.layers) {
    for (i = 1; i <= num_menu_layers; i++) {
      document.layers['menu' + i].visibility = 'hidden';
    }

    document.layers['mask'].visibility = 'visible';
    document.layers['menu' + menu_layer_no].visibility = 'visible';
  } else if (document.all) {
    for (i = 1; i <= num_menu_layers; i++) {
      document.all('menu' + i).style.visibility = 'hidden';
    }

    document.all('mask').style.visibility = 'visible';
    document.all('menu' + menu_layer_no).style.visibility = 'visible';
  } else {
    for (i = 1; i <= num_menu_layers; i++) {
      document.getElementById('menu' + i).style.visibility = 'hidden';
    }

    document.getElementById('mask').style.visibility = 'visible';
    document.getElementById('menu' + menu_layer_no).style.visibility = 'visible';
  }
	
	if (document.form0 && hide_first_form) {
  	document.form0.style.visibility = 'hidden'; // hide search form
	}
}

function HideAll(hide_first_form) {
  if (document.layers) {
    for (i = 1; i <= num_menu_layers; i++) {
      document.layers['menu' + i].visibility = 'hidden';
    }

    document.layers['mask'].visibility = 'hidden';
  } else if (document.all) {
    for (i = 1; i <= num_menu_layers; i++) {
      document.all('menu' + i).style.visibility = 'hidden';
    }

    document.all('mask').style.visibility = 'hidden';
  } else {
    for (i = 1; i <= num_menu_layers; i++) {
      document.getElementById('menu' + i).style.visibility = 'hidden';
    }

    document.getElementById('mask').style.visibility = 'hidden';
  }
	
	if (document.form0 && hide_first_form) {
  	document.form0.style.visibility = 'visible'; // show search form
	}
}

function open_menu_layer(menuname, vis, bg_color, nleft, ntop, nwidth, nheight) {
  document.writeln('<div id="' + menuname + '" style="position:absolute; left:' + nleft + 'px; top:' + ntop + 'px; width:' + nwidth + 'px; height:' + nheight + 'px; z-index:3; visibility:' + vis + '">');
  document.writeln('<table class="menuDropDown" border="0" cellpadding="0" cellspacing="0" width="' + nwidth + '">');
}

function close_menu_layer() {
  document.writeln('</table>');
  document.writeln('</div>');
}

function add_main(nwidth, nheight, url, itemtext, menucss, menu_layer_no, bg_color, hl_color, hide_first_form) {
  document.write('<td width="' + nwidth + '" class="' + menucss + '" onMouseOut="this.className=\'' + menucss + '\'" onClick="parent.location=\'' + url + '\'"');
	
  if (nheight == 0) {
    document.write(' onMouseOver="this.className=\'' + menucss +'_H\'; HideAll(' + hide_first_form + ')">');
  } else {
    document.write(' onMouseOver="this.className=\'' + menucss +'_H\'; ShowMenu(' + menu_layer_no + ', ' + hide_first_form + ')">');
  }

  document.write('<img src="/pics/t.gif" width="' + nwidth + '" height="1" border="0"><br>');
	document.writeln('<img src="/pics/t.gif" width="2" height="2" border="0">' + itemtext + '</td>');
}

function add_main_only(nwidth, nheight, url, itemtext, menucss, menu_layer_no, bg_color, hl_color, hide_first_form) {
  document.write('<td width="' + nwidth + '" class="' + menucss + '" onMouseOut="this.className=\'' + menucss + '\'" onClick="parent.location=\'' + url + '\'"');
	
  if (nheight == 0) {
    document.write(' onMouseOver="this.className=\'' + menucss +'_H\'">');
  } else {
    document.write(' onMouseOver="this.className=\'' + menucss +'_H\'">');
  }

  document.write('<img src="/pics/t.gif" width="' + nwidth + '" height="1" border="0"><br>');
	document.writeln('<img src="/pics/t.gif" width="2" height="2" border="0">' + itemtext + '</td>');
}

function add_item_button(url, itemtext, menucss, item_height, bg_color, hl_color) {
  if (itemtext == "-") {
	  document.write('<tr><td class="' + menucss + '" valign="top"><img src="/pics/t.gif" width="8" height="1"></td></tr>');
    document.write('<tr><td class="' + menucss + '" valign="top"><img src="/pics/ruler.gif" width="100%" height="7" align="absmiddle"></td></tr>');
	} else if (itemtext == "*") {
    document.write('<tr><td class="' + menucss + '" valign="top"><img src="/pics/t.gif" width="8" height="3"></td></tr>');
	} else {
    document.write('<tr><td class="' + menucss + '" valign="top" onMouseOver="this.className=\'' + menucss +'_H\'" onMouseOut="this.className=\'' + menucss + '\'" onClick="parent.location=\'' + url + '\'">');
    document.writeln('<img src="/pics/t.gif" width="8" height="' + item_height + '" align="absmiddle">' + itemtext + '</td></tr>');
	}
}

//-->