//Password Script
//Version 0.32
//Written by Steven Kohus
//suhok17-AT-hotmail.com

//Generates a web page URL to go to based on the username and password

//Strength of this script is generating pages that grant access to the 
//web site based on the idea that general users will not be able to 
//guess the name of the web pages contained within this site.

//A server-side password script would be much more secure than this 
//javascript, but this will stop most average users from gaining 
//access.  Plus nothing sensitive or valueable is on this site, so 
//nothing truely secure is needed.

//Note: This script is still a work-in-progress, so some features not
//implemented yet.

//Those web page URLs generated display a welcome screen and grant 
//access to the site or part of the site this password script is meant
//to protect.

//Get browser type
var iens6=document.all||document.getElementById;
var ns4=document.layers;

function Login(){
    //Flag for whether or not username and password are valid
    var done=0;

    //Variable to contain the URL of the generated address
    var myURL="";

    //Error message for invalid password
    var defMsg="Invalid password or username.  Please make sure you spelled your Username and Password correctly.  If you still have problems, then click 'Help' to see how to reach me.";

    //Get username and convert it to lowercase
    var myUser=document.login.username.value;
    myUser=myUser.toLowerCase();

    //Get password and convert it to lowercase
    var myPass=document.login.password.value;
    myPass=myPass.toLowerCase();

    if (myUser != "" && myPass != "")
    {
        //Construct access page URL
        myURL = 'access/'
        myURL = myURL + myUser.substring(0,1);
        myURL = myURL + myPass.substring(2,3);
        myURL = myURL + myUser.substring(3,4);
        myURL = myURL + myPass.substring(1,2);
        myURL = myURL + myUser.substring(1,2);
        myURL = myURL + myPass.substring(3,4);
        myURL = myURL + myUser.substring(myUser.length-2,myUser.length-1);
        myURL = myURL + myPass.substring(myPass.length-2,myPass.length-1);
        myURL = myURL + myUser.length + myPass.length + '.html';        
        //Grant access if it matches a real url, else a 404 error will occur
	SetCookie('VisitorName',document.login.username.value, exp);
        window.location.href = myURL;
    }
    else
    {
        alert("Please fill in both your username and password before clicking 'Login'.");
    }
}

function ClearMe(){
    //Clears the form's contents
    document.login.password.value="";
    document.login.username.value="";
}

function loginHelp() {
    var popupWin = window.open('loginhelp.html#mytable','LoginHelp', 'status,dependent,width=650,height=450,left=100,top=100')
}
