

    function getFirstParaElement()
    {
    if (fieldsetElement.hasChildNodes())
    {
    for(var i=0; i < fieldsetElement.childNodes.length; i++)
    {
    var child = fieldsetElement.childNodes[i];
    if (child != null)
    {
    if (child.tagName == "P") return child;
    }
    }
    }
    }

    function addCustomRegionOptions(listBox, itemArray)
    {
    for (var i=0; i < itemArray.length; i++)
    {
    listBox.options[i] = new Option( itemArray[i][0], itemArray[i][1] );
    }
    }

    function removeGeoSearchBox()
    {
    var geo = document.getElementById("qs-locality");
    if (geo != null) {
    var parent = geo.parentNode;
    if (geo != parent){
    parent.removeChild(geo);
    }
    }
    }

    function removeChildren(parent)
    {
    if (parent.hasChildNodes())
    {
    while(cell.childNodes.length >= 1 )
    {
    parent.removeChild( parent.firstChild );
    }
    }
    }

    function deleteOptions(cs)
    {
    if (cs == null) return;

    var cs;
    var formOptions = cs.options;
    for(var i=0; i < formOptions.length; i++)
    {
    formOptions[i] = null;
    if (formOptions.length > 0)
    {
    return deleteOptions(cs);
    }
    }
    }

    function addOptions(s,o,db)
    {
    var s;
    var o;
    var db;
    var pound = String.fromCharCode(163);
    for(var i=0; i < o.length; i++)
    {
    var maxValue = maxPrices[db];
    var addPlus = (s.getAttribute("id") == 'hip');
    s.options[i] = new Option(pound + addCommas(Number(o[i])) + Options(Number(o[i]),db,addPlus), Number(o[i]), addPlus);
    if (s.getAttribute("id") == 'hip' && Number(o[i]) == maxValue)
    {
    s.selectedIndex = i;
    }
    }
    }



    function Options(val,db,addPlus)
    {
    var add;
    var val;
    var db;
    var maxValue = maxPrices[db];
    if (addPlus && val == maxValue) {
    add = (db==2) ? ' p.c.m.+' : '+';
    } else {
    add = (db==2) ? ' p.c.m.' : '';
    }
    return add;
    }

    function addCommas(nStr)
    {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
    }

    function changeSubmitType(selected_type)
    {
    var inputs = document.getElementById("qs-submit").getElementsByTagName("input");
    for(var i=0; i < inputs.length; i++)
    {
    var ci = inputs[i];
    if (ci.getAttribute("name") == 'dbtype' )
    { ci.setAttribute("value", selected_type); return false; }
    }
    }

    function getFormTypeText(selected_type)
    {
    switch(selected_type){
    case 1: return "Sales"; break;
    case 2: return "Rentals"; break;
    default: return "Other"; break;
    }
    }

    function radioClick(selected_type, ele)
    {
    var lowprice = document.getElementById("lop");
    var highprice = document.getElementById("hip");
    var legendText = document.createTextNode( getFormTypeText(selected_type) );
    var legend = formElement.getElementsByTagName("legend")[0];
    legend.replaceChild(legendText,legend.firstChild);

    var lowPriceOptions = priceRanges[selected_type];
    var highPriceOptions = lowPriceOptions;

    
    if (customRegionSelector) {
    var customRegionListBox = document.getElementById("alo");
    if (typeof(customRegions[selected_type]) == "undefined") {
    if (customRegionListBox != null) {
    var customRegionsPara = document.getElementById("qs-regions");
    fieldsetElement.removeChild( customRegionsPara );
    }

    if (typeof(addGeoSearchBox) == 'function') addGeoSearchBox();
    } else {
    if (customRegionListBox == null)
    {
    addCustomRegionSelector();
    removeGeoSearchBox();
    }
    customRegionListBox = document.getElementById("alo");
    deleteOptions(customRegionListBox);
    addCustomRegionOptions(customRegionListBox, customRegions[selected_type]);
    }
    } else {
    if (typeof(addGeoSearchBox) == 'function') addGeoSearchBox();
    }

    deleteOptions(lowprice);
    deleteOptions(highprice);
    addOptions(lowprice, lowPriceOptions, selected_type);
    addOptions(highprice, highPriceOptions, selected_type);

    changeSubmitType(selected_type);

    }
  

      var quicksearchDiv = document.getElementById("quicksearch");



      var formElement = document.createElement("form");
      var fieldsetElement = document.createElement("fieldset");
      var legendElement = document.createElement("legend");
      var labelElement = document.createElement("label");
      var selectElement = document.createElement("select");
      var optionElement = document.createElement("option");
      var inputElement = document.createElement("input");
      var paraElement = document.createElement("p");
      var unorderedElement = document.createElement("ul");
      var listItemElement = document.createElement("li");
      var textElement = document.createTextNode("empty");

      quicksearchDiv.appendChild(formElement);
      formElement.appendChild(fieldsetElement);
      fieldsetElement.appendChild(legendElement);

      var priceRanges = new Array();
      var maxPrices = new Array();

      var customRegions = new Array();
      var customRegionSelector = false;

      var legendText = document.createTextNode("Sales");
      legendElement.appendChild(legendText);

      
    var formAction = 'http://search.thinkproperty.com/oceanandcountry/property/search';
    var formMethod = 'post';
    var formID = 'search';

    var prices = [
    
      '0',
      '25000',
      '50000',
      '75000',
      '100000',
      '125000',
      '150000',
      '175000',
      '200000',
      '300000',
      '400000',
      '500000',
      '600000',
      '700000',
      '800000',
      '900000',
      '1000000',
      '3000000',
      '6000000'];
    maxPrices[1] = 6000000;
    priceRanges[1] = prices;
  

      formElement.setAttribute("action", formAction);
      formElement.setAttribute("method", formMethod);
      formElement.setAttribute("id", formID);



      
          var regions1 = [
          
            ['All','ALL'],
            ['Looe','Looe'],
            ['Polperro','Polperro'],
            ['Seaton / Downderry','Seaton / Downderry']];
          customRegions[1] = regions1;
        

        customRegionSelector = true;

        function addCustomRegionSelector() {var paraElement = document.createElement("p");
    var paraID = 'qs-regions';
    paraElement.setAttribute("id", paraID);

        labelElement = document.createElement("label");
        labelElement.setAttribute("for", "alo" );
        textElement = document.createTextNode("Regions");
        labelElement.appendChild(textElement);
        paraElement.appendChild(labelElement);
        selectElement = document.createElement("select");
        selectElement.setAttribute("name","alo");
        selectElement.setAttribute("id","alo");
        paraElement.appendChild(selectElement);
        var firstPara = getFirstParaElement();
        if (firstPara != null) {
        firstPara.parentNode.insertBefore(paraElement, firstPara);
        } else {
        fieldsetElement.appendChild(paraElement);
        }
        }
      var paraElement = document.createElement("p");
    var paraID = 'qs-beds';
    paraElement.setAttribute("id", paraID);labelElement = document.createElement("label");
    labelElement.setAttribute("for", "bed" );
    
        textElement = document.createTextNode("Bedrooms");
      
    labelElement.appendChild(textElement);
    paraElement.appendChild(labelElement);


    selectElement = document.createElement("select");
    selectElement.setAttribute("name","bed");
    selectElement.setAttribute("id","bed");
    paraElement.appendChild(selectElement);optionElement = document.createElement("option");
        optionElement.setAttribute("value", "-1");
        
        textElement = document.createTextNode("Studio");
        optionElement.appendChild(textElement);selectElement.appendChild(optionElement);optionElement = document.createElement("option");
        optionElement.setAttribute("value", "0");
        optionElement.setAttribute("selected", "selected");
        textElement = document.createTextNode("No preference");
        optionElement.appendChild(textElement);selectElement.appendChild(optionElement);optionElement = document.createElement("option");
        optionElement.setAttribute("value", "1");
        
        textElement = document.createTextNode("1+");
        optionElement.appendChild(textElement);selectElement.appendChild(optionElement);optionElement = document.createElement("option");
        optionElement.setAttribute("value", "2");
        
        textElement = document.createTextNode("2+");
        optionElement.appendChild(textElement);selectElement.appendChild(optionElement);optionElement = document.createElement("option");
        optionElement.setAttribute("value", "3");
        
        textElement = document.createTextNode("3+");
        optionElement.appendChild(textElement);selectElement.appendChild(optionElement);optionElement = document.createElement("option");
        optionElement.setAttribute("value", "4");
        
        textElement = document.createTextNode("4+");
        optionElement.appendChild(textElement);selectElement.appendChild(optionElement);optionElement = document.createElement("option");
        optionElement.setAttribute("value", "5");
        
        textElement = document.createTextNode("5+");
        optionElement.appendChild(textElement);selectElement.appendChild(optionElement);fieldsetElement.appendChild(paraElement);var paraElement = document.createElement("p");
    var paraID = 'qs-pricerange';
    paraElement.setAttribute("id", paraID);labelElement = document.createElement("label");
    labelElement.setAttribute("for", "lop" );
    
        textElement = document.createTextNode("Minimum Price");
      
    labelElement.appendChild(textElement);
    paraElement.appendChild(labelElement);


    selectElement = document.createElement("select");
    selectElement.setAttribute("name","lop");
    selectElement.setAttribute("id","lop");
    paraElement.appendChild(selectElement);labelElement = document.createElement("label");
    labelElement.setAttribute("for", "hip" );
    
        textElement = document.createTextNode("Maximum Price");
      
    labelElement.appendChild(textElement);
    paraElement.appendChild(labelElement);


    selectElement = document.createElement("select");
    selectElement.setAttribute("name","hip");
    selectElement.setAttribute("id","hip");
    paraElement.appendChild(selectElement);fieldsetElement.appendChild(paraElement);var paraElement = document.createElement("p");
    var paraID = 'qs-submit';
    paraElement.setAttribute("id", paraID);
    var hiddenField = document.createElement("input");
    hiddenField.setAttribute("name", "key");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("value", "oceanandcountry");
    paraElement.appendChild(hiddenField);
  
    var hiddenField = document.createElement("input");
    hiddenField.setAttribute("name", "dbtype");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("value", "1");
    paraElement.appendChild(hiddenField);
  
    var hiddenField = document.createElement("input");
    hiddenField.setAttribute("name", "action");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("value", "search");
    paraElement.appendChild(hiddenField);
  
    var submitButton = document.createElement("button");
    submitButton.setAttribute("type", "submit");
    if (submitButton.type == "button") {
    /*IE doesnt like setting attributes to buttons in javascript */
    try{
    submitButton = document.createElement("<button type=\"submit\" id=\"submit\" name=\"name\" value=\"Search now!\"></button>");
    } catch(err) {
    submitButton = document.createElement("input");
    submitButton.setAttribute("type", "submit");
    }
    }
    submitButton.setAttribute("id", "submit");
    submitButton.setAttribute("name", "submit");
    textElement = document.createTextNode("Search now!");
    submitButton.appendChild(textElement);
    paraElement.appendChild(submitButton);
    fieldsetElement.appendChild(paraElement);
  

      radioClick( 1 );
    