/*  Script changed By Real Software on 26 aug 2003
    Author Karel Goossens.

    - Changes made to Positioning of the menubar.
    - Changes made to Width of images for menuItem.
    - Changes made to positioning menuItem images.
    - Changes made to menuItem: can now point to a href.

    Positioning of the menubar:

    the menubar position can be set to a fixed position on the screen, providing
    u set an image in your htmlpage.  This image must have the property id="positioner"
    use a spacer for this, with the properties width="1" height="1".  Use a second spacer
    with the propertie onload set to onload="reloadWindow()"  This wil force the first
    positioning,  this must be done after the positioner image so that its coördinates are
    known.

    You can modifie the position of the menubar relatively to the position of the
    positioner image by use of the variable positionerOffset.

    If all these variables and spacers are omited, the default operation method will be
    in use.

    Width of the images of the menuItems.

    create an array named "menuImageWidthArray", assign in sequence the width of every
    menuItem bitmap. If omited the default value or the value of the variable menuImgWidth
    will be used.

    Positioning of the menuItem images.

    Create an array named "positionArray", assign in sequence the position of every
    menuItem bitmap (the first starts at position 0 normaly), If omited the default value
    will be used.

    MenuItem can now point to a href.

    Create an array named "menuClickArray", assign in sequence the url that you wish
    to assign to the menuItem.  The array is checked in sequence, so you can omit elements
    after the last menuItem you wish to provide with a url. All folowing menuItems will
    have the javascript:void(0) assigned as a link.  If you wish you can fill preceding
    menuItems with javascript:void(0) if you wish them not to be clickable.

    Omitting this array will result in default behavior, all menuItems will be set to
    javascript:void(0).
*/
if (!totalMenuWidth) var totalMenuWidth = 0;
if (!additionalScroll) var additionalScroll = 0;

var DOM     = (document.getElementById);
var NS4     = (document.layers);
var NS6     = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
var IE      = (document.all);
var IE4     = (IE && !DOM);
var IE5     = (IE && DOM);
var Mac     = (navigator.appVersion.indexOf("Mac") != -1);
var IEMac   = (IE && Mac);
var IE4Mac  = (IE4 && Mac);
var IE5Mac  = (IE5 && Mac);
var NS      = (NS4 || NS6);

if (IE)  {var addToMenuXPos = (document.body.clientWidth) ? ((document.body.clientWidth-totalMenuWidth)/2) : 0;}
if (NS4) {var addToMenuXPos = (window.innerWidth) ? ((window.innerWidth-totalMenuWidth)/2)-8 : 0;}
if (NS6) {
	var addToMenuXPos = (window.innerWidth) ? ((window.innerWidth-totalMenuWidth)/2)-8 : 0;
	window.innerWidth--;
}
if (addToMenuXPos < 0) addToMenuXPos = 0;

if (DOM) {
	function reloadWindow() {
		positionImage=document.getElementById('positioner')
		if (positionImage!=null){
		  if (!window.positionerOffset) var positionerOffset = 0;
		  positionImage.style.position='absolute';
		  document.getElementById('fullMenu').style.left = positionImage.offsetLeft+positionerOffset;
		  positionImage.style.position='relative';
		} else {
		  if (IE)  {
		    var addToMenuXPos = (document.body.clientWidth) ? ((document.body.clientWidth-totalMenuWidth)/2) : 0;
		  }
		  if (NS6) {
		 	if (document.height > window.innerHeight) {
				var addToMenuXPos = (window.innerWidth) ? ((window.innerWidth-totalMenuWidth)/2)-8 : 0;
			} else {
				var addToMenuXPos = (window.innerWidth) ? ((window.innerWidth-totalMenuWidth)/2) : 0;
			}
		  }
		  if (addToMenuXPos < 0) addToMenuXPos = 0;
		  document.getElementById('fullMenu').style.left = addToMenuXPos;
		}
	}

	window.onresize = reloadWindow;
}

if (NS4) {
	function reloadWindowNS() {
		window.location.reload(window.location.href)
	}
	function regenerate() {
		window.onresize=reloadWindowNS;
	}
	window.onload = regenerate;
}

var _allMenusArray = new Array();

function Menu() {
	this.id = _allMenusArray.length;
	this.menuImgSrcOn = "/imgs/spacer.gif";
	this.menuImgSrcOff = "/imgs/spacer.gif";
	this.moving = 0;
	this.menuXPos = 0;
	this.menuYPos = 66;
	this.menuImgWidth = 160;
	this.menuImgHeight = 20;
	this.menuHeight = 0;
	this.menuWidth = 160;
	this.position = 0;

	this.itemHeight = 20;
	this.border = false;
	this.borderWidth = 1;
	this.borderColor = "CCCCCC";
	this.separator = true;
	this.separatorHeight = 2;
	this.bgColor = "888888";
	this.hoverColor = "777777";
	this.speed = 10;
	this.step = 10;

	this.itemsContent = new Array();
	this.itemsURL = new Array();

	_allMenusArray[this.id] = this;

	this.addSubmenuItem = function(itemContent, itemUrl) {
		var index = this.itemsContent.length;
		this.itemsContent[index] = itemContent;
		this.itemsURL[index] = itemUrl;
		if (this.border == true) {
			this.menuHeight = (this.itemHeight+this.borderWidth)*(index+1)+this.borderWidth+additionalScroll;
			this.position = -((this.itemHeight+this.borderWidth)*(index+1)+this.borderWidth+additionalScroll);
		} else {
			this.menuHeight = this.itemHeight*(index+1)+additionalScroll;
			this.position = -this.itemHeight*(index+1)+additionalScroll;
		}
		if (this.separator == true) {
			this.menuHeight += this.separatorHeight*(index+1);
			this.position -= this.separatorHeight*(index+1);
		}

	};

  this.move = function() {
		if (this.moving == 1) {
			if (this.position < 0) {
				this.position += this.step;
				if (this.position >= 0) {
					this.position = 0;
					this.moving = 0;
				}
			}
		} else if (this.moving == -1) {
			if (this.position > -this.menuHeight) {
				this.position -= this.step;
				if (this.position <= -this.menuHeight) {
					this.position = -this.menuHeight;
					this.moving = 0;
					if (DOM) {
					  	document.getElementById('menuBox'+this.id).style.left = -2000;
					  	document.getElementById('menuBox'+this.id).style.top = -2000;
					}
					if (NS4) {
						eval("document.menuBox"+this.id+".zIndex=-1");
						eval("document.menuBox"+this.id+".document.menuItem"+this.id+".zIndex=-1");
						eval("document.menuBox"+this.id+".left = -2000");
						eval("document.menuBox"+this.id+".top = -2000");
					}
				}
			}
		}

		if (DOM) {
			document.getElementById("menuItem"+this.id).style.top = this.position;
		}

		if (NS4) {
			eval("document.menuBox"+this.id+".document.menuItem"+this.id+".top="+this.position);
		}

		if (this.moving != 0) {
			setTimeout("_allMenusArray["+this.id+"].move()",this.speed);
		}
	};

	this.show = function() {
		if (this.moving == 1) {
			return;
		}

		if (this.moving == 0) {
			if (DOM) {
			  	document.getElementById('menuBox'+this.id).style.left = this.menuXPos;
			  	document.getElementById('menuBox'+this.id).style.top = this.menuYPos+this.menuImgHeight;
				document.getElementById("menuItem"+this.id).style.visibility = "visible";
			}
			if (NS4) {
				eval("document.menuBox"+this.id+".zIndex=9");
				eval("document.menuBox"+this.id+".document.menuItem"+this.id+".zIndex=10");
				eval("document.menuBox"+this.id+".document.menuItem"+this.id+".visibility='show'");
				eval("document.menuBox"+this.id+".left = "+eval(this.menuXPos+addToMenuXPos)+";");
				eval("document.menuBox"+this.id+".top = "+eval(this.menuYPos+this.menuImgHeight)+";");
				eval("document.menuBox"+this.id+".onmouseover = function() { _allMenusArray["+this.id+"].show(); };");
				eval("document.menuBox"+this.id+".onmouseout = function() { _allMenusArray["+this.id+"].hide(); };");
			}
			this.moving = 1;
			setTimeout("_allMenusArray["+this.id+"].move()",this.speed);
		}
		else {
			this.moving = 1;
		}
	};

	this.hide = function() {
		if (this.moving == -1) {
			return;
		}

		if (this.moving == 0) {
			this.moving = -1;
			setTimeout("_allMenusArray["+this.id+"].move()",this.speed);
		}
		else {
			this.moving = -1;
		}
  };

  // ************ The draw function ***************
  this.draw = function() {
    var hrefLink = 'javascript:void(0);';
    if (window.menuClickArray){
      if ( menuClickArray.length > this.id ){
        hrefLink = menuClickArray[this.id];
      }
    }
    if (window.menuImageWidthArray){
      if (menuImageWidthArray.length > this.id ){
        this.menuImgWidth= menuImageWidthArray[this.id];
      }
    }

    if (window.positionArray){
      if (positionArray.length > this.id ){
        this.menuXPos=positionArray[this.id];
      }
    }
    document.write('	<div id="menuImage'+this.id+'" class="menuImage" onMouseOver="_allMenusArray['+this.id+'].show();" onMouseOut="_allMenusArray['+this.id+'].hide();">');
	if (this.id == currentmenuitem) {
        document.write('	<a href="'+ hrefLink +'" onMouseOver="_allMenusArray['+this.id+'].show();" onMouseOut="_allMenusArray['+this.id+'].hide();"><img name="'+this.menuImgSrcOn+'" src="'+this.menuImgSrcOn+'" width="'+this.menuImgWidth+'" height="'+this.menuImgHeight+'" border="0" alt="'+this.menuAltText+'"></a>');
	} else {
	      document.write('	<a href="'+ hrefLink +'" onMouseOver="_allMenusArray['+this.id+'].show();" onMouseOut="_allMenusArray['+this.id+'].hide();"><img name="'+this.menuImgSrcOff+'" src="'+this.menuImgSrcOff+'" width="'+this.menuImgWidth+'" height="'+this.menuImgHeight+'" border="0" alt="'+this.menuAltText+'"></a>');
	}
	document.write('    </div>');
    document.write('	<div id="menuBox'+this.id+'" class="menuBox" align="left">');
    document.write('	<div id="menuItem'+this.id+'" class="menuContent" onMouseOver="_allMenusArray['+this.id+'].show();" onMouseOut="_allMenusArray['+this.id+'].hide();">');
  	document.write('		<table cellpadding="0" cellspacing="0" border="0" bgcolor="'+this.borderColor+'">');
  	if (additionalScroll > 0) {
  		document.write('<tr><td bgcolor="#FFFFFF"><img src="/imgs/spacer.gif" border="0" width="1" height="1"></td></tr>');
  	}
  	if (this.border == true) {
  		document.write('<tr><td><table cellpadding="0" cellspacing="'+this.borderWidth+'" border="0" width="100%">');
  	}
    for (var i = 0; i < this.itemsContent.length; i++) {
    	this.subMenuItem = 'menuItem'+this.id+'sub'+i;
			if (this.separator == true) {
				document.write('<tr><td height="1" class="separatorTop" onMouseDown="openSubMenuItem(\''+this.itemsURL[i]+'\','+this.id+')" onmouseover="javascript:subHover(\''+this.subMenuItem+'\',\''+this.hoverColor+'\');" onmouseout="javascript:subHover(\''+this.subMenuItem+'\',\''+this.bgColor+'\');"><img src="/imgs/spacer.gif" width="2" height="1" border="0"></td></tr>');
			}
			//when opening new windows from the menu, make sure there are no extra parameters attached to the href string
			if (this.itemsURL[i].indexOf('window.open') > -1){
				document.write('<tr><td bgcolor="'+this.bgColor+'" class="menuItem" height="'+this.itemHeight+'" onMouseDown="document.location=\''+this.itemsURL[i]+'\'" onmouseover="javascript:subHover(\''+this.subMenuItem+'\',\''+this.hoverColor+'\');" onmouseout="javascript:subHover(\''+this.subMenuItem+'\',\''+this.bgColor+'\');" id="'+this.subMenuItem+'"><nobr>&nbsp;&nbsp;<a href="'+this.itemsURL[i]+'" class="menuItem">'+this.itemsContent[i]+'</a>&nbsp;&nbsp;&nbsp;</nobr><br><img src="/imgs/spacer.gif" border="0" width="'+this.menuWidth+'" height="1"></td></tr>');
			}else{
				document.write('<tr><td bgcolor="'+this.bgColor+'" class="menuItem" height="'+this.itemHeight+'" onMouseDown="openSubMenuItem(\''+this.itemsURL[i]+'\','+this.id+')" onmouseover="javascript:subHover(\''+this.subMenuItem+'\',\''+this.hoverColor+'\');" onmouseout="javascript:subHover(\''+this.subMenuItem+'\',\''+this.bgColor+'\');" id="'+this.subMenuItem+'"><nobr>&nbsp;&nbsp;<a href="'+this.itemsURL[i]+'" onclick="switchNavbarPos('+this.id+')" class="menuItem">'+this.itemsContent[i]+'</a>&nbsp;&nbsp;&nbsp;</nobr><br><img src="/imgs/spacer.gif" border="0" width="'+this.menuWidth+'" height="1"></td></tr>');
			}
			if (this.separator == true) {
				document.write('<tr><td height="1" class="separatorBot" onMouseDown="openSubMenuItem(\''+this.itemsURL[i]+'\','+this.id+')" onmouseover="javascript:subHover(\''+this.subMenuItem+'\',\''+this.hoverColor+'\');" onmouseout="javascript:subHover(\''+this.subMenuItem+'\',\''+this.bgColor+'\');"><img src="/imgs/spacer.gif" width="2" height="1" border="0"></td></tr>');
			}
    }
  	if (this.border == true) {
  		document.write('</table></td></tr>');
  	}
    document.write('</table></div></div>');

		if (DOM) {
			document.getElementById('fullMenu').style.left = addToMenuXPos;
			document.getElementById('menuImage'+this.id).style.visibility = "visible";
			document.getElementById('menuImage'+this.id).style.left = this.menuXPos;
		  	document.getElementById('menuImage'+this.id).style.top = this.menuYPos;
		  	if (NS) {
		  		document.getElementById('menuBox'+this.id).style.width = this.menuWidth*2;
		  	}
		  	document.getElementById('menuBox'+this.id).style.left = -2000;
		  	document.getElementById('menuBox'+this.id).style.top = -2000;
	    	document.getElementById('menuItem'+this.id).style.top = -this.menuHeight;
		}
		if (NS4) {
			eval("document.menuBox"+this.id+".width = "+eval(this.menuWidth * 2)+";");
			eval("document.menuImage"+this.id+".visibility = 'show'");
			eval("document.menuImage"+this.id+".left = "+eval(this.menuXPos+addToMenuXPos)+";");
			eval("document.menuImage"+this.id+".top = this.menuYPos;");
			eval("document.menuImage"+this.id+".onmouseover = function() { _allMenusArray["+this.id+"].show(); };");
			eval("document.menuImage"+this.id+".onmouseout = function() { _allMenusArray["+this.id+"].hide(); };");
		}

  };

}
var switchLocationUrl;
function openSubMenuItem(url, mi_id) {
	switchNavbarPos(mi_id);
	switchLocationUrl = url;
	setTimeout('document.location = switchLocationUrl;', 50);
}

function switchNavbarPos(mi_id) {
	G_day = new Date();
	G_seed = G_day.getTime();
	rand = parseInt(((G_seed - (parseInt(G_seed / 1000, 10) * 1000)) / 10) / 100 * 100000 + 1, 10);

	newpos = new Image;
	newpos.src='/navbarpos.jhtml?' + 'mi=' + mi_id + "&foo=" + rand;
}

function subHover(subMenu,color) {
	if (DOM) {
		document.getElementById(subMenu).style.backgroundColor = color;
	}
	if (NS4) {
		eval("document."+subMenu+".bgColor='"+color+"';");
	}
}


function openExternalWarningWindow(url,name,w,h) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=no,menubar=no,toolbar=no,status=no,location=no';
	window.open(url,name,settings);
	return false;
}

function openCenteredWindow(url,name,w,h) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=no,menubar=no,toolbar=no,status=no,location=no';
	window.open(url,name,settings);
}

function bgprint(doctype)
{
	printfrom=window.location.href.replace('bgdisplay','bgprint');
	printfrom=printfrom.replace('education/detail','bgprint');
	printfrom=printfrom.replace('clinical_info/detail_trial','bgprint');
	printfrom=printfrom.replace('congresses/detail','bgprint');
	printfrom=printfrom.replace('events/detail','bgprint');
	printfrom=printfrom.replace('news/detail','bgprint');
	printfrom=printfrom.replace('disease/item_detail','bgprint');
	printfrom=printfrom.replace('disease/detail','bgprint');
	printfrom=printfrom.replace('product/detail','bgprint');
	printfrom=printfrom.replace('faqdisplay','bgprint');
	if (doctype == "disease" || doctype == "product" || doctype == "clinicaltrail" || doctype == "congresses" || doctype == "events" || doctype == "news" || doctype == "faq") {
		printfrom=printfrom+"&doctype="+doctype;
	}
	
	window.open(printfrom,'popup','scrollbars=no,resizable=no,width=200,height=100,menubar=no,toolbar=no,status=no,location=no');
}

