function setArticle(_action,value,type) {
    // Create new JsHttpRequest object.
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
        	
            // Write result to pae element ($_RESULT become responseJS). 
            if(req.responseJS.setarticle == 'ok') {
            	//
            	if(_action=='showCommentFrm'){            		
            		document.getElementById('commentpreloader').style.visibility = 'hidden';
            		document.getElementById('addComment').innerHTML = req.responseJS.contentBlock;
            		//window.location.reload();
            	}
            	//
            	if(_action=='addComment'){
            		//alert('comment');
            		if(req.responseJS.errormessage == 'ok'){
            			document.getElementById('commentpreloader').style.visibility = 'hidden';
            			document.getElementById('addComment').innerHTML = req.responseJS.contentBlock;
            		} else {
            			document.getElementById('addComment').innerHTML = '';
            			window.location.reload();
            		}
            	}
            }
            // Write debug information too (output become responseText).
            if(req.responseText){
	           alert(req.responseText);
	           //document.getElementById('addmess').innerHTML = req.responseText;
            }    
        }
    }    
   	//alert(_action);
    if((_action=='setOutOnPage') || (_action=='setSortBy')) document.getElementById('setoptpreloader').style.visibility = 'visible';
    if((_action=='showCommentFrm') || (_action=='addComment')) document.getElementById('commentpreloader').style.visibility = 'visible';
    if(_action=='setRank') document.getElementById('setrankpreloader').style.visibility = 'visible';
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/news/ajax/php/article_loader.php', true);
    // Send whole form data to backend.
    if(type == 'item') req.send( { '_action': _action, 'item': value} );
    if(type == 'form') req.send( { 'form': value } );
}

//
function showCharNumber(dest,outer,max){
	if(dest.value.length > max ) dest.value = dest.value.substr(0,max);
	outer.innerHTML = 'Осталось ' + (max - dest.value.length) + ' из ' + max;
}
