




function Control() {
}

Control.ENTER_KEY = 13;
Control.processing = false;
Control.loading = true;
Control.formAction;

Control.keyCode = function(event) {
	if (window.event) { // IE
		return window.event.keyCode;
	} else if (event.which) { // Mozilla
		return event.which;
	} else {
		return 0;
	}
}

Control.keyCodeEnter = function(event) {
	return (Control.keyCode(event) == Control.ENTER_KEY);
}

Control.limitLength = function(ctrl, n) {
	if (ctrl && ctrl.value.length > n) {
		ctrl.value = ctrl.value.substring(0, n);
	}
	ctrlCount = eval();
	if ($(ctrl.id + '_counter')) {
		$(ctrl.id + '_counter').update('<span class="small_light">'+ctrl.value.length+' of '+ n +' characters</span>');
	}
}

Control.preProcess = function() {
	Control.processing = true;
	//$('processingIndicator').show();
}

Control.postProcess = function() {
	Control.processing = false;
	//$('processingIndicator').hide();
}

Control.postLoad = function() {
	Control.loading = false;
}

Control.allowApplicationEvent = function() {
	//return (!(Control.loading || Control.processing));
	return true;
}

Control.submit = function(ctx, cmd) {
	if (Control.allowApplicationEvent()) {
		try {
			if (!validateFields('pageForm')) {
				return false;
			}
		} catch (e) {
			//window.alert('validation error');
		}
		Control.preProcess();
		$('context').setValue(ctx);
		$('command').setValue(cmd);
		$('uri').setValue('');
		$('pageForm').submit();
		
		return true;
	} else {
		return false;
	}
}

Control.submitNoValidate = function(ctx, cmd) {
	if (Control.allowApplicationEvent()) {
		Control.preProcess();
		$('context').setValue(ctx);
		$('command').setValue(cmd);
		$('uri').setValue('');
		$('pageForm').submit();
		
		return true;
	} else {
		return false;
	}
}

Control.navigate = function(uri) {
	$('context').setValue('');
	$('command').setValue('navigate');
	$('uri').setValue(uri);
	$('pageForm').submit();
}

Control.reset = function(uri)
{
	$('context').setValue('');
	$('command').setValue('reset');
	$('uri').setValue(uri);
	$('pageForm').submit();
}

Control.cancel = function() {
	$('context').setValue('');
	$('command').setValue('cancel');
	$('uri').setValue('');
	$('pageForm').submit();
}
