function login(username,password){

 var member = null;
 var loggedin = 0;
 var un = '';
 var n = I.length;
 var c = 0;
 var hv = 0;
 var thv = 0;
 var t = '';
 var a = 0;
 
 for(c=0;c<password.length;c++) {
  if(c<username.length) {
   t = t + username.substring(c,c+1);
   }
  t = t +  password.substring(c,c+1);
  }
 if (c<username.length) {
  t = t + username.substring(c,username.length);
  }
 
 for(c=0;c<t.length;c++) {
  thv = thv + t.charCodeAt(c);
  }
 hv=(thv % 8);

 for(c=0;c<t.length;c++) {
  if(c>0) {
   if(c<(t.length-1)) {
     t = t.substring(0,c)+ String.fromCharCode(t.charCodeAt(c)+hv+((c+1) % 2)) + t.substring(c+1,t.length); 
   } else {
     t = t.substring(0,c)+ String.fromCharCode(t.charCodeAt(c)+hv+((c+1) % 2)); 
   }
  } else {  
    t = String.fromCharCode(t.charCodeAt(c)+hv+((c+1) % 2))+t.substring(c+1,t.length); 
  }
 }
 for(c=0;c<n && !loggedin; c++){ 
 if(t==I[c][0]) {
    loggedin = (I[c][2]);
    un = (I[c][1]);
	 for(c=0;c<un.length;c++) {
	  if(c>0) {
	   if(c<(un.length-1)) {
	    if(un.charCodeAt(c)==32) {
	     un = un.substring(0,c)+ ' ' + un.substring(c+1,un.length); 
	     }
	    else {
	     un = un.substring(0,c)+ String.fromCharCode(un.charCodeAt(c)-hv-((c+1) % 2)) + un.substring(c+1,un.length); 
	     }
	   } else {
	    if(un.charCodeAt(c)==32) {
	     un = un.substring(0,c)+' '; 
	     }
	    else {
	     un = un.substring(0,c)+ String.fromCharCode(un.charCodeAt(c)-hv-((c+1) % 2)); 
	     }
	   }
	  } else {  
	    if(un.charCodeAt(c)==32) {
	     un = ' '+un.substring(c+1,un.length); 
	     }
	    else {
	     un = String.fromCharCode(un.charCodeAt(c)-hv-((c+1) % 2))+un.substring(c+1,un.length); 
	     }
	  }
	 }
    member = c;
	break; // User validated, terminate the for loop.
   }
 } 
 
 if(loggedin>0){
  setCookie("fowspv",loggedin+10000);
  setCookie("fowsun",un);
  setCookie("fowsem",document.logon.username.value);
  window.location.reload(true);
 } else {
  top.location.href ="http://www.faberoptime.com/accessdenied.htm";
 }  
}

function logout() {
 deleteCookie("fowspv");
 deleteCookie("fowsun");
 window.location.reload(true);
}

var ckTemp = document.cookie;

function setCookie(name, value) { 
 if (value != null && value != 0) {
  if (document.logon.RememberMe.checked) {
   var date = new Date();
   date.setTime(date.getTime()+(24*60*60*1000));
   document.cookie=name + "=" + escape(value) + "; expires=" + date.toGMTString() + ";";
  } else {
   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(value,dodeny) {
 var temp = (getCookie('fowspv') / 10000);
 if (temp) {
  if (temp&value) {
   return 1; 
  } else {
   if (dodeny==1) {
    top.location.href ="http://www.faberoptime.com/accessdenied.htm";
   } else {
    return 0;
   }
  }
 } else {
  return null;
 }
}

function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
} 

function BuildPanel(value) {
 if (value == null) {
  document.write('<form name="logon"><table width="140" background="http://www.faberoptime.com/images/liveb.gif" cellspacing="0" cellpadding="3" style="border-style: outset; border-width: 1px; background-color: #FFFFFF;"><tr><td align="center">');
  document.write('<small><font size="2" color="#FFFFFF"><img border="0" src="http://www.faberoptime.com/images/keys.gif" width="16" height="16" alt="Sign In"> <b>Sign In</b></font></small><br>');
  document.write('<small><font face="Verdana" size="1"><input type="text" name="username"  SIZE="18" style="font-family: Verdana; font-size: 8pt" value="Your email" onFocus="clearText(this)"></font></small><br>');
  document.write('<small><font face="Verdana" size="1"><input type="password" name="password"  SIZE="18" style="font-family: Verdana; font-size: 8pt" value="password" onFocus="clearText(this)"></font></small><br>');
  document.write('<small><font face="Verdana" size="1"  color="#FFFFFF"><input type="checkbox" id="checker" name="RememberMe" checked>Remember Me<br>');
  document.write(' <input type="button" value="Sign In" name="Logon"  style="font-family: Verdana; font-size: 8pt" onclick="login(username.value,password.value)"> <a href="http://www.faberoptime.com/restricted.htm"><img border="0" src="http://www.faberoptime.com/images/help.gif" width="16" height="16" alt="About Restricted Content..." align="middle"></a>'); 
  document.write('</td></tr></table></form>');
 } else {
  document.write('<form name="frmLogoff"><table width="140" background="http://www.faberoptime.com/images/live.gif" cellspacing="0" cellpadding="3"  style="border-style: outset; border-width: 1px; background-color: #FFFFFF;"><tr><td align="center">');
  document.write('<small><font size="3" color="#FFFFFF"><img border="0" src="http://www.faberoptime.com/images/keys.gif" width="16" height="16" alt="Signed In"> <b>Signed In</b></font></small><br>');
  document.write('<small><font face="Verdana" size="1" color="#FFFFFF">as\n'+getCookie("fowsem")+'<br>');
  document.write('<input type="button" name="btLogoff" value="Sign Out" style="font-family: Verdana; font-size: 8pt" onclick="logout();"> <a href="http://www.faberoptime.com/restricted.htm"><img border="0" src="http://www.faberoptime.com/images/help.gif" width="16" height="16" alt="About Restricted Content..." align="middle"></a></td></tr></table>');
  document.write('</form></small></font>');
 }
}
