/// <reference path='~/jQuery/jQuery-vsdoc.js' />
var _cal = Object()

_cal.OnLoad = function()
{
	_cal.SelectedMenu = $('.menu.clientArea.sel')
	_cal.error = $('#error')
	_cal.table = $('#calTable')
	_cal.clientName = $('#clientName')
	_cal.password = $('#password')
	var errorWidth = _cal.error.width()
	var left = Math.floor((_mp.Frame.width - errorWidth) / 2)
	_cal.error.css({opacity:'show', top:'114px', left: left + 'px'})
	
	var tableWidth = _cal.table.width()
	left = Math.floor((_mp.Frame.width - tableWidth) / 2) - 43 // Allow for UserName and Password are not centred
	_cal.table.css({ top: 150 + 'px', left: left + 'px'})
	
	_cal.clientName.add(_cal.password)
			.click(function(event) { event.target.focus() } )
			.focus(function() { _cal.error.hide() })
	_cal.clientName.keyup( function(event) {
			if (event.keyCode == 13)
				_cal.password.focus()
		})
	_cal.password.keyup( function(event) {
			if (event.keyCode == 13)
				Login(_cal.Client, _cal.Admin)
		})
	$('#enter').click(function() { Login(_cal.Client, _cal.Admin) })
	$('#cancel').click(function() {
		_cal.HidePage()
		_mp.SelectedMenu.css({ zIndex: 0 });
		_mp.SetMenuServices()
		_mp.HideCurrentPage = null
	})
}

_cal.HidePage = function() {
	if (_mp.SelectedMenu)
		_mp.SelectedMenu.css({ zIndex: 0 })
	_cal.error.hide()
	_cal.table.hide()
}

_cal.DrawPage = function() {
	$('#clientName')[0].value = ''
	$('#password')[0].value = ''
	_cal.error.hide()
	_cal.table.show()
	$('#clientName')[0].focus()
	return _cal.SelectedMenu;
}

// Called from Login.js
_cal.Client = function(name) {
	_cal.HidePage()
	_cap.DrawPage(name)
}

// Called from Login.js
_cal.Admin = function() {
	window.location = 'Admin/Folders.aspx';
}

