var xmlHttpA = false;
var xmlHttp = false;
var xmlHttpHITS = false;
var xmlHttpDemo = false;
try {
  xmlHttpA = new ActiveXObject("Msxml2.XMLHTTP");
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  xmlHttpHITS = new ActiveXObject("Msxml2.XMLHTTP");
  xmlHttpDemo = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttpA = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttpHITS = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttpDemo = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttpA = false;
	xmlHttp = false;
	xmlHttpHITS = false;
	xmlHttpDemo = false;
  }
}

if (!xmlHttpA && typeof XMLHttpRequest != 'undefined') {
  xmlHttpA = new XMLHttpRequest();
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
if (!xmlHttpHITS && typeof XMLHttpRequest != 'undefined') {
  xmlHttpHITS = new XMLHttpRequest();
}
if (!xmlHttpDemo && typeof XMLHttpRequest != 'undefined') {
  xmlHttpDemo = new XMLHttpRequest();
}

function updateMainPage() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	   document.getElementById("mainpage").innerHTML = response;
	   document.getElementById("mypoolname").focus();
	   getenter();
  }
}
function updatePageHITS() {
  if (xmlHttpHITS.readyState == 4) {
    var response = xmlHttpHITS.responseText;
	   document.getElementById("myhits").innerHTML = response;
	 
  }
}
function updatePageA() {
  if (xmlHttpA.readyState == 4) {
    var response = xmlHttpA.responseText;
	if (response == "Admin"){
  		document.open('console.php','_top','',true);
	} 
	else if (response == "Guest"){
  		document.open('guest.php','_top','',true);
	}
	else {
	    document.getElementById("mylogin").innerHTML = response;
	}
  }
}

function updatePageDemo() {
  if (xmlHttpDemo.readyState == 4) {
   var response = xmlHttpDemo.responseText;
 		document.open('demo.htm','_top','',true);
  }
}

//function updatePageDemo() {
 // if (xmlHttpDemo.readyState == 4) {
 //   var response = xmlHttpDemo.responseText;
//	if (response == "Admin"){
 // 		document.open('console.php','_top','',true);
//	} 
//	else if (response == "Guest"){
//  		document.open('guest.php','_top','',true);
//	}
//	else {
//	    document.getElementById("mylogin").innerHTML = response;
//	}
 // }
//}

function mainlogin() {
  // Build the URL to connect to
  var url = "mainlogin.php";
  
  // Open a connection to the server
  xmlHttp.open('GET', url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = updateMainPage;

  // Send the request
  xmlHttp.send(null);
 
}

function hits() {
  // Build the URL to connect to
  var url = "hits.php";
  
  // Open a connection to the server
  xmlHttpHITS.open('GET', url, true);

  // Setup a function for the server to run when it's done
  xmlHttpHITS.onreadystatechange = updatePageHITS;

  // Send the request
  xmlHttpHITS.send(null);
}



function clearmessage(){
	document.getElementById("mylogin").innerHTML = "";
	document.getElementById("mypass").value = "";
	document.getElementById("mypoolname").value = "";
	document.getElementById("mypoolname").focus();
}

function validatelogin() {
  var mypoolname = document.getElementById("mypoolname").value;
  
  if ((mypoolname == null) || (mypoolname == "")){
  	alert("Please Enter Your Hockey Pool Name.");	
   	return (false);
   }

  var mypass = document.getElementById("mypass").value;
  if ((mypass == null) || (mypass == "")){
  	alert("Pleast Enter Your Password.");
  return (false);
  }
  
  var  rememberme = 0;
  if (document.getElementById("rememberme").checked == true){
	 rememberme = 1;
  }
  
  // Build the URL to connect to
  var url = "login.php"+"?poolname="+escape(mypoolname)+"&passtxt="+escape(mypass)+"&rememberme="+escape(rememberme);
  
  // Open a connection to the server
  xmlHttpA.open('GET', url, true);

  // Setup a function for the server to run when it's done
  xmlHttpA.onreadystatechange = updatePageA;

  // Send the request
  xmlHttpA.send(null);
}

function demo() {

  // Build the URL to connect to
 // var url = "login.php"+"?poolname=demo"+"&passtxt=demo";
 
  var url = "demo.htm";
  
  // Open a connection to the server
  xmlHttpDemo.open('GET', url, true);

  // Setup a function for the server to run when it's done
  xmlHttpDemo.onreadystatechange = updatePageDemo;

  // Send the request
  xmlHttpDemo.send(null);
}
function passEvent(e) {
            if (!e)
                var e = window.event;
            var code = e.keyCode;
            if (code == 13) {
                document.getElementById("loginbtn").focus();
            }
}

function getenter() {
     document.getElementById("mypass").onkeydown = passEvent;
}

/* Modified to support Opera */
function bookmarkme(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
