
function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function ajax_fast_search_loc(id_field,table,field,value,field_id)
{
	el = document.getElementById('finder');
	place = document.getElementById('place');
	loading = document.getElementById('loading');
	
	serverPage="/bxml.php?param="+el.value+"&table="+table+"&field="+field+"&value="+value+"&field_id="+field_id+"&id_field="+id_field+"&callfunc=put&type=ul";
	
	loading.style.display = "block";

	var xmlhttp=getXmlHttp();

	xmlhttp.open("GET",serverPage);
	xmlhttp.onreadystatechange = function() {
 		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			place.style.display = "block";
			place.innerHTML = xmlhttp.responseText;
			loading.style.display = "none";
			document.getElementById('banned_user_id').value='';
		}
		
	}
	
	xmlhttp.send(null);	
}

function ajax_fast_search_tag()
{
	el = document.getElementById('finder');
	place = document.getElementById('place');
	loading = document.getElementById('loading');
	value = el.value;
	var find = value.split(",");
	var count = find.length;
	//alert(find[count-1]);
	value = find[count-1];
//	alert(value);
	serverPage="/bxml.php?param="+value+"&table=tags&field=tag&value=finder&field_id=&id_field=id&callfunc=put_tag&type=line";
	
	loading.style.display = "block";

	var xmlhttp=getXmlHttp();

	xmlhttp.open("GET",serverPage);
	xmlhttp.onreadystatechange = function() {
 		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			place.style.display = "block";
			place.innerHTML = xmlhttp.responseText;
			loading.style.display = "none";
		}
		
	}
	
	xmlhttp.send(null);	
}

function put(id,value,field,field_id)
{
	el = document.getElementById(field);
	el_id = document.getElementById(field_id);
	if (el&&el_id)
	{
		el.value = value;
		el_id.value = id;
		place.style.display = "none";
	}
}

function ltrim(s)
{
	var l=0;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	return s.substring(l, s.length);
}

function put_tag(id,value,field,field_id)
{
	el = document.getElementById(field);
	if (el)
	{
		res = el.value;
		var find = res.split(",");
		
		var count = find.length;
		for (m=0;m<count-1;m++)
		{
			find[m] = ltrim(find[m]);
		}
		
		find[count-1]=value;
		
		s = find.join(', ');
		el.value = s;
		place.style.display = "none";
	}
}

function show(nam)
{
	ccat = document.getElementById('ccat');
	if (ccat)
	{
		if (ccat.style.display == 'block')
			ccat.style.display = 'none';
		else
			ccat.style.display = 'block';
	}
}

function showel(el)
{
	qwe = document.getElementById(el);
	if (qwe)
	{
		if (qwe.style.display == 'block')
			qwe.style.display = 'none';
		else
			qwe.style.display = 'block';
	}
}

function created()
{
	show('ccat');
	ccat = document.getElementById('ccat');
	ref = document.getElementById('ref');
	
	if (ccat){ 
		ref.click();
	}
}

function refreshing()
{
	place = document.getElementById('refresh_place');
	pc = document.getElementById('place_for_content');
	pc.innerHTML = place.innerHTML;
	place.innerHTML = '<input type="submit" id="ref" class="button button-highlighted" value="asd" />';
}