//--------- AJAX -----------------------------------------------------
function new_files(files,host)
{
	var url = host+'get_librery.php';
	var post = 'files='+files;
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
						return xmlhttp.responseText;
					}
				}
		}
	xmlhttp.send(post);
} 

function user_bun(id,host)
{
	var url = host+'user_bun.php';
	var post = 'id='+id;
    document.getElementById('user_bun').style.display = 'none';
    document.getElementById('spinner_user_bun').style.display = '';
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
						xmlhttp.responseText;
						document.getElementById('spinner_user_bun').style.display = 'none';
                        document.getElementById('user_bun').style.display = '';
					}
				}
		}
	xmlhttp.send(post);
}

function user_del(id,host)
{
	var url = host+'user_del.php';
	var post = 'id='+id;
   
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
					   jQuery('#'+id).animate({ opacity: 'hide' }, "slow");
						xmlhttp.responseText;
					}
				}
		}
	xmlhttp.send(post);
}


function user_spamer(id,host)
{
	var url = host+'user_spamer.php';
	var post = 'id='+id;
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
					   $('#'+id).animate({ opacity: 'hide' }, "slow");
					   xmlhttp.responseText;
					}
				}
		}
	xmlhttp.send(post);
}



function rss_bun(id,host)
{
	var url = host+'rss_bun.php';
	var post = 'id='+id;
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
						xmlhttp.responseText;
						document.getElementById('spinner_rss_bun').style.display = 'none';
					}
				}
		}
	xmlhttp.send(post);
}

function rss_del(id,host)
{
	var url = host+'rss_del.php';
	var post = 'id='+id;
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
						xmlhttp.responseText;
					}
				}
		}
	xmlhttp.send(post);
}


function rss_mes_del(id,host,podrobnee)
{
	var url = host+'.php';
	var post = 'id='+id;
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
						xmlhttp.responseText;
						if(podrobnee) document.location = podrobnee;
					}
				}
		}
	xmlhttp.send(post);
}

function rss_to_mes(id,host)
{
	var url = host+'rss_to_mess.php';
	var post = 'id='+id;
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
						document.location = xmlhttp.responseText;
					}
				}
		}
	xmlhttp.send(post);
}


function admin_news_del(id,host)
{
	document.getElementById('spinner_del').style.display = '';
	var url = host+'admin_news_del.php';
	var post = 'id='+id;
	if(document.all)
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function ()
		{
			if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.responseText)
					{
						xmlhttp.responseText;
						document.getElementById('spinner_del').style.display = 'none';
					}
				}
		}
	xmlhttp.send(post);
}
//------------------ users ---------------------------------------------
function edit_user(id,S){
	document.getElementById('status').value = document.getElementById('status_'+id).value;
	document.getElementById('user_id').value = id;
	document.getElementById('login').value = document.getElementById('login_'+id).value;
	document.getElementById('name').value = document.getElementById('name_'+id).value;
	document.getElementById('email').value = document.getElementById('email_'+id).value;
	document.getElementById('about').value = document.getElementById('about_'+id).value;
	document.getElementById('ads_code').value = document.getElementById('ads_code_'+id).value;
	document.getElementById('submit').value = S;
}

function edit_clear(){
	document.getElementById('status').value = '2';
	document.getElementById('user_id').value = '';
	document.getElementById('login').value = '';
	document.getElementById('name').value = '';
	document.getElementById('email').value = '';
	document.getElementById('about').value = '';
}
//----------------------------------------------------------------------

function for_IE_on(id){
	var ua = navigator.userAgent.toLowerCase();
	//Определим Internet Explorer
	if (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1)
		document.getElementById(id).className = 'board_hover_ie';
}

function for_IE_off(id){
	var ua = navigator.userAgent.toLowerCase();
	//Определим Internet Explorer
	if (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1)
		document.getElementById(id).className = 'board';
}

function enter_window(whot){
	if(whot == 'open'){
		document.body.style.overflow = 'hidden';
		$("#all_block").slideDown("slow");
		$("#window").slideToggle("slow");
	}
	if(whot == 'close'){
		$("#window").slideUp("slow");
		$("#all_block").slideUp("slow");
		document.body.style.overflow = '';
	}
}

function add_window(whot){
	if(whot == 'open'){
		//document.body.style.overflow = 'hidden';
		$("#all_block").slideDown("slow");
		$("#add_window").slideToggle("slow");
	}
	if(whot == 'close'){
		$("#add_window").slideUp("slow");
		$("#all_block").slideUp("slow");
		//document.body.style.overflow = '';
	}
}

function rss_parser(whot){
	if(whot == 'open'){
		document.body.style.overflow = 'hidden';
		$("#all_block").slideDown("slow");
		$("#rss_parser").slideToggle("slow");
	}
	if(whot == 'close'){
		$("#rss_parser").slideUp("slow");
		$("#all_block").slideUp("slow");
		document.body.style.overflow = '';
	}
}

function lib_window(whot,url){
	if(whot == 'open'){
		//$("#add_window").slideUp("slow");
		document.getElementById('img_alt').value = document.getElementById('caption').value;
		jQuery('#upload_panel').show();
        $("#lib_window").slideDown("slow");
	}
	if(whot == 'close'){
		$("#lib_window").slideUp("slow");
        jQuery('#height').val('');
        jQuery('#width').val('');
        jQuery('#upload_panel').show();
        document.getElementById('iframe').src = 'file_add_input.php';
        document.getElementById('iframe').disabled = '';
        document.getElementById('save_to_server').disabled = '';
        document.getElementById('result_src').disabled = '';
        document.getElementById('result_src').value = '';
	}
}

function add_users(whot){
	if(whot == 'open'){
		document.body.style.overflow = 'hidden';
		$("#all_block").slideDown("slow");
		$("#users").slideToggle("slow");
	}
	if(whot == 'close'){
		$("#users").slideUp("slow");
		$("#all_block").slideUp("slow");
		document.body.style.overflow = '';
		edit_clear();
	}
}

function url_file_check(id1,id2){
	
	if(document.getElementById(id1).className == 'button1'){
		document.getElementById(id1).className = 'button2';
		document.getElementById(id2).className = 'button1';
		document.getElementById('url').style.display = '';
		document.getElementById('file').style.display = 'none';
	}else
	{
		document.getElementById(id1).className = 'button1';
		document.getElementById(id2).className = 'button2';
		document.getElementById('url').style.display = 'none';
		document.getElementById('file').style.display = '';
	}
}

var clientPC = navigator.userAgent.toLowerCase();
var clientVer = parseInt(navigator.appVersion);
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);



function check_form_add(){
	var caption = document.getElementById('caption').value;
	var message = document.getElementById('message').value;
	var tags	= document.getElementById('tags').value;
    var ankor	= document.getElementById('ankor').value;
	if(caption == ''){alert('Not enter the title');  return false;}
	if(message == ''){alert('Not enter the message');return false;}
	if(tags    == '' && ankor == 'false'){alert('Not enter the tags');   return false;}
	return true;
}

function whaiting(id){
	wait_img = document.getElementById(id).style.display = '';
}

function edit_(id){
	var div = document.getElementById(id);
	if(div.style.display == 'none')
		div.style.display = '';
	else
		div.style.display = 'none';
}

function tag_it(txtstart,txtend) {

document.editor_form.message.focus();

if (document.selection) {    
 	var rng = document.selection.createRange();
 	if (rng.text) {
   document.selection.createRange().text = txtstart + rng.text + txtend;
   } else {
   document.editor_form.message.value += txtstart  + txtend;
   }
 	document.editor_form.message.focus();
 	}
else if (document.editor_form.message.selectionStart || document.editor_form.message.selectionStart == '0') {

var selStart = document.editor_form.message.selectionStart;
var selEnd = document.editor_form.message.selectionEnd; 
var s = document.editor_form.message.value;     

s = s.substring(0, selStart) + txtstart + s.substring(selStart, selEnd) + txtend + s.substring(selEnd, s.length);
 document.editor_form.message.value = s; 
if (selEnd != selStart) {
 document.editor_form.message.selectionStart = selStart;
 document.editor_form.message.selectionEnd = selEnd + txtstart.length + txtend.length;
 } else {
 document.editor_form.message.selectionStart = selStart + txtstart.length;
 document.editor_form.message.selectionEnd = document.editor_form.message.selectionStart;
 }
} else {   
document.editor_form.message.value += txtstart + txtend;   
}
}



function get_link(text1,text2){
    var title = '';
    if (document.editor_form.message.selectionStart || document.editor_form.message.selectionStart == '0') {
        var selStart = document.editor_form.message.selectionStart;
        var selEnd = document.editor_form.message.selectionEnd; 
        var s = document.editor_form.message.value;     
        title = s.substring(selStart, selEnd);
    }
    var link = prompt(text1,'http://');
	if(title == ''){
        title = prompt(text2);
	   tag_it('<noindex><a rel="nofollow" target="_blank" href="'+link+'">'+title,'</a></noindex>');
    }else tag_it('<noindex><a rel="nofollow" target="_blank" href="'+link+'">','</a></noindex>');
}


function link_add(){

	var txtstart = '<noindex><a rel="nofollow" target="_blank" href="';
	var txtcenter = '">';
	var txtend = '</a></noindex>';

	document.editor_form.message.focus();
	
	if (document.selection) {    
	 	var rng = document.selection.createRange();
	 	if (rng.text) {
	   document.selection.createRange().text = txtstart + rng.text + txtend;
	   } else {
	   document.editor_form.message.value += txtstart  + txtend;
	   }
	 	document.editor_form.message.focus();
	 	}
	else if (document.editor_form.message.selectionStart || document.editor_form.message.selectionStart == '0') {
	
	var selStart = document.editor_form.message.selectionStart;
	var selEnd = document.editor_form.message.selectionEnd; 
	var s = document.editor_form.message.value;     
	
	s = s.substring(0, selStart) + txtstart + s.substring(selStart, selEnd) + txtcenter + s.substring(selStart, selEnd)+ txtend + s.substring(selEnd, s.length);
	 document.editor_form.message.value = s; 
	if (selEnd != selStart) {
	 document.editor_form.message.selectionStart = selStart;
	 document.editor_form.message.selectionEnd = selEnd + txtstart.length + txtend.length+'123';
	 } else {
	 document.editor_form.message.selectionStart = selStart + txtstart.length;
	 document.editor_form.message.selectionEnd = document.editor_form.message.selectionStart;
	 }
	} else {   
	document.editor_form.message.value += txtstart + txtend;   
	}
}

function input_new_img(url,img_url){
	var tag;
	var alt    = document.getElementById('img_alt').value;
    var title  = document.getElementById('img_title').value;
	var height = document.getElementById('height').value*1;
	var width  = document.getElementById('width').value*1;
	var m_height;
	var m_width;
	var message = document.getElementById('message');
    if(!img_url)
        img_url= document.getElementById('result_src').value;
	if(img_url != ''){
		img_url = url+img_url;
		if(height != '') m_height = ' height="'+height+'" ';else m_height = '';
		if(width != '') m_width = ' width="'+width+'" ';else m_width = '';
        if(title) title = "title=\""+title+"\"";
		tag = '<img src="'+img_url+'" '+title+' alt="'+alt+'"'+m_height+''+m_width+' />';
		lib_window('close','');
		tag_it(tag,'');
	}
}

function margin_m(z){
	var margin = document.getElementById('margin_menu').value;
	if(z == '+'){
		margin++;
		document.getElementById('margin_menu').value = margin;
	}
	if(z == '-'){
		margin--;
		document.getElementById('margin_menu').value = margin;
	}
	var menu_item_1 = document.getElementById('menu_item_1');
	var menu_item_2 = document.getElementById('menu_item_2');
	var menu_item_3 = document.getElementById('menu_item_3');
	var menu_item_4 = document.getElementById('menu_item_4');
	var menu_item_5 = document.getElementById('menu_item_5');
	var menu_item_6 = document.getElementById('menu_item_6');
	var menu_item_7 = document.getElementById('menu_item_7');
	var menu_item_8 = document.getElementById('menu_item_8');
	var menu_item_9 = document.getElementById('menu_item_9');
	menu_item_1.style.paddingLeft = margin;
	menu_item_2.style.paddingLeft = margin;
	menu_item_3.style.paddingLeft = margin;
	menu_item_4.style.paddingLeft = margin;
	menu_item_5.style.paddingLeft = margin;
	menu_item_6.style.paddingLeft = margin;
	menu_item_7.style.paddingLeft = margin;
	menu_item_8.style.paddingLeft = margin;
	menu_item_9.style.paddingLeft = margin;
}
