var httplogin = createRequestObject();



var httptowns = createRequestObject();



var http_poll = createRequestObject();



var XMLHttp = createRequestObject();



var http_banners = createRequestObject();



var http_statsRubrikiStatii = createRequestObject();



var httpSendDiscountMail = 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+'&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://bania.bg/account.htm"; }



		if (log_out=='exit') { window.location="http://bania.bg"; }



	}



}







function towns() {



	httptowns.open('get', 'towns.php?z='+Math.random());



	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());



	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)+'&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;



	}



}







//search pages







function visual_search(text,type,page){



http.open('get', 'search.php?text='+encodeURIComponent(text)+'&type='+encodeURIComponent(type)+'&page='+page+'&z='+Math.random());



http.onreadystatechange = searchHandleInfo;



http.send(null);



}



//--------------------







function mili_time() {



var d = new Date();



return d.valueOf();



}







//var url='';



function banners(id, ev, url, target) {
	if (url!=null) {
		url=url.replace("http://", "");
//		alert(url);
	}

//	if(id==23 && ev=='onclick') alert('baners.php?id='+id+'&event='+ev+'&url='+url+'&target='+target+'&z='+mili_time());
	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("http://"+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







function sendDisc(id,mail){



	httpSendDiscountMail.open('get', 'response.php?type=sendDisc&id='+id+'&mail='+mail+'&z='+Math.random());



	httpSendDiscountMail.onreadystatechange = handleSendDiscountMail;



	httpSendDiscountMail.send(null);



}







function handleSendDiscountMail(){



	if(httpSendDiscountMail.readyState == 4) {



		if (httpSendDiscountMail.responseText!='') {



			var response=httpSendDiscountMail.responseText;



			alert(response);	



		}



	}



	



}
