/**
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * 
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
 * License for the specific language governing rights and limitations under the License.
 * 
 * The Original Code is Alchitect Core Server.
 * 
 * The Initial Developer of the Original Code is Darrell Brogdon.
 * Portions created by Darrell Brogdon are Copyright (C) 2002-2009 Darrell Brogdon.
 * All Rights Reserved.
 * 
 * Contributor(s): .
 * 
 * @package AlchitectCoreUI
 */
/** 
 * @fileoverview Include this class in your HTML to get access to all other necessary classes.
 * @author Darrell Brogdon &lt;{@link http://mailto:darrell@brogdon.net darrell@brogdon.net}&gt;
 * @copyright 2002-2009 Darrell Brogdon - All Rights Reserved
 * @version 1.0.0.0 
 */
//ASInclude('/core/ui/vendor/jquery/jquery-1.3.2.js');
//ASInclude('/core/ui/vendor/jquery/jquery.cookie.js');
//ASInclude("/core/ui/vendor/json2.js");
//ASInclude("/core/ui/classes/ASException.js");
ASInclude("/core/ui/classes/ASObject.js");
//ASInclude("/core/ui/classes/ASAuthentication.js");
ASInclude("/core/ui/classes/ASForm.js");
//ASInclude("/core/ui/classes/ASSanitizer.js");
//ASInclude("/core/ui/classes/ASValidater.js");

/**
 * A global instance of ASForm.
 *
 * This is necessary so that ASForm is available throughout the application.
 *
 * @type Object
 */
var AS_FORM;

/**
 * The current version of Alchitect UICore.
 * @type String
 */
var ALCHITECT_VERSION = '1.0.0.0';

/**
 * @class The Application class.  
 * Include this class in your HTML to get access to all other necessary classes.
 * @constructor
 * @returns An instance of ASApplication
 * @type Object
 */
function ASApplication()
{
	AS_FORM = new ASForm();

	AS_FORM.registerHook(AS_FORM.checkRequiredHook);
}

function page()
{
	var path_parts = window.location.pathname.split('/');
	return path_parts[2];
}

function URLPath(with_app)
{
	var app_dir		= 'ui';
	var new_parts	= [];
	var x			= 0;
	var path_parts = window.location.pathname.split('/');
	var path_stop	= 'app';
	
	if (null == with_app)
	{
		with_app = false;
	}
	
	for (; x<path_parts.length; x++)
	{
		if (false == with_app && path_stop == path_parts[x])
		{
			break;
		}

		new_parts.push(path_parts[x]);

		if (app_dir == path_parts[x])
		{
			break;
		}
	}
	
	return new_parts.join('/').replace(/\/$/, '');
}

/**
 * Utility function for including other classes.
 *
 * @param The path to the file to be included.
 * @returns Void
 * @type Void
 */
function ASInclude(file)
{
	document.write('<script type="text/javascript" src="' + URLPath() + file + '"></script>');
}
