var httplogin = createRequestObject();

var httptowns = createRequestObject();

var http_poll = createRequestObject();

var httpvic = createRequestObject();

var XMLHttp = createRequestObject();

var http_banners = createRequestObject();

var http_statsRubrikiStatii = createRequestObject();



function submitenter(myfield, e) {

	var keycode;

	if (window.event) keycode = window.event.keyCode;

	else if (e) keycode = e.which;

	else return true;



	if (keycode == 13) {

		return false;

	} else return true;

}



// login

var log_out='';

function login(name, pass){

	httplogin.open('get', '../start.php?ch=1&name='+name+'&pass='+pass+'&sub=da'+'&z='+Math.random());

	httplogin.onreadystatechange = loginHandleInfo;

	if (name=='exit') { log_out=name; }

	httplogin.send(null);

}

//--------------------



function loginHandleInfo(){

	if(httplogin.readyState == 1) {

		// document.getElementById('oh').innerHTML = 'Loading...';

		;

	}

	if(httplogin.readyState == 4) {

		var response = httplogin.responseText;

		var result=response.split('!@#');

		document.getElementById('vhod').innerHTML = result[0];

	}

	if (result[1]=='OK') { window.location="http://www.bania.bg/account.htm"; }

	if (log_out=='exit') { window.location="http://www.bania.bg"; }

}



function towns() {

	httptowns.open('get', '../towns.php?z='+Math.random()+'&sub=da');

	httptowns.onreadystatechange = townsHandleInfo;

	httptowns.send(null);

}



function townsHandleInfo(){

	if(httptowns.readyState == 1){

	// document.getElementById('oh').innerHTML = 'Loading...';

	;

	}

	if(httptowns.readyState == 4){

	 var response = httptowns.responseText;

		document.getElementById('towns').innerHTML = response;

	}

}



function show_poll() {

	http_poll.open('get', '../poll.php?z='+Math.random()+'&sub=da');

	http_poll.onreadystatechange = pollHandleInfo;

	http_poll.send(null);

}



function vote(ans, id) {

	if (ans!='') {

		http_poll.open('get', '../poll.php?ans='+ans+'&id='+id+'&z='+Math.random());

		http_poll.onreadystatechange = pollHandleInfo;

		http_poll.send(null);

	} else {

		alert('За да гласувате първо трябва да изберете отговор!');

	}

}



function pollHandleInfo(){

	if(http_poll.readyState == 1){

	// document.getElementById('oh').innerHTML = 'Loading...';

	;

	}

	if(http_poll.readyState == 4){

	 var response = http_poll.responseText;

		document.getElementById('anketata').innerHTML = response;

	}

}



function poll_arch() {

	http.open('get', '../poll_arch.php?z='+Math.random());

	http.onreadystatechange = searchHandleInfo;

	http.send(null);

}



function short_search(text, type, town) {

	http.open('get', '../search.php?text='+encodeURIComponent(text)+'&type='+encodeURIComponent(type)+'&town='+encodeURIComponent(town)+'&sub=da'+'&z='+Math.random());

	http.onreadystatechange = searchHandleInfo;

	http.send(null);

}



//search pages



function visual_search(text,type,page){

http.open('get', '../search.php?text='+encodeURIComponent(text)+'&type='+encodeURIComponent(type)+'&page='+page+'&sub=da&z='+Math.random());

http.onreadystatechange = searchHandleInfo;

http.send(null);

}

//--------------------



function searchHandleInfo(){

	if(http.readyState == 1){

	// document.getElementById('oh').innerHTML = 'Loading...';

	;

	}

	if(http.readyState == 4){

	 var response = http.responseText;

		document.getElementById('middleside').innerHTML = response;

	}

}



//vicyt 

function vicyt() {

httpvic.open('get', '../vicyt.php?z='+Math.random());

httpvic.onreadystatechange = viewvicyt;

httpvic.send(null);

}



function viewvicyt(){

	if(httpvic.readyState == 1){

	// document.getElementById('oh').innerHTML = 'Loading...';

	;

	}

	if(httpvic.readyState == 4){

	 var response = httpvic.responseText;

		document.getElementById('vicyt').innerHTML = response;

	}

}

//---------------

function mili_time() {

var d = new Date();

return d.valueOf();

}



//var url='';

function banners(id, ev, url, target)

{

	http_banners.open('get', '../baners.php?id='+id+'&event='+ev+'&url='+url+'&target='+target+'&z='+mili_time(), false);

	http_banners.onreadystatechange = banersHandleInfo;

	http_banners.send(null);

	if (ev=='onclick' && url!='') {

		if (target=='1') {

			window.open(url);

		} else {

			window.location=url;

		}

	}

}



function banersHandleInfo(){

	

	if(http_banners.readyState == 4) {

		if (http_banners.responseText!='') {

			/*var response = eval("("+http_banners.responseText+")");

	//		alert(response.target+' '+response.url);

			if (response.event=='onclick' && response.url!='') {

				if (response.target=='1') {

					window.open(response.url);

				} else {

					window.location=response.url;

				}

			}*/

		}

	}

}



//stats Rubriki Statii
function statsRubrikiStatii(type,id)
{	
	http_statsRubrikiStatii.open('get', '../response.php?id='+id+'&type='+type+'&z='+Math.random());
	http_statsRubrikiStatii.onreadystatechange = statsRubrikiStatiiHandleInfo;
	http_statsRubrikiStatii.send(null);
}
function statsRubrikiStatiiHandleInfo(){
	if(http_statsRubrikiStatii.readyState == 4) {
		if (http_statsRubrikiStatii.responseText!='') {
			var response=http_statsRubrikiStatii.responseText;
			//alert(response);
		}
	}
}



//stats Rubriki Statii