/*

-------------------------------------------------------------------

 Login Script Version 1.9

 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. Its

main purpose is to demonstrate the javascript techniques used.

The author takes no responsibility for data loss

resulting from the use of this script.

-------------------------------------------------------------------



INSTRUCTIONS - Read Before Using Script



If you are using frames, the code referred to in steps 2 - 5 must be put in the 

pages displayed in the frames and NOT in the parent document.



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 the 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>

 

 To use your own image instead of the grey button change the type from button to image

 and add src="myimage.gif" where myimage.gif is the image (including the path to it if

 needed, you want to use.

 

Step 6:

Upload this script and your html pages to the relevant directories

on your server. 









*/



//----------------------------------------------------------------

//  Usernames, Passwords & User Pages - These require configuration.

//----------------------------------------------------------------

var successpage = "newsroom_literature_members.php"; // The page users go to after login, if they have no personal page.

var loginpage = "newsroom_literature.php"; //Change this to the page the login panel is on.



var imgSubmit = ""; //Change to the path to your login image,if you don't want the standard button, otherwise do not change.

var imgReset = "";  //Change to the path to your reset image,if you don't want the standard button, otherwise do not change.



var users = new Array();



users[0] = new Array("ces1","e128iiua","");

users[1] = new Array("ces2","89jj71op",""); 

users[2] = new Array("ces3","990oouaq",""); 

users[3] = new Array("ces4","pp0a1226",""); 

users[4] = new Array("ces5","kkla7812",""); 

users[5] = new Array("ces6","hhr89112",""); 

users[6] = new Array("ces7","kklaqqi8",""); 

users[7] = new Array("ces8","60as331o",""); 

users[8] = new Array("ces9","opqa9991",""); 

users[9] = new Array("ces10","aawes991","");  

users[10] = new Array("ces11","poa10223","");

users[11] = new Array("ces12","nbal901j",""); 

users[12] = new Array("ces13","lpa1102f",""); 

users[13] = new Array("ces14","dlsp338q",""); 

users[14] = new Array("ces15","aapowwe9",""); 

users[15] = new Array("ces16","ppoqwe01",""); 

users[16] = new Array("ces17","llkamzxc",""); 

users[17] = new Array("ces18","0a2klm4f",""); 

users[18] = new Array("ces19","lkaqp01b",""); 

users[19] = new Array("ces20","1opa200e","");  

    

//----------------------------------------------------------------

//  Login Functions

//----------------------------------------------------------------

function login(username,password){

 var member = null;

 var loggedin = 0;

 var members = users.length;

 for(x=0;x<members && !loggedin; x++){

 if((username==users[x][0])&&(password==users[x][1])){

    loggedin = 1;

    member = x;

	break; // User validated, terminate the for loop.

   }

 } 

 

 if(loggedin==1){

  if(users[member][2] != "") {

   successpage = users[member][2];

  }

  setCookie("login",1);

  if (top.location.href != location.href){

   location.href = successpage;           

  }else{

   top.location.href = successpage;  

  }

 }else{

  alert('Access Denied.');

 }  

}



function logout() {

 deleteCookie("login");

 if (top.location.href != location.href){

  location.href = loginpage;           

 }else{

  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('You must first login to access this area.'); 

  if(top.location.href != location.href){

   location.href = loginpage;           

  }else{

   top.location.href = loginpage;  

  }

 }

}



//----------------------------------------------------------------

// Login Panel

//----------------------------------------------------------------



function BuildPanel() {

document.write('<STYLE>.text570 {font-family:verdana; font-size: 11px; color: #666666; height: 19; width: 120; border: 1px solid #000000;}.text5 {font-family:verdana; font-size: 11px; color: #000000;}</STYLE>');

document.write('<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff"><tr><td width="437" valign="top" class="link1"></td></tr></table>');

document.write('<table width="250" border="0" cellpadding="0" cellspacing="0" valign="top"><tr><td valign="top"><BR>');

document.write('<font class="text1">You must login to access this resource.</font></td></tr><TR><td><BR>');

document.write('<form name="logon"><table align="left" border="0" valign="top"><tr><td valign="top">');

document.write('<small><font class="text1"><STRONG>Username:</STRONG></font></small></td>');

document.write('<td valign="middle"><small><font class="text1"><input type="text" name="username" class="text1"></font></small></td></tr>');

document.write('<tr><td align="right"><small><font class="text1"><STRONG>Password:</STRONG></font></small></td>');

document.write('<td><small><font face="Verdana" size="-2"><input type="password" name="password" class="text1"></font></small></td></tr>');

document.write('</td></tr></table></body>');

if(imgSubmit == ""){

 document.write('<tr><td align="center" colspan="2"><p><input type="button" value="Login" name="Logon" style="width: 45px; height: 21px; font-family: verdana; font-size:11px; font-weight:bold; color: #ffffff; border-style: solid; border-width: 1px; border-color: #333333; background-color: #999999" onclick="login(username.value,password.value)">'); 

} else {

 document.write('<tr><td align="center" colspan="2"><p><input type="image" src="'+imgSubmit+'" name="Logon" onclick="login(username.value,password.value)">');

}

if(imgReset == ""){

 document.write('&nbsp <input type="reset" style="width: 45px; height: 21px; font-family: verdana; font-size:11px; font-weight:bold; color: #ffffff; border-style: solid; border-width: 1px; border-color: #333333; background-color: #999999" value="Reset" name="Reset">');

} else {

 document.write('<input type="image"  src="'+imgReset+'" name="Reset" onclick="logon.reset();">');

}

document.write('</p></td></tr></table></form>');

}


