﻿






var WebSite = ({
	Logout: function() {
		this._Logout();
	},
	_Logout: function() {
		self.location.replace('/secure/logout.aspx');
	},
	Save: function() {
		__doPostBack('ctl00$cmdSave', '');
	},
	Cancel: function() {
		__doPostBack('ctl00$cmdCancel', '');
	},
	Submit: function(obj, validate) {
	
		if (validate && cv) {
			if (!cv.validate()) {
				cv.render();
				return;
			}
		}

		_id = obj.id.replace(/_/gi, '$');

		if (onbeforepostback()) {
			__doPostBack(_id, '');
		}

		//__doPostBack(_id, '');

	},
	Navigate: function(path) {
		//self.location.replace(path);
		self.location.href = path;
	},
	Exec: function(command) {
		//alert(command);
		switch (typeof (command)) {
			case 'string':
				if (command == '') { alert('Invalid command: Command value is empty.'); return; };
				try {
					eval(command)
				} catch (e) {
					alert('Invalid command: ' + e.message)
				}
				break;
			case 'function':
				command();
				break;
			default:
				alert('Invalid command: Command not recognized.');
		}
	},
	ChangeLanguage: function(lcid) {
		this.Navigate('/changelanguage.aspx?lcid=' + lcid);
	},
	Buttons: ({
		_orgColor: [],
		Save: null,
		Cancel: null,
		Disable: function(cmd) {

			if (cmd.disabled) return;

			var obj = jQuery('#' + cmd.id);


			if (!this._orgColor[cmd.id]) {
				var _color = '';
				if (obj.hasClass('black')) { _color = 'black' }
				if (obj.hasClass('red')) { _color = 'red' }
				if (obj.hasClass('green')) { _color = 'green' }
				if (obj.hasClass('orange')) { _color = 'orange' }
				this._orgColor.addKey(cmd.id, _color);
			}

			cmd.disabled = true;
			obj.removeClass(_color);
			obj.addClass('disabled');
		},
		Enable: function(cmd) {

		if (!cmd.disabled) return;
		
			cmd.disabled = false;
			var _color = 'black';
			if (this._orgColor[cmd.id]) {
				_color = this._orgColor[cmd.id];
				this._orgColor[cmd.id] = '';
			}

			jQuery('#' + cmd.id).addClass(_color);
			jQuery('#' + cmd.id).removeClass('disabled');
		},
		Toggle: function(cmd) {
			if (cmd.disabled) {
				this.Enable(cmd);
			} else {
				this.Disable(cmd);
			}
		}
	})
})



WebSite.UI = function() {
}

WebSite.UI.OnEnterClick = function() { }
WebSite.UI.OnEscClick = function() { }
WebSite.UI.AllowFormSubmit = function() { }

WebSite.UI.RegisterDefaultEvents = function() {
	ShortcutMan.registerShortcut('13', WebSite.UI.OnEnterClick);
	ShortcutMan.registerShortcut('27', WebSite.UI.OnEscClick);
	ShortcutMan.registerShortcut('c81', WebSite.UI.OnEscClick);
}

WebSite.UI.Click = function(cmdId) {
	if (getObj(cmdId)) {
		var _onclick = getObj(cmdId).getAttribute('onclick');
		WebSite.Exec(_onclick);
	}
}

function onbeforepostback() { return true; } // event


function RegisterClientChange() {
	this.RegisterChanges = false;
	this._hasChanges = false;
}

RegisterClientChange.prototype.Register = function(obj) {
	if (!this.RegisterChanges) return;

	this._hasChanges = false; // reset the flag

	var _monitorFields = [];

	if (!_monitorFields.exists(obj.Name, 'Name')) _monitorFields.add(obj);
	_newValue = (obj.NewValue != null) ? obj.NewValue : getObj(obj.Name).value
	for (var iField = 0; iField < _monitorFields.length; iField++) {
		if (_monitorFields[iField].OrgValue != _newValue) {
			this._hasChanges = true;
		}
	}

	RegisterClientChange_OnChange(this._hasChanges);
}

RegisterClientChange.prototype.HasChanges = function() {
	return this._hasChanges
}

function fieldObj(name, orgValue, newValue) {
	this.Name = name;
	this.OrgValue = orgValue;
	this.NewValue = (newValue != 'undefined') ? newValue : null;
}

function RegisterClientChange_OnChange(hasChanges) { }
