	

	
		//local variables
		var userCache = {};
		var localUserCache = {};
		var viewed = -1;
		var activeSpeaker = null;
		var localId = -1;
		
		function clearUserTable(){
				dwr.util.removeAllRows("peoplebody", { 
					filter:function(tr) {
						     return (tr.id!="pattern");
			     	}
			     });
		}
		
		/**
		**	Set up the table with all existing users out there.
		**/
		function setUpTable(){
				Conference.getConferenceUsers(function(users){	
					clearUserTable();	
			    	var user, id;
			    	users.sort(function(p1, p2) { return p1.company.localeCompare(p2.company); });
			    	for (var i=0;i<users.length;i++){
			    		user = users[i];
			    		id = user.userId;
			    		dwr.util.cloneNode("pattern", { idSuffix:id });
			    		dwr.util.setValue("tableName" +id, user.name);
			    		dwr.util.setValue("tableCity" +id, user.city);
			    		dwr.util.setValue("tableState" +id, user.state);
			    		dwr.util.setValue("tableCompany" + id, user.company);
			    		DWRUtil.byId("pattern" + id).style.display = "";
			    		userCache[id] = user;
			    	}
			   });
		}
		
		function getConferenceName(){
			Conference.pushConferenceName();
		}
			    	
	    function toggleLoginType(){
		    $(".manualLogin").toggle("slow");
		    $(".loginForm").toggle("slow");
	    }
	
		function closeLoginBox(){
			 $(".manualLogin:visible").toggle("slow");
	    	 $(".loginForm:visible").toggle("slow");
	    	 $(".secondaryLoginForm:visible").toggle("slow");
		}
		function openLoginBox(){
			// $(".manualLogin:visible").toggle("slow");
	    	 $(".loginForm").toggle("slow");
		}
		
		/**
			Check if a conference is running currently
		**/
		function checkExistingConference(){
			Conference.getConferenceId(function(confId){
				if (confId==-1){
					alert('There are no conferences currently running, please try back later');
					location.href='http://riskpronet.com';
				}else{
				
				}
			});
		}
		
		/**
			Check if a conference is running currently
		**/
		function checkAdminExistingConference(){
			Conference.getConferenceId(function(confId){
				if (confId!=-1){
				     if(confirm('A conference is currently in progress, to log in as a second administrator, click ok, to cancel existing conference and start a new one, click cancel')){
				     	$(".loginForm").hide("fast");
				     	$(".secondaryLoginForm").show("fast");
				     	getSecondaryRPNEmployees();
				     }else{
				     	closeConference();
				     	location.href='index.jsp?adminuser=true';
				     }
				}else{
				
				}
			});
		}
		
		/**
		Open the conference, show hidden divs
		**/
		function openConference(){
			setUpTable();
			populateChat();
			getConferenceName();
			$(".hiddenItem").show("slow");
			$("div#users").show("slow");
		}
		
		/**
			Close the conference
		**/
		function closeConference(){
			$(".hiddenItem").hide("slow");
			$("div#users").hide("slow");
		}
		
		/**
			Log in a user to the page from the drop-downs
		**/
	  	function loginUser(){
			var userName = DWRUtil.getValue("employeeList");
			if (userName==null || userName =="-1"|| userName ==""){
				alert('please select a name from the list');
			}else{
				var companyName = DWRUtil.getValue("companyList");
				Conference.loginUser(companyName, userName, setLocalUser);	
				closeLoginBox();
				openConference();
			}
		 }
		 
		 		/**	Log in a second (or third...) administrator
		**/
	  	function loginDupeAdminUser(){
			var userName = DWRUtil.getValue("secondaryEmployeeList");
			if (userName==null || userName =="-1"|| userName ==""){
				alert('please select a name from the list');
			}else{
				var companyName = "27:RiskProNet";
				Conference.loginUser(companyName, userName, setLocalUser);	
				closeLoginBox();
				openConference();
				populateMinutes();
			}
		 }
		 
		 		/**	Log in the administrator
		**/
	  	function loginAdminUser(){
			var userName = DWRUtil.getValue("employeeList");
			if (userName==null || userName =="-1"|| userName ==""){
				alert('please select a name from the list');
			}else{
				var companyName = "27:RiskProNet";
				Conference.loginUser(companyName, userName, setLocalUser);	
				closeLoginBox();
				openConference();
			}
		 }
		 /**
		 	Log in a user to the page from the manual entries
		 **/
		 function addManualConferenceUser(){
		 	var user = { firstName:null, lastName:null, company:null, city:null, state:null,email:null };
		 	if (DWRUtil.getValue("firstName")==""||DWRUtil.getValue("lastName")==""||DWRUtil.getValue("company")==""){
		 		alert('Please fill out all fields to log in');
		 	}else{
			 	dwr.util.getValues(user);
			 	dwr.engine.beginBatch();
			 		Conference.loginManualUser(user, setLocalUser);
			 		closeLoginBox();
					openConference();
			    dwr.engine.endBatch();
			   }
		 }
		 
		 /**
		 Create a new conference
		 **/
		 function createNewConference(){
		 	var adminName = DWRUtil.getValue("employeeList");
		 	var pgId = DWRUtil.getValue("pgList");
		 	var confName = DWRUtil.getValue("confName");
		 	Conference.createConference(pgId, confName);		 
		 	loginAdminUser();
		 }
		 
		 /**
		 Close the conference
		 **/
		 function closeConference(){
		 	if (confirm('Are you sure you want to close the conference?  All users will be logged off!')){
		 		Conference.closeConference();
		 		openLoginBox();
		 		localUserCache = {};
		 	}
		 	
		 }
		 
		 /**
		 	Set the active user(s) for this page
		 **/
		 function setLocalUser(user){
		 	var id;
			    id = user.userId;
			    localId=id;
	    		dwr.util.cloneNode("localuserpattern", { idSuffix:id });
	    		dwr.util.setValue("localUserName" +id, user.name);
	    		DWRUtil.byId("localuserpattern" + id).style.display = "";
	    		localUserCache[id] = user;
		 }
		 
		 /**
		 	Populates the minutes entry box for dupe admin login.
		 **/
		 function populateMinutes(){
		   		Conference.populateMinutes();
		 }
		 
		 /**
		 Publish the administrators minutes
		 **/
		 function publishMinutes(){
		 	var minuteText = DWRUtil.getValue("pushMinutes");
		 	Conference.pushMinutes(minuteText);
		 }
		 /**
		 save the administrators minutes
		 **/
		 function saveMinutes(){
		 	var minuteText = DWRUtil.getValue("pushMinutes");
		 	Conference.saveMinutes(minuteText);
		 }
		 
		/**
		 Send a chat request
		 **/
		 function saveChat(){
		 	var chatText = DWRUtil.getValue("pushChat");
		 	var user = localUserCache[localId];
		 	Conference.saveChat(user, chatText);
		 	DWRUtil.setValue("pushChat", "");
		 }
		 
		 /**
		 	Populates the chat entry box for dupe admin login.
		 **/
		 function populateChat(){
		   		Conference.populateChat();
		 }
		 
		 /**
		 	Swap between showing all and showing none.
		 **/
		 function showAll(){
		 	DWRUtil.removeAllOptions('employeeList');
		 	DWRUtil.removeAllOptions('companyList');
			 var swap = DWRUtil.getValue("swapper");
			 	if (swap=="Show All Users"){
			 		DWRUtil.setValue("swapper", "Show Group Users");
			 	}else{
			 		DWRUtil.setValue("swapper","Show All Users");
			 	}
		 	getCompanies();
			 	
		 }
		 
		 /**
		 	Set the active speaker
		  **/
		 	function setSpeaker(eleid){
		 		var user = localUserCache[eleid.substring(5)];
		 		dwr.engine.beginBatch();
		 			Conference.setActiveSpeaker(user);
		 			activeSpeaker = user;
		 		dwr.engine.endBatch();
		 		
		 	}
		 	
		 	/**
		 	* Align the chat window so it is at the bottom of the scroller
		 	**/
		 	function alignChat(){
		 		var objDiv = document.getElementById("displayChat");
				objDiv.scrollTop = objDiv.scrollHeight;
		 	}
		 	
		  /**
		  Log out the user
		  **/
		 	function logout(eleid){
		 		var user = localUserCache[eleid.substring(5)];
		 		if (confirm('Are you sure you want to log out of the conference?')){
			 		//dwr.engine.beginBatch();
			 		Conference.logoutUser(user);
			 		//dwr.engine.endBatch();		 		
			 		//location.href='http://riskpronet.com';
			 		}		 		
		 	}
		 	
		 	 function confirmExit()
		  {
		    return "You have attempted to leave this conference.  If you refresh the page or go to a different location you will be logged out of the conference.  Are you sure you want to exit this page?";
		  }
		  
		  function exitLogout(){
		  
		  }
		
		 /**
		 Handle populating the company lists
		 **/
		 function getCompanies(){
		 	var swap = DWRUtil.getValue("swapper");
		 	if (swap=="Show All Users"){
		 		getPGCompanies();
		 	}else{
		 		getAllCompanies();
		 	}
		 }
		  function getPGCompanies(){
		 	Conference.getPGCompanyListing(insertCompanies);
		 }		 
		 function getAllCompanies(){
		 	Conference.getCompanyListing(insertCompanies);
		 }
		 function insertCompanies(companies){		 
		 	DWRUtil.addOptions("companyList", {"":"Select a Partner Firm"});
		 	DWRUtil.addOptions("companyList", companies);
		 }
		 
		 /**
		 	Populate the employees list off of the company listings
		 **/
		  function getEmployees(){
		  	getAllEmployees();
		  	/**  Disabling this for now..
		 	var swap = DWRUtil.getValue("swapper");
		 	if (swap=="Show All Users"){
		 		getPGEmployees();
		 	}else{
		 		getAllEmployees();
		 	}
		 	**/
		 }
		 function getPGEmployees(){
		 	var membId = DWRUtil.getValue("companyList");
		 	Conference.getPGEmployeeListing(membId, insertEmployees);
		 }
		 function getAllEmployees(){
		 	var membId = DWRUtil.getValue("companyList");
		 	Conference.getEmployeeListing(membId, insertEmployees);
		 }
		 
		 // get just the riskpronet employees
		 function getRPNEmployees(){
		 	Conference.getRiskProNetEmployeeListing(insertEmployees);
		 }
		 
		 function getSecondaryRPNEmployees(){
		 	Conference.getRiskProNetEmployeeListing(insertSecondaryEmployees);
		 }
		 
		 function insertSecondaryEmployees(employees){
		 	DWRUtil.removeAllOptions('secondaryEmployeeList');
		 	DWRUtil.addOptions("secondaryEmployeeList", {"-1":"Select your name"});
		 	DWRUtil.addOptions("secondaryEmployeeList", employees);
		 }
		 
		 function getAllPracticeGroups(){
		 	Conference.getAllPracticeGroups(insertPracticeGroups);		 	
		 }
		 
		  function insertPracticeGroups(pgroups){
		 	DWRUtil.removeAllOptions('pgList');
		 	DWRUtil.addOptions("pgList", {"-9":"No Practice Group (unrecorded)"});
		 	DWRUtil.addOptions("pgList", pgroups);
		 }
		 
		 function insertEmployees(employees){
		 	DWRUtil.removeAllOptions('employeeList');
		 	DWRUtil.addOptions("employeeList", {"-1":"Select your name"});
		 	DWRUtil.addOptions("employeeList", employees);
		 }
		 
		 
		 