var xmlHttp;
var root = 'http://'+location.hostname+'/';

function ajax_http()
{
	try
    {
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
	return xmlHttp;
}

function clean_str(str)
{
	str=str.replace(/&/gi,"");
	str=str.replace(/</gi,"");
	str=str.replace(/>/gi,"");
	
	return str;
}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.value = this.value.substring(0,maxLength);
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

function add_click_to_banner(id)
{
	xmlHttp_1=ajax_http();
	
	var url= root + "includes/ajax/adsClicks.inc.php";
	var parameters="id="+ encodeURI(id);
	
	xmlHttp_1.onreadystatechange=function()
	{
	
	}
	 xmlHttp_1.open('POST', url, true);
	 xmlHttp_1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlHttp_1.setRequestHeader("Content-length", parameters.length);
     xmlHttp_1.setRequestHeader("Connection", "close");
     xmlHttp_1.send(parameters);
}

function showCalendar(year, month, day, type)
{
	xmlHttp_2=ajax_http();
	
	var url= root + "includes/ajax/showCalendar.inc.php";
	var parameters="year="+ encodeURI(year) + "&month="+ encodeURI(month) + "&day="+ encodeURI(day) + "&type="+ encodeURI(type);
	var divv = '';
	
	if(type == 1){divv = "ajaxCalendar";}else{divv = "ajaxArchiveCalendar";};
	
	xmlHttp_2.onreadystatechange=function()
	{
		if(xmlHttp_2.readyState==4)
  		{
			document.getElementById(divv).innerHTML = xmlHttp_2.responseText;
		}
	}
	 xmlHttp_2.open('POST', url, true);
	 xmlHttp_2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlHttp_2.setRequestHeader("Content-length", parameters.length);
     xmlHttp_2.setRequestHeader("Connection", "close");
     xmlHttp_2.send(parameters);
}

function readComment(id, type)
{
	xmlHttp_3=ajax_http();
	
	var url= root + "includes/ajax/readComm.inc.php";
	var parameters = "id=" + encodeURI(id) + "&type=" + encodeURI(type);
	
	xmlHttp_3.onreadystatechange=function()
	{
		if(xmlHttp_3.readyState==4)
  		{
			document.getElementById("comment_"+id).innerHTML = xmlHttp_3.responseText;
		}
	}
	 xmlHttp_3.open('POST', url, true);
	 xmlHttp_3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlHttp_3.setRequestHeader("Content-length", parameters.length);
     xmlHttp_3.setRequestHeader("Connection", "close");
     xmlHttp_3.send(parameters);
}

function activateComments()
{
	var tmp = confirm('Вие сте човек ?');
	if(tmp == 1)
	{
		xmlHttp_4=ajax_http();
		
		var url= root + "includes/ajax/activateComments.inc.php";
		var parameters = "";
		
		xmlHttp_4.onreadystatechange=function()
		{
			if(xmlHttp_4.readyState==4)
	  		{
	  			bot_check=1;
				document.getElementById("activateButtonid").style.display = 'none';
				document.getElementById("sthshow").innerHTML = xmlHttp_4.responseText;
			}
		}
		 xmlHttp_4.open('POST', url, true);
		 xmlHttp_4.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	     xmlHttp_4.setRequestHeader("Content-length", parameters.length);
	     xmlHttp_4.setRequestHeader("Connection", "close");
	     xmlHttp_4.send(parameters);
 	}
}

function view(tab, all)
{
	for (var i=1; i<=all; i++) 
	{
		document.getElementById("top"+i).style.display = 'none';
		document.getElementById("toptitle"+i).className = '';
	}
	document.getElementById('top'+tab).style.display = 'block';
	document.getElementById('toptitle'+tab).className = 'h';

}
