var login=function()
{
	var usersAndKeys = [2]; 
	var correntUser=[2];	
	var correntClub=[1];

	var deviceType;
	var database;

	var connectionPage = {
		inputSection:
			"<div class = '+deviceType+'>"+
			"<div class='login-page'>"+

				"<div class='form'>"+
					"<div class='login-form'>"+
						"<img src ='images/pictureLogo.jpg' width='200' height='110'/>"+
						"<input value='g@g.com' id='username' type='text' placeholder='הכנס שם משתמש'/>"+
						"<input value='123123' id='password' type='password' placeholder='הכנס סיסמה'/>"+
						"<button id = 'cmdLogin' >התחבר</button></br>"+
						"<img id='loader' src='images/homepreloader.gif'/ width ='40%'>"+
					"</div>"+
				"</div>"+
			"</div>"+
		"</div>"
	};
		
	var stateMap = {$container : null };
	
	var initModule = function($container) 
	{
		database = firebase.database();			// A reference for the database
		stateMap.$container = $container;
		$("body").html(connectionPage.inputSection);
		$("#cmdLogin").click(loginClick);
	};
		
//---------------------------------------------------------------------------------------------------//

	var loginClick = function(e)
	{
		var username = document.getElementById("username").value;
		var password = document.getElementById("password").value;
		if(username == "" || password == "")
		{
			alert("אנא הכנס שם משתמש וסיסמה");
			return;
		}
				// validateAndPushUser(username,password);

		var auth = firebase.auth();
		auth.onAuthStateChanged(function(user) {
			if (user) 
			{
				// User is signed in.
				var ref = firebase.database().ref("users");
				ref.once("value")
				.then(function(data)		
				{
					var allUsers = data.val();   // get the whole tree of clubhouses
					var keys = Object.keys(allUsers);	// get all keys
					
					usersAndKeys[0]= allUsers;
					usersAndKeys[1] = keys;
					correntUser[1] = user.uid; 
					correntUser[0] = allUsers[user.uid];
					correntClub[0] = allUsers[user.uid].clubhouseKey;
				});
				
			} 
		});
	
		var promise = auth.signInWithEmailAndPassword(username,password);
		promise.then(function(user){
			var ref = firebase.database().ref("users");
				ref.once("value")
				.then(function(data)		
				{
					var allUsers = data.val();   // get the whole tree of clubhouses
					var keys = Object.keys(allUsers);	// get all keys
					
					usersAndKeys[0]= allUsers;
					usersAndKeys[1] = keys;
					correntUser[1] = user.uid; 
					correntUser[0] = allUsers[user.uid];
					correntClub[0] = allUsers[user.uid].clubhouseKey;
				});

			$("#loader").css("display", "inline-block");
				setTimeout(function()
				{ 
					mainPage.openMainPage(correntUser[0]); 
				}, 500);
		});
		promise.catch(function(err){alert(err.message);});
	}

//-------------------------------------------------------------------------------------------
	
	var rejectUser = function(data)			// in case password or username are not exist
	{
		alert("שם משתמש או סיסמה אינם נכונים");
		document.getElementById("username").value = "";
		document.getElementById("password").value = "";
	}

//---------------------------------------------------------------------------------------------------//

	var allreadyOnline = function()
	{
		alert("המשתמש כבר נמצא במערכת - במידה ונתקלת בבעיה פנה למנהל המורשה");
		document.getElementById("username").value = "";
		document.getElementById("password").value = "";
	};

//---------------------------------------------------------------------------------------------------
	
	var getObj=function(key)
	{
		return usersAndKeys[0][key];	
	}

//---------------------------------------------------------------------------------------------------//	
   	
return { initModule : initModule,
		 usersAndKeys:usersAndKeys,
		 correntUser:correntUser,
		 correntClub:correntClub,
		 getObj:getObj};
}();

$(document).ready(function() {login.initModule($("#login")) ; });
@@ -376,23 +376,8 @@
 put 
-value='g@g.com'
  id=
@@ -449,22 +449,8 @@
 put 
-value='123123'
  id=

fix index