// JavaScript Document

function nucleus_login(){
  var user = document.getElementById('user').value;
  var passwrd = document.getElementById('passwrd').value;  
  var poststr = encodeURI("login="+user+"&");
  poststr += encodeURI("password="+passwrd+"&"); 
  poststr += encodeURI("action=login"); 
  //alert(poststr);
  var modreq=getHTTPObject();  
  url = urls.index+"nucleus/index.php";
  //alert(url);
  modreq.open('POST', url, true);
  modreq.onreadystatechange=function(){
    if (modreq.readyState == 4) {
      if (modreq.status == 200) { 
        //location.href=urls.index+"stargate.php";       
        //alert(modreq.responseText);
        //hashLoginPassword(stuff, sessionid); 
        smf_login(user,passwrd)
        //document.submit();       
      } else {
        alert('There was a problem with makePOSTRequest.');
      }
    }  
  }  
  modreq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  modreq.setRequestHeader("Content-length", poststr.length);
  modreq.setRequestHeader("Connection", "close");
  modreq.send(poststr);
}

function smf_login(user,passwrd){
  var poststr = encodeURI("user="+user+"&");
  poststr += encodeURI("passwrd="+passwrd);  
  httpPost = false;
  url = urls.index+"smf/?action=login2";
  var httpPost=getHTTPObject();
  httpPost.open('POST', url, true);
  httpPost.onreadystatechange=function(){
    if (httpPost.readyState == 4) {
      if (httpPost.status == 200) { 
        location.href=urls.index+"smf/index.php";         
      } else {
        alert('There was a problem with makePOSTRequest.');
      }
    }  
  }  
  httpPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  httpPost.setRequestHeader("Content-length", poststr.length);
  httpPost.setRequestHeader("Connection", "close");
  httpPost.send(poststr);
}

function sso_logout(){
  var url = urls.index+"?action=logout";
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        location.href=urls.index+"stargate.php";
        smf_logout();
        nucleus_logout();
      } else {
        alert('There was a problem with makePOSTRequest.');
      }
    }
  }
  modreq.send(null);
}

function smf_logout(){
  var sesc = document.getElementById('sesc').value;
  var url = urls.index+"smf?action=logout&sesc="+sesc;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        location.href=urls.index+"stargate.php";        
      } else {
        alert('There was a problem with makePOSTRequest.');
      }
    }
  }
  modreq.send(null);
}

function nucleus_logout(session_id){ 
  //alert(urls.index);
  //var sesc = document.getElementById('sesc').value;
  var nocache = Math.random();
  var url = urls.index+"nucleus/?action=logout"+"&nocache="+nocache;
  //alert(url);
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);    
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        //alert(modreq.responseText);
        //location.href=urls.index+"begin.php?action=logout";
        var nocache = Math.random();
        location.href=urls.index+"smf/?action=logout;sesc="+session_id
        return true;
      } else {
        alert('There was a problem with makePOSTRequest.');
      }
    }
  }
  modreq.send(null);
}

