var searchArea = document.getElementById("searchgeo");
var searchType = document.getElementById("searchtype");

var form = document.Start;

function SubmitForm()
{
	__doPostBack('btnSearch', '');	
}

function LookUpArea( opt )
{           
    var PropertyType = "";
    for (var  i = 0; i < form.elements.length; i++ )
    {
        if ( form.elements[i].type == "checkbox" )
        {
            if ( form.elements[i].id.indexOf( "chklPropertyType" ) != -1 )
            {
                if (  form.elements[i].checked )
                {
                    PropertyType = PropertyType + "1";
                }
                else
                {
                    PropertyType = PropertyType + "0";
                }
            }
        }
    }
    if ( opt == "-1" )		        
    {
       CallServer( searchType.value + "," + PropertyType );
    }
    else
    {
        CallServer( opt.value + "," + PropertyType );
    }

}
function setItemsToZero( select )
{
    var b = 0;
    var e = 0;
    var nodeText = "";
    if( select.length > 0 )
    {
        for( var i = 0; i < select.length; i++ )
        {
            b = select.options[i].text.indexOf("(");
            e  = select.options[i].text.indexOf(")");
            if ( b != -1 && e != -1 && e > b )
            {
                select.options[i].text = select.options[i].text.substring( 0, b ) + " (0 listings)";
            }
        }
    }	
}
function ReceiveServerData( XML )
{
    searchArea.options.length = 0;
    populateList( searchArea, XML, "<SC>", "</SC>", "<DC>", "</DC>" );
}
function populateList( lstBox, rsp, vb, ve, tb, te)
{
    var scb = 0;
    var sce = 0;
    var dcb = 0;
    var dce = 0;
    var flg = 0;
    var nodeText = ""; 
    var nodeId = "";
    var i = 0;
    
    while ( true )
    {
        scb = rsp.indexOf(vb, scb) + vb.length;
        if ( scb == -1 + vb.length )
        {
            return;
        }
        if ( flg > scb )
        {
            return;
        }
        else
        {
            flg = scb;
        }
        sce = rsp.indexOf(ve, scb);
        dcb = rsp.indexOf(tb, dcb) + tb.length;
        dce = rsp.indexOf(te, dcb);
         nodeId = rsp.slice( scb, sce );
         nodeText = rsp.slice( dcb, dce );                  
        appendToSelect(lstBox, nodeId, nodeText, i);
        i++;
    }
}
function appendToSelect(select, value, content, i)
{
	var opt;
	opt = document.createElement("option");
    if ( i == 0 )
	{
	    opt.selected = true;
	}
	opt.value = value;
	opt.appendChild(document.createTextNode( content ));
	select.appendChild(opt);
}                          


