HJ.Login = Class.create();

HJ.Login.prototype = {
   
   initialize: function(returnToObject, showLoginPageContent, showReturnDialog) {
   	  this.returnToObject = returnToObject;
      this.userId = "HJ User";
	  this.userFullName = "None";	 
	  this.signUpEmail = null;
	  this.userEmail = HJ.requestQueryString.get("user_email", null);
	  this.IsNewSignUp = false;
	  this.IsSignupAfterLogin = false;
	  this.userId = null;
	  this.password = null;
	  this.showContactImporter = false;
	  this.showLoginPageContent = showLoginPageContent;
	  this.showReturnDialog  = (typeof(showReturnDialog) == 'undefined') ? true : showReturnDialog;
	  ajaxEngine.commFailureHandler = commFailure;
	  ajaxEngine.timoutHandler = commTimedout;
	  this.saveTemplateAction = HJ.requestQueryString.get("saveTemplate", null);
	  this.templateStep = HJ.requestQueryString.get("step", "0");
	  return false;
   },
   
   cleanup: function() {
      if (this.loginLink != null && this.loginLink != undefined) {
		  this.loginLink.onclick = null;
		  this.sendPasswordLink.onclick = null;
		  this.signupLink.onclick = null;
		 // this.submitEmailLink.onclick = null;
      }
   },
   
   //  Appending to original to handle url request query string, which dictates the template entry point of the 
   //  non-signed in users
   startStep1: function() {
   	   	   	
   	if (this.userEmail == null) {
		var s = HJ.requestQueryString.get("contextId", null);
		if (s != null) {
			ajaxEngine.setContextId(s);
		} else {
			s = HJ.readCookie(HJ.COOKIE_CONTEXT_ID);
			if (s != null && s != "") {
				ajaxEngine.setContextId(s);
			}
		}
   	} else {
  		ajaxEngine.setContextId(null);
   		var response = new Object();
   		response.responseText = HJ.NO_CURRENT_SESSION;
   		this.checkLoginRequired(response); // force login if email address is specified as a parameter
		return false;
   	}

   this.startCheckLoginRequired();
   return false;
   },
	
  startCheckLoginRequired: function() {
      var req = new Af.DataRequest(svcURL, this.checkLoginRequired.bind(this), this.requestFailedCommon.bind(this), null,
      this.requestTimedOutCommon.bind(this));
      req.addService("adminSvc.loginRequired", "loginRequired");
      ajaxEngine.processRequest(req);
      return false;
   },
   
	checkLoginRequired: function(response) {	  
		hideModalMessageDialog();
				
		if (response.responseText == HJ.NO_CURRENT_SESSION) {
			// invalidate the context
		    HJ.eraseCookie(HJ.COOKIE_CONTEXT_ID);
	  	    GATrackAction(GA_ACTION_START_LOGIN);
			
		    if (this.returnToObject !=null)
		   	{
				if (this.showReturnDialog)
		   			showMessageDialog("You need to become a member or log in before performing this action.  Start your free trial now.", 'Log In or Become a Member', 300, 100);  		
		   	}

			// Make sure that the login page content shows up
			if (this.showLoginPageContent != null && this.showLoginPageContent == "true") {
				//document.getElementById("homeFooter").style.display = "none";
				if(app.footer == null || app.footer == 'undefined' )
				{
					app.footer = new HJ.Footer();
					app.footer.doLoadTemplate();
				}
				this.url = basePageURL + "SigninContent.htm";
				this.targetContainerId = "MainArea";
				if(this.tl == null) {
					this.tl = new Af.TemplateLoader(this.url, this.targetContainerId, null);
					this.tl.listener = this;
					this.tl.loadTemplate();
				} else {
					this.tl.reAttachElement();
				}
			} else {
				// skip loading of login content but invoke post-template loading method
				this.templateLoaded();
			}
		} else if (response.responseText == HJ.NO_CURRENT_SUBSCRIPTION) {
			var dlg = showConfirmDialog(
					"Jooners is now a subscription service. Please consider signing up today! " +
					"You'll get another free trial month before any charges are made.<br /><br />" +
					"For just the cost of a good book, you can put organizing volunteers on" +
					" auto-pilot for the entire year!<br /><br />" +
					"For our new subscription service, please agree to our new " +
					"<a href='#' onClick=\"return window.open('LegalAgreement.htm','_blank','toolbar=yes, " +
					"location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, " +
					"copyhistory=yes, width=800, height=600');\">Terms of Service</a>.",
					"Subscription Needed", 
					300, 250, 
					this.goToSubscriptionPage.bind(this), this.logout.bind(this), 
					true);
			if (dlg != null) {
				var buttons = document.getElementsByClassName("ButtonStyle");
				for (var i=0; i<buttons.length; i++) {
					if (buttons[i].innerHTML == "OK") {
						buttons[i].innerHTML = "I agree";
						continue;
					}
					if (buttons[i].innerHTML == "Cancel") {
						buttons[i].innerHTML = "No thank you";
					}
				}
			}
			return;
		} else {
			// user has logged in
      		// set user defined variable so that this visit can be segmented
			if (pageTracker != null && pageTracker != 'undefined') {
				try {
					pageTracker._setVar("member");
				} catch (ex) {
				}
			}
      	
			this.userId = response.responseText;
			this.getUserName();
			
			if (this.saveTemplateAction != null) {
				// user was in the middle of saving a template in the new framework
				window.location = basePageURL + "OrganizeShifts.htm?step=" + this.templateStep;
				return false;
			}
			this.startStep2();
		}
	},
	
	goToSubscriptionPage: function() {
		if (this.userEmail != null) {
			window.location = basePageURL + "/subscription?userEmail=" + this.userEmail;
		} else {
			window.location = basePageURL + "/subscription";
		}
		return false;
	},
   
   //for the login
   login: function(){	 
      var email = document.getElementById("txtEmailId").value;
      if (email == null) {
         email = "";
         } else {
         email = trim(email);
      }
      if (email == "") {
         showMessageDialog("Please enter your email address to begin registration .<br/>", "Request", 300, 100);
         return false;
      }
	  if(validator.validateEmail(email)==false){
		  showMessageDialog("Please enter a valid email address.","Request",250,100, null, true);
		  return false;
	  }
      var pw = document.getElementById("txtPassword").value;
      if (pw == null) {
         pw = "";
      }

      var keepLogin = document.getElementById("chkAutoLogin");

      
      this.userEmail = email;
      this.password = pw;
      this.keepLoggedIn = keepLogin.checked;
      
      var req = new Af.DataRequest(svcURL, this.loginSuccessful.bind(this), this.loginFailed.bind(this), null,
      this.loginTimedOut.bind(this));
      req.addService("adminSvc.login", "login");
      
      var s = "<login>";
      s += "<userId>" + email + "</userId>";
      s += "<pw>" + pw + "</pw>";
      s += "<keepLoggedIn>" + this.keepLoggedIn + "</keepLoggedIn>";
      s += "</login>";
      req.xmlDoc = s;
      showModalMessageDialog("Logging in ... please wait", 240, 40);
      ajaxEngine.processRequest(req);
      
      return false;
   },
   
   loginSuccessful: function(response) {

      var resp = response.responseText.split(";");
      var contextId = resp[0];
      var userCred = resp[1];

      hideModalMessageDialog();

	  GATrackAction(GA_ACTION_SUCCESSFUL_LOGIN);
      ajaxEngine.setContextId(contextId);	 
      
      var d = new Date();   
	  d.setDate(d.getDate() + HJ.COOKIE_CONTEXT_ID_EXPIRATION_DAYS);
      
      d_str = d.toGMTString();
      var keepLogin = document.getElementById("chkAutoLogin");

      if(keepLogin && keepLogin.checked) {
        d_str = 3650;
        HJ.createCookie(HJ.COOKIE_KEEP_LOGGED_IN, userCred, d_str);
      }

      if (this.userId != null) {
		  HJ.createCookie(HJ.COOKIE_USER_ID, this.userId, d_str);
      }

      if (this.userEmail != null) {
    	  HJ.createCookie(HJ.COOKIE_USER_EMAIL_ID, this.userEmail, d_str);
      }


        HJ.createCookie(HJ.COOKIE_CONTEXT_ID, contextId, d_str);
        ajaxEngine.setContextId(contextId);
        

		this.startCheckLoginRequired(); 
   },
   
   
   loginFailed: function(dataRequest, msg) {
      hideModalMessageDialog();
      showMessageDialog("We do not recognize your email address and password combination.<br/> If you need your password, please click Send me my password", "Authentication failed", 400, 150);
   },
   
   loginTimedOut: function(dataRequest) {
      hideModalMessageDialog();
      showMessageDialog("We do not recognize your email address and password combination.<br/> If you need your password, please click Send me my password", "Authentication failed", 400, 150);
   },
   
   startStep2: function() {
      _useFile = false;
      //document.getElementById("resources").style.display = "none";
      ajaxEngine.loginRequiredHandler = loginRequired;
      app.initialize1();
	  initializeTimer();
   },
   
   // Function to Save EmailId to the text File at Server Side
   submitEmail: function(){
      var s = "";
      var userId = trim(document.getElementById("saveEmailId").value);
      if (userId == "") {
         s = "Please enter a valid email address to receive information about Jooners. <br/>";
      }
      if (s != "") {
         showMessageDialog(s, "Request", 400, 150);
         return;
      }
      if (userId == "Enter your email address") {
         return;
      }
	  if(validator.validateEmail(userId)==false){
		  showMessageDialog("Please enter a valid email address.","Request",250,100, null, true);
		  return;
	  }
      var req = new Af.DataRequest(svcURL, this.requestSavedSuccessful.bind(this), this.requestFailedCommon.bind(this),
      null, this.requestTimedOutCommon.bind(this));
      req.addService("PublicService", "submitEmail");
      req.addParameter("saveEmailId", userId);
      ajaxEngine.processRequest(req);
      return false;
   },
   
   requestSavedSuccessful: function(response) {
      debugA("Completed successful: ");
      showMessageDialog("Thank you.  We will contact you when our site becomes public.", "Success !", 300, 100);
	document.getElementById("saveEmailId").value = "Enter your email address";
   },
   
   requestFailedCommon: function(dataRequest, msg) {
      showMessageDialog("We are currently unable to save your email address. Please try to enter it again.", "Excuse us!", 350, 100);
   },
   
   requestTimedOutCommon: function(dataRequest) {
      showMessageDialog("We are currently unable to save your email address. Please try to enter it again.", "Excuse us!", 350, 100);
   },
   
   
   signup: function(){
      var s = "";
      var userId = trim(document.getElementById("singupEmail").value);
      if (userId == "" || userId == "Enter your email address here") {
         s = "Please enter your email address to begin registration .<br/>";
      }
      if (s != "") {
         showMessageDialog(s, "Request", 300, 100);
         return false;
      }
	  if(validator.validateEmail(userId)==false){
		 showMessageDialog("Please enter a valid email address.","Request",300,100,null, true);
		 return false;
	  }

	  this.signUpEmail = userId;
      
      var req = new Af.DataRequest(svcURL, this.requestVerifySuccessful.bind(this), this.requestFailedVerify.bind(this),
      null, this.requestTimedOutCommon.bind(this));
      req.addService("PublicService", "verifyUser");
      req.addParameter("emailId", userId);
      ajaxEngine.processRequest(req);
      return false;
      
   },
   
   requestVerifySuccessful: function(response) {
	if(response.responseText == "alreadySignedUp") {
		showMessageDialog("This email address is already signed up.<br/>"+
			"Please try another.", "Excuse us!", 350, 120);
		return;
	}
	this.doSignup();
   },
   
  
   requestFailedVerify: function(dataRequest, msg) {
      if ("NOT_LISTED_USER" == msg) {
         showMessageDialog( "<p>We're sorry. We don't recognize the information you have given us. Please try again.</p>" + 
	"<p>Currently our site is only open to invited guests. If you would like to be contacted when we are open to the public, please enter your email in the box at the lower left corner of page.</p> <p> Thank You !</p>"
         , " Invited Guests Only", 350, 200);
      } else {
         showMessageDialog("The email you have entered does not match our records.  Please try again.", "Informing You", 350, 100);
      }
   },
   
   
   doSignup: function(){
	   var s = HJ.readCookie(HJ.COOKIE_CONTEXT_ID);
	   if (s != null && s != "") {
		   window.location = basePageURL + "Signin.htm";
		   return false;
	   }
	   
	  this.IsNewSignUp = true;
	  GATrackAction(GA_ACTION_START_REGISTRATION);
      var tl = new Af.TemplateLoader(basePageURL + "SignUp2.html", "MainArea");
      tl.listener = this;
      tl.loadTemplate();
   },
   
   joinHJ: function() {
      var s = "";
	  var email = "";
      var userId = trim(document.getElementById("userId").value);
      
      if (userId == "") {
         s = "Please enter a screen name you will use while on Jooners. It will be used to protect your identity.<br/>";
      }
	  if(this.signUpEmail == null) {
		   email = trim(document.getElementById("email").value);
		  
		  if (email == "") {
			 s += "Please enter your email address.<br/>";
		  }
		  if(validator.validateEmail(email)==false){
			 //s +="The email address you entered doesn't match our records.  Please try again.<br/>";
			 s +="Please enter a valid email address.<br/>";
		   }
	  } else {
		  email = this.signUpEmail;
	  }
      if (s != "") {
         showMessageDialog(s, "Request", 330, 150, null, true);		
         return;
      }

      var filter =  /[0-9a-zA-Z]$/;
      var password = trim(document.getElementById("password").value);
      var rptPassword = trim(document.getElementById("rptPassword").value);

      if(!filter.test(password) || !filter.test(rptPassword) || rptPassword.length < 6 || password.length < 6) {		
			  if(password.length < 6 || rptPassword.length < 6) {
				showMessageDialog("Password must be at least 6 characters.", "Excuse us!", 320, 110);
				return;
			  } 
			  showMessageDialog("No Special characters allowed.", "Excuse us!", 320, 110);
			  return;
		  }	  
      if (password != rptPassword) {
         showMessageDialog("The password you entered doesn't match.  Please try again.", "Request", 300, 100);
         return;
      }
      
      var agreedCheck = document.getElementById("agreedCheck");
      
      debugA("agreedCheck.checked: " + agreedCheck.checked);
      if (agreedCheck != null && !agreedCheck.checked) {
					showMessageDialog("Please read our User Agreement and check the box to agree to its terms.", "Request", 350, 100);
         return;
      }
      
      var lName = trim(document.getElementById("lName").value);
      var fName = trim(document.getElementById("fName").value);
      var zip = trim(document.getElementById("zip").value);
      
      var s = '<user class="User">';
      s += xmlP("userId", userId);
      s += xmlP("email", email);
      s += xmlP("password", password);
      s += xmlP("rptPassword", rptPassword);
      s += xmlP("lName", lName);
      s += xmlP("fName", fName);
      s += xmlP("zip", zip);
      s += "</user>";
      
      this.userId = userId;
      this.userEmail = email;
      this.password = password;
      
      var req = new Af.DataRequest(svcURL, this.joinSuccessful.bind(this), this.joinFailed.bind(this), null,
      this.joinTimedOut.bind(this));
      req.addService("adminSvc.register", "register");
      
      req.xmlDoc = s;
      app.showBusy();
      
      ajaxEngine.processRequest(req);
      
   },
   
   joinSuccessful: function(response) {
       app.endBusy();
	         
      if (this.userId != null) {
		  HJ.createCookie(HJ.COOKIE_USER_ID, this.userId, HJ.COOKIE_CONTEXT_ID_EXPIRATION_DAYS);
      }

      if (this.userEmail != null) {
    	  HJ.createCookie(HJ.COOKIE_USER_EMAIL_ID, this.userEmail, HJ.COOKIE_CONTEXT_ID_EXPIRATION_DAYS);
      }


      // track with google analytics and locally
      GATrackAction(GA_ACTION_SUCCESSFUL_REGISTRATION);
	  ActionTracker.track(ActionTracker.TRACKED_ACTION_SUCCESSFUL_REGISTRATION);

      window.location = basePageURL + "/subscription?userEmail="+this.userEmail;
      return false;

      HJ.createCookie(HJ.COOKIE_CONTEXT_ID, response.responseText, 
			HJ.COOKIE_CONTEXT_ID_EXPIRATION_DAYS);
      ajaxEngine.setContextId(response.responseText);

		this.startCheckLoginRequired();
		this.showContactImporter = true;
   },
   
   
   joinFailed: function(dataRequest, msg) {
       app.endBusy();
      showMessageDialog(msg , "A problem was encountered", 350, 100);
	  //showMessageDialog(msg+"We are currently unable to process your registration.<br/> Please try again.", "Excuse us!", 350, 100);
	 },
   
   joinTimedOut: function(dataRequest) {
	   hideModalMessageDialog();
      showMessageDialog("We are currently unable to process your registration.<br/> Please try again.", "Excuse us!", 300, 100);
   },
   
   
   logout: function () {	 
      var req = new Af.DataRequest(svcURL, this.logoutStep2.bind(this), this.requestFailedCommon.bind(this), null,
      this.requestTimedOutCommon.bind(this));
      req.addService("adminSvc.logout", "logout")
      ajaxEngine.processRequest(req);
      this.IsSignupAfterLogin = true;
      showModalMessageDialog("Logging out ...", 240, 40);
      return false;
   },
   
  
   logoutStep2: function () {	
	  stopTimer();
      HJ.eraseCookie(HJ.COOKIE_CONTEXT_ID);
      HJ.eraseCookie(HJ.COOKIE_USER_EMAIL_ID);
      HJ.eraseCookie(HJ.COOKIE_KEEP_LOGGED_IN);
      HJ.eraseCookie('JSESSIONID');
      HJ.eraseCookie('JSESSIONID', '/rose');
      //HJ.eraseCookie('_hj_uid_');
	  //window.location = basePageURL + "j_acegi_logout";
	  hideModalMessageDialog();
	  window.location = basePageURL + "Signin.htm";
	  return false;  
   },
   
   doVerifyUser: function(){
      var tl = new Af.TemplateLoader(basePageURL + "NeedPassword.htm", "signinContainer");
      tl.listener = this;
      tl.loadTemplate();
      return false;
   },
   
   verifyPassword:function(){
      var s = "";
      var userId = trim(document.getElementById("txtEmailId").value);
      if (userId == "") {
         s = "Please enter your email address and we will send you your password.<br/>";
      }
      if (s != "") {
         showMessageDialog(s, "Request", 400, 150);
         return;
      }
      
      var req = new Af.DataRequest(svcURL, this.requestVerifyUserIdSuccessful.bind(this), this.requestFailedVerifyUserId.bind(this),
      null, this.requestTimedOutCommon.bind(this));
      req.addService("PublicService", "verifyUser");
      req.addParameter("emailId", userId);
      ajaxEngine.processRequest(req);
   },
   
   requestVerifyUserIdSuccessful: function(response) {
      this.doVerifyUser();
   },
   
    requestFailedVerifyUserId: function(dataRequest, msg) {
      if ("NOT_LISTED_USER" == msg) {
         showMessageDialog("Please enter the email address you used to sign-up with Jooners.", "Request", 350, 100);
         } else {
         showMessageDialog("This email was returned from the server and is undeliverable.", "Excuse us!", 350, 100);
      }
   },
 
   doSendPassword:function(){
      var s = "";
      var emailId = trim(document.getElementById("emailId").value);
      if (emailId == "") {
         s = "Please enter your email address  to get the password<br/>";
      }
      if(validator.validateEmail(emailId)==false){
				s +="The email address you gave us is not valid.  Please try again.";
			}
			if (s != "") {
         showMessageDialog(s, "Request", 400, 150, null, true);
         return;
      }
      this.enteredEmail = emailId;
      var req = new Af.DataRequest(svcURL, this.sendPasswordSuccessful.bind(this), this.failedtoSendEmail.bind(this),
      null, this.requestTimedOutSendEmail.bind(this));
      req.addService("AccessControlSvc", "sendPassword");
      req.addParameter("emailId", emailId);
      ajaxEngine.processRequest(req);
      
   },
   
   sendPasswordSuccessful: function(response)	{
      showMessageDialog("This email has been successfully sent." , "Success!", 300, 80);
      this.doSentSuccessful();
   },
   
   failedtoSendEmail: function(dataRequest, msg) {
      showMessageDialog(msg, "Excuse us!", 350, 100);
   },
   
   requestTimedOutSendEmail: function() {
      showMessageDialog("We are currently unable to send your password.  Please request it again.", "Excuse us!", 350, 100);
   },
   
   doSentSuccessful:function(){
      var template = new Af.TemplateLoader(basePageURL + "PasswordSent.htm", "signinContainer");
      template.listener = this;
      this.showSent = false;
      template.loadTemplate();
      this.showSent=true;
   },
   
   templateLoaded:function(){
        
	   if (this.showSent != null && this.showSent == true) {
		   this.showSent = false;
		   document.getElementById('sendTo').innerHTML = this.enteredEmail;
	   }
        var browserName=navigator.appName;
		var browserVer=parseInt(navigator.appVersion);
		if (browserName=="Microsoft Internet Explorer" && browserVer<=6) {
			document.getElementById('joonersLogo').src = 'img/logo.gif';
		}
        
        
        this.loginLink = document.getElementById("loginLink");
        this.sendPasswordLink = document.getElementById("sendPasswordLink");
        this.signupLink = document.getElementById("signupLink");
      //  this.submitEmailLink = document.getElementById("submitEmailLink");
		this.fbOkButton = document.getElementById("fbOkButton");
		this.pwElement = document.getElementById("txtPassword");
		
		var signUpEmailElem = document.getElementById('singupEmail');
		if (signUpEmailElem != null) {
			Event.observe(signUpEmailElem, 'click',
                 this.eraseTextFieldValue.bindAsEventListener(this));
		}

		if(this.fbOkButton != null){
			//this.fbOkButton.onclick = this.homepageBtnClicked.bind(this);
		}
        if(this.loginLink != null){
			this.loginLink.onclick = this.login.bind(this);
		}
		
		if (this.pwElement != null) {
            Event.observe(this.pwElement, 
                          'keypress', 
                          this.processPasswordKeypress.bindAsEventListener(this));
		}
		
		if(this.sendPasswordLink != null){
			this.sendPasswordLink.onclick = this.doVerifyUser.bind(this);
		}
		if(this.signupLink != null){
			this.signupLink.onclick = this.signup.bind(this);
		}
		/*if(this.submitEmailLink != null){
			this.submitEmailLink.onclick = this.submitEmail.bind(this);
		} */
		
		var emailIdElem = document.getElementById("txtEmailId"); 
		if (emailIdElem == null) {
		   return;
		}

		if (this.userEmail == null) {
			this.userEmail = HJ.readCookie(HJ.COOKIE_USER_EMAIL_ID);
		}
		
		if (this.userId == null) {
			this.userId = HJ.readCookie(HJ.COOKIE_USER_ID);
		}
		
		if (this.userEmail != null) {
			this.userEmail = this.userEmail.replace(/%40/ig, '@');
			emailIdElem.value = this.userEmail;
		}
		
      if(this.showSent){
         var sentTo = document.getElementById("sendTo");
         sentTo.innerHTML =  this.enteredEmail;
      }
	  if(this.IsNewSignUp) {
		  this.IsNewSignUp = false;		 
		  var email = document.getElementById("email");
		  if(this.signUpEmail != null) {
			email.readOnly = true;
			email.value = this.signUpEmail; 
		  }
		  return;
	  } else if (this.IsSignupAfterLogin) {
		  this.IsSignupAfterLogin = false;
	  }
   },
   
   goBack:function(){
      window.location.href ="index.htm";
   },
	
   goSignIn:function(){
      window.location.href ="Signin.htm";
   },

	doCancel:function(){
		window.location.href ="index.htm";
	},
	getUserName: function() {
		var req = new Af.DataRequest(svcURL, this.reqGetUserComplete.bind(this), this.reqGetUserFailed.bind(this),
		null, this.reqGetUserTimeOut.bind(this));
		req.addService("AccessControlSvc", "getUserProfile");
		req.addParameter("userId",this.userId);
		ajaxEngine.processRequest(req);
	},
	reqGetUserComplete: function(response) {
		var xds = new Af.XMLToDataSet(response.responseXML);
		this.userData = xds.data;
		this.userFullName = this.userData["fName"];
		this.userEmail = this.userData["email"];
        var d = new Date();   
	    d.setDate(d.getDate() + HJ.COOKIE_CONTEXT_ID_EXPIRATION_DAYS);

        d_str = d.toGMTString();
        var keepLogin = HJ.readCookie(HJ.COOKIE_KEEP_LOGGED_IN);

        if(keepLogin && keepLogin != "") {
            d_str = 3650;
        }
		HJ.createCookie(HJ.COOKIE_USER_EMAIL_ID, this.userEmail, d_str);
	},
	reqGetUserFailed: function() {
		this.userFullName = this.userId;
	},
	reqGetUserTimeOut: function() {
		this.userFullName = this.userId;
	},

	homepageBtnClicked: function(){
		index.fbOkBtnClicked();
	},
	pingCompleted : function(response){
	 //debugA(response.responseText);
	 //debug("Ping succeeded ...");
	 startTimer();
	},
	
	pingFailed : function(response){
		debug("Ping failed ...");
		loginRequired();
    },
	
	processPasswordKeypress: function(event) {
		Event.extend(event);
	   	if (event.keyCode != null && event.keyCode == Event.KEY_RETURN) {
	   	  	this.login();
	    	return false;
	    }
	},
	
	eraseTextFieldValue: function(event) {
		Event.extend(event);
		if (Event.element(event).value == 'Enter your email address here') {
			Event.element(event).value = '';
		}
	}
}
 //  Code to start timer on user's successful sign - in , which take care of user session.
 // and if user's session expires it redirect to index page.

	var count;
	var timerID = null;
	var timerRunning = false;
	//milliseconds * seconds * minutes	
	var delay = 1000*60*5;

	function initializeTimer()
	{
		timerID = null;
		timerRunning = false;		
		stopTimer();
		/* disable timer from all domains
        if (currentDomain != DEV_DOMAIN) {
		    startTimer();
        }
        */
	}

	function stopTimer()
	{
		if(timerRunning) {
			clearTimeout(timerID);
		}
		timerRunning = false;
	}

	function startTimer()
	{
	   //debugA("Scheduling ping ...");
	   timerID = setTimeout("sendPingRequest()", delay);
	   timerRunning = true;	
	}
	
	function sendPingRequest()
	{
		//debugA("Pinging ...");
		if (currentDomain == DEV_DOMAIN) {
			return;
		}
		var req = new Af.DataRequest(svcURL, login.pingCompleted.bind(this), login.pingFailed.bind(this),
		null, login.pingFailed.bind(this));
		req.addService("PingService", "ping");
		ajaxEngine.processRequest(req);
	}
	

    function loginRequired() {
		stopTimer();
		var s = '<h1><span style="font-size:18.0pt">You\'re Now Signed Off</span></h1>' + 
                '<p style="font-size:12.0pt">Thank you for using <em>Jooners</em>. Your session has ended.</p>' + 
                '<p style="font-size:12.0pt">In order to access your account information, you will need to <a href="Signin.htm">Sign In</a> again.<br/> </p>';
                
        showMessageDialog(s, "Request", 400, 200, login.goSignIn, false, true);
    }
    
    function commFailure(ex) {
		stopTimer();
        try {
            console.log(ex.stack);
        } catch (consoleException) {
            // nothing, doesn't work on IE.
        }
		var s = '<h1><span style="font-size:18.0pt">Your session on Jooners has ended due to an interruption in communications.</span></h1>' + 
                '<p style="font-size:12.0pt">We are sorry for the inconvenience.</p>' + 
                '<p style="font-size:12.0pt">In order to access your account information, you will need to <a href="Signin.htm">Sign In</a> again.<br/> </p>' + 
                '<p style="font-size:12.0pt">If the problem persists, please try in few minutes. We may be temporarily out of service for maintenance.</p>';
                
        showMessageDialog(s, "Request", 600, 240, login.goSignIn, false, true);
    };

    function commTimedout() {
		stopTimer();
		var s = '<h1><span style="font-size:18.0pt">Your session on Jooners has ended due to an interruption in communications.</span></h1>' + 
                '<p style="font-size:12.0pt">We are sorry for the inconvenience.</p>' + 
                '<p style="font-size:12.0pt">In order to access your account information, you will need to <a href="Signin.htm">Sign In</a> again.<br/> </p>' + 
                '<p style="font-size:12.0pt">If the problem persists, please try in few minutes. We may be temporarily out of service for maintenance.</p>';
                
        showMessageDialog(s, "Request", 600, 240, login.goSignIn, false, true);
    };

