/*
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
code language:		javascript 1.8
folder name:            files/dclib_5.05/dcjs_5.0
class name:             dcjs_request
class type:             static
version:                1.0
date:                   20120108
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(){this.f_construct();}

///*    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 = null;

///*    class system init ////////////////////////////////////////////////////////////////////////////////////
	DCJS_request.f_initSystem = function()
		{
		///h : inti jq address
		DCJS_request.f_initJQAddress();
		}

///*    class constructor ////////////////////////////////////////////////////////////////////////////////////
	DCJS_request.prototype.f_construct = function()
		{
		}

///*    public static functions //////////////////////////////////////////////////////////////////////////////

///*    ------------------------------------------------------------------------------------------------------
	/**
	 * set root url of the dcphp project
	 *
	 * @access public
	 * @param
	 * @return void
	 *
	 */
	DCJS_request.f_checkWindowLoading = function()
		{
		return(DCJS_request.__b_window_load_complete);
		}

///*    ------------------------------------------------------------------------------------------------------
	/**
	 * 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(null, true);
		$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)
		{
		$s_part = $s_part.split('///').join('/');
		$s_part = $s_part.split('//').join('/');
		$s_part = $s_part.split(':/').join('://');
		if($s_part.charAt(0) == '/')
			{
			$s_part = $s_part.substring(1);
			}
		if($s_part.charAt($s_part.length - 1) == '/')
			{
			$s_part = $s_part.substring(0, ($s_part.length - 1));
			}
		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_setURI = function($s_uri)
		{
		window.open(DCJS_request.f_getRoot() + "/" + $s_uri + "/#/", '_self');
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * 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_getURI_split = function($i_index)
		{
		///h : properties
		var $a_uri
		
		$a_uri = DCJS_request.f_getPath().split('/');
		return($a_uri[$i_index]);
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * 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_getURI = function()
		{
		return(DCJS_request.f_getPath());
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * 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_setInitialStatus = function($s_status, $b_reset)
		{
		///h : update address
		var $s_status_current;

		$s_status_current = DCJS_request.f_getStatus(true, true);
		if(($s_status_current == '') || ($s_status_current == 'init'))
			{
			DCJS_request.f_setStatus($s_status, true);
			}
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * 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, $b_overwrite)
		{
		///h : special case
		if($s_status == 'init')
			{
			$s_status = '';
			}
		
		///h : update address
		if($b_overwrite == true)
			{
			jQuery.address.history(false);
			}
		jQuery.address.value($s_status);
		jQuery.address.history(true);
		DCJS_request.f_cleanURL();
		}

///*	------------------------------------------------------------------------------------------------------
	/**
	 * 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, $b_intern)
		{
		///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);
			}
			
		if($b_intern != true)
			{
			$s_status = (($s_status == '') ? 'init': $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 = null;

		///h : check clean status
		$s_status = DCJS_request.f_getStatus(null, true);

		///h : update intern status
		if($s_status != DCJS_request.__s_status)
			{
			DCJS_request.f_cleanURL();
			DCJS_request.__s_status = $s_status;
			jQuery(window).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 ////////////////////////////////////////////////////////////////////////////////////

///*    init class ///////////////////////////////////////////////////////////////////////////////////////////
jQuery(document).bind('ready', 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:
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
*/
