/***************************************************************************
Popover script
****************************************************************************/

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

var bw = lib_bwcheck()

var fromX = 15 //How much from the actual mouse X should the description box appear?
var fromY = 15 //How much from the actual mouse Y should the description box appear?

//To set the font size, font type, border color or remove the border or whatever,
//change the clDescription class in the stylesheet.

//Makes crossbrowser object.
function makeObj(obj)
{								
  this.evnt = bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
	
	if(!this.evnt)
	  return false
	
	this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0;	
  this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0;		
	this.writeIt=b_writeIt;																
	
	return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function b_writeIt(i_text)
{
	if (bw.ns4)
	{
	  this.wref.write(text);
	  this.wref.close();
	}
	else 
	  this.wref.innerHTML = i_text;
}

//Capturing mousemove
var descx = 0;
var descy = 0;

function popmousemove(e)
{
  descx = bw.ns4||bw.ns6?e.pageX:event.x;
  descy = bw.ns4||bw.ns6?e.pageY:event.y;
}

var oDesc;

//Shows the messages
function popup(i_text)
{
  popup('', i_text, 'BR');
}

function popup(i_caption, i_text)
{
  popup(i_caption, i_text, 'BR');
}

// i_caption  : The title of the popup dialog window
// i_text     : The text to appear in the popup window
// i_position : The position of the window relative to the cursor
//              TL: top left
//              TR: top right
//              BL: bottom left
//              BR: bottom right
function popup(i_caption, i_text, i_position)
{
    if(oDesc)
    { 
      if(i_caption.length > 0)
        oDesc.writeIt('<div class="clOverWidth"><div class="clCaption">' + i_caption + '</div><br><div class="clDescription">' + i_text + '</div></div>');
      else
        oDesc.writeIt('<div class="clOverWidth"><div class="clDescription">' + i_text + '</div></div>');

      // Get the sizes of the popup and parent window
	    var popupWidth = oDesc.wref.offsetWidth;
	    var popupHeight = oDesc.wref.offsetHeight;
	    var bodyWidth = document.body.offsetWidth;
	    var bodyHeight = document.body.offsetHeight;
		  
		  // Get the vertical scrollpostition to start from
		  if(bw.ie5||bw.ie6)
		    descy = descy+document.body.scrollTop;

      var leftPos = 0;
      var topPos = 0;
	    
	    
	    if(i_position == 'BR')
	    {
	      // Check if the popup won't bounce out of screen
	      leftPos = descx + fromX;
	      if((leftPos + popupWidth) > bodyWidth)
	        leftPos = bodyWidth - popupWidth - 25; // 25 pixels is the width of the scrollbar on the right

        topPos = descy + fromY;
		  }
		  else if(i_position == 'TR'){
		    leftPos = descx + fromX;
	      if((leftPos + popupWidth) > bodyWidth)
	        leftPos = bodyWidth - popupWidth - 25;
	        
	      topPos = descy - fromY - popupHeight;
		    if(topPos < document.body.scrollTop)
		      topPos = document.body.scrollTop;
		  }
		  else if(i_position == 'TL')
		  {
		    leftPos = descx - fromX - popupWidth;
		    if(leftPos < 0)
		      leftPos = fromX;
		      
		    topPos = descy - fromY - popupHeight;
		    if(topPos < document.body.scrollTop)
		      topPos = document.body.scrollTop; 
		      
		  }else if(i_position == 'WC'){
		    topPos = (bodyWidth - popupWidth)/2;
		    leftPos = (bodyHeight - popupHeight)/2;
		  }
		  
		  oDesc.css.top = topPos + px;
		  oDesc.css.left = leftPos + px;
		  oDesc.css.visibility = "visible";
    }
}

//Hides it
function popout()
{
	if(oDesc)
	  oDesc.css.visibility = "hidden";
}

function setPopup()
{
   	if(bw.ns4)
   	  document.captureEvents(Event.MOUSEMOVE);
    
    document.onmousemove = popmousemove;
	  oDesc = new makeObj('divDescription');
}



/***************************************************************************
Fading news scripts
****************************************************************************/

//scroller width
var swidth = 100
//scroller height
var sheight = 100
//background color
var sbcolor = '#FFFFFF'
//scroller's speed
var sspeed = 1
// The message
var msg = ''

var resumesspeed = sspeed

function startNews(i_msg)
{
  msg = i_msg;
  
  if(document.all)
    iemarquee(slider);
  else if(document.getElementById)
    ns6marquee(document.getElementById('slider'));
  else if(document.layers)
    ns4marquee(document.slider1.document.slider2);
}

function iemarquee(whichdiv)
{
  // Use this div because it is outside all content divs of the page
  contentDiv = eval('divDescription');
  iediv = eval(whichdiv)
  iediv.style.pixelTop = sheight
  iediv.innerHTML = msg
  // Set the message to the contentdiv too to get the height of the text
  contentDiv.innerHTML = msg
  sizeup = contentDiv.offsetHeight
  ieslide()
}

function ieslide()
{
  if (iediv.style.pixelTop>=sizeup*(-1))
  {
    iediv.style.pixelTop-=sspeed
    setTimeout("ieslide()",100)
  }
  else
  {
    iediv.style.pixelTop=sheight
    ieslide()
  }
}

function ns4marquee(whichlayer)
{
  ns4layer=eval(whichlayer)
  ns4layer.top=sheight
  ns4layer.document.write(msg)
  ns4layer.document.close()
  sizeup=ns4layer.document.height
  ns4slide()
}

function ns4slide()
{
  if (ns4layer.top>=sizeup*(-1))
  {
    ns4layer.top-=sspeed
    setTimeout("ns4slide()",100)
  }
  else
  {
    ns4layer.top=sheight
    ns4slide()
  }
}

function ns6marquee(whichdiv)
{
  ns6div=eval(whichdiv)
  ns6div.style.top=sheight
  ns6div.innerHTML=msg
  sizeup=ns6div.offsetHeight
  ns6slide()
}

function ns6slide()
{
  if (parseInt(ns6div.style.top)>=sizeup*(-1))
  {
    ns6div.style.top=parseInt(ns6div.style.top)-sspeed
    setTimeout("ns6slide()",100)
  }
  else
  {
    ns6div.style.top=sheight
    ns6slide()
  }
}

/***************************************************************************
Default enter button for control script
****************************************************************************/

function setDefaultButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
}

/****************************************************************************
STANDARD FUNCTIONS
****************************************************************************/

function gotoUrl(URL){
  document.location.href = URL;
}


/***************************************************************************
Menu Rollover script (from imageready)
****************************************************************************/

function swapImg(OBJ, URL){
	OBJ.src = URL;
}

/***************************************************************************
  DHTML DROPDOWN MENU
***************************************************************************/
	function showMenu(ID){
		if(document.getElementById('portalMenu_'+ID).style.display == "block"){
			setTimeout("",500);
			document.getElementById('portalMenu_'+ID).style.display = "none";
			document.getElementById('portalMenu_'+ID).className = "top";
		}else{
			document.getElementById('portalMenu_'+ID).style.display = "block";
			document.getElementById('portalMenu_'+ID).className = "topHover";
		}
	}
	
/***************************************************************************
  OPEN MODAL WINDOW
***************************************************************************/
function openModalWindow(URL,NAME){
  if(window.showModalDialog){
    var modalWin = window.showModalDialog(URL,NAME);
  }else{
    alert("not supported modalwin");
  }
}