/**
 * Error handler object
 *
 * methods:
 *
 * properties:
 *	
 */


/**
 * constructor
 *		o - HTML Error object
 */
function BxError (o)
{
	alert(o.message + "\n" + o.description);
}


/**
 * constructor
 *		s1 - error message
 *		s2 - error description
 */
function BxError (s1, s2)
{
	alert(s1 + "\n" + s2);
}

/**
 * Load specified js modules and run load handlers
 *
 */
function BxScriptLoader()
{
	this.loadScript = null;
	this.loadAfterXml = null;
	this.scriptsCounter = 0;
	this.scriptsCount = 0;
	this.scripts = null;
	this.afterScriptsArrayLoading = null;
}




/*
*	execute script.onload method
*/
BxScriptLoader.prototype._afterLoading = function()
{
	if(this.loadScript && typeof(this.loadScript.onload) == 'function')
		this.loadScript.onload();
		
	if(this.scriptsCount == 0)
		this.loadScript = null;
}


/*
*	indicates that script is loaded successfully
*	tries to execute script.onload function
*/
BxScriptLoader.prototype.scriptLoaded = function()
{
	//---opera only*******if((/opera/i).test(navigator.userAgent) )
	if(/MSIE/.test(navigator.userAgent))	//all ie group
		this._afterLoading();
}


/**
 * Set script that will be loaded
 * 
 * @param	string	script			 full url of the script
 */
BxScriptLoader.prototype.setScript = function(script)
{
	this.loadScript = script;
}













/**
 * Set script for running after loading xml data from server
 *
 * @param	string	script
 */
BxScriptLoader.prototype.setAfterXml = function(script)
{
	this.loadAfterXml = script;
}


/**
 * Run script after loading xml data from server
 *
 * @param	string	script
 */
BxScriptLoader.prototype.runAfterXml = function(script)
{
	if(typeof(this.loadAfterXml) == 'function')
		this.loadAfterXml();
		
	this.loadAfterXml = null;
}








/**
 * Common method for js scripts loading
 *
 * @param	string	href
 * @param	bool	isArray
 * @param	string	path
 */
BxScriptLoader.prototype.runScript = function(href, isArray, path)
{
	this.loadScript = document.createElement('script');
	
	if(isArray == true)
	{
        var $this = this;
		this.loadScript.onload = function()
		{
			$this.scriptsCounter++;
			if($this.scriptsCounter < $this.scriptsCount)
			{
				$this.runScript('', true, path);
			}
			else
			{
				for(var i = 0; i < $this.scriptsCount; i++)
				{
					var s = "g" + $this.scripts[i] + " = new " + $this.scripts[i] + "();";
					try
					{
						eval(s);
					}
					catch(e)
					{
						
					}
				}
				
				this.scripts = null;
				this.scriptsCount = 0;
				this.scriptsCounter = 0;
				
				if($this.afterScriptsArrayLoading != null)
					$this.afterScriptsArrayLoading();
			}
		}
		
		href = path + this.scripts[this.scriptsCounter] + '.js';
	}
	
	document.body.appendChild(this.loadScript);
	this.loadScript.type = "text/javascript";
	
	if(this.loadScript.setAttribute)
		this.loadScript.setAttribute('src', href);
	else
		this.loadScript.src = href;

}


/**
 * Runs script array
 *
 * @param	array		arrayScripts
 * @param	function	loading handler
 * @param	string		path
 */
BxScriptLoader.prototype.runScriptArray = function(arrayScripts, h, path)
{
	this.scriptsCounter = 0;
	this.scriptsCount = arrayScripts.length;
	this.scripts = arrayScripts;
	
	if(typeof(h) == "function")
		this.afterScriptsArrayLoading = h;
	else
		this.afterScriptsArrayLoading = null;
	
	this.runScript('', true, path);
}


/*
*	create the BxLoader
*/
var gScriptLoader = null;
gScriptLoader = new BxScriptLoader();/**
 * load xml data object
 *
 * methods:
 *
 * properties:
 *		request - XMLHttpRequest or 'Microsoft.XMLHTTP' ActiveX object
 */


/**
 * constructor
 *		url	- url with xml data to open
 *		h	- handler function
 */
function BxXmlRequest(url, h, async)
{	
	if (!url.length) return;

	/**
	 * local handler function
	 */
	var f = function (r, url, h)
	{
		if (r.readyState == 4) // only if req shows "loaded"
	    {
		    if (r.status == 200 || r.status == 304) // only if "OK"
			{
	            h (r);
		    }
			else
	        {
				var s = '';
				//for (var i in r) s += i + "      ";
		        //alert("XML read failed:" + r.status +  "\n There was a problem retrieving the XML data:\n" + url);
			}
	    }
	}

	var r;

	// IE
	if(typeof ActiveXObject!="undefined")
	{
		try
		{
			r = new ActiveXObject("Microsoft.XMLHTTP")

			// register handler function
			r.onreadystatechange = function(  ) 
			{
				f (r, url, h);
			}

			r.open("GET", url, async);
			r.send();  
		}
		catch(a)
		{
		}
	}
	else  if (window.XMLHttpRequest)
	{
		r = new XMLHttpRequest();
	
		// register handler function
		r.onload = function () 
		{
			f (r, url, h);
		}

		r.open("GET", url, async);
		r.send(null);  
	}	

	if (!r)
	{
		//var e = new BxError("httpxml object creation failed", "please upgrade your browser");
	}
	else
	{
		this.request = r;
	}

}


BxXmlRequest.prototype.getRetNodeValue = function (r_xml, tagname)
{
		// IE
    if (window.ActiveXObject)
	{
		var e = r_xml.responseXML.getElementsByTagName(tagname)[0];
		if (e.firstChild)
			return e.firstChild.nodeValue;
		else
			return '';
	}
	// Mozilla
    else if (window.XSLTProcessor)
	{			
		var e = r_xml.responseXML.getElementsByTagName(tagname)[0];
		return e.textContent;
	}
    else
	{
		var e = r_xml.responseXML.getElementsByTagName(tagname)[0];
		return e.textContent;
	}

	return  0;
}
/**
 * xml/xsl transformation
 *
 * methods:
 *
 * properties:
 */

/**
 * constructor
 *		url_xml	- url with xml data to open
 *		url_xsl	- url with xsl data to merge with xml
 *		h		- user handler function
 */
function BxXslTransform(url_xml, url_xsl, h, o, iForceServerXsl)
{	
	var r_xsl;
	var r_xml;
	var no_xsl = 0;
	var browserType;
	var caller = null;	
	
	if(typeof(BxXslTransform.arguments[3]) == 'object')
		this.caller = BxXslTransform.arguments[3];
	
    var safari = navigator.vendor && navigator.vendor.search('Apple') > -1 ? true : false;
    var konq = navigator.vendor && navigator.vendor.search('KDE') > -1 ? true : false;    

	if ((!window.ActiveXObject && !window.XSLTProcessor) || window.opera || safari || konq || window._bx_force_server_xsl || iForceServerXsl /*@cc_on || true @*/)
	{
		if (url_xml.indexOf ("?") == -1)
			url_xml += "?trans=1&trans_url_xsl=" + encodeURIComponent(url_xsl);
		else
			url_xml += "&trans=1&trans_url_xsl=" + encodeURIComponent(url_xsl);
		no_xsl = 1;		
	}    

	// xml load handler
	var h_xml = function (r)
	{
		if(no_xsl) //browserType == 'opera')
		{					
			var s = r.responseText;
			s = s.replace (/\xC2\xA0/g, '&#160');
			h(s);
			return false;
		}

		if (r)  // Mozilla
		{
			r_xml = r;
		}

		if (r_xml.readyState == 4) // IE
		{			
			if (200 == r_xml.status || (r_xml.parseError && !r_xml.parseError.errorCode))
			{
//				new BxError("xml load failed", r_xml.parseError.reason);
				if ((r_xsl && r_xsl.readyState == 4) || no_xsl)
				{										
					h_res (r_xml, r_xsl);
				}
			}
		}
	}

	// xsl load handler
	var h_xsl = function (r)
	{
		if (r) // Mozilla
		{
			r_xsl = r;
		}
		
		if (r_xsl.readyState == 4) // IE
		{			
			if (200 == r_xsl.status || (r_xsl.parseError && !r_xsl.parseError.errorCode))
			{				
//				new BxError("xsl load failed", r_xsl.parseError.reason);
				if (r_xml && r_xml.readyState == 4) 
				{					
					h_res (r_xml, r_xsl);
				}
			}
		}
	}


	// it fires after both (xml and xsl handlers) functions called
	var h_res = function (r_xml, r_xsl)
	{
	    var f;


		// IE
	    if(window.ActiveXObject)
		{
			try
			{
		        f = r_xml.transformNode (r_xsl);
			}
			catch (e)
			{
				//var ee = new BxError(e.message, e.description);
			}
		}
		// Mozilla
	    else if (window.XSLTProcessor)
		{

	        var x = new XSLTProcessor();			

		    x.importStylesheet(r_xsl.responseXML);

	        var ff = x.transformToFragment(r_xml.responseXML, window.document);

			if (XMLSerializer)
			{
				f = ((new XMLSerializer()).serializeToString(ff));
			}
			else
				alert("xml serialization failed\nplease upgrade your browser");
		}
	    else
		{
			//	var e = new BxError("xslt transformation failed", "please upgrade your browser");
			if (XMLSerializer)
			{
				f = ((new XMLSerializer()).serializeToString(r_xml.responseXML));
			}
			else
				alert("xml serialization failed \n please upgrade your browser");
		}

		// call user defined handler function		
		h (f);
	}


	// IE
	if(!no_xsl && window.ActiveXObject)
	{

		var b = new ActiveXObject("MSXML2.DOMDocument");
		r_xml = b;
		b.async = true;
		b.load (url_xml);
		b.onreadystatechange = h_xml;

		b = new ActiveXObject("MSXML2.DOMDocument");
		r_xsl = b;
		b.async = true;
		b.load (url_xsl);
		b.onreadystatechange = h_xsl;
	}
	// Mozilla
	else if (!no_xsl && window.XSLTProcessor)
	{
		new BxXmlRequest (url_xml, h_xml, true);
		new BxXmlRequest (url_xsl, h_xsl, true);
	}
	// other browsers
	else
	{
		//browserType = 'opera';
		new BxXmlRequest (url_xml, h_xml, true);
	}


}


// Window Class

function BxWnd (sXML, sXSL)
{
    this._sXML = sXML ? sXML : aBxConfig['urlRoot'] + "Util/wnd/";   // xml url
    this._sXSL = sXSL;   // xsl url
    this._iWidth = 400; // window width
    this._iHeight = 400; // window height
    window._gBxWnd = this;
}

BxWnd.prototype.show = function (title)
{
    if (!this._sXML) return false;
    if (!this._sXSL) return false;

	showScreen();

	var $this = this;

	var h = function (r)
	{		
        r = r.replace ('{title}', title);

		showHTML (r, $this.getWidth(), $this.getHeight());
		
		hideScreen();

        $this.onLoadComplete ();
	}

	new BxXslTransform (this._sXML, this._sXSL, h);

	return false;
}

BxWnd.prototype.setSize = function (iW, iH)
{
    this._iWidth = iW;
    this._iHeight = iH;
}

BxWnd.prototype.setWidth = function (i)
{
    this._iWidth = i;
}

BxWnd.prototype.getWidth = function ()
{
    return this._iWidth;
}

BxWnd.prototype.setHeight = function (i)
{
    this._iHeight = i;
}

BxWnd.prototype.getHeight = function ()
{
    return this._iHeight;
}


BxWnd.prototype.onLoadComplete = function ()
{
    return true;
}

BxWnd.prototype.onClose = function ()
{
    return true;
}

// Message Box

BxWndMsgBox.prototype = BxWnd.prototype;

function BxWndMsgBox (title, text)
{   
    this._sXML = aBxConfig['urlRoot'] + "Util/wnd/" + text;   // xml url
    this._sXSL = aBxConfig['urlSystemXsl'] + "wnd.xsl";   // xsl url       
    this._iWidth = 300; // window width
    this._iHeight = 200; // window height

    this.show (title);   
}




// Class for replacing HTML using XSL transformation

function BxContent ()
{
    this._iForceServerXsl = 0;
}

BxContent.prototype.getXmlNodeValue = function (sXmlUrl, sXmlNode)
{
    var $this = this;

	var h = function (r)
	{		
		var o = new BxXmlRequest('','','');			
		var ret = o.getRetNodeValue (r, sXmlNode);
        $this.onLoadComplete (ret);
	}	
	
	new BxXmlRequest (sXmlUrl, h, true);

    return false;
}

BxContent.prototype.add = function (rElement, sXML, sXSL) {	
    if (!sXML.length) sXML = aBxConfig['urlRoot'] + "Util/empty_xml/";
    if (!sXSL) return false;    
    
	showScreen();
	var $this = this;
 
    var oElement = (typeof rElement) == 'string' ? $(rElement) : rElement;    
    if (!oElement) return false;    

	var responseHandler = function (sContent)
	{					
		oElement.innerHTML += sContent;		
		hideScreen();
        $this.onLoadComplete (oElement);
	}

	new BxXslTransform (sXML, sXSL, responseHandler);
	return false;
}
BxContent.prototype.remove = function (rParentElement, rChildElement) {
    var oParentElement = (typeof rParentElement) == 'string' ? $(rParentElement) : rParentElement;
    if (!oParentElement) return false;		
	var oChildElement = (typeof rChildElement) == 'string' ? $(rChildElement) : rChildElement;
    if (!oChildElement) return false;		
    
    oParentElement.removeChild(oChildElement);    
	return false;
}
BxContent.prototype.replace = function (elem, sXML, sXSL)
{
    if (!sXML.length) sXML = aBxConfig['urlRoot'] + "Util/empty_xml/";
    if (!sXSL) return false;

	showScreen();

	var $this = this;
  
    var e = 'string' == (typeof elem) ? $(elem) : elem;
    if (!e) return false;

	var h = function (r)
	{				
		e.innerHTML = r;
		
		hideScreen();

        $this.onLoadComplete (e);
	}
	
	new BxXslTransform (sXML, sXSL, h, null, this._iForceServerXsl);

	return false;
}

BxContent.prototype.fillCombo = function (elem, sXML)
{
    if (!sXML) return false;

    showScreen();

    var $this = this;

    var e = 'string' == (typeof elem) ? $(elem) : elem;
    if (!e) return false;

   	var h = function (r)
    {
        var items = r.responseXML.getElementsByTagName('item');
        e.options.length = 0;
	    for (var i = 0; i < items.length; i++)
    	{
        	var id = items[i].firstChild.firstChild.nodeValue;            
			var name = items[i].firstChild.nextSibling.firstChild.nodeValue;
	    	
            e.options[e.options.length] = new Option(name, id);
        }

        hideScreen();

        e.disabled = false;
        if (e.options[0]) e.options[0].selected = true;
        
        $this.onLoadComplete (e);
    }

    new BxXmlRequest(sXML, h, 1);

    return false;
}

BxContent.prototype.onLoadComplete = function (e)
{
    return true;
}

BxContent.prototype.setForceServerXsl = function (i)
{
    this._iForceServerXsl = i;
}


function BxJsForms ()
{

}

// get value

BxJsForms.prototype.get = function (s)
{
	if (document.forms[this.name].elements[s])
		return document.forms[this.name].elements[s];
			
	s += '[]';	
	return document.forms[this.name].elements[s];
}

// err rhandling

BxJsForms.prototype.showErr = function (s, err)
{
	var o = document.getElementById ('f_err_' + s);
    if (!o) return;
    o.innerHTML = err;
	o.style.display = 'inline';
}

BxJsForms.prototype.hideErr = function (s)
{
	var o = document.getElementById ('f_err_' + s);
	if (!o) return;
	o.style.display = 'none';
}

// check functions 

BxJsForms.prototype.checkRegExp = function (e, p)
{	
	if (e && undefined == e.name) // process set of radio/check boxes
	{		
		var s = '';
		var ret = false;
		for (var i=0; i < e.length ; ++i)
		{
			if (!e[i].checked) continue;
			var r = new RegExp (p['regexp'], p['regexp_mod']);
			if (!r.test(e[i].value)) return false;
			ret = true;
		}		
		return ret;
	}
	var r = new RegExp (p['regexp'], p['regexp_mod']);
	return r.test(e.value);
}

BxJsForms.prototype.checkLen = function (e, p)
{
	var s = e.value;
	if (!s || s.length < p['min'] || s.length > p['max']) return false;
	return true;
}

BxJsForms.prototype.checkAvail = function (e, p)
{
	if (!e) return false;
	var s = e.value; 
	if (!s || !s.length) return false;
	return true;
}

BxJsForms.prototype.isEnabled = function (e, p)
{	
	if (!e) return false;
	var s = e.checked; 
	if (!s) return false;
	return true;
}
BxJsForms.prototype.checkPassword = function (e, p)
{		
	var sPassword = e.value;
	var sConfirm = $(e.id + '_confirm').value;		
	
	//--- Check Length ---//	
	if(!sPassword.length || !sConfirm.length || sPassword.length != sConfirm.length) return false;
	
	//--- Check Content ---//
	if(sPassword != sConfirm) return false;
		
	return true;
}/**
 * remove cookie function
 *	@param c	cookie name
 *	@param r	redirect url
 */
function logout(c, r)
{
	//document.cookie = c + '=; path=/; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	//document.location = r;
	document.location = r + 'logout?logout=1';
	return false;
}


/**
*	clone block and append it to container
*
*	sContainer		container
*	sTarget			source element to clone
*	sPostfix		unique postfix for id
*	idArray			array with ids to change
*/
function cloneBlock(vContainer, vTarget, sPostfix, idArray)
{
	oContainer = Var2Obj(vContainer);
	oTarget = Var2Obj(vTarget);
	
	oContainer.appendChild(oTarget.cloneNode(true));

	oNewBlock = oContainer.lastChild;

	iRand = sPostfix;

	str = oNewBlock.innerHTML;

	for(i = 0; i < idArray.length; i++)
		str = str.replace(new RegExp('id="' + idArray[i] + '[0-9]*"', "ig"), 'id="' + idArray[i] + iRand + '"');

	for(i = 0; i < idArray.length; i++)
		str = str.replace(new RegExp('id=' + idArray[i] + '[0-9]*', "ig"), 'id="' + idArray[i] + iRand + '"');
		
	oNewBlock.id = String(oNewBlock.id).replace(new RegExp('[0-9]*', "ig"), '') + iRand;

	oNewBlock.innerHTML = str;
	
	return oNewBlock;
}


/**
 * Search element by id in specified container
 *
 * @param	variant	vContainer
 * @param	string	sTargetId
 *
 * @return	object					found element
 */
function getElementById(vContainer, sTargetId)
{
	vContainer = Var2Obj(vContainer);
	
	if(vContainer.id == sTargetId)
		return vContainer;
		
	vContainer = vContainer.firstChild;
	
	oRes = null;
	
	while(isVal(vContainer))
	{
		if(vContainer.id == sTargetId)
			return vContainer;
			
		oRes = getElementById(vContainer, sTargetId);
		
		if(isVal(oRes) && oRes.id == sTargetId)
			return oRes;
			
		vContainer = vContainer.nextSibling;
	}
	
	return null;
}





/**
 * Return object, that is parent for specified child and it's ID like specified ID
 * 
 * @param	variant	vChild
 * @param	string	sTrgetId
 * @return	object
 */
function getParentById(vChild, sTargetId)
{
	vChild = Var2Obj(vChild);
	
	
	while(vChild.id != undefined && !isVal(vChild.id.match(new RegExp(sTargetId, 'ig'))))
		vChild = vChild.parentNode;
	
	return isVal(vChild.id) ? vChild : null;
}


/**
 * Insert HTML code into specified container before specified child
 * 
 * @param	string	sNewHtml
 * @param	variant	vContainer
 * @param	variant	vChild
 */
function insertHtmlBefore(sNewHtml, vContainer, vChild)
{
	vChild = Var2Obj(vChild);
	vContainer = vChild.parentNode; 
		
	oTxt = document.createElement('div');
	oTxt.innerHTML = sNewHtml;
	oNewNode = oTxt.firstChild;
		
	while(isVal(oNewNode))
	{
		vContainer.insertBefore(oNewNode.cloneNode(true), vChild);
		oNewNode = oNewNode.nextSibling;
	}
	
	delete(oTxt);
}

/**
 * Find element in string HTML code by ID
 * 
 * @param	string	sNewHtml
 * @param	string	sId
 *
 * @return	object
 */
function getElementFromHtml(sNewHtml, sId)
{
	oTmp = document.createElement('div');
	oTmp.innerHTML = sNewHtml;
	
	return getElementById(oTmp, sId);
}


/**
 * Set hover effects for all form elements (text inputs, passwords inputs, textareas)
 * 
 */
function hoverEffects() {
	//get all 
	var elements = document.getElementsByTagName('input');
	var j = 0;
	var hovers = new Array();
	for (var i4 = 0; i4 < elements.length; i4++) {
		if((elements[i4].type=='text')||(elements[i4].type=='password')) {
			hovers[j] = elements[i4];
			++j;
		}
	}
	elements = document.getElementsByTagName('textarea');
	for (var i4 = 0; i4 < elements.length; i4++) {
		hovers[j] = elements[i4];
		++j;
	}
	
	//add focus effects
	for (var i4 = 0; i4 < hovers.length; i4++) {
		hovers[i4].onfocus = function() {this.className += "Hovered";}
		hovers[i4].onblur = function() {this.className = this.className.replace(/Hovered/g, "");}
	}
}


/**
 * Check is variable is defined and not empty or null
 *
 * @param	string	name
 * @return	bool
 */
function isVal(variable)
{
	return (variable != '' && variable != undefined && variable != null);
}


/*
*	Search element in array
*/
function arraySearch(needle, haystack)
{
	var found = false;
	
	for(var i = 0; i < haystack.length; i++)
	{
		if(haystack[i] == needle)
		{
			found = true;
			break;
		}
	}
	
	if(found)
		return i
	else
		return -1;
}


/*
*	Delete element by value
*/
function arrayDelElement(value, haystack)
{
	return arrayMoveL(arraySearch(value, haystack), haystack);
}


/*
*	Delete element by index
*/
function arrayDelElementByIndex(index, haystack)
{
	return arrayMoveL(index, haystack);
}


/*
*	Move all elements one position left starting from index position
*/
function arrayMoveL(index, haystack)
{
	if(index < 0 || index > haystack.length)
		return haystack;
		
	for(var i = index; i < haystack.length-1; i++)
		haystack[i] = haystack[i+1];
		
	haystack.pop();
		
	return haystack;
}


/*
*	Print Array Information
*/
function printArrayInfo(array)
{
	alert(array + "\n"+array.length);
}


/**
 * Set cookie with specified name and value
 *
 * @param	string	name
 * @param	string	value
 * @param	int		hours			experiation time
 * @return
 */
function setCookie(name, value, hours)
{
	if(!isVal(hours))
		hours = 12;
		
	if(hours)
	{
		var date = new Date();
		date.setTime(date.getTime()+(hours*3600));
		var expires = "; expires=" + date.toGMTString();
	}
	else
		var expires = "";
	document.cookie = name+'='+value+expires+'; path=/';
}


/**
 * Get cookie by name
 *
 * @param	string	name
 * @return	string
 */
function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


/**
 * Unset Cookie by name
 *
 * @param	string	name
 */
function unsetCookie(name)
{
	set_cookie(name,"",-1);
}


/*
*	Hide preload screen
*/
function hideScreen()
{
	hideObject('sys_ploading');

	//hideObject('loading');

	//hideObject('screen');
	//hideObject('screenMessage');
}

/*
*	Show preload screen
*/
function showScreen()
{
//	var o;
//	o1 = Var2Obj('screen');	
//	o1.style.top = getScroll () + "px";
//	o1 = Var2Obj('screenMessage');
//	o1.style.top = getScroll () + "px";	
//	showObject('screen');
//	showObject('screenMessage');

//	loading ('LOADING');

	showObject('sys_ploading');
//	var e = document.getElementById('page_is_loading');
//	if (e) e.style.display = 'block';
}


/**
 * create and display loading message
 */
function loading (sid)
{
	var d = document.getElementById ("loading");
	var e = document.body; // getElementById('content');

	if (d)
	{
		d.firstChild.innerHTML = sid + "...";
		d.style.top = getScroll() - 30 + "px";
		d.style.left = 0 + "px";
		d.style.display = "inline";
	}
	else
	{
		var t = document.createTextNode(sid + "...");
		var d = document.createElement("div");
		var s = document.createElement("span");

		e.appendChild (d);

		d.id = "loading";
/*		
		d.style.position = "absolute";
		d.style.zIndex = "50000";
		d.style.textAlign = "center";
		d.style.width = e.clientWidth + "px";
		d.style.height = (window.innerHeight ? (window.innerHeight + 30) : screen.height) + "px";
		d.style.top = getScroll() - 30 + "px";
		d.style.left = 0 + "px";
		d.style.display = "inline";
		d.style.backgroundImage = "url(/img/loading_bg.gif)";		
*/		
		d.style.cssText = "z-index:50000;position:absolute;top:" + (getScroll() - 30) + "px; left:0px;width:" + e.clientWidth + "px;height:" + (window.innerHeight ? (window.innerHeight + 30) : screen.height) + "px;filter:alpha(opacity=50);-moz-opacity:.50;opacity:.50;background-color:#ccc;text-align:center";
		
		s.style.border = "1px solid #B5B5B5";
		s.style.backgroundColor = "#F3F3F3";
		s.style.color = "#333333";
		s.style.padding = "20px";
		s.style.fontWeight = "bold";
		s.style.lineHeight = d.style.height;
		s.style.cssText += ';alpha(opacity=100);-moz-opacity:1.0;opacity:1.0';

		d.appendChild(s);
		s.appendChild(t);
	}
}


/**
*	Hide object by Id
*	@param	int		id
*/
function hideObject(id)
{
	var oObject = Var2Obj(id);
	if (oObject) oObject.style.display = 'none';
}


/**
*	Show object by Id
*	@param	int		id
*/
function showObject(id)
{
	var oObject = Var2Obj(id);
	if (oObject) oObject.style.display = 'block';
}


/**
 * Add for with stated parameters and content and submit it
 *
 * @param	string	sAction
 * @param	string	sContent
 * @param	string	sWndName		target frame to submit into
 * @param	string	sFileName
 * @TODO	remove last parameter and test the function
 */
function addSubmitForm(sAction, sContent, sWndName, sFileName)
{
	sId = String(sWndName).match(/[0-9]+/);
	
	if(isVal(document.getElementById(sWndName)))
	{
		//	frame and form are already created then submit form
		document.getElementById("addImgForm" + sId).submit();
		return false;
	}
	
	
	//	create iframe - trget frame for submission
	oWnd = getBrowserType() == 'ie' ? document.createElement('<' + 'iframe' + ' name="' + sWndName + '">') : document.createElement('iframe');
	oWnd.name = sWndName;
	oWnd.id = sWndName;
	oWnd.className = 'hidden';
	
	
	//	create form for submission
	oFrm = getBrowserType() == 'ie' ? document.createElement('<form' + ' name="addImgForm' + sId + '" enctype="multipart/form-data">') : document.createElement('form');
	oFrm.action = sAction;
	oFrm.innerHTML = sContent;
	oFrm.method = 'post';
	oFrm.name = "addImgForm" + sId;
	oFrm.id = oFrm.name;
	oFrm.enctype = "multipart/form-data";
	oFrm.className = 'hidden';
	oFrm.target = sWndName;
	
	document.body.appendChild(oFrm);
	document.body.appendChild(oWnd);
	
	oFrm.appendChild(document.getElementById('addImgFldReal' + sId));
	
	oFrm.submit();
	
	document.getElementById('addImgItmReal' + sId).innerHTML = '';
	hideObject('addImgItmReal' + sId);
	document.getElementById('addImgFldReal' + sId).parentNode.removeChild(document.getElementById('addImgFldReal' + sId));
}


/**
 * Create and return created hidden input with specified name and value
 *
 * @param	string	sName
 * @param	string	sValue
 * @return	object
 */
function addHiddenInput(sName, sValue)
{
	oRnd = getBrowserType() == 'ie' ? document.createElement('<input name="' + sName + '">') : document.createElement('input');
	oRnd.type = 'hidden';
	oRnd.className = 'hidden';
	oRnd.name = sName;
	oRnd.value = sValue;
	
	return oRnd;
}


/**
 * Return object with specified by vVar
 * If vVar is object then returns it directly
 *
 * @param	variant	vVar		ID of object
 * @return	object
 */
function Var2Obj(vVar)
{
	return typeof(vVar) != 'object' ? document.getElementById(vVar) : vVar;
}


/**
 * Returns browser type
 *
 * @return	string			browser type
 */
function getBrowserType()
{
	// browser name
	ua = navigator.userAgent.toLowerCase(); 
	res = '';
	
	res	= (ua.indexOf('gecko') != -1) ? 'gecko' : res;
	res	= ((ua.indexOf('gecko') != -1) && ua.indexOf("gecko/") + 14 == ua.length) ? 'mozilla' : res;
	res	= ((ua.indexOf('gecko') != -1) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) ) ? 'netscape' : res;
	res	= ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ) ? 'ie' : res;
	res	= (ua.indexOf("opera") != -1) ? 'opera' : res;
	
	return res;
}







aBxMeta =
{
	'article_frozen_for_adding' : 'Article is frosen for editing',
	'blocks_deleted': 'Blocks were deleted',
	'compare'	:	'Compare',
	'close'		:	'Close',
	'view'		:	'View',
	'add_category_form' : 'Add Category',
	'edit_category_form' : 'Edit Category'
};


/**
 * Language function (show words by metas)
 *
 * @param	string	sMeta		metaword
 * @return	string				real phrase, associated with specified metaword
 */
function w(sMeta)
{
	
	if(isVal(aBxMeta[sMeta]))
		return aBxMeta[sMeta];
		
	return '_js_' + sMeta + '_';
}


/**
 * Out specified text in new browser window
 *
 * @param	variant	s		text to show
 */
function debugOut(s)
{
	wnd = window.open();
	wnd.document.write(s);
}

/**
 * get center browser point by horizontally
 */
function getCenterHor ()
{
	return document.body.clientWidth / 2;
}

/**
 * get center browser point by vertically
 */
function getCenterVer ()
{
	var y;

    if (navigator.appName == "Microsoft Internet Explorer")
        y = document.documentElement.scrollTop
    else
        y = window.pageYOffset;

	y += (window.innerHeight ? (window.innerHeight + 30) : screen.height) / 2;
	
	return y;
}


// -------------------------------------------


function getScroll()
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
//		return document.body.scrollTop;
		return document.documentElement.scrollTop
	}
	else
	{
		return window.pageYOffset;
	}
}

function correctPNG() 
{
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
}

var oldHandler = window.onload;
if(typeof window.onload != 'function') {
	window.onload = correctPNG();
}
else {
	window.onload = function() {
		if(oldHandler) oldHandler();
		correctPNG();
	}
}

function eHeight (e)
{
	if (!e) return 0;
	return e.clientHeight > 0 ? e.clientHeight : e.offsetHeight;
}

function fixTreeHeight ()
{
	var eCart = document.getElementById ('shopping_cart');
	var h = eHeight(eCart);
	var eZone = document.getElementById ('zone');
	if (!eZone) return;
	if (eHeight(eZone) < (470+h)) eZone.style.height = 470 + h + 'px';
}


/**
 * show login form
 */
function showLoginForm ()
{
    var w = new BxWnd ('', aBxConfig['urlSystemXsl'] + 'wnd_login_form.xsl');
    w.setSize (420,400);
    w.show ('Login');
    return false;
}


/**
 * show search form
 */
function showSearchForm ()
{
	showScreen();

	var $this = this;

	var h = function (r)
	{		
		showHTML (r, 400, 200);
		
		hideScreen();
	}

	new BxXslTransform (aBxConfig['urlRoot'] + "Join/search_form", aBxConfig['urlRoot'] + "system/layout/default/xsl/search_form.xsl", h);

	return false;
}


/**
 * show resend activation letter form
 */
function showResendActivationForm ()
{
    var w = new BxWnd ('', aBxConfig['urlSystemXsl'] + 'resend_activation_form.xsl');
    w.show ('Resend activation letter');
    return false;
}


/**
 * show resend activation letter form
 */
function showForgotPasswordForm ()
{
    hideHTML();
    var w = new BxWnd ('', aBxConfig['urlSystemXsl'] + 'wnd_forgot_pwd_form.xsl');
    w.setSize (420,400);
    w.show ('GET LOGIN INFO');
    return false;
}


function hideHTML ()
{
	var l = document.getElementById ("show_html");
	
	if (l)
	{
		document.body.removeChild(l);
	}

    if (window._gBxWnd)
    {
        window._gBxWnd.onClose ();
//        delete window._gBxWnd;
        window._gBxWnd = null;
    }
}

function showHTML (html, w, h)
{
	var d = document.getElementById ("show_html");
	var e = document.body; 

	if (d)
	{
		var div = d.firstChild;
		div.innerHTML = html;
		d.style.top = getScroll() - 30 + "px";
		d.style.left = 0 + "px";
		d.style.display = "block";
		if (w) div.style.width = w + 'px';
		if (h) div.style.height = h + 'px';
		div.style.top = parseInt(d.style.height)/2 - h/2 - 10 + 'px';
		div.style.width = parseInt(d.style.width)/2 - w/2 - 10 + 'px';
	}
	else
	{
		var d = document.createElement("div");
		var div = document.createElement("div");

		e.appendChild (d);

		d.id = "show_html";
		d.style.position = "absolute";
		d.style.zIndex = "49000";
		d.style.textAlign = "center";
		d.style.width = e.clientWidth + "px";
		d.style.height = (window.innerHeight ? (window.innerHeight + 30) : screen.height) + "px";			
		d.style.top = getScroll() - 30 + "px";
		d.style.left = 0 + "px";
		d.style.display = "inline";
		d.style.backgroundImage = "url("+aBxConfig['urlSystemImg']+"loading_bg.gif)";

		div.innerHTML = html;
		div.style.position = "absolute";
		if (w) div.style.width = w + 'px';
		if (h) div.style.height = h + 'px';
		div.style.top = parseInt(d.style.height)/2 - h/2 - 10 + 'px';
		div.style.left = parseInt(d.style.width)/2 - w/2 - 10 + 'px';

		d.appendChild(div);
	}
}

/**
 * fly 'o' id html object from (x0,y0) to (x1,y1)
 * after flying completed execute 'run' code
 * addscroll  - determine scroll position, 1 or 0
 */
function fly (o, run, x0, y0, x1, y1, addscroll)
{
	var to = 25;

	var fly = document.getElementById(o)
	if (!fly) return false
	
	if (parseInt(fly.style.left) < 0)
	{
		if (addscroll)
		{
			if (navigator.appName == "Microsoft Internet Explorer")
			{
				y0 += document.documentElement.scrollTop
				x0 += document.documentElement.scrollLeft
			}
			else
			{
				y0 += window.pageYOffset;
				x0 += window.pageXOffset;
			}
		}

		var e = fly.parentNode
		while (e.tagName != 'BODY')
		{
			x0 -= e.offsetLeft;
			y0 -= e.offsetTop;
			e = e.parentNode;
		}	
		

		fly.style.left = x0 + 'px'
		fly.style.top = y0 + 'px'
		setTimeout('fly(\''+o+'\',\''+run+'\','+x0+','+y0+','+x1+','+y1+')', to)
	}
	else
	{
		var x = parseInt(fly.style.left)

		x += x0 < x1 ? 30 : -30;

		var y = (x - x0) * (y1 - y0) / (x1 - x0) + y0

		var exeed_x = 0
		var exeed_y = 0

		if (x0 < x1) exeed_x = x > x1 ? 1 : 0
		else         exeed_x = x < x1 ? 1 : 0

		if (y0 < y1) exeed_y = y > y1 ? 1 : 0
		else         exeed_y = y < y1 ? 1 : 0

		fly.style.left = (exeed_x ? x1 : x) + 'px'
		fly.style.top = (exeed_y ? y1 : y) + 'px'
		
		if (!exeed_x && !exeed_y)
		{
			setTimeout('fly(\''+o+'\',\''+run+'\','+x0+','+y0+','+x1+','+y1+')', to);
		}
		else
		{
			fly.style.left = '-1000px'
			fly.style.top = '-1000px'
			if (run.length) eval (run)				
		}		
	}

	return false
}

function addToCart (id, e)
{
	var add = 120;
	var cc = document.getElementById('cart_container');
	
	return fly ('fly', 'window.iframe_cart.document.location="' + aBxConfig['urlRoot'] + 'ExpertsAccount/add_to_cart/' + id + '/"', e.clientX, e.clientY, 20, cc.offsetTop+add, 1)	
}

function setButtonWait (o, disabled)
{
	if (disabled)
	{
		o.disabled = true;
		if (window._old_title != "Please wait...") window._old_title = o.value;
		o.value = "Please wait...";
	}
	else
	{
		o.disabled = false;
		if (window._old_title)
			o.value = window._old_title;
	}
}

function $(id)
{
    return document.getElementById(id);
}

/*****************************************************
    photos handling functions
*****************************************************/

		function openGalleryBig (iID, iIdImage)
		{
			window.open(aBxConfig['urlRoot'] + "images/gallery/" + iID + (iIdImage ? '/' + iIdImage : '') + "/", 'gallery_big', 'menubar=0,resizable=0,width=260,height=375,');
		}
		
		function openGalleryReal (iID, iIdImage)
		{
			var win = window.open(aBxConfig['urlRoot'] + "images/gallery_real/" + iID + (iIdImage ? '/' + iIdImage : '') + "/", 'gallery_real', 'menubar=0,resizable=0,width=810,height=725,');
			win.moveTo(0,0);
		}
				
        function onClickThumb (sDir, pathBig, iId, iIdImage)
        {
            var imgBig = $('pr_big');

            if ($('loading_photo')) $('loading_photo').style.display = 'block';

            imgBig.onclick = function () { openGalleryReal(iId, iIdImage) };            
            
            imgBig.onload = function () { if ($('loading_photo')) $('loading_photo').style.display = 'none'; };

            imgBig.src = sDir + pathBig;            

            if (imgBig.readyState && imgBig.readyState != 'complete')
            {
                var img = new Image ();
                img.src = sDir + pathBig;
                img.onload = function () { imgBig.src = this.src; };            
            }
        }

        function moveScrollRightAuto (availWidth, b)
        {
            if (b)
                scrollTimerId = setInterval ('moveScrollRight('+availWidth+')', 100);
            else
                clearInterval (scrollTimerId);
        }

        function moveScrollLeftAuto (b)
        {
            if (b)
                scrollTimerId = setInterval ('moveScrollLeft()', 100);
            else
                clearInterval (scrollTimerId);
        }

        function moveScrollRight (availWidth)
        {
            var step = 10;
            var e=$('photos_scroll'); 

            var left = parseInt(e.style.left ? e.style.left : 0);
            var width = parseInt(e.style.width);

            if (left - step - 13 + width > availWidth)
            {
                e.style.left = left - step + 'px';
            }
            else
            {
                e.style.left = availWidth - width + 13 + 'px';
                moveScrollRightAuto (availWidth, false);
            }
        }

        function moveScrollLeft ()
        {
            var step = 10;
            var e=$('photos_scroll'); 

            var left = parseInt(e.style.left ? e.style.left : 0);

            if (left + step < 0 )
            {             
                e.style.left = left + step + 'px';
            }
            else
            {
                e.style.left = '0px';
                moveScrollLeftAuto (false);
            }
        }


function getNextWithClass (e, sClassName)
{
    var en = e.nextSibling;
    while (en && en.className != sClassName)
    {
        en = en.nextSibling;
        if (!en) break;
    }
    return en;
}

function getFirstChildWithClass (eParent, sClassName)
{
    var e_first = eParent.firstChild;
    while (e_first && e_first.className != sClassName)
    {
        e_first = e_first.nextSibling;
        if (!e_first) break;
    }
    return e_first;
}

function getLastChildWithClass (eParent, sClassName)
{
    var e_last = eParent.lastChild;
    while (e_last && e_last.className != sClassName)
    {
        e_last = e_last.previousSibling;
        if (!e_last) break;
    }
    return e_last;
}

function getAllChildWithClass (eParent, sClassName)
{
    var e_ret = new Array();
    var e_last = eParent.lastChild;
    while (e_last)
    {
        if (e_last.className == sClassName)
        {
            e_ret.push(e_last);
        }   
        e_last = e_last.previousSibling;
        if (!e_last) break;
    }
    return e_ret;
}

function getChildNumWithClass (eParent, sClassName)
{
    var count = 0;
    var e_tmp = eParent.firstChild;
    while (e_tmp)
    {
        if (sClassName == e_tmp.className)
            ++count;
            
        e_tmp = e_tmp.nextSibling;			
    }
    return count;
}

function animator (sId, sId2, sEval, h)
{
	var st = 7;
	var d = 100;
	
	var e = $(sId);
	var e2 = $(sId2);
	var hh = parseInt(e.style.height);
	if (e2) var hh2 = parseInt(e2.style.height);	
	
	hh += st;
	if (e2) hh2 -= st;
	if (hh < h)
	{		
		e.style.height = hh + 'px'			
		if (e2) e2.style.height = hh2 + 'px'
		setTimeout ("animator('"+sId+"','"+sId2+"',\""+sEval+"\","+h+")", d);
	}
	else
	{
		hh = h;		
		e.style.height = hh + 'px';
		
        eval (sEval);
	}
}


function animator2 (sId, sId01, sId02, sId2, sEval, pos)
{
    var ww2, ll2, ll01, ll02;

	var st = 10;
	var d = 70;
	
	var e = $(sId);
	var e2 = $(sId2);
    var e01 = $(sId01);
    var e02 = $(sId02);

	var ll = parseInt(e.style.left);
	if (e2) ww2 = parseInt(e2.style.width);	
    if (e2) ll2 = parseInt(e2.style.left);	
    if (e01) ll01 = parseInt(e01.style.left);	
    if (e02) ll02 = parseInt(e02.style.left);	
	
	ll += st;
    if (e2) ww2 -= st;
    if (e2) ll2 += st;
    if (e01) ll01 += st;
    if (e02) ll02 += st;

	if (ll < pos)
	{				
		if (e2) e2.style.width = ww2 + 'px'
        if (e2) e2.style.left = ll2 + 'px'
        if (e02 && e2) e02.style.left = ll02 + 'px'
        if (e01 && e2) e01.style.left = ll01 + 'px'
        e.style.left = ll + 'px'

		setTimeout ("animator2('"+sId+"','"+sId01+"','"+sId02+"','"+sId2+"',\""+sEval+"\","+pos+")", d);
	}
	else
	{
		ll = pos;		
		e.style.left = ll + 'px';
	
        if (e02 && e2) e02.style.left = (ll + 190) + 'px'
        if (e01 && e2) e01.style.left = (ll + 190 + 190) + 'px'
	
        eval (sEval);
	}
}
