

var timerID = null;
var timerOn = false;
var timecount = 500;
var what = null;
var newbrowser = true;
var check = false;

var menu_links = new Array();
menu_links[0] = "<a href='/index.php'>News</a> | <a href='/botw.php' title='Bound of the Week'>BotW</a>";
menu_links[1] = "Bounds: <a href='/bounds.php'>Archive 1.14</a> | <a href='/authors.php'>Authors</a> | <a href='/bound_upload.php'>Upload a bound</a> | <a href='/pending_bounds.php'>Pending Uploads</a> | <a href='/sc/archive-0-9.html'>Old Archive</a> | <a href='/sc/scmaps.html'>Old Authors</a>";
menu_links[2] = "Time Attack: <a href='/reps.php'>Replay DB</a> | <a href='/rankings.php'>Rankings</a> | <a href='/replay_upload.php'>Upload .rep</a> | <a href='/pending_replays.php'>Pending Replays</a> | <a href='/srf.php'>SRF</a>";
//menu_links[3] = "UMS Maps: Defence | Games | Experimental | Instructional";
menu_links[3] = "Tutorials: <a href='/swf/BoundMaker.php' target='_blank'>Bound Maker</a> | <a href='tut01.php'>Colors 1.14</a> | <a href='tut03.php'>Overlapping Text</a> | <a href='tut05.php'>Sound Compression</a> | <a href='tutorials.php'>More</a>";
menu_links[4] = "Files: <a href='scmu.php'>SCMU</a> | <a href='/files.php'>More</a>";
menu_links[5] = "Sites!";
menu_links[6] = "Shoutbox - Post your thoughts!";

function changetext(whichcontent) {
  if (document.all || document.getElementById) {
    cross_el = document.getElementById ? document.getElementById("menulinks") : document.all.menulinks;
    cross_el.innerHTML = whichcontent;
  } else if (document.layers) {
    document.menulinks.write(whichcontent);
    document.menulinks.close();
  }
}



function init() {
 if (document.layers) {
 layerRef="document.layers";
 styleSwitch="";
 visibleVar="show";
 screenSize = window.innerWidth;
 what ="ns4";
 }
 else if(document.all) {
 layerRef="document.all";
 styleSwitch=".style";
 visibleVar="visible";
 screenSize = document.body.clientWidth + 18;
 what ="ie4";
 }
 else if(document.getElementById) {
 layerRef="document.getElementByID";
 styleSwitch=".style";
 visibleVar="visible";
 what="dom1";
 }
 else {
 what="none";
 newbrowser = false;
 }
check = true;
}



function hide() {
  hideDiv('menu_bounds');
  hideDiv('menu_reps');
  hideDiv('menu_ums');
  hideDiv('menu_tutorial');
  hideDiv('menu_files');
}

function hideDiv(menuname) {
  if(check) {
    if (what =="none") {
      return;
    } else if (what == "dom1") {
      document.getElementById(menuname).style.visibility="hidden";
    } else {
      eval(layerRef+'["'+menuname+'"]'+styleSwitch+'.visibility="hidden"');
    }
  } else {
    return;
  }
}

function showMenu(menuid) {
  if(check) {
    if (what =="none") {
      return;
    } else if (what == "dom1") {
      document.getElementById(menuid).style.visibility = "visible";

    } else {
      eval(layerRef+'["'+menuid+'"]'+styleSwitch+'.visibility="visible"');
    }
  } else {
    return;
  }
}

function startTime() {
  if (timerOn == false) {
    timerID = setTimeout( "hide()" , timecount);
    timerOn = true;
  }
}


function stopTime() {
  if (timerOn) {
    clearTimeout(timerID);
    timerID = null;
    timerOn = false;
  }
}

/* Shows / Hides the shoutbox div */
function expandshout() {
  var shouts = document.getElementById("shouts");
  var sbutton = document.getElementById("minimize_shout");

  if(shouts.className == 'shoutmin') {
    shouts.className = 'shoutmax';
    sbutton.innerHTML = "<a onclick='expandshout();' href='#shout'><img src='/img/topsite/min.gif' border='0' title='Hide'></a>";
    setCookie("show_shoutbox", "show", 2);
  } else {
    shouts.className = 'shoutmin';
    sbutton.innerHTML = "<a onclick='expandshout();' href='#shout'><img src='/img/topsite/max.gif' border='0' title='Show'></a>";
    setCookie("show_shoutbox", "hide", 2);
  }
}

/* Sets a cookie to your specifications.
 * Expires 'expires' number of days after today.
 * Uses '/' as default path.
 */
function setCookie(name,value,expires) {
  var today = new Date();
  today.setTime( today.getTime() );

  // convert days to milliseconds
  if (expires) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date(today.getTime() + expires);

  document.cookie = name + "=" + value + "; expires=" + expires_date.toGMTString() + "; path=/";
}

function closeshout(textstring) {
  alert(textstring);
}


/* Used for update_pending_replays.php.
 * When a "Checker" finishes verifying one replay,
 *  this will hide the form (or re-show the form)
 *  to make it easier to see the next one.
 */
function imdone(num,chkbox,clrdone,clrnotdone) {
	var reptitle = document.getElementById(num);
	var repform = document.getElementById('dataform' + num);
	//var chkbox = document.getElementsByName('checkin' + num)[0];

	if (chkbox.checked) {
		reptitle.style.background = clrdone;
		repform.style.display = 'none';
	} else {
		reptitle.style.background = clrnotdone;
		repform.style.display = 'block';
	}
}
/* Same thing as above.
 * Except: Disable/Enable Release/Remove checkbox is the other is checked.
 */
function adminimdone(num,chkbox,clrdone,clrnotdone) {
	var reptitle = document.getElementById(num);
	var repform = document.getElementById('dataform' + num);
	var chkrel = document.getElementsByName('adminRelease' + num)[0];
	var chkrem = document.getElementsByName('adminRemove' + num)[0];

	// Release was clicked
	if (chkrel.name == chkbox.name) {
		if (chkbox.checked) {
			chkrem.disabled = true;
			reptitle.style.background = clrdone;
			repform.style.display = 'none';
		} else {
			chkrem.disabled = false;
			reptitle.style.background = clrnotdone;
			repform.style.display = 'block';
		}
	// Remove was clicked
	} else if (chkrem.name == chkbox.name) {
		if (chkbox.checked) {
			chkrel.disabled = true;
			reptitle.style.background = clrdone;
			repform.style.display = 'none';
		} else {
			chkrel.disabled = false;
			reptitle.style.background = clrnotdone;
			repform.style.display = 'block';
		}
	}
}

/* Used in: update_pending_replays.php
 * unrevs() - array with all pend #'s (pn) to be showed
 * Shows all un-reviewed (grey) replays
 * This helps cutdown lag on browsers, because
 * not as many form elements are loaded to the screen.
 */
function adminShowUnReviewed(unrevs) {
	// Convert string to array (of pend #'s)
	// Because you cant pass a php-array to a javascript-array!
	var unrevsarray = unrevs.split(",");
	var unrevdiv;
	for(i = 0; i < unrevsarray.length; i++){
		unrevdiv = document.getElementById('unrev' + unrevsarray[i]);
		unrevdiv.className = 'visible';
	}
}
