var SLS_Location = "http://www.webdevproject.com/SLS/"; // The URL to the SLS folder
var cursorInt = 0;
var loginInProgress = 0;

/****************************************
** Secure Login System JavaScript Core **
*****************************************

===============
=== License ===

Copyright (C) 2010 Graphix of WebDevProject.com
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".

Created by Graphix of WebDevProject.com
Visit us at: http://www.webdevproject.com/
Contact: http://www.webdevproject.com/

Or you can PM at DaniWeb (username: Graphix)

=== License ===
===============

*/

function PerformLogin() {

 if (loginInProgress == 0) {
 
 loginInProgress = 1;

 var lg_user = document.getElementById('SLS_login_user').value;
 var lg_pass = document.getElementById('SLS_login_pass').value;
 
 var ajax = false;

 // Create the object:

 // Choose the objecttype, depending on what is supported:
 if (window.XMLHttpRequest) {

    // IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
    ajax = new XMLHttpRequest();

 } else if (window.ActiveXObject) { // Old IE-browsers

    // Make the type Msxml2.XMLHTTP, if possible:
    try {
        ajax = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) { // Else use the other type:
        try {
            ajax = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) { }
    }

 }

 // Retrieving the data from the page

 if (ajax) {

   var url = SLS_Location + "core/SLS-Login.php?user=" + encodeURIComponent(lg_user) + "&password=" + encodeURIComponent(lg_pass);
   
   ajax.open('GET', url);
   
   // Sends request
   ajax.send(null);

   // Function that handles response
   ajax.onreadystatechange=function(){
   
     // If everything is OK:
     if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
	 
          // Returns the value to the document
		  //alert(ajax.responseText);
		  var ret_vars = ajax.responseText.split(',');
          if (ret_vars[0] == 'Succes') {
			SimulateLogInSucces();
		  } else {
			SimulateLogInFail();
		  }
	 }
	 
	 // If the file could not have been found:
	 if ( (ajax.readyState == 4) && ((ajax.status == 404) || (ajax.status == 0)) ) {
	 
	   alert('Could not open Secure Login System Uniform Resource Locator:\n' + SLS_Location + 'core/SLS-Login.php');
	 
	 }
	 
    }


 } else { // AJAX is not useable
     alert('It is not possible to connect, please update your browser.');
 }
 
 
 }

 
}

function PerformLogout() {

 var ajax2 = false;

 // Create the object:

 // Choose the objecttype, depending on what is supported:
 if (window.XMLHttpRequest) {

    // IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
    ajax2 = new XMLHttpRequest();

 } else if (window.ActiveXObject) { // Old IE-browsers

    // Make the type Msxml2.XMLHTTP, if possible:
    try {
        ajax2 = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) { // Else use the other type:
        try {
            ajax2 = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) { }
    }

 }


 // Retrieving the data from the page

 if (ajax2) {

   var url2 = SLS_Location + "core/SLS-Logout.php";

   ajax2.open('GET', url2);

   // Sends request
   ajax2.send(null);
   
   // Function that handles response
   ajax2.onreadystatechange=function(){
    // If everything is OK:
     if ( (ajax2.readyState == 4) && (ajax2.status == 200) ) {
		  location.reload(true);
	 }
	 
	 // If the file could not have been found:
	 if ( (ajax2.readyState == 4) && (ajax2.status == 404) ) {
	 
	   alert('Could not open Secure Login System Uniform Resource Locator:\n' + SLS_Location + 'core/SLS-Logout.php');
	 
	 }
	 
    }


 } else { // AJAX is not useable
     alert('It is not possible to connect, please update your browser.');
 }

 
}

function SimulateLogInSucces() {
 if (navigator.appName == 'Microsoft Internet Explorer') {
 ClearText();
 cursorInt = setInterval('ToggleCursor()', 300);
 setTimeout(function(){ AddTextIE('Initializing...'); }, 1000);
 setTimeout(function(){ AddTextIE('<br />Connecting...'); }, 2000);
 setTimeout(function(){ AddTextIE('<br />Verifying user...'); }, 3000);
 setTimeout(function(){ AddTextIE('<br />Verifying password...'); }, 4000);
 setTimeout(function(){ AddTextIE('<br />Verifying details...'); }, 5000);
 setTimeout(function(){ AddTextIE('<br />Acces granted...'); }, 6000);
 setTimeout(function(){ AddTextIE('<br />Exiting...'); }, 7000);
 setTimeout(function(){ clearInterval(cursorInt); document.getElementById('SLS_lg_001').style.display = 'none'; loginInProgress = 0; }, 7500);
 setTimeout(function(){ location.reload(true); }, 8000);
 } else {
 ClearText();
 cursorInt = setInterval('ToggleCursor()', 300);
 setTimeout(function(){ AddText('Initializing...'); }, 1000);
 setTimeout(function(){ AddText('\nConnecting...'); }, 2000);
 setTimeout(function(){ AddText('\nVerifying user...'); }, 3000);
 setTimeout(function(){ AddText('\nVerifying password...'); }, 4000);
 setTimeout(function(){ AddText('\nVerifying details...'); }, 5000);
 setTimeout(function(){ AddText('\nAcces granted...'); }, 6000);
 setTimeout(function(){ AddText('\nExiting...'); }, 7000);
 setTimeout(function(){ clearInterval(cursorInt); document.getElementById('SLS_lg_001').style.display = 'none'; loginInProgress = 0; }, 7500);
 setTimeout(function(){ location.reload(true); }, 8000);
 }
}
function SimulateLogInFail() {
 if (navigator.appName == 'Microsoft Internet Explorer') {
 ClearText();
 cursorInt = setInterval('ToggleCursor()', 300);
 setTimeout(function(){ AddTextIE('Initializing...'); }, 1000);
 setTimeout(function(){ AddTextIE('<br />Connecting...'); }, 2000);
 setTimeout(function(){ AddTextIE('<br />Verifying user...'); }, 3000);
 setTimeout(function(){ AddTextIE('<br />Verifying password...'); }, 4000);
 setTimeout(function(){ AddTextIE('<br />Verifying details...'); }, 5000);
 setTimeout(function(){ AddTextIE('<br />Acces denied...'); }, 6000);
 setTimeout(function(){ AddTextIE('<br />Exiting...'); }, 7000);
 setTimeout(function(){ clearInterval(cursorInt); document.getElementById('SLS_lg_001').style.display = 'none'; loginInProgress = 0; }, 7500);
 } else {
 ClearText();
 cursorInt = setInterval('ToggleCursor()', 300);
 setTimeout(function(){ AddText('Initializing...'); }, 1000);
 setTimeout(function(){ AddText('\nConnecting...'); }, 2000);
 setTimeout(function(){ AddText('\nVerifying user...'); }, 3000);
 setTimeout(function(){ AddText('\nVerifying password...'); }, 4000);
 setTimeout(function(){ AddText('\nVerifying details...'); }, 5000);
 setTimeout(function(){ AddText('\nAcces denied...'); }, 6000);
 setTimeout(function(){ AddText('\nExiting...'); }, 7000);
 setTimeout(function(){ clearInterval(cursorInt); document.getElementById('SLS_lg_001').style.display = 'none'; loginInProgress = 0; }, 7500);
 }
}

var g_i = 0;

function AddText(text) {
	var charAr = new Array();
	var length = text.length;
	var i = 0;
	for (i = 0; i < length; i++) {
		charAr[i] = text.substr(i, 1);
	}
	var to = 800 / length;
	var x = 0;
	while (x < length) {
		setTimeout(function(){ 
		document.getElementById('SLS_prog_text').innerHTML += charAr[g_i];
		g_i++;
		}, parseInt(to * (x + 1)));
		x++;
	}
	g_i = 0;
}
function ClearText() {
	document.getElementById('SLS_prog_text').innerHTML = "";
}
function ToggleCursor() {
	if (document.getElementById('SLS_lg_001').style.display != 'none') {
		document.getElementById('SLS_lg_001').style.display = 'none';
	} else {
		document.getElementById('SLS_lg_001').style.display = 'inline';
	}
}

function AddTextIE(text) {
	document.getElementById('SLS_prog_text').innerHTML += text;
}

function EnableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     if (key == 13) {
		PerformLogin();
	 }
}

function ShowLoginPopup() {
document.getElementById('SLS_FullScreen').style.display='inline';
document.getElementById('SLS_Popup').style.display='inline';
}

function HideLoginPopup() {
clearInterval(cursorInt);
document.getElementById('SLS_FullScreen').style.display='none';
document.getElementById('SLS_Popup').style.display='none';
}

document.write("<div id='SLS_FullScreen' class='SLS_FullScreen' onclick='HideLoginPopup()'></div>");
document.write("<div id='SLS_Popup' class='SLS_center_c_login'>");
document.write(" <div class='SLS_pos_container'>");
document.write("  <form class='SLS_login_container' id='SLS_login_container' onsubmit='PerformLogin(); return false;' action='' method='post'>");
document.write("   <table>");
document.write("    <tr><td class='SLS_inp_pretext'>User:</td><td><input class='SLS_login_txtinp_1' type='text' id='SLS_login_user' maxlength='255' onkeypress='EnableEnterKey(event); return true;' /></td></tr>");
document.write("    <tr><td class='SLS_inp_pretext'>Password:</td><td><input class='SLS_login_txtinp_1' type='password' id='SLS_login_pass' maxlength='255' onkeypress='EnableEnterKey(event); return true;' /></td></tr>");
document.write("   </table>");
document.write("  </form>");
document.write("  <div class='SLS_prog_text' style='white-space:pre;'><span id='SLS_prog_text'></span><span class='SLS_Login_StatusTxt' style='display:none;' id='SLS_lg_001'>|</span></div>");
document.write("  <div class='SLS_login_logo'>");
document.write("   <div class='SLS_Login_IMG' alt='' border='0' /></div>");
document.write("  </div>");
document.write("  <div class='SLS_login_toptext'>");
document.write("   Secure log in");
document.write("  </div>");
document.write(" </div>");
document.write("</div>");
