//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Common Javascript functions.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//Pop up and center a window regardless of screen resolution.
function popup_in_center (tp, thename, tb, ht, wd) {
  screen_width = screen.width;
  screen_height = screen.height;

  if(screen_height <= 600){
  	var leftPos = 0, topPos = 0;
  }else{
	var leftPos = (screen_width - wd)/2, topPos = (screen_height - ht)/2;
  }

  thepopup=window.open(tp, thename, 'toolbar='+tb+',location=no,directories=no,status=yes,'+'menubar=no,resizable=no,scrollbars=yes,copyhistory=no,height='+ht+',width='+wd+',top='+topPos+',left='+leftPos+'');
}

/********************************************************************************************************************/

//Pop up special DAWN Case window.
function popup_case (tp, thename, tb, ht, wd) {

  screen_width = screen.width;
  screen_height = screen.height;

  if(screen_height <= 600){
    var leftPos = -190, topPos = -240;
  }else{
	var leftPos = (screen_width - wd)/2-190, topPos = (screen_height - ht)/2-240;
  }
  
  thecase=window.open(tp, thename, 'toolbar='+tb+',location=no,directories=no,status=yes,'+'menubar=no,resizable=yes,scrollbars=yes,copyhistory=no,height='+ht+',width='+wd+',top='+topPos+',left='+leftPos+'');

}

/********************************************************************************************************************/

//Function to load a "GeoCities" type floating window.
function always_on_top (themessage){

//enter your message in this part, including any html tags
var message=themessage;

//enter 0 for always display, 1 for a set period, 2 for random display mode
var displaymode=0

//if displaymode is set to display for a set period, enter the period below (1000=1 sec)
var displayduration=10000

function regenerate(){
  window.location.reload()
}

var which=0

function regenerate2(){
if (document.layers)
  setTimeout("window.onresize=regenerate",400)
}

function display2(){
  if (document.layers){
    if (topmsg.visibility=="show")
      topmsg.visibility="hide"
    else
      topmsg.visibility="show"
    }
  else if (document.all){
    if (topmsg.style.visibility=="visible")
      topmsg.style.visibility="hidden"
    else
      topmsg.style.visibility="visible"
    setTimeout("display2()",Math.round(Math.random()*10000)+10000)
  }
}

if (document.all){
  document.write('<span id="topmsg" style="position:absolute;visibility:hidden">'+message+'</span>')
}

function logoit(){
  document.all.topmsg.style.left=document.body.scrollLeft+document.body.clientWidth/2-document.all.topmsg.offsetWidth/2
  document.all.topmsg.style.top=document.body.scrollTop+document.body.clientHeight-document.all.topmsg.offsetHeight-4
}

function logoit2(){
  topmsg.left=pageXOffset+window.innerWidth/2-topmsg.document.width/2
  topmsg.top=pageYOffset+window.innerHeight-topmsg.document.height-5
  setTimeout("logoit2()",90)
}

function setmessage(){
  document.all.topmsg.style.left=document.body.scrollLeft+document.body.clientWidth/2-document.all.topmsg.offsetWidth/2
  document.all.topmsg.style.top=document.body.scrollTop+document.body.clientHeight-document.all.topmsg.offsetHeight-4
  document.all.topmsg.style.visibility="visible"
  if (displaymode==1)
    setTimeout("topmsg.style.visibility='hidden'",displayduration)
  else if (displaymode==2)
    display2()
  window.onscroll=logoit
  window.onresize=new Function("window.location.reload()")
}

function setmessage2(){
  topmsg=new Layer(window.innerWidth)
  regenerate2()
  topmsg.document.write(message)
  topmsg.document.close()
  logoit2()
  topmsg.visibility="show"
  if (displaymode==1)
    setTimeout("topmsg.visibility='hide'",displayduration)
  else if (displaymode==2)
    display2()
}

if (document.layers)
  window.onload=setmessage2
else if (document.all)
  window.onload=setmessage
}

/********************************************************************************************************************/

//Rollovers.
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/********************************************************************************************************************/

//Netscape 4 Resize fix.
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/********************************************************************************************************************/
