﻿var http_request = false;
   function makeRequest(url, parameters, fname) {
      http_request = false;
      if (window.XMLHttpRequest) {
         http_request = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert("Cannot create XMLHTTP instance");
         return false;
      }
      http_request.onreadystatechange = fname;
      http_request.open("GET", url + parameters, true);
      http_request.send(null);
   }
   
   function checkLogin() {
      makeRequest("/GetAjax.aspx", "", getUser);
   }
   function getUser() {
      var lblUser = document.getElementById("lblUser");
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            var text = http_request.responseText;
            if (text != "$?!")
               lblUser.innerHTML = "<img src=\"/images/icon_account.gif\" width=\"27\" height=\"29\" />Welcome back,&nbsp;&nbsp;<a href=\"/MyAccount.aspx\">" + text + "</a>";
            else
               lblUser.innerHTML = "<img src=\"/images/icon_account.gif\" width=\"27\" height=\"29\" /><a href=\"/MyAccount.aspx\">My Account</a>&nbsp;&nbsp;&nbsp;<img src=\"/images/icon_login.gif\" width=\"34\" height=\"29\" /><a href=\"/Login.aspx\">Log In</a>";
         } else {
            lblUser.innerHTML = "<img src=\"/images/icon_account.gif\" width=\"27\" height=\"29\" /><a href=\"/MyAccount.aspx\">My Account</a>&nbsp;&nbsp;&nbsp;<img src=\"/images/icon_login.gif\" width=\"34\" height=\"29\" /><a href=\"/Login.aspx\">Log In</a>";
         }
      } else {
         lblUser.innerHTML = "<img src=\"/images/icon_account.gif\" width=\"27\" height=\"29\" /><a href=\"/MyAccount.aspx\">My Account</a>&nbsp;&nbsp;&nbsp;<img src=\"/images/icon_login.gif\" width=\"34\" height=\"29\" /><a href=\"/Login.aspx\">Log In</a>";
      }
   }
