function RenderResults()
{
	var strSearchQueryString      = document.getElementById( "hdnSearchQueryString"      ).value;
	var strSearchQueryBedrooms    = document.getElementById( "hdnSearchQueryBedrooms"    ).value;
	var strSearchQueryMinPrice    = document.getElementById( "hdnSearchQueryMinPrice"    ).value;
	var strSearchQueryMaxPrice    = document.getElementById( "hdnSearchQueryMaxPrice"    ).value;
	var strOrigPropID             = document.getElementById( "hdnOrigPropID"             ).value;
	var strBedroomsW              = document.getElementById( "hdnBedroomsW"              ).value;
	var strPriceRangeW            = document.getElementById( "hdnPriceRangeW"            ).value;
	var strSearchQueryTargetPrice = document.getElementById( "hdnSearchQueryTargetPrice" ).value;
	var strTargetPriceW           = document.getElementById( "hdnTargetPriceW"           ).value;
	var strLocationW              = document.getElementById( "hdnLocationW"              ).value;
	
	if( strSearchQueryBedrooms    != "" )
		strSearchQueryString += "&xBdrms="        + strSearchQueryBedrooms;
	if( strSearchQueryMinPrice    != "" )
		strSearchQueryString += "&xMinPrice="     + strSearchQueryMinPrice;
	if( strSearchQueryMaxPrice    != "" )
		strSearchQueryString += "&xMaxPrice="     + strSearchQueryMaxPrice;
	if( strOrigPropID             != "" )
		strSearchQueryString += "&xOrigPropID="   + strOrigPropID;
	if( strBedroomsW              != "" )
		strSearchQueryString += "&xBedroomsW="    + strBedroomsW;
	if( strPriceRangeW            != "" )
		strSearchQueryString += "&xPriceRangeW="  + strPriceRangeW;
	if( strSearchQueryTargetPrice != "" )
		strSearchQueryString += "&xTargetPrice="  + strSearchQueryTargetPrice;
	if( strTargetPriceW           != "" )
		strSearchQueryString += "&xTargetPriceW=" + strTargetPriceW;
	if( strLocationW              != "" )
		strSearchQueryString += "&xLocationW="    + strLocationW;

	var txtPagerPageNumber1 = document.getElementById( "txtPagerPageNumber1" );
	if( txtPagerPageNumber1 != null )
		strSearchQueryString = strSearchQueryString.replace( /Page=1/, "Page=" + txtPagerPageNumber1.value );
	
	var pnlTarget = document.getElementById( "pnlRenderResuls" );
	var oXmlHttp  = zXmlHttp.createRequest();
	
	oXmlHttp.open( "post", "RenderResults.aspx", true );
	oXmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	
    oXmlHttp.onreadystatechange = function()
	{
        if( oXmlHttp.readyState == 4 )
		{
            if( oXmlHttp.status == 200 )
			{
                pnlTarget.innerHTML = oXmlHttp.responseText;
            }
        }
    };
    // Add a random parameter to the end of this url to enforce no-caching
    oXmlHttp.send( strSearchQueryString + "&xRnd=" + Math.random() );
}

function PagerChangePage( nTotalPages )
{
	var txtPagerPageNumber1 = document.getElementById( "txtPagerPageNumber1"  );
	var txtPagerPageNumber2 = document.getElementById( "txtPagerPageNumber2"  );
	
	// Validate page number before proceeding
	var strCheckOK  = "0123456789";
	var strCheckStr = txtPagerPageNumber1.value;
	var fAllValid   = true;
	for( var i = 0; i < strCheckStr.length; i++ )
	{
		var ch = strCheckStr.charAt( i );
		for( var j = 0; j < strCheckOK.length; j++ )
		{
			if( ch == strCheckOK.charAt( j ) )
				break;
			else
			{
				if( j == strCheckOK.length - 1 )
				{
					fAllValid = false;
					break;
				}
			}
		}
		if( fAllValid == false )
			break;
	}
	if( fAllValid == false )
		txtPagerPageNumber1.value = txtPagerPageNumber2.value = 1;
	
	if( txtPagerPageNumber1.value > nTotalPages )
		txtPagerPageNumber1.value = txtPagerPageNumber2.value = nTotalPages;
	
	RenderResults();
}

function PagerGo( strPagerPageNumberID, nTotalPages )
{
	var txtPagerPageNumber  = document.getElementById( strPagerPageNumberID  );
	var txtPagerPageNumber1 = document.getElementById( "txtPagerPageNumber1" );
	var txtPagerPageNumber2 = document.getElementById( "txtPagerPageNumber2" );
	
	txtPagerPageNumber1.value = txtPagerPageNumber2.value = txtPagerPageNumber.value;
	PagerChangePage( nTotalPages );
}

function PagerPrev( nTotalPages )
{
	var txtPagerPageNumber1 = document.getElementById( "txtPagerPageNumber1" );
	var txtPagerPageNumber2 = document.getElementById( "txtPagerPageNumber2" );
	
	var nCurrentPage = txtPagerPageNumber1.value;
	if( nCurrentPage > 1 )
	{
		nCurrentPage--;
		txtPagerPageNumber1.value = txtPagerPageNumber2.value = nCurrentPage;
		PagerChangePage( nTotalPages );
	}
}

function PagerNext( nTotalPages )
{
	var txtPagerPageNumber1 = document.getElementById( "txtPagerPageNumber1" );
	var txtPagerPageNumber2 = document.getElementById( "txtPagerPageNumber2" );
	
	var nCurrentPage = txtPagerPageNumber1.value;
	if( nCurrentPage < nTotalPages )
	{
		nCurrentPage++;
		txtPagerPageNumber1.value = txtPagerPageNumber2.value = nCurrentPage;
		PagerChangePage( nTotalPages );
	}
}

function formatCurrency( num )
{
	num = num.toString().replace( /\$|\,/g,'' );
	
	if( isNaN( num ) )
		num = "0";
	
	sign = ( num == ( num = Math.abs( num ) ) );
	num  = Math.floor( num * 100+0.50000000001 );
	num  = Math.floor( num / 100 ).toString();

	for( var i = 0; i < Math.floor( ( num.length - ( 1 + i ) ) / 3 ); i++ )
		num = num.substring( 0, num.length - ( 4 * i + 3 ) ) + ',' + num.substring( num.length - ( 4 * i + 3 ) );
		
	return( ( ( sign ) ? '' : '-' ) + '$' + num );
}

