var path="db/";
document.write(
'<link href="db/Styles/nstyle/extra.css" type="text/css" rel="stylesheet">' +
'<form id="searchbox_small" class="edit" style="MARGIN: 0 0 20px 0" name="searchbox_small" action="' + path + 'n_list.php?ccsForm=searchbox" method="get" target="_top">  ' +
'  <h3 class="text1_search_small"><label for="searchbox_small_search">Search property by name</label></h3> ' +
'  <p><input id="searchbox_small_search" style="WIDTH: 95%" maxlength="60" value="" name="s_keyword"></p> ' +
'  <h3 class="text1_search_small"><label for="s_search_type">I want to...</label></h3> ' +
'  <p>' +
'  <select id="s_search_type" style="width: 70%" name="s_search_type">' +
'    <option value="" selected>&lt;rent&nbsp;or&nbsp;buy&gt;</option>' +
'  </select>' +
' </p> ' +
' <h3 class="text1_search_small"><label for="s_type">Object type ...</label></h3> ' +
'  <p><select id="s_type" style="width: 70%" name="s_type">' +
'      <option value="" selected>Villa/App.</option>' +
'     </select>' +
' </p>' +
' ' +
'  <h3 class="text1_search_small"><label for="s_min_bedrooms">Bedrooms</label></h3> ' +
'  <p>' +
'    <div style="width: 95%; text-align: center;"> ' +
'  <div style="width:42%;float:right;"><select id="s_max_bedrooms" style="width:100%" name="s_max_bedrooms">' +
'  <option value="" selected>&lt;max&gt;</option>' +
'  </select></div>' +
' <div style="float:left;width: 42%"><select style="width:100%" id="s_min_bedrooms"  name="s_min_bedrooms">' +
'       <option value="" selected>&lt;min&gt;</option> ' +
'      </select></div><div style="margin:0;padding:3px 0;border:0;">to</div>' +
' </div></p> ' +
'  <div style="clear: both;"><h3 class="text1_search_small"><label for="s_area">Area</label></h3> ' +
'  <p>' +
'  <select id="s_area" style="WIDTH: 95%" name="s_area" onchange="fill_project_listbox(this)">' +
'    <option value="" selected>&lt;select&nbsp;an&nbsp;area&gt;</option> ' +
'  </select>' +
' </p></div>' +
' <h3 class="text1_search_small"><label for="s_project">Project</label></h3> ' +
'  <p>' +
'  ' +
'  <select id="s_project" style="WIDTH: 95%" name="s_project">' +
'    <option value="" selected>&lt;select&nbsp;a&nbsp;project&gt;</option> ' +
'  </select> ' +
'  <p class="tdbutton">' +
'  <input class="Button" id="searchbox_smallButton_DoSearch" type="submit" alt="Search" value="Search" name="Button"></p>' +
'</form>');

function fill_project_listbox() {
  var dependentElement = $("s_project");
  sender = $("s_area");
  new Ajax.Request(path + "/services/ws_s_project.php?area_id=" + sender.value, {
    method: "get",
    requestHeaders: ["If-Modified-Since", new Date(0)],
    onLoading:  function(transport) {
                  dependentElement.options.length = 0;
                  dependentElement.options[0] = new Option("<select a project>", "")           
                },
    onSuccess:  function(transport) {
                  var valueRows = eval(transport.responseText);
                  for (var i = 0; i < valueRows.length; i++) {
                    dependentElement.options[dependentElement.options.length] = new Option(valueRows[i]["1"], valueRows[i]["0"]);
                  } 
                }, 
    onFailure:  function(transport) {
                  alert(transport.responseText);
                }
  });
}

function fill_listbox(el, service_url) {
  var element = $(el)
  new Ajax.Request(service_url, {
    method: "get",
    requestHeaders: ["If-Modified-Since", new Date(0)],    
    onSuccess: function(transport) {
      var valueRows = eval(transport.responseText);
      for(var i=0; i < valueRows.length; i++) {        
        element.options[element.options.length] = new Option(valueRows[i][1], valueRows[i][0]);
      }
    },
    onFailure: function(transport) {
      alter(transport.responseText);
    }
  });
}
fill_listbox("s_search_type", path + "/services/ws_s_search_type.php");
fill_listbox("s_type", path + "/services/ws_s_object_type.php");
fill_listbox("s_min_bedrooms", path + "/services/ws_s_bedrooms.php");
fill_listbox("s_max_bedrooms", path +"/services/ws_s_bedrooms.php");
fill_listbox("s_area", path + "/services/ws_s_area.php");    
fill_project_listbox();
