bebo.ui.LoginForm = new Class({
   initialize: function(form) {
      this.ele = ele = $(form);

      if(!this.ele) { //no signin form
         return;
      }
      
      this.cookieUser=Cookie.read('Username') || Cookie.read('Email');
      this.username = usr = $E('input[name=EmailUsername]', ele);
      this.password = pwd = $E('input[type=password]', ele); //password field
      this.passwordText = pwdTxt = $E('.password-text', ele); //password text field
      
      this.usernameTxt = this.username.value;
      this.passwordTxt = this.passwordText.value;
      
      if(this.cookieUser) {
         this.username.value=this.cookieUser;
         this.username.removeClass('inactive');
      } else {
        usr.addEvent('focus', this.usernameFocus.bindWithEvent(this));
        usr.addEvent('blur', this.usernameBlur.bindWithEvent(this));
      }
      
      pwd.addEvent('blur', this.swapToText.bindWithEvent(this));
      pwdTxt.addEvent('focus', this.swapToPassword.bindWithEvent(this));
   },
   
   usernameFocus: function() {
      if (this.usernameTxt == this.username.value) {
         this.username.value = "";
         this.username.removeClass('inactive');
      }
   },
   
   usernameBlur: function() {
      if (this.username.value.trim() == "") {
         this.username.value = this.usernameTxt;
         this.username.addClass('inactive');
      }
   },
   
   swapToPassword: function() {
      this.passwordText.setStyle('display','none');
      this.password.setStyle('display','');
      this.password.focus();
   },
   
   swapToText: function() {
      if (this.password.value.trim() != "") {return;}

      this.password.setStyle('display','none');
      this.passwordText.setStyle('display','');
   }
});

document.addEvent('endofbody', function() {
   tmp = new bebo.ui.GlobalSearchBox('search-form');
   tmp = new bebo.ui.LoginForm('login-form');
   
   $('connect').addEvent('focus', function() {
      this.value = '';
      this.removeClass('inactive');
   });
   
   var tl = $('swfonbebonow');
   if (tl != null) {
        start_onBeboNow();
		var c = tl.innerHTML;
		c = c.split(' ').join('');
		c = c.split('\n').join('');
		c = c.split('\r').join('');
		c = c.split('\t').join('');
		if (c == "") {
			tl.set('html', "" +
				"<center>" +
				"<p class='empty'>" +
				"<b>This content requires the Flash Player</b>" +
				"</p> <br /><br />" +
				"<p class='empty'> <a href='http://www.adobe.com/go/getflashplayer'>" +
				"	<img src='http://s.bebo.com/img/get_adobe_flash_player.png' alt='Get Adobe Flash Player'>" +
				"</a> </p>" +
				"</center>" +
				"<br />" +
			"");
		}
	}	
   tmp = new Request.JSONP({url: 'http://my.screenname.aol.com/_cqr/login/checkStatus.psp?cb=setProperAOLmessage'}).send();

});

function setProperAOLmessage(hasAOLCredentials) {
	if ((hasAOLCredentials == 1) &&($('pAuthForLogin')!=null)) {
		$('pAuthForLogin').style.display = "none";
		$('pAuthForCreds').style.display = "block";
	}	
}


