var xmlhttp;

function sendData(fragment_url)
{
    xmlhttp = null;
    if (window.XMLHttpRequest) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }
	xmlhttp.open('GET', fragment_url);
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
                //alert(xmlhttp.responseText);
        }
    }
    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult')
    xmlhttp.send(null);
    return false;
}
    
function news_showBlockAndLoad(fragment_url,bl,id,title)
{
	xmlhttp = null;
    if (window.XMLHttpRequest) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }
	var element = document.getElementById(bl);
	var element_show = document.getElementById(bl+'_show');
	var element_load = document.getElementById(bl+'_load');
    var theURL = fragment_url;
	element_load.style.display = 'block';
	element_show.style.display = 'none';
    xmlhttp.open('GET', fragment_url);
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            element.innerHTML = xmlhttp.responseText;
			element_load.style.display = 'none';
			element_show.style.display = 'block';
			try
			{
				if(title=='edit')
				{
					tinyMCE.execCommand('mceToggleEditor',false,'main_news_edit_minitext_'+id);
					tinyMCE.execCommand('mceToggleEditor',false,'main_news_edit_text_'+id);
				}
			}
			catch(err){}
        }
    }
    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult')
    xmlhttp.send(null);
    return false;
}
    
function news_showBlockAndLoadPOST_save(fragment_url,bl,post_str,id)
{
	xmlhttp = null;
    if (window.XMLHttpRequest) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }
	var element = document.getElementById(bl);
    var theURL = fragment_url;
    element.innerHTML = 'Loading...';
	element.style.display = 'block';
    xmlhttp.open('POST', fragment_url);
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            if(bl=='admin_panel_block')element.innerHTML = '<div align=\"right\" style=\"padding-bottom:5px;font-size:12px;font-family:Verdana, Arial;\">[<a href=\"#\" onclick=\"document.getElementById(\'admin_panel_block\').style.display=\'none\';return false;\" style=\"text-decoration:none;color:#900;\"><b>X</b></a>]</div>'+xmlhttp.responseText;
            else element.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttp.send(post_str);
    return false;
}

function hidden_news_edit_backs(id)
{
	document.getElementById('main_news_edit_all_'+id+'_show').style.display='none';
	document.getElementById('main_news_edit_all_'+id+'_load').style.display='none';
}

function hidden_news_edit_backs_comment(id)
{
	document.getElementById('main_news_edit_comment_all_'+id+'_show').style.display='none';
	document.getElementById('main_news_edit_comment_all_'+id+'_load').style.display='none';
}

function main_news_send_comment(idnews,comment_block,text,kap,fragment_url)
{
	xmlhttp = null;
    if (window.XMLHttpRequest) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }
	var comment_block = document.getElementById(comment_block);
    var theURL = fragment_url;
	
    comment_block.innerHTML = '<div style="margin:5px;padding:5px;background:#FFF;border:#999 solid 1px;"><img src="/resource/images/loading.gif" align="absmiddle"><b style="font-size:16px;padding-left:10px;">Отправление данных</b></div>';
	comment_block.style.display = 'block';
	
	post_str = 'type=ajax&id='+escape(idnews)+'&main_news_edit_comment_add='+escape(document.getElementById(text).value)+'&main_news_edit_comment_add_kap_rand='+escape(kap)+'&send=add_comment';
	
    xmlhttp.open('POST', fragment_url);
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            if(xmlhttp.responseText.substr(0,9)=='<!--OK-->')
			{
				document.getElementById('main_news_comment_text').innerHTML = document.getElementById(text).value;
				document.getElementById('new_comment_table').style.display = 'block';
				document.getElementById(text).value = '';
			}
			comment_block.innerHTML = xmlhttp.responseText;
			//alert(xmlhttp.responseText);
        }
    }
    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttp.send(post_str);
    return false;
}