 (function () {

 NC.widget.DashboardManager = function() {
	/* private variables and methods */
	
		var selectLocationDialog = null;
		var selectCategoryDialog = null;
		var selectProfileDialog = null;
		var selectPreferencesDialog = null;
		var selectPrivacyDialog = null;
		var updateLoginDialog = null;
 	
 	 	return {
 	 		/* public methods */
 	 		
			showJsSelectLocationPopup: function( event, userId) {
				var pars = 'UserId=' + userId + '&rand=' + new Date().getTime(); // force refresh
				pars = encodeURI( pars);
				this.dialog = new NC.widget.ValidatedModalDialog(
					'js_selectLocation.php?', 
					pars, 
					NC.util.AjaxDialogDisplay.DialogWrapper, 
					'JsSelectLocation',
			 		function( updateUrl, updateParms, updateTarget) // submission function
			 		{
			 			updateUrl += '?' + updateParms;
						NC.util.AjaxManager._xmlHttpGet(updateUrl,  updateTarget, false);
						NC.widget.StateManager.setSelectLocationsFlag();
			 		}, 
			 		'js_updateSelectedLocations.php',
			 		'JsPrefLocationDiv',
			 		function( form, errorDiv) // validation function
			 		{
						return true;	
			 		},
			 		'JsSelectLocationError',
			 		true
				);	
				selectLocationDialog = this.dialog;
				// position
				var widthX = 425;
				var leftX = (NC.util.Dom.getViewportWidth() - widthX)/2 ;
				var topY = 200 ;
				this.dialog.show( leftX, topY, widthX);		
			},
			
			getSelectLocationDialog: function() {
				return selectLocationDialog;
			},
			
			showJsSelectCategoryPopup: function( event, userId)
			{
				var pars = 'UserId=' + userId + '&rand=' + new Date().getTime(); // force refresh
				pars = encodeURI( pars);
				this.dialog = new NC.widget.ValidatedModalDialog(
					'js_selectCategory.php?', 
					pars, 
					NC.util.AjaxDialogDisplay.DialogWrapper, 
					'JsSelectCategory',
			 		function( updateUrl, updateParms, updateTarget) // submission function
			 		{
			 			updateUrl += '?' + updateParms;
						NC.util.AjaxManager._xmlHttpGet(updateUrl,  updateTarget, false);
						NC.widget.StateManager.setSelectCategoriesFlag();
			 		}, 
			 		'js_updateSelectedCategories.php',
			 		'JsPrefCategoryDiv',
			 		function( form, errorDiv) // validation function
			 		{
						return true;	
			 		},
			 		'JsSelectCategoryError',
			 		true
				);
				selectCategoryDialog = this.dialog;	
				// position
				var widthX = 275;
				var leftX = (NC.util.Dom.getViewportWidth() - widthX)/2 ;
				var topY = 200 ;
				this.dialog.show( leftX, topY, widthX);		
			},

			getSelectCategoryDialog: function() {
				return selectCategoryDialog;
			},
			
			showJsSelectProfilePopup: function ( event, userId) {
				var pars = 'UserId=' + userId + '&rand=' + new Date().getTime(); // force refresh
				pars = encodeURI( pars);
				this.dialog = new NC.widget.ValidatedModalDialog(
					'js_selectProfile.php?', 
					pars, 
					NC.util.AjaxDialogDisplay.DialogWrapper, 
					'JsSelectProfile',
			 		function( updateUrl, updateParms, updateTarget) // submission function
			 		{
			 			updateUrl += '?' + updateParms;
						NC.util.AjaxManager._xmlHttpGet(updateUrl,  updateTarget, false);
			 		}, 
			 		'js_updateProfile.php',
			 		'JsPrefProfileDiv',
			 		function( form, errorDiv) // validation function
			 		{
						return true;	
			 		},
			 		'JsSelectProfileError',
			 		true
				);	
				selectProfileDialog = this.dialog;
				// position
				var widthX = 350;
				var leftX = (NC.util.Dom.getViewportWidth() - widthX)/2 ;
				var topY = 200 ;
				this.dialog.show( leftX, topY, widthX);		
			},

			getSelectProfileDialog: function() {
				return selectProfileDialog;
			},
			
			showJsSelectPreferencesPopup: function ( event, userId)
			{
				var pars = 'UserId=' + userId + '&rand=' + new Date().getTime(); // force refresh
				pars = encodeURI( pars);
				this.dialog = new NC.widget.ValidatedModalDialog(
					'js_selectPreferences.php?', 
					pars, 
					NC.util.AjaxDialogDisplay.DialogWrapper, 
					'JsSelectPreferences',
			 		function( updateUrl, updateParms, updateTarget) // submission function
			 		{
			 			updateUrl += '?' + updateParms;
						NC.util.AjaxManager._xmlHttpGet(updateUrl,  updateTarget, false);
			 		}, 
			 		'js_updatePreferences.php',
			 		'JsPrefPreferencesDiv',
			 		function( form, errorDiv) // validation function
			 		{
						return true;	
			 		},
			 		'JsSelectPreferencesError',
			 		true
				);	
				selectPreferencesDialog = this.dialog;
				// position
				var widthX = 325;
				var leftX = (NC.util.Dom.getViewportWidth() - widthX)/2 ;
				var topY = 200 ;
				this.dialog.show( leftX, topY, widthX);		
			},

			getSelectPreferencesDialog: function() {
				return selectPreferencesDialog;
			},
			
			showHideWork: function () {
				var check = document.getElementById( 'ShowWorkExperience');
				var div = document.getElementById('experienceoptions');
				if (check != null && div != null) {
					var value = NC.util.Dom.getValue(check);
					if (value != null) {
						div.style.display = 'block';
					}
					else {
						div.style.display = 'none';
					}
				}
			},			
			
			showHideEducation: function () {
				var check = document.getElementById( 'ShowEducation');
				var div = document.getElementById('educationoptions');
				if (check != null && div != null) {
					var value = NC.util.Dom.getValue(check);
					if (value != null) {
						div.style.display = 'block';
					}
					else {
						div.style.display = 'none';
					}
				}
			},			
			
			showJsSelectPrivacyPopup: function ( event, userId, update)
			{
				/*
				 * get privacy flag from back end
				 */
				var profileFlag = 0;
				var callback =
				{
	  				success:function( o) {
	  					profileFlag = parseInt(o.responseText);
	  					proceed = true;
						var pars = 'UserId=' + userId + '&ProfileFlag=' + profileFlag + '&rand=' + new Date().getTime(); // force refresh
						pars = encodeURI( pars);
						this.dialog = new NC.widget.ValidatedModalDialog(
							'js_selectUserPrivacy.php?', 
							pars, 
							'centercontent', //NC.util.AjaxDialogDisplay.DialogWrapper, 
							'JsSelectUserPrivacy',
					 		function( updateUrl, updateParms, updateTarget) // submission function
					 		{
					 			updateUrl += '?' + updateParms;
								var callback1 =
								{
					  				success:function( o) {
										NC.widget.StateManager.setUpdatedSecurityFlag();
//					  					NC.widget.ResumeUploadManager.deletePreviousResumeInfo();
				      					NC.util.AjaxManager.showCurrentMainFrameContent();
					  				},
					
					  				failure:function( o) {
					  				},
					
									scope: this    				
								};
								var connection = new NC.util.AjaxConnection( 'GET', updateUrl, '');
								connection.executeMethod( callback1);
					 		}, 
					 		'setProfileFlag.php',
					 		'JsPrefPrivacyDiv',
					 		function( form, errorDiv) // validation function
					 		{
								return true;	
					 		},
					 		'JsSelectPreferencesError',
					 		false
						);	
						selectPrivacyDialog = this.dialog;
				 		var widthX = 400;
				 		var heightY = 300;
				 		var leftX = (NC.util.Dom.getViewportWidth() - widthX)/2 ;
				 		var topY = (NC.util.Dom.getViewportHeight() - heightY)/2;
						this.dialog.show( leftX, topY, 400);	
						function showHideDivs() {	
							NC.widget.DashboardManager.showHideEducation();
							NC.widget.DashboardManager.showHideWork();
						}
						window.setTimeout( showHideDivs, 200); // wait a bit and then show or hide the divs
	  				},
	
	  				failure:function( o) {
	  					profileFlag = 0;
	  					proceed = false;
	  					alert( "failed");
	  				},
	
					scope: this    				
				};
				var connection = new NC.util.AjaxConnection( 'GET', 'getProfileFlag.php', '');
				connection.executeMethod( callback);
			},

			getSelectPrivacyDialog: function() {
				return selectPrivacyDialog;
			},
			
			showJsUpdateLoginPopup: function ( event, userId)
			{
				this.dialog = new NC.widget.ValidatedModalDialog(
					'js_updateLogin.php?', 
					'', 
					'centercontent', 
					'JsUpdateLogin',
			 		function( updateUrl, updateParms, updateTarget) // submission function
			 		{
			 			updateUrl += '?' + updateParms;
						var callback1 =
						{
			  				success:function( o) {
								if (o.responseText.length == 0) {
									NC.util.AjaxManager.showCurrentMainFrameContent();
								}
								else {
									NC.messages.showError( o.responseText);
								}
			  				},
			
			  				failure:function( o) {
								NC.messages.showError( "There was a system error.");
			  				},
			
							scope: this    				
						};
						var connection = new NC.util.AjaxConnection( 'GET', updateUrl, '');
						connection.executeMethod( callback1);
			 		}, 
			 		'updateLoginInfo.php',
			 		'',
			 		function( form, errorDiv) // validation function
			 		{
						var password = '';
						var password1 = '';
						var email = '';
						var screenName = '';
						var message = '';
						var controls = form.elements;
						for (var ci = 0; ci < controls.length; ci++) {
							if (controls[ci].name == 'Email') {
								email = NC.util.Dom.getValue(controls[ci]);
							}
							else 
								if (controls[ci].name == 'Password') {
									password = NC.util.Dom.getValue(controls[ci]);
								}
								else 
									if (controls[ci].name == 'Password1') {
										password1 = NC.util.Dom.getValue(controls[ci]);
									}
									else 
										if (controls[ci].name == 'ScreenName') {
											screenName = NC.util.Dom.getValue(controls[ci]);
										}
						}
						if (email.length == 0) {
							message = 'Please enter an email address';
						}
						if (password.length >= 0 && password1.length >= 0 && password != password1) {
							if (message.length > 0) {
								message += '<br>';
							}
							message += 'The password and repeat password do not match';
						}
						if (screenName.length == 0) {
							if (message.length > 0) {
								message += '<br>';
							}
							message += 'Please enter a screen name';
						}
						if (message.length > 0) {
							NC.messages.showError( message);
							return false;
						}
						return true;
						/*
						var callback1 =
						{
			  				success:function( o) {
		      					errorMessage = o.responseText;
								if (errorMessage.length > 0) {
									showError(message);
									return  false;
								}
								else {
									return true;
								}
								
			  				},
			
			  				failure:function( o) {
								NC.messages.showError('We could not validate your entry. Please try back later.')
								return  false;
			  				},
			
							scope: this    				
						};
						var connection = new NC.util.AjaxConnection( 'GET', updateUrl, '');
						connection.executeMethod( callback1);
						*/
			 		},
			 		'JsUpdateLoginError',
			 		false
				);	
				updateLoginDialog = this.dialog;
		 		var widthX = 400;
		 		var heightY = 300;
		 		var leftX = (NC.util.Dom.getViewportWidth() - widthX)/2 ;
		 		var topY = (NC.util.Dom.getViewportHeight() - heightY)/2;
				this.dialog.show( leftX, topY, 400);	
			},

			getUpdateLoginDialog: function() {
				return updateLoginDialog;
			},
			
					
			onUseMsa:function ()
			{
				/*
				var location = document.getElementById('Location');
				var zipCode = document.getElementById('ZipCode');
				var maxRadius = document.getElementById('MaxRadius');
				NC.util.Dom.disable(zipCode);
				NC.util.Dom.disable(maxRadius);
				NC.util.Dom.enable(location);
				*/
			},
			
			onUseZip:function ()
			{
				/*
				var location = document.getElementById('Location');
				var zipCode = document.getElementById('ZipCode');
				var maxRadius = document.getElementById('MaxRadius');
				NC.util.Dom.enable(zipCode);
				NC.util.Dom.enable(maxRadius);
				NC.util.Dom.disable(location);
				*/
			},

			selectMsaOption: function() {
				var zipOption = document.getElementById('UseZip');
				zipOption.checked = false;
				var msaOption = document.getElementById( 'UseMsa');
				msaOption.checked = true;
			},
			
			selectZipOption: function() {
				var zipOption = document.getElementById('UseZip');
				zipOption.checked = true;
				var msaOption = document.getElementById( 'UseMsa');
				msaOption.checked = false;
			}
			
 	 		
 	 	}
  }	
();

})(); 	
 
