﻿function setlinks() {
  if (document.getElementById('loginlink')){ // if no login link then skip this function
   var ssurl = 'https://' + location.hostname + '/emc/default.asp?';
   var rightLoginLink = document.getElementById('loginlink');
   rightLoginLink.href = ssurl;
  }
}

function expandContract(linkID) {
   if (linkID != ""){                // where on the menu the user is
      obj=document.getElementById(linkID);
      mainLinkID = "x" + linkID;
      key=document.getElementById(mainLinkID);
      if (obj.style.display!="none") {
         obj.style.display="none";
	     key.style.background = "url(../borders/images/menu_closed.gif) no-repeat 0 .4em";
         }
       else {
         obj.style.display="block";
	     key.style.background = "url(../borders/images/menu_open.gif) no-repeat 0 0.4em";
         }
      } // end of if (item != "")
      return false;
} 
     
function Toggle() { // linknumber is used by page to highlight
   expandContract(item);
   if (typeof linknumber == "undefined") {}
   else if (linknumber != "null") {
	   obj=document.getElementById(linknumber);
	   obj.style.backgroundColor="#FFF";
   }
}

function random_imglink(){
	var myimages=new Array()
	//specify random images below. You can have as many as you wish
	if (depth == 2)
		{ var addURL = '../';}
	else
		{var addURL = '';}       
		//specify random images below. You can have as many as you wish
		myimages[0] = addURL + 'borders/images/flag/flag_01.jpg';
		myimages[1] = addURL + 'borders/images/flag/flag_02.jpg';
		myimages[2] = addURL + 'borders/images/flag/flag_03.jpg';
		myimages[3] = addURL + 'borders/images/flag/flag_04.jpg';
		myimages[4] = addURL + 'borders/images/flag/flag_05.jpg';
		myimages[5] = addURL + 'borders/images/flag/flag_06.jpg';
		myimages[6] = addURL + 'borders/images/flag/flag_07.jpg';
		myimages[7] = addURL + 'borders/images/flag/flag_08.jpg';
		myimages[8] = addURL + 'borders/images/flag/flag_09.jpg';
		myimages[9] = addURL + 'borders/images/flag/flag_10.jpg';
	
		var ry=Math.floor(Math.random()*myimages.length);
	
		if (ry==0)
			ry=1;
		var codefragment = "<img src='" +myimages[ry]+ "' width='195' height='126' border='0'>";
		return codefragment;
}

function setTopImage()
{
  var rotatingImageCell = document.getElementById('imagecell');
  rotatingImageCell.style.width="195px";
  rotatingImageCell.innerHTML = random_imglink();
}

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
     window.onload = fn;
    }
    else
    {
     window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}
addLoadListener(setTopImage);
addLoadListener(Toggle);
addLoadListener(setlinks);