/*
-------------------------------------------------------------------
 Login Script Version 1.5
 By H G Laughland 
 http://www.laughland.biz

This script can be used free of charge and may only be
redistributed the same way. The disclaimer must remain
intact.

DISCLAIMER: Use this script with caution. This script is not 
the most secure method available, for protecting material on 
your site. The author takes no responsibility for data loss
resulting from the use of this script.
-------------------------------------------------------------------

INSTRUCTIONS - Read Before Using Script

Step 1
In the Usernames & Passwords section, configure the variables as
indicated by the comments.
 
Step 2:
Add the following code to the <head> section of your login page: 
 <script src="scripts/login.js"></script> 
Change "scripts/login.js" to reflect the correct path to this script
file on your server. 
 
Step 3:
Add this code to the login page, at the place you want the login
panel to show:
 
 <script language="JavaScript">
  BuildPanel();
 </script>
 
Step 4:
Add the following code to the <head> section of each page procteded
by this script:
 
 <script src="scripts/login.js"></script>
 <script language="JavaScript">
  checkCookie();
 </script>

Change "scripts/login.js" to reflect the correct path to this script
file on your server.
 
Step 5: 
On the page that is to have the logout button, paste this code where you
want the button to be:

 <form action="" name="frmLogoff">
  <input type="button" name="btLogoff" value="log out" onclick="logout();">
 </form>
 
Step 6:
Upload this script and your html pages to the relevant directories
on your server.   

*/

//----------------------------------------------------------------
//  Usernames & Passwords - These require configuration.
//----------------------------------------------------------------

var successpg = "login/main.html";  //Change this to the page to go to after succuessful login.
var loginpage = "index.html"; //Change this to the page the login panel is on.

var users=new Array(members);
var passes=new Array(members);

var members = 2; // The total number of member logins minus 1. 
                 // Increment as you add new logins.
				 
users[0]="workforce"; passes[0]="connections"; // Change these two entries to valid logins.
users[1]="username2"; passes[1]="password2"; // Add addtional logins, straight after these, as 
                                             // required, followig the same format. Increment the 
											 // numbers in the square brackets, in new each one.
//----------------------------------------------------------------
//  Login Functions
//----------------------------------------------------------------
function login(username,password){
 var loggedin = 0;
 for(x=0;x<members && !loggedin; x++){
 if((username==users[x])&&(password==passes[x]))
  loggedin = 1;
 } 
 if(loggedin==1){
  top.location.href = successpg;
  setCookie("login",1); }
 else
  alert('Incorrect username or password');  
}

function logout() {
 deleteCookie("login");
 top.location.href = loginpage;
}

//----------------------------------------------------------------
// Cookie Handler
//----------------------------------------------------------------
var ckTemp = document.cookie;

function setCookie(name, value) { 
 if (value != null && value != "")
  document.cookie=name + "=" + escape(value) + ";";
 ckTemp = document.cookie;
 }
 
function deleteCookie(name) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function getCookie(name) { 
 var index = ckTemp.indexOf(name + "=");
 if(index == -1) return null;
  index = ckTemp.indexOf("=", index) + 1;
 var endstr = ckTemp.indexOf(";", index);
 if (endstr == -1) endstr = ckTemp.length;
 return unescape(ckTemp.substring(index, endstr));
 }
  
function checkCookie() {
 var temp = getCookie("login");
 if(!temp==1) {
  alert('Please Register to Enter'); 
 top.location.href=loginpage; }
}

//----------------------------------------------------------------
// Login Panel
//----------------------------------------------------------------

function BuildPanel() {
document.write('<form name="logon">');
document.write('<small><font face="Verdana" color="#666666" size="1">Username:&nbsp;</font></small>');
document.write('<small><font face="Verdana"><input type="text" name="username" size="5"></font></small>');
document.write('<small><font face="Verdana" color="#666666" size="1">&nbsp;Password:&nbsp;</font></small>');
document.write('<small><font face="Verdana"><input type="password" name="password" size="6">&nbsp;</font></small>');
document.write('<input type="button" value="Login" name="Logon" onclick="login(username.value,password.value)">'); 
// document.write('<br><small><font face="Verdana" color="#666666" size="1"><a href="register.html">Register New User</a></font></small>&nbsp;&nbsp;&nbsp;');
document.write('</form>');
}

