
var searchURI    = '/kereso/fgep_start/';

/*--------------------------------------
	Script Stuff
--------------------------------------*/
var searchReq = false;
var t = null;
var searchReqLast = "";
var searchReqThis = "";
var isIE = false;

// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	searchReq = new XMLHttpRequest();
}


function searchReqInit() {

   price1 = document.getElementById('price1');
   price2 = document.getElementById('price2');
   res1 = document.getElementById('res1');
   res2 = document.getElementById('res2');
   focal1 = document.getElementById('focal1');
   focal2 = document.getElementById('focal2');
   review = document.getElementById('review');
   discontinued = document.getElementById('discontinued');
   resultE = document.getElementById('result');
   category = document.getElementById('category');
   zoom = document.getElementById('zoom');
   sort = document.getElementById('sort');
}

function searchReqStart(page) {
	if(page!=1) {
		ppE.value = 0;
	}
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("searchReqDoReq()",100);
}

function searchReqDoReq() {
        for (var x = 0; x < category.options.length; x++) {
          if (category.options[x].selected) {
            selectedCategory = category.options[x].value;
          }
        }
        for (var x = 0; x < zoom.options.length; x++) {
          if (zoom.options[x].selected) {
            selectedZoom = zoom.options[x].value;
          }
        }
        for (var x = 0; x < sort.options.length; x++) {
          if (sort.options[x].selected) {
            selectedSort = sort.options[x].value;
          }
        }
        reviewValue = (review.checked) ? 1 : 0;
        searchReqThis = 'price1/' + encodeURI(price1.value) + '/price2/' + encodeURI(price2.value) +
                        '/res1/' + encodeURI(res1.value) + '/res2/' + encodeURI(res2.value) +
                        '/focal1/' + encodeURI(focal1.value) + '/focal2/' + encodeURI(focal2.value) +
                        '/review/' + encodeURI(reviewValue) + '/category/' + encodeURI(selectedCategory) + 
			'/zoom/' + encodeURI(selectedZoom) + '/discontinued/' +  encodeURI(discontinued) +
			'/sort/' + encodeURI(selectedSort);
	if (searchReqLast != searchReqThis) {
		if (searchReq && searchReq.readyState < 4) {
			searchReq.abort();
		}
		if (window.XMLHttpRequest) {
			if(isIE) {
				searchReq = new XMLHttpRequest();
			}
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject || isIE) {
			searchReq = new ActiveXObject("Microsoft.XMLHTTP");
		}

		resultE.innerHTML = "<h3 id=status>Keresés...</h3><img src='http://pixinfo.com/i/pixinfo_logo_rotating.gif'>";
		searchReq.onreadystatechange = searchReqProcessReqChange;
		searchReq.open("GET", searchURI + searchReqThis);
		searchReqLast = searchReqThis;
		searchReq.send(null);
	}
}

function searchReqProcessReqChange() {
	if (searchReq.readyState == 4) {
		resultE.innerHTML = searchReq.responseText;
	}
}

function searchReqPage(p) {
  ppE.value=p;
  searchReqStart(1);
}

addEvent(window, 'load', searchReqInit, false);
