// JavaScript Document// JavaScript Document
var xmlHttpresult;
var start;
function offeradsearch(nextstart,display){
	start = nextstart;
	var result = document.getElementById("result");
	
	var option = document.getElementById("selectpropertytype");
	var selectoffertype = document.getElementById('selectoffertype');
	var selectpriceoperator = document.getElementById('selectpriceoperator');
	var txtprice = document.getElementById('price');
	var txtkeywords = document.getElementById('searchfor');
	var selectdistrict = document.getElementById('selectdistrict');
	var selectcity = document.getElementById('selectcity');
	
	//edited @  20 02 09
	var date_from = document.getElementById('date_from');
	var date_to = document.getElementById('date_to');
	
	//select attribute div and go through all the elements inside it and insert all the data to an  2-d Array
	var attributediv = document.getElementById('attributes');
	var allContainedattributeoptions = attributediv.getElementsByTagName('select');
	var allContainedattributeinputs = attributediv.getElementsByTagName('input');
		var attributes = new Array();
		
		for (var i = 0; i < (allContainedattributeoptions.length+allContainedattributeinputs.length); i++) {
			attributes[i] = [' ', ' '];
			
		}
		var index = 0;
		for (var p = 0; p < (allContainedattributeoptions.length); p++) {
		 attributes[p][0] = allContainedattributeoptions[p].id;
		 attributes[p][1] = allContainedattributeoptions[p].value;

		//alert(attributes[p][0]);
		//alert(attributes[p][1]);
		index = p+1;
		}
		for (var q = index; q < (allContainedattributeoptions.length+allContainedattributeinputs.length); q++) {
		 attributes[q][0] = allContainedattributeinputs[q - index].id;
		 attributes[q][1] = allContainedattributeinputs[q - index].value;

		//alert(attributes[q][0]);
		//alert(attributes[q][1]);
		}
		
		
	var facilitiesdiv = document.getElementById('facilities');
	var allContainedfacilitiesinput = facilitiesdiv.getElementsByTagName('input');
	var facilities = new Array();
		
		for (var i = 0; i < (allContainedfacilitiesinput.length); i++) {
			facilities[i] = [' ', ' '];
		}
		for (var p = 0; p < (allContainedfacilitiesinput.length); p++) {
		 facilities[p][0] = allContainedfacilitiesinput[p].id;
		 facilities[p][1] = allContainedfacilitiesinput[p].checked;

		//alert(facilities[p][0]);
		//alert(facilities[p][1]);
		}
	
	var url = "Scripts/offeradsearch.php";
	
	var type = option.value;
		url += "?type="+type;
	var offertype = selectoffertype.value;
		url += "&offertype="+offertype;
	var priceoperator = selectpriceoperator.value;
		url += "&priceoperator="+priceoperator;
	var price = txtprice.value;
		url += "&price="+price;
	var searchkeywords = txtkeywords.value;
		url += "&searchkeywords="+searchkeywords;
	var district = selectdistrict.value;
		url += "&district="+district;
	if(display == 'frmsubmit'){
		var city = selectcity.value;
		url += "&city="+city;
	}
	//edited @ 200209
	var date_from = date_from.value;
		url += "&date_from="+date_from;
	var date_to = date_to.value;
		url += "&date_to="+date_to;
	url += "&start="+start;

	url += "&attributes="+attributes;
	
	url += "&facilities="+facilities+"&sid="+Math.random();

	result.innerHTML = '<table height="100%" cellspacing="2"><tr><td><img src="images/ajax-loader.gif" alt="Please Wait"/></td><td></td></tr></table>';

	xmlHttpresult = getXmlHttpObject();

	if (xmlHttpresult == null){
		alert ("Browser Does not Support AJAX");
		return;
		}


  xmlHttpresult.onreadystatechange=state_Changeresult;
  xmlHttpresult.open("GET",url,true);
  xmlHttpresult.send(null);

	}
	
	
function state_Changeresult(){
	if(xmlHttpresult.readyState == 4){
	var result = document.getElementById("result");
	result.innerHTML = xmlHttpresult.responseText;
	window.location = "#results"; 
	var selectpagination = document.getElementById('selectpagination');
	if(selectpagination.value != ''){
		
	var pagination = document.getElementById('paginationvalue');
	var	paginationvalue = pagination.value;
		selectnumber = (start/paginationvalue); 
		selectpagination.options[selectnumber].selected = true;
		}}
	
	}
	

