// JavaScript Document
var xmlHttp, _field, _id, _act;
/*****************************************************************/

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


function changeRatio(id, dir){
	_id = id;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Ваш браузер не поддерживает HTTP Request");
		return;
	}
	var url="core/users/change_ratio.php?user_id="+id+'&dir='+dir;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = checkRatio_res;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function checkRatio_res(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById("ratio_"+_id).innerHTML=xmlHttp.responseText 
 } 	
 return;
}

function checkLogin(el){
	var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (document.getElementById(el).value == "") {
        error = "Вы не ввели имя пользователя.\n";
    } else if ((document.getElementById(el).value.length < 5) || (document.getElementById(el).value.length > 20)) {
        error = "Длина должна быть от 5 до 20 символов.\n";
    } else if (illegalChars.test(document.getElementById(el).value)) {
        error = "Вы ввели запрещеные символы.\n";
    } 
		
	if(error!=''){
		document.getElementById('result').style.display='block';
		document.getElementById("result").innerHTML = error;
	}else{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Ваш браузер не поддерживает HTTP Request");
		return;
	}
	var url="core/user/check_user.php?user="+document.getElementById(el).value;
	document.getElementById('loading').style.display='block';
	document.getElementById('result').style.display='none';
	//document.getElementById('h_'+_field).innerHTML=xmlHttp.responseText 
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.onreadystatechange = checkLogin_res;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	}
}

function checkLogin_res(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById('loading').style.display='none';
	document.getElementById('result').style.display='block';
	document.getElementById("result").innerHTML=xmlHttp.responseText 
 } 	
 return;
}

function show_hidden_info(id, field){
	_field=field;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Ваш браузер не поддерживает HTTP Request");
		return;
	}
	var url="core/board/show_hidden_info.php?id="+id+"&field="+field+"&ajax=1";
	document.getElementById('h_'+_field).style.display='none'; 
	document.getElementById('l_'+_field).style.display='block';
	//document.getElementById('h_'+_field).innerHTML=xmlHttp.responseText 
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.onreadystatechange=show_res;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function show_res(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById("h_"+_field).style.display='';
	document.getElementById("l_"+_field).style.display='none';
	document.getElementById("h_"+_field).innerHTML=xmlHttp.responseText 
 } 	
 return;
}
function show_variants(field_type){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Ваш браузер не поддерживает HTTP Request");
		return;
	}
	var url="view/cats/fconstr/fields_var.php?field_type="+field_type+"&ajax=1";
	
	url=url+"&sid="+Math.random();
	//alert(url);
	//document.getElementById("loading_favourites").style.display = "";
	xmlHttp.onreadystatechange=show_var_res;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function show_var_res(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	
	document.getElementById("new_field_container").innerHTML=xmlHttp.responseText 
 } 	
 return;
}

function Notepad(id, act){
	_id = id;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Ваш браузер не поддерживает HTTP Request");
		return;
	}
	var url="core/board/NotepadChange.php?&act="+act+"&id="+id+"&ajax=1";
	
	url=url+"&sid="+Math.random();
	//alert(url);
	//document.getElementById("loading_favourites").style.display = "";
	xmlHttp.onreadystatechange=show_Notepad_res;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function show_Notepad_res(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById("fav_item_"+_id).innerHTML=xmlHttp.responseText;
	np = getCookie('notepad').split("#")
	if(getCookie('notepad')!='')document.getElementById("notepad_count").innerHTML=np.length; else document.getElementById("notepad_count").innerHTML='';
 } 	
 return;
}

function CheckUncheck(id, act){
	_id = id;
	_act = act;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Ваш браузер не поддерживает HTTP Request");
		return;
	}
	var url="core/board/checkListChange.php?&act="+act+"&id="+id+"&ajax=1";
	
	url=url+"&sid="+Math.random();
	//alert(url);
	//document.getElementById("loading_favourites").style.display = "";
	xmlHttp.onreadystatechange=show_Checked_res;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function show_Checked_res(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	if(_act=='del_all'){
		document.getElementById("count_selected").innerHTML='0'
	}else{
		document.getElementById("check_uncheck_butt_"+_id).innerHTML=xmlHttp.responseText;
		values = getCookie('sel_posts_board_admin').split("#");
		values = values.remove("");
		values = values.remove(" ");
		values = values.remove("+");
		values = values.unique();
		if(getCookie('sel_posts_board_admin')!='')document.getElementById("count_selected").innerHTML=values.length; else document.getElementById("count_selected").innerHTML='0';
	}
 } 	
 return;
}

function eventHandler(name, url)
{
	var checkName=name;
 	location.replace(url+"?act=change_check&name="+checkName);

}
/************************************************************/
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
