
// START MONITOR LINKS

function Init(){

if(document.getElementById && document.getElementsByTagName){

if(document.getElementById('wrap')){
var MyDiv1 = document.getElementById('wrap');
var MyLinks1 = MyDiv1.getElementsByTagName('a');
for(var i=0;i<MyLinks1.length;i++){
MyLinks1[i].onfocus=function(){
this.blur();
};
}
}

if(document.getElementById('m1')){
var Menu1 = document.getElementById('m1');
Menu1.onmouseover = function(){ menu('m1','active'); };
Menu1.onmouseout = function(){ menu('m1','inactive'); };
}

if(document.getElementById('m2')){
var Menu2 = document.getElementById('m2');
Menu2.onmouseover = function(){ menu('m2','active'); };
Menu2.onmouseout = function(){ menu('m2','inactive'); };
}

if(document.getElementById('m3')){
var Menu3 = document.getElementById('m3');
Menu3.onmouseover = function(){ menu('m3','active'); };
Menu3.onmouseout = function(){ menu('m3','inactive'); };
}

if(document.getElementById('m4')){
var Menu4 = document.getElementById('m4');
Menu4.onmouseover = function(){ menu('m4','active'); };
Menu4.onmouseout = function(){ menu('m4','inactive'); };
}

if(document.getElementById('m5')){
var Menu5 = document.getElementById('m5');
Menu5.onmouseover = function(){ menu('m5','active'); };
Menu5.onmouseout = function(){ menu('m5','inactive'); };
}

if(document.getElementById('m6')){
var Menu6 = document.getElementById('m6');
Menu6.onmouseover = function(){ menu('m6','active'); };
Menu6.onmouseout = function(){ menu('m6','inactive'); };
}

if(document.getElementById('m7')){
var Menu7 = document.getElementById('m7');
Menu7.onmouseover = function(){ menu('m7','active'); };
Menu7.onmouseout = function(){ menu('m7','inactive'); };
}

if(document.getElementById('m8')){
var Menu8 = document.getElementById('m8');
Menu8.onmouseover = function(){ menu('m8','active'); };
Menu8.onmouseout = function(){ menu('m8','inactive'); };
}

if(document.getElementById('timeanddate')){
ShowTime();
}

if(document.getElementById('gamecellwrapper')){
OverAndOut('div1');
OverAndOut('div2');
ViewMore('viewmore');
}

if(document.getElementById('browsepage')){
ViewGameBox('viewgamebox');
}

if(document.getElementById('searchbox')){
CreateSearchForm();
}

if(document.getElementById('jumplistdiv')){
CreateGameList()
}

}
}

// START: create searchbox

function SubmitSearch(){
var SearchDiv = document.getElementById('searchterm');
if(SearchDiv.value == "" || SearchDiv.value == null){
alert('Please enter search term before submitting');
SearchDiv.value = '';
SearchDiv.focus();
}
else {
document.forms["searchform"].submit();
}
}

function CreateSearchForm(){
var searchform = "";
searchform = searchform + '<form id="searchform" name="searchform" method="post" action="'+searchurl+'">';
searchform = searchform + '<input type="text" id="searchterm" name="searchterm" value="">';
searchform = searchform + '<input type="button" src="'+imagepath+'clear.gif" id="searchbutton" onclick="SubmitSearch()">';
searchform = searchform + '</form>';
document.getElementById('searchbox').innerHTML = searchform;
}

// END: create searchbox

// START: getElementsByClassName FUNCTION

function getElementsByClassName(node,classname) {
if (node.getElementsByClassName) { // use native implementation if available
return node.getElementsByClassName(classname);
} else {
return (function getElementsByClass(searchClass,node) {
if ( node == null )
node = document;
var classElements = [],
els = node.getElementsByTagName("*"),
elsLen = els.length,
pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"), i, j;

for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
})(classname, node);
}
}

// START: Home page mouseover, mouseout, and onclick functions

function OverAndOut(myClass){
var elements = getElementsByClassName(document, myClass),
n = elements.length;
for (var i = 0; i < n; i++) {
var e = elements[i];
e.onmouseover = function(){
this.className = myClass+'a';
}
e.onmouseout = function(){
this.className = myClass;
}
e.onclick = function(){
window.location = this.firstChild.href;
}
}
}

function ViewMore(myClass){
var elements = getElementsByClassName(document, myClass),
n = elements.length;
for (var i = 0; i < n; i++) {
var e = elements[i];
e.onmouseover = function(){
this.src = imagepath + 'viewmoreover.gif';
}
e.onmouseout = function(){
this.src = imagepath + 'viewmore.gif';
}
}
}

// START: Browse mouseover, mouseout, and onclick functions

function ViewGameBox(myClass){
var elements = getElementsByClassName(document, myClass),
n = elements.length;
for (var i = 0; i < n; i++) {
var e = elements[i];
e.onmouseover = function(){
this.style.backgroundColor = '#b3c6df';
}
e.onmouseout = function(){
this.style.backgroundColor = '#ccd9ea';
}

}
}

// START MENU

function menu(id,action){
elem = document.getElementById(id);
m_tagged = document.getElementById(m_tagged_id);
if (action == 'active') {
elem.className = 'active';
if(id != m_tagged_id) m_tagged.className = 'inactive';
}
else {
elem.className = 'inactive';
m_tagged.className = 'active';
}

}

// START: bookmark page

function bookmark(url,title){
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
window.external.AddFavorite(url,title);
} else if (navigator.appName == "Netscape") {
window.sidebar.addPanel(title,url,"");
} else {
alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
}
}

// START: delete favorite game

function DeleteFavorite(gameid,userid){
var agree=confirm("Are you sure you wish to delete this game from your favorites?");
if (agree){
window.location = baseurl + "index.php?action=deletefavoritegame&userid=" + userid + "&gameid=" + gameid;
return false;
}
else {
return false;
}
}

// START: misc popups

function popUpGame(URL){
winpops=window.open(URL,"","width=800,height=600,left=0,top=0,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0");
}

function popUpPage(URL,windowname){
winpops=window.open(URL,windowname,"width=900,height=700,left=0,top=0,status=0,scrollbars=1,resizable=1,menubar=0,location=0,toolbar=0");
winpops.focus();
}


// NOTES ON JS TIME AND DATE

// getTime() - Number of milliseconds since 1/1/1970 @ 12:00 AM
// getSeconds() - Number of seconds (0-59)
// getMinutes() - Number of minutes (0-59)
// getHours() - Number of hours (0-23)
// getDay() - Day of the week(0-6). 0 = Sunday, ... , 6 = Saturday
// getDate() - Day of the month (0-31)
// getMonth() - Number of month (0-11)
// getFullYear() - The four digit year (1970-9999)

function TimeAndDate(){

var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var day = currentTime.getDay();
var month = currentTime.getMonth() + 1;
var date = currentTime.getDate();
var year = currentTime.getFullYear();
var ap = "am";
var dayword = "";
var monthword = "";

if(hours > 11){ ap = "pm"; }
if(hours > 12){ hours = hours - 12; }
if(hours == 0){ hours = 12; }
if(hours < 10){ hours = " " + hours; }

if(seconds < 10){ seconds = "0" + seconds; }
if(minutes < 10){ minutes = "0" + minutes; }

if(day == 0){ dayword = "Sunday"; }
if(day == 1){ dayword = "Monday"; }
if(day == 2){ dayword = "Tuesday"; }
if(day == 3){ dayword = "Wednesday"; }
if(day == 4){ dayword = "Thursday"; }
if(day == 5){ dayword = "Friday"; }
if(day == 6){ dayword = "Saturday"; }

if(month == 1){ monthword = "Jan"; }
if(month == 2){ monthword = "Feb"; }
if(month == 3){ monthword = "Mar"; }
if(month == 4){ monthword = "Apr"; }
if(month == 5){ monthword = "May"; }
if(month == 6){ monthword = "Jun"; }
if(month == 7){ monthword = "Jul"; }
if(month == 8){ monthword = "Aug"; }
if(month == 9){ monthword = "Sep"; }
if(month == 10){ monthword = "Oct"; }
if(month == 11){ monthword = "Nov"; }
if(month == 12){ monthword = "Dec"; }

var TimeAndDate = "It is currently " + hours + ":" + minutes + ":" + seconds + " " + ap + " on " + dayword + ", " + date +" "+ monthword + " " + year;
document.getElementById('timeanddate').innerHTML = TimeAndDate;
}

function ShowTime(){
var MyTimer = setInterval(function(){TimeAndDate();},500);
}

// End Local Time
