$(document).ready(function(){

	refreshNews();

});
	
	function refreshNews()
	{
		var id = window.location.hash;
		var id2 = id.substring(1);
		if (id != "") 
		{
			showContent('news_download.php',id2);
		}
		//alert(id);
	};
	
	function showList()
	{
		document.getElementById('list_news').style.display='block';
		document.getElementById('contentBody').style.display='none';
		//document.getElementById('buttons_download').style.display='none';
		document.getElementById('archive').style.display='block';
	};
	
	function showContent(link, id)
	{  
		document.getElementById('list_news').style.display='none';
		document.getElementById('archive').style.display='none';
		document.getElementById('contentBody').style.display='block';
		//document.getElementById('buttons_download').style.display='block';
		var params = 'id=' + encodeURIComponent(id);
        var cont = document.getElementById('contentBody');  
        var loading = document.getElementById('loading');  
        cont.innerHTML = loading.innerHTML;  
        var http = createRequestObject();  
        if( http )   
        {  
			http.evalScripts = true;
			cont.evalScripts = true;
            http.open('post', link);
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.send(params);
            http.onreadystatechange = function () 
		    {  
                if(http.readyState == 4)   
                {  
                    cont.innerHTML = http.responseText; 
					evalScripts(http.responseText);
                }  
            }  
        }  
        else   
        {  
            document.location = link;  
        } 
		/*
		var cont2 = document.getElementById('buttons_download');  
        var loading = document.getElementById('loading');  
        //cont2.innerHTML = loading.innerHTML;  
        var http2 = createRequestObject();  
        if( http2 )   
        {  
			http2.evalScripts = true;
			cont2.evalScripts = true;
            http2.open('post', link2);
			http2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http2.send(params);
            http2.onreadystatechange = function () 
		    {  
                if(http2.readyState == 4)   
                {  
                    cont2.innerHTML = http2.responseText; 
					evalScripts(http2.responseText);
                }  
            }  
        }  
        else   
        {  
            document.location = link2;  
        }  */
    }  
    // создание ajax объекта  
    function createRequestObject()   
    {  
        try { return new XMLHttpRequest() }  
        catch(e)   
        {  
            try { return new ActiveXObject('Msxml2.XMLHTTP') }  
            catch(e)   
            {  
                try { return new ActiveXObject('Microsoft.XMLHTTP') }  
                catch(e) { return null; }  
            }  
        }  
    }  
	
	evalScripts = function(s)
	{
		if (s.search(/<\s*script[^>]*>/) != -1)
		{
			var $head = document.getElementsByTagName("head")[0] || document.documentElement;
			var r = s.split(/<\s*\/\s*script\s*>/i);
			var r2 = []; var r3 = []; var strScript = '';
			for (var i=0; i < r.length; i++)
			{
				r2 = r[i].match(/<\s*script[^>]+src="([^"]+)"[^>]*>/i)
				if (r2)
				{
					var objScript = document.createElement("SCRIPT");
					objScript.src = r2[1];
					$head.appendChild(objScript);
					continue;
				}
				r3 = r[i].split(/<\s*script[^>]*>/i);
				if (r3.length == 2)
				{
					strScript = r3[1].replace(/function\s+([^(]+)/g, '$1=function');
					strScript = strScript.replace(/^(\s*<!--|\s*<!\[CDATA\[)/,"");
					strScript = strScript.replace(/(-->\s*|\]\]>\s*)$/g,"");
					window.eval( strScript );
				}
			}
		}
	}
