var js_site_url = 'http://www.zarstvo.com';
var js_site_content_url = 'http://www.zarstvo.com';

// THESE EXTERNAL VARIABLES SHOULD BE DEFINED
// IN THE FILE WHICH RUN THIS SCRIPT
// js_lang, jsf_id, jsf_src

var incl_js_files = Array();
// do not allow include of the code files
// implied that they are already included
addElementToArray( incl_js_files, 'jquery' );

function LoadJScript( file_name, use_lang )
{
	if( inArray( incl_js_files, file_name ) == 0 )
	{
		if( !use_lang )
		{
			document.write('<script type="text/javascript" src="'+jsf_src+'/'+jsf_id+'/'+file_name+'.js'+'"></script>');
            addElementToArray( incl_js_files, file_name );
		}
		else
		{
            document.write('<script type="text/javascript" src="'+jsf_src+'/'+jsf_id+'/'+js_lang+'/'+file_name+'.js'+'"></script>');
            addElementToArray( incl_js_files, file_name );
		}
	}
}

function addElementToArray( a, e )
{
    a[a.length] = e;
}

function inArray( a, e )
{
	for( i = 0; i < a.length; i++ )
	{
		if( a[i] == e )
		{
			return 1;
		}
	}

	return 0;
}

function DumpObject( d, l )
{
    if (l == null) l = 1;
    var s = '';
    if (typeof(d) == "object") {
        s += typeof(d) + " {\n";
        for (var k in d) {
            for (var i=0; i<l; i++) s += "  ";
            s += k+": " + DumpObject(d[k],l+1);
        }
        for (var i=0; i<l-1; i++) s += "  ";
        s += "}\n"
    } else {
        s += "" + d + "\n";
    }
    return s;
}

/* Array prototype, matches value in array: returns bool */
Array.prototype.inArray = function (value)
{
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
}

/* insert an element after a particular node */
function insertAfter(parent, node, referenceNode)
{
	parent.insertBefore(node, referenceNode.nextSibling);
}

function openpopup( url, w, h, wn )
{
	l = (screen.width/2)  - (w/2);
	t = (screen.height/2) - (h/2);

	win1 = window.open( url, wn, 'left='+l+', top='+t+', width='+w+', height='+h+', status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes' );
}

function redirectto( url )
{
	self.location = url;
}

function ButtonFormSubmit( form_id, ac, msg, needconfirm )
{
	confirmed = needconfirm ? confirm( msg ) : true;
	if( confirmed )
	{
		document.getElementById( form_id ).action = ac;
		document.getElementById( form_id ).submit();
	}
}

function CReload( id )
{
	try
	{
		var req = new JsHttpRequest();
		req.onreadystatechange = function()
		{
			if( req.readyState == 4 )
			{
				if( req.responseText )
				{
		            document.getElementById(id).src = req.responseText;
				}
			}
		}

		req.caching = false;
		u = js_site_url + '/captcha_reload.php?y=0.' + Math.random();
	 	req.loader = 'script';
	 	req.open('GET',u,true);
	 	req.send({});
 	}
 	catch(e)
 	{}
}