var Util = 
{
	libraryStyle :
	{
/*
		"templates/":				["tab_view.css", "body_style.css", "tab_view.css", "irock_product_table.css", "dialog.css", "menu_bullets.css", "irock_tabs.css"],
		"stylesheets/themes":		["default.css", "theme1.css", "mac_os_x.css", "alphacube.css", "darkX.css", "spread.css", "alert.css", "alert_lite.css", "eurocrimea.css"],//, "eurocrimea.css"],
		"style/dialog_elements":	["dialog.css"],
		// Styles for windows popups
		"style/dialog_themes":		["default.css", "tioti.css"]
*/
		// Styles for windows popups
		"templates/css/dialog_elements":	["dialog.css"],
"templates/css/dialog_themes":		["default.css", "mac_os_x.css", "alphacube.css", "darkX.css", "spread.css", "alert.css", "alert_lite.css", "eurocrimea.css"]
	},

	libraryScript :
	{
		/* =================================== */
		/* Don't modify order of these fields! */
		/* =================================== */
		"includes/js/util":		["behaviour.js","base.js"],
		"includes/js":			["irock_functions.js"],
//		"includes/js/dialog":	["AbstractDialogClass.js", "OverlayClass.js", "userregister.js"],
//		"includes/js/onload":	["onLoadDialog.js"],
		"includes/js/windows":	["prototype.js", "effects.js", "window.js", "debug.js", "windows_functions.js","tooltipclass.js"],
		"includes/js/ajax":		["ajax.js", "ajax_dynamic_content.js", "irock_requests.js"]
//		"inc_src/js":			["ajax_dynamic_content.js", "ajax.js", "ajax_tooltip.js", "irock_requests.js", "irock_tabs.js", "functions.js" , "windows_functions.js"]
	},

	importStyle : function()
	{
		var library = Util.libraryStyle;

		for( var libraryPath in library )
		{
			var libraryList = library[libraryPath];
			for(var i=0; i<libraryList.length; i++)
			{
				var libraryName = libraryPath + "/" + libraryList[i];
				document.write('<link rel="stylesheet" type="text/css" href="http://eurocrimea.com/' + libraryName + '" />\n');
			}
		}
	},

	importScript : function()
	{
		var library = Util.libraryScript;

		for( var libraryPath in library )
		{
			var libraryList = library[libraryPath];
			for(var i=0; i<libraryList.length; i++)
			{
				var libraryName = libraryPath + "/" + libraryList[i];
				document.write('<script type="text/javascript" src="http://eurocrimea.com/' + libraryName + '"></script>\n');
			}
		}
	},

	/**
	 * Checks entry element in array
	 * Checks entry substring in string
	 * @param el <Array,String>
	 * @param searchEl <String>
	 * @return boolean True if contains
	 */
	isContains : function( el, searchEl )
	{
		if (typeof el == "string")
		{
			if ( el.indexOf( searchEl ) != -1)
				return true;
			else
				return false;
		}
		else if(typeof el == "object")
		{
			for(var i=0; i< el.length; i++)
			{
				if (el[i] == searchEl)
					return true;
			}
			return false;
		}
	},

	/**
	 * Does some blocks stripped
	 * @param parentEl - element's id for stripping its childs
	 * @param stripTag - elements with this tag will be stripped
	 * @param stripFirstPosition - [0|1] - define position of first stripped element among all stripped elements
	 */
	StripBlocks : function( parentEl, stripTag, stripFirstPosition )
	{
		if ( !$(parentEl) ) return false;
		$A( $(parentEl).getElementsByTagName(stripTag) ).each
		(
			function(stripedBlock, index)
			{
				if ( Element.hasClassName( stripedBlock, "even") )
					Element.removeClassName(stripedBlock, "even");

				if ( (index+1)%2 == stripFirstPosition )
					Element.addClassName(stripedBlock, "even");
			}
		);
		return true;
	},

	/**
	 * Search first ancestor of the element by its tagname
	 * @param {Element|String} element Element or its id
	 * @param {String} tagName Tagname of searchable element
	 * @return {Element}
	 */
	GetFirstAncestorByTagName : function( element, tagName )
	{
		var element = $(element);
		while( element.parentNode.nodeName.toLowerCase() != tagName.toLowerCase() )
		{
			element = element.parentNode;
		}
		return element.parentNode;
	},

	/**
	 *	Search childs of element by those tagName
	 *	@param _parent	- referense to element
	 *	@param _tagName	- searchable tageName
	 *	@return array of children
	 */
	getChildrenByTagName : function( _parent, _tagName )
	{
		var childArray = new Array();
		var children = _parent.childNodes;

		for (var i=0; i<children.length; i++){
			if ( children[i].tagName && children[i].tagName.toLowerCase() == _tagName.toLowerCase())
				childArray.push( children[i] );
		}
		return childArray;
	},

	/**
	 *	Check for element nodes
	 *	@param _parent	- referense to element
	 *	@return boolean
	 */
	hasElements : function( _parent )
	{
		var children = _parent.childNodes;
		for (var i=0; i<children.length; i++)
		{
			if ( children[i].nodeType == 1)
				return true;
		}
		return false;
	},

	/**
	 *	Search first child of element with nodeType <Element>
	 *	@param _parent - base element to lookup from
	 */
	getFirstChild : function( _parent )
	{
		// We should check type of node, because Gecko-browers don't ignore whitespaces

		var el = _parent.firstChild;

		while (  el != null ) {
			if ( el.nodeType == 1)
					return el;
			el = el.nextSibling;
		}
		return null;
	},

	/**
	 *	Search last child of element with nodeType <Element>
	 *	@param _parent - base element to lookup from
	 */
	getLastChild : function ( _parent )
	{
		// We should check type of node, because Gecko-browers don't ignore whitespaces

		var el = _parent.lastChild;

		while (  el != null )	{
			if (el.nodeType == 1)
				return el;
			el = el.previousSibling;
		}

		return null;
	},

	/**
	 * Returns element with specified tag names next to specified element or null
	 * if no such element can be found.
	 *
	 *	@param	_elem		base element to lookup from
	 *	@param	_tagName	tag name (array of names) of element to look for
	 */
	getNextElement: function(_elem, _tagName)
	{
		var next=_elem.nextSibling;
		var names=(typeof(_tagName)=="string")?new Array(_tagName):_tagName;

		while (next!=null)
		{
			if (next.tagName)
			{
				var name=new String(next.tagName).toLowerCase();
				for (var i=0; i<names.length; i++)
					if (name==names[i])
						return next;
			}
			next=next.nextSibling;
		}

		return next;
	},


	RemoveDescendants : function( el)
	{
		while( el.firstChild )
		{
			el.removeChild( el.firstChild );
		}
	},

    /**
     * Removes all spaces at the begin and the end of string
     * Replaces all multiple spaces for single space at mediaum of the string
     * \s 	Corresponds to the symbol of whitespace. Equivalent /[ \f\n\r\t\v]/.
     */
	RemoveSpaces: function(str)
	{
		return str.replace(/^\s+/g, "").replace(/\s+$/g, "").replace(/\s+/g, /\s/);
	},

    /**
     * Calls RemoveSpaces and
     * Removes all whitespace symbols (\n \t etc...) except space symbol
     * \f  	Corresponds to symbol of the remittance of the format (FF).
     * \n 	Corresponds to symbol a linefeed (LF).
     * \r 	Corresponds to symbol of the return the carriage (CR).
     * \s 	Corresponds to the symbol of whitespace. Equivalent /[ \f\n\r\t\v]/.
     * \t 	Corresponds to symbol to tabulations (HT).
     * \v   Corresponds to symbol to vertical tabulation (VT).
     */
	RemoveWhiteSpaces: function(str)
	{
		return Util.RemoveSpaces(str).replace(/[\n\t\r\f\v]*/g, "");
	}

}

Util.importStyle();
Util.importScript();
