var successpage = "http://www.pmbonline.co.uk/backstage/index.html";
var loginpage = "http://www.pmbonline.co.uk/backstage/index.html"; 
var imgSubmit = ""; 
var imgReset = ""; 
var users = new Array();

users[0] = new Array("mikeyj","mikeyj","mikeyj.html"); 
users[1] = new Array("breathe","attitude","breathe.html");     
users[2] = new Array("businessasusual","dirty","businessasusual.html");   
users[3] = new Array("davelindley","backwards","davelindley.html");    
users[4] = new Array("fleshresonance","feast","fleshresonance.html");   
users[5] = new Array("floron","god","floron.html");   
users[6] = new Array("hayze","ipswich","hayze.html");     
users[7] = new Array("if6was9","hendrix","if6was9.html");   
users[8] = new Array("jimmyyoung","beneking","jimmyyoung.html");    
users[9] = new Array("katecassidy","shaming","katecassidy.html");   
users[10] = new Array("mortice","mayhem","mortice.html");   
users[11] = new Array("philfrazier","union","philfrazier.html");    
users[12] = new Array("raywilkins","max","raywilkins.html");   
users[13] = new Array("rodgerchristmann","ania","rodgerchristmann.html");  
users[14] = new Array("thinking","hongkong","thinking.html");    
users[15] = new Array("michaelfargnoli","soundwaves","michaelfargnoli.html");   
users[16] = new Array("seismicanamoly","roller","seismicanamoly.html");  
users[17] = new Array("standby","currie","standby.html"); 
users[18] = new Array("yj2","100miles","yj2.html"); 
users[19] = new Array("questionnaire","saturday","questionnaire.html"); 
users[20] = new Array("boogaboo","theboog","boogaboo.html"); 
users[21] = new Array("driver","history","driver.html"); 
users[21] = new Array("liquidblue","super","liquidblue.html"); 
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('OOPS! 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('OOPS! Access Denied!'); 
  if(top.location.href != location.href){
   location.href = loginpage;           
  }else{
   top.location.href = loginpage;  
  }
 }
}

//----------------------------------------------------------------

// Login Panel
//----------------------------------------------------------------

function BuildPanel() {
document.write('<form name="logon"><table align="left" border="0"><tr><td align="right">');
document.write('<small><span style="font-size:12"><font face="Arial"><b>Username:</b></span></small></td>');
document.write('<td><small><span style="font-size:12"><font face="Arial"><input type="text" name="username" size="20"></font></span></small></td></tr>');
document.write('<tr><td align="right"><small><span style="font-size:12"><font face="Arial"><b>Password:</b></font></span></small></td>');
document.write('<td><small><span style="font-size:12"><font face="Arial"><input type="password" name="password" size="20"></font></small></td></tr>');
if(imgSubmit == ""){
 document.write('<tr><td align="right" colspan="2"><p><input type="button" value="Log In" name="Logon" 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)">');
}
document.write('</p></td></tr></table></form>');
}


