/*
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
code language:		javascript 1.8
folder name:            files/dclib_5/dcjs_5.0
class name:             dcjs_request
class type:             static
version:                1.0
date:                   20110615
copyright:              massimo cardascia
url:                    www.plustic.de / www.dot-control.com
code style:		whitesmiths style variant - 8 spaces tab - http://en.wikipedia.org/wiki/indent_style
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
*/

///*	class definition /////////////////////////////////////////////////////////////////////////////////////
function DCJS_request()
	{
///*    class versioning /////////////////////////////////////////////////////////////////////////////////////
	DCJS_request.__s_classVersion = '5.00';			///h : dclib intern class version
	DCJS_request.__s_className = 'DCJS_request';		///h : dclib intern class name
	DCJS_request.__s_classType = 'class';			///h : dclib intern class type

///*    class properties /////////////////////////////////////////////////////////////////////////////////////
	DCJS_request.__s_status = '';

///*    class system init ////////////////////////////////////////////////////////////////////////////////////
	DCJS_request.f_initSystem = function()
		{
		///h : inti jq address
		DCJS_request.f_initJQAddress();
		}

///*    class constructor ////////////////////////////////////////////////////////////////////////////////////
	this.f_construct = function()
		{
		}
	this.f_construct();

///*    public static functions //////////////////////////////////////////////////////////////////////////////


///*    ------------------------------------------------------------------------------------------------------
	/**
	 * set root url of the dcphp project
	 *
	 * @access public
	 * @param
	 * @return void
	 *
	 */
	DCJS_request.f_cleanURL = function()
		{
		///h : properties
		var $s_url;
		var $s_url_status;

		///h : get base path
		$s_url_status = DCJS_request.f_getStatus();

		$s_url = (DCJS_request.f_getRoot() + '/' + DCJS_request.f_getPath() + '/' + DCJS_request.f_getQuery() + '/#/');
		
		if($s_url_status != '')
			{
			$s_url += ($s_url_status + '/');
			}
		$s_url = DCJS_request.f_clean($s_url) + '/';

		///h : update url if necessary
		if(window.location != $s_url)
			{
			location.replace($s_url);
			}
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * init all data later used in project. putting all data and easy to acces vars, arrays or
	 * data storages. interface to project backend if existing.
	 *
	 * @access private
	 * @return void
	 *
	*/
	DCJS_request.f_getRoot = function()
		{
		return(DCJS_request.f_clean(location.protocol + '//' + location.host));
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * init all data later used in project. putting all data and easy to acces vars, arrays or
	 * data storages. interface to project backend if existing.
	 *
	 * @access private
	 * @return void
	 *
	*/
	DCJS_request.f_getQuery = function()
		{
		return(DCJS_request.f_clean(window.location.search));
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * init all data later used in project. putting all data and easy to acces vars, arrays or
	 * data storages. interface to project backend if existing.
	 *
	 * @access private
	 * @return void
	 *
	*/
	DCJS_request.f_clean = function($s_part)
		{
		if($s_part[0] == '/')
			{
			$s_part = $s_part.substring(1);
			}
		if($s_part[$s_part.length - 1] == '/')
			{
			$s_part = $s_part.substring(0, ($s_part.length - 1));
			}
		$s_part = $s_part.split('///').join('/');
		$s_part = $s_part.split('//').join('/');
		$s_part = $s_part.split(':/').join('://');
		return($s_part);
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * init all data later used in project. putting all data and easy to acces vars, arrays or
	 * data storages. interface to project backend if existing.
	 *
	 * @access private
	 * @return void
	 *
	*/
	DCJS_request.f_getPath = function()
		{
		return(DCJS_request.f_clean(window.location.pathname));
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * init all data later used in project. putting all data and easy to acces vars, arrays or
	 * data storages. interface to project backend if existing.
	 *
	 * @access private
	 * @return void
	 *
	*/
	DCJS_request.f_setStatus = function($s_status)
		{
/*
		///h : check last char
		if($s_status.substring($s_status.length - 1) != '/')
			{
			$s_status += '/';
			}
*/
		///h : update address
		jQuery.address.value($s_status);
		jQuery.address.update();
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * init all data later used in project. putting all data and easy to acces vars, arrays or
	 * data storages. interface to project backend if existing.
	 *
	 * @access private
	 * @return void
	 *
	*/
	DCJS_request.f_getStatus = function($b_clean)
		{
		///h : properties
		var $s_status = '';
		var $i_index = -1;

		///h : clean status
		$s_status = jQuery.address.value();
		$i_index = $s_status.indexOf('?');
		if($i_index > 0)
			{
			$s_status = $s_status.substr(0, $i_index);
			}

		///h : clean status
		if($b_clean != false)
			{
			$s_status = DCJS_request.f_clean($s_status);
			}
		///h : return
		return($s_status);
		}

///*    public functions /////////////////////////////////////////////////////////////////////////////////////

///*    pivate static functions //////////////////////////////////////////////////////////////////////////////

///*	------------------------------------------------------------------------------------------------------
	/**
	 * init all data later used in project. putting all data and easy to acces vars, arrays or
	 * data storages. interface to project backend if existing.
	 *
	 * @access private
	 * @return void
	 *
	*/
	DCJS_request.f_updateStatus = function()
		{
		///h : properties
		var $s_status = '';

		///h : check clean status
		$s_status = DCJS_request.f_getStatus();

		///h : update intern status
		//$s_status = DCJS_request.f_clean($s_status);
		if($s_status != DCJS_request.__s_status)
			{
			DCJS_request.__s_status = $s_status;
			}
		jQuery(DCJS_request).trigger('statusChange');
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * init all data later used in project. putting all data and easy to acces vars, arrays or
	 * data storages. interface to project backend if existing.
	 *
	 * @access private
	 * @return void
	 *
	*/
	DCJS_request.f_initJQAddress = function($s_status)
		{
		///h : init jq address for anchor status change
		DCJS_request.f_cleanURL();
		jQuery.address.autoUpdate(false);
		jQuery.address.bind('change', {}, function($o_event){DCJS_request.f_updateStatus();});
		}

///*    private functions ////////////////////////////////////////////////////////////////////////////////////

        }

///*    direct execution /////////////////////////////////////////////////////////////////////////////////////
DCJS_request();
DCJS_request.f_initSystem();

/*
--------------------------------------------------------------------------------------------------------------
description:
--------------------------------------------------------------------------------------------------------------
project is the main class of the dclib php framework.
project store all the main functions and is used as global wrappert to hold important functions and vars.
--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
events:
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
getter properties:
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
usage:
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
*/
