// ******************************** START TIPAS *******************************88


function createRequestObject()
{
        var ro;
        var browser = navigator.appName;

        if(browser == "Microsoft Internet Explorer") {
                // on IE, we have to use ActiveX
                ro = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
          // on every other browser, we can directly create a new XMLHttpRequest object
                ro = new XMLHttpRequest();
        }
  return ro;
}

var http = createRequestObject();

// this function should be called for user input
// it opens up a php page with a querystring of 'action'
// this function could probably be adapted to POST
function sndReq(action)
{
        http.open("get", "ajax.php?action=" + action);
        http.onreadystatechange = handleResponse;
        http.send(null);
}


// the response in this case is formatted as follows:
// object|text
// where object is the id of the HTML element we are going to update
// and text is what it will be updated to
// this could obviously work a lot better with some XML
function handleResponse()
{
        if(http.readyState == 4) {
           var response = http.responseText;
           var update = new Array();

			if(response.indexOf('|' != -1)) {
			update = response.split("|");
			document.getElementById(update[0]).innerHTML = update[1];
			}
		}
}

// ***************************** END TIPAS ***************************************

// ******************

var http2 = createRequestObject();

// this function should be called for user input
// it opens up a php page with a querystring of 'action'
// this function could probably be adapted to POST
function sndMst(action)
{
        http2.open("get", "http://www.pietulietuva.lt/mst.php?action=" + action);
        http2.onreadystatechange = handleResponse2;
        http2.send(null);
}


// the response in this case is formatted as follows:
// object|text
// where object is the id of the HTML element we are going to update
// and text is what it will be updated to
// this could obviously work a lot better with some XML
function handleResponse2()
{
        if(http2.readyState == 4) {
           var response = http2.responseText;
           var update = new Array();

        if(response.indexOf('|' != -1)) {
           update = response.split("|");
           document.getElementById(update[0]).innerHTML = update[1];
    }
  }
}
// ******************
//***************** ADD AJAX ************

var http3 = createRequestObject();

function turtas(action)
{
        http3.open("get", "http://www.pietulietuva.lt/add_ajax.php?action=" + action);
        http3.onreadystatechange = handleResponse3;
        http3.send(null);
}
function handleResponse3()
{
		if(http3.readyState == 4) {
           var response = http3.responseText;
           var update = new Array();

        if(response.indexOf('|' != -1)) {
           update = response.split("|");
           document.getElementById(update[0]).innerHTML = update[1];
    }
  }
}

//*************** END ADD AJAX *********
var http4 = createRequestObject();

function nuoma(action)
{
        http4.open("get", "http://www.pietulietuva.lt/add.php?action=" + action);
        http4.onreadystatechange = handleResponse4;
        http4.send(null);
}
function handleResponse4()
{
		if(http4.readyState == 4) {
           var response = http4.responseText;
           var update = new Array();

        if(response.indexOf('|' != -1)) {
           update = response.split("|");
           document.getElementById(update[0]).innerHTML = update[1];
    }
  }
}

// NUOMA
function rajonas() {
	var ra = document.getElementById('viit').selectedIndex
	sndMst(ra);
}

function test() {
	alert("test")
}

function valy() {
  document.getElementById('paieska').reset()
  cookie_delete()
}

function deta() {
  window.location = "/index.php?option=com_ezrealty&Itemid=26&task=search&kriuge=1"
}
function dtipas() {
	var hh = document.getElementById('tiik').selectedIndex
	sndReq(hh);
}

function paies() {
	window.location = "/index.php?kriuge="
}
function visi() {
	window.location = "http://www.pietulietuva.lt/index.php?option=com_adsmanager&page=show_all&Itemid=0"
}
function talpinti() {
	window.location = "/index.php?option=com_adsmanager&page=write_ad&Itemid=0"
}


// cookie source ------------------------------------------------

function cookie_check() {
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

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 ""
}
