/* 
 * Insiderater.com
 * Map based listing : ajax and javascript codes
 * Jijesh N.S
 * Logicmanse.com
 */


// money format
function formatMoney(n) {
    return "$ " + n.toLocaleString().split(".")[0] ;
}

// the kool part here
function MM_preloadImages()
{ //v3.0
    var d=document;
    if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
        for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image;
                d.MM_p[j++].src=a[i];
            }
    }
}
// number formating function
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;
}


// ajax jquery functions
$(document).ready(function(){
	
	$("#but_search1").click(function(){
		
        outerLayout.close("east");
        var neigh_values=   new Array();
        $.each($("input[name='chb_neighborhood[]']:checked"), function() {
            neigh_values.push("'"+$(this).val()+"'");
        });

        var mopt_values=   new Array();
        $.each($("input[name='chb_moreopt[]']:checked"), function() {
            mopt_values.push($(this).val());
        });
        
        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        var price   =   $("#price_start").val()+"_"+$("#price_end").val();
        var size    =   $("#size_start").val()+"_"+$("#size_end").val();
        var sqft    =   $("#sqft_start").val()+"_"+$("#sqft_end").val();
        var filter_type=$("#hid_filter").val();
        var sort_val    =   $("#lst_sort").val();

        $("#pager_current").val(30);
        $("#page_now").val(1);

        
               
      // for initial values
			$.ajax({
                    type: "GET",
                    url: "map/ajax_new_map_includes.php",
                    data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
                    success: function(html){
                        var html_array  =   html.split('#nsj#');
                        var page_info_txt   =   html_array[0]+" Properties Found. Page 1 of "+html_array[1];
                        $("#toal_property",window.parent.document).val(html_array[0]);
                        $("#toal_pages",window.parent.document).val(html_array[1]);
                        $("#div_pageinfo",window.parent.document).html(page_info_txt);

                        // re-set pager value
                        if(html_array[0]>30){
                            $("#pager_current",window.parent.document).val(30);
                        }else{
                            $("#pager_current",window.parent.document).val(0);
                        }
                        $("#page_now",window.parent.document).val(1);
                    }
                });

               // for display
                $.ajax({
                    type: "GET",
                    url: "map/ajax_new_map_listing.php",
                    data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
                    success: function(html){
                        $("#showprop",window.parent.document).html(html);
                        
                        
                        if(filter_type == 'newdev')
                        {
							initialize("map/xmlnewdev.php?neigb="+neigh_values+"&mopt="+mopt_values);
					    }
					    if(filter_type == 'rental')
                        {
							initialize("map/xmlrent.php?price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&neigb="+neigh_values+"&mopt="+mopt_values);
						}
						if(filter_type == 'buildings')
                        {
							initialize("map/xmlbuildings.php?neigb="+neigh_values+"&mopt="+mopt_values); 	
						}
						if(filter_type == 'sales')
                        {
							initialize("map/xmlsales.php?price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&neigb="+neigh_values+"&mopt="+mopt_values);
						}
					    
					                            
					    $("#div_loading_gif").css('visibility','hidden');
                    }
                });     	
         });

 $("#rd_type_rentals").click(function(){
	 
	 
	
          // re-assign all the values

        $("#div_loading_gif").css('visibility','visible');
        $("#price_start").val(0);
        $("#price_end").val(10100);
        var price   =   "0_10100";

        $("#size_start").val(0);
        $("#size_end").val(15);
        var size    =   "0_15";

        $("#sqft_start").val(0);
        $("#sqft_end").val(3010);
        var sqft    =   "0_3010";

        $("#pager_current").val(30);
        $("#page_now").val(1);

        // reset all Sort By Options
        $('#lst_sort option').remove();
        $('#lst_sort optgroup').remove();
        manage_sort_by_list('rental');
        
        outerLayout.close("east"); 
        initialize("map/xmlrent.php");
        
        // for initial values
        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_includes.php",
            data: "type=rental&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30 ",
           //data: "type=rental&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
            success: function(html){
                var html_array  =   html.split('#nsj#');
                var page_info_txt   =   addCommas(html_array[0])+" Properties Found. Page 1 of "+html_array[1];
                $("#toal_property").val(addCommas(html_array[0]));
                $("#toal_pages").val(html_array[1]);
                $("#div_pageinfo").html(page_info_txt);
            }
        });


      
      // for display
        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_listing.php",
            data: "type=rental&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30",
            success: function(html){
                $("#showprop").html(html);
                $("#div_loading_gif").css('visibility','hidden');
            }
        });
        document.getElementById('lst_sort').selectedIndex = 0;
        document.getElementById('iframe_price').src='map/ifram_price.php';
        document.getElementById('iframe_size').src='map/ifram_size.php';
        document.getElementById('iframe_sqft').src='map/ifram_sqft.php';
        
        
        //neighborhood options
        $("input[name='chb_neighborhood[]']").attr('checked',false);
        $('#chb_neighborhood_all').attr('checked',true);
        $('#neighbor_div').slideUp("slow");
        $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");

        //more options
        $("input[name='chb_moreopt[]']").attr('checked',false);
        $('#chb_moreopt_all').attr('checked',true);
        $('#moreopt_div').slideUp("slow");
        $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");

        // slider display
        $("#watermark_price").css('visibility','hidden');
        $("#watermark_size").css('visibility','hidden');
        $("#watermark_sqft").css('visibility','hidden');

        // more option Rental Checkbox enabled
        $("#more_opt_rent").attr('disabled',false);

        document.getElementById('hid_filter').value='rental';
        document.getElementByID('rd_type_buildings').checked=TRUE;
        return false;
    });


      $("#rd_type_buildings").click(function(){

        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        $("#price_start").val(0);
        $("#price_end").val(8500000);
        var price   =   "0_8500000";

        $("#size_start").val(0);
        $("#size_end").val(15);
        var size    =   "0_15";

        $("#sqft_start").val(0);
        $("#sqft_end").val(8500);
        var sqft    =   "0_8500";
        
        $("#pager_current").val(30);
        $("#page_now").val(1);

        // reset all Sort By Options
        $('#lst_sort option').remove();
        $('#lst_sort optgroup').remove();
        manage_sort_by_list('buildings');
        
        outerLayout.close("east");
        
        

        // for initial values
        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_includes.php",
            data: "type=buildings&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30",
            success: function(html){
                var html_array  =   html.split('#nsj#');
                var page_info_txt   =   addCommas(html_array[0])+" Properties Found. Page 1 of "+html_array[1];
                $("#toal_property").val(addCommas(html_array[0]));
                $("#toal_pages").val(html_array[1]);
                $("#div_pageinfo").html(page_info_txt);
                initialize("map/xmlbuildings.php"); 
            }
        });
        
        
       // for display
        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_listing.php",
            data: "type=buildings&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30",
            success: function(html){
                $("#showprop").html(html);
                $("#div_loading_gif").css('visibility','hidden');
            }
        });
        document.getElementById('lst_sort').selectedIndex = 0;
        document.getElementById('iframe_price').src='map/ifram_price_hide.php';
        document.getElementById('iframe_size').src='map/ifram_size_hide.php';
        document.getElementById('iframe_sqft').src='map/ifram_sqft_hide.php';

        // slider display
        $("#watermark_price").css('visibility','visible');
        $("#watermark_size").css('visibility','visible');
        $("#watermark_sqft").css('visibility','visible');

        // more option Rental Checkbox enabled
        $("#more_opt_rent").attr('disabled',false);

        //neighborhood options
        $("input[name='chb_neighborhood[]']").attr('checked',false);
        $('#chb_neighborhood_all').attr('checked',true);
        $('#neighbor_div').slideUp("slow");
        $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");

        //more options
        $("input[name='chb_moreopt[]']").attr('checked',false);
        $('#chb_moreopt_all').attr('checked',true);
        $('#moreopt_div').slideUp("slow");
        $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");

        document.getElementById('hid_filter').value='buildings';
        document.getElementByID('rd_type_buildings').checked=TRUE;
        return false;
    });
    
    $("#rd_type_new_dev").click(function(){

        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        $("#price_start").val(0);
        $("#price_end").val(8500000);
        var price   =   "0_8500000";

        $("#size_start").val(0);
        $("#size_end").val(15);
        var size    =   "0_15";

        $("#sqft_start").val(0);
        $("#sqft_end").val(8500);
        var sqft    =   "0_8500";

        $("#pager_current").val(30);
        $("#page_now").val(1);

        // reset all Sort By Options
        $('#lst_sort option').remove();
        $('#lst_sort optgroup').remove();
        manage_sort_by_list('newdev');

        outerLayout.close("east");
       
        
        
        // for initial values
        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_includes.php",
            data: "type=newdev&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30",
            success: function(html){
                var html_array  =   html.split('#nsj#');

                //var page_info_txt   =   html_array[0]+" Properties Found. Page 1 of "+html_array[1];
                var page_info_txt   =   addCommas(html_array[0])+" Properties Found. Page 1 of "+html_array[1];
                $("#toal_property").val(addCommas(html_array[0]));
                $("#toal_pages").val(html_array[1]);
                $("#div_pageinfo").html(page_info_txt);
                initialize("map/xmlnewdev.php");
            }
        });
        
                        
        // for display
        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_listing.php",
            data: "type=newdev&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30",
            success: function(html){
                $("#showprop").html(html);
                $("#div_loading_gif").css('visibility','hidden');
            }
        });
        document.getElementById('lst_sort').selectedIndex = 0;
        document.getElementById('iframe_price').src='map/ifram_price_hide.php';
        document.getElementById('iframe_size').src='map/ifram_size_hide.php';
        document.getElementById('iframe_sqft').src='map/ifram_sqft_hide.php';

        // slider display
        $("#watermark_price").css('visibility','visible');
        $("#watermark_size").css('visibility','visible');
        $("#watermark_sqft").css('visibility','visible');

        // more option Rental Checkbox enabled
        $("#more_opt_rent").attr('disabled',false);

        //neighborhood options
        $("input[name='chb_neighborhood[]']").attr('checked',false);
        $('#chb_neighborhood_all').attr('checked',true);
        $('#neighbor_div').slideUp("slow");
        $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");

        //more options
        $("input[name='chb_moreopt[]']").attr('checked',false);
        $('#chb_moreopt_all').attr('checked',true);
        $('#moreopt_div').slideUp("slow");
        $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");

        document.getElementById('hid_filter').value='newdev';
        document.getElementByID('rd_type_new_dev').checked=TRUE;
        return false;
    });

    $("#rd_type_sales").click(function(){

        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        $("#price_start").val(0);
        $("#price_end").val(50001000);
        var price   =   "0_50001000";

        $("#size_start").val(0);
        $("#size_end").val(15);
        var size    =   "0_15";

        $("#sqft_start").val(0);
        $("#sqft_end").val(4010);
        var sqft    =   "0_4010";

        $("#pager_current").val(30);
        $("#page_now").val(1);

        // reset all Sort By Options
        $('#lst_sort option').remove();
        $('#lst_sort optgroup').remove();
        manage_sort_by_list('sales');
 
        outerLayout.close("east");
       
        

        // for initial values
        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_includes.php",
            data: "type=sales&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30",
            success: function(html){
                var html_array  =   html.split('#nsj#');
                var page_info_txt   =   addCommas(html_array[0])+" Properties Found. Page 1 of "+html_array[1];
                $("#toal_property").val(addCommas(html_array[0]));
                $("#toal_pages").val(html_array[1]);
                $("#div_pageinfo").html(page_info_txt);
                initialize("map/xmlsales.php");
            }
        });

         
        // for display
        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_listing.php",
            data: "type=sales&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort=1_ASC&limit=0,30",
            success: function(html){
                $("#showprop").html(html);
                $("#div_loading_gif").css('visibility','hidden');
            }
        });
        document.getElementById('lst_sort').selectedIndex = 0;
        document.getElementById('iframe_price').src='map/ifram_price2.php';
        document.getElementById('iframe_size').src='map/ifram_size.php';
        document.getElementById('iframe_sqft').src='map/ifram_sqft2.php';

        // slider display
        $("#watermark_price").css('visibility','hidden');
        $("#watermark_size").css('visibility','hidden');
        $("#watermark_sqft").css('visibility','hidden');
        
        // more option Rental Checkbox disabled
        $("#more_opt_rent").attr('disabled',true);


        //neighborhood options
        $("input[name='chb_neighborhood[]']").attr('checked',false);
        $('#chb_neighborhood_all').attr('checked',true);
        $('#neighbor_div').slideUp("slow");
        $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");

        //more options
        $("input[name='chb_moreopt[]']").attr('checked',false);
        $('#chb_moreopt_all').attr('checked',true);
        $('#moreopt_div').slideUp("slow");
        $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");

        document.getElementById('hid_filter').value='sales';
        document.getElementByID('rd_type_sales').checked=TRUE;
        return false;
    });
    
    
    

    $("#lst_sort").change(function(){

        // ajax listing
        $("#div_loading_gif").css('visibility','visible');
        var price   =   $("#price_start").val()+"_"+$("#price_end").val();
        var size    =   $("#size_start").val()+"_"+$("#size_end").val();
        var sqft    =   $("#sqft_start").val()+"_"+$("#sqft_end").val();
        var filter_type=$("#hid_filter").val();
        var sort_val    =   $("#lst_sort").val();

        // reset all Sort By Options
        if(filter_type=='rental' || filter_type=='sales')
        {
            $("#lst_sort option:eq(0)").text('A-Z');
            $("#lst_sort option:eq(1)").text('Z-A');
            $("#lst_sort option:eq(2)").text('Lowest - Highest');
            $("#lst_sort option:eq(3)").text('Highest - Lowest');
            $("#lst_sort option:eq(4)").text('Lowest - Highest');
            $("#lst_sort option:eq(5)").text('Highest - Lowest');
            $("#lst_sort option:eq(6)").text('Lowest - Highest');
            $("#lst_sort option:eq(7)").text('Highest - Lowest');
            $("#lst_sort option:eq(8)").text('Lowest - Highest');
            $("#lst_sort option:eq(9)").text('Highest - Lowest');
            $("#lst_sort option:eq(10)").text('(F-) - (A+)');
            $("#lst_sort option:eq(11)").text('(A+) - (F-)');
        }else{
            $("#lst_sort option:eq(0)").text('A-Z');
            $("#lst_sort option:eq(1)").text('Z-A');
            $("#lst_sort option:eq(2)").text('(F-) - (A+)');
            $("#lst_sort option:eq(3)").text('(A+) - (F-)');
        }
        
//        $("#lst_sort option:eq(12)").text('Oldest - Newest');
//        $("#lst_sort option:eq(13)").text('Newest - Oldest');

        var pager_limit =   $("#pager_current").val()+",30";

        // new label @ the time od select the options
        if(sort_val=='1_ASC') {
            $("#lst_sort option:selected").text('Address:A-Z');
        }
        if(sort_val=='1_DESC') {
            $("#lst_sort option:selected").text('Address:Z-A');
        }
        if(sort_val=='2_ASC') {
            $("#lst_sort option:selected").text('Price:Lowest - Highest');
        }
        if(sort_val=='2_DESC') {
            $("#lst_sort option:selected").text('Price:Highest - Lowest');
        }
        if(sort_val=='3_ASC') {
            $("#lst_sort option:selected").text('SqFt:Lowest - Highest');
        }
        if(sort_val=='3_DESC') {
            $("#lst_sort option:selected").text('SqFt:Highest - Lowest');
        }
        if(sort_val=='4_ASC') {
            $("#lst_sort option:selected").text('Size:Lowest - Highest');
        }
        if(sort_val=='4_DESC') {
            $("#lst_sort option:selected").text('Size:Highest - Lowest');
        }
        if(sort_val=='5_ASC') {
            $("#lst_sort option:selected").text('Beds:Lowest - Highest');
        }
        if(sort_val=='5_DESC') {
            $("#lst_sort option:selected").text('Beds:Highest - Lowest');
        }

        if(sort_val=='6_ASC') {
            $("#lst_sort option:selected").text('Top Rated:(F-) - (A+)');
        }
        if(sort_val=='6_DESC') {
            $("#lst_sort option:selected").text('Top Rated:(A+) - (F-)');
        }

//        if(sort_val=='7_ASC') {
//            $("#lst_sort option:selected").text('Year Built:Oldest - Newest');
//        }
//        if(sort_val=='7_DESC') {
//            $("#lst_sort option:selected").text('Year Built:Newest - Oldest');
//        }

        // menu options
        var mopt_values=   new Array();
        $.each($("input[name='chb_moreopt[]']:checked"), function() {
            mopt_values.push($(this).val());
        });

        var neigh_values=   new Array();
        $.each($("input[name='chb_neighborhood[]']:checked"), function() {
            neigh_values.push("'"+$(this).val()+"'");
        });

        $.ajax({
            type: "GET",
            url: "map/ajax_new_map_listing.php",
            data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit="+pager_limit+"&neigb="+neigh_values+"&mopt="+mopt_values,
            success: function(html){
                $("#showprop").html(html);
                $("#div_loading_gif").css('visibility','hidden');
            }
        });

    });

    $("#pre_100").click(function(){ // previous 100 records

        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        var price   =   $("#price_start").val()+"_"+$("#price_end").val();
        var size    =   $("#size_start").val()+"_"+$("#size_end").val();
        var sqft    =   $("#sqft_start").val()+"_"+$("#sqft_end").val();
        var filter_type=$("#hid_filter").val();
        var sort_val    =   $("#lst_sort").val();

        // menu options
        var mopt_values=   new Array();
        $.each($("input[name='chb_moreopt[]']:checked"), function() {
            mopt_values.push($(this).val());
        });

        var neigh_values=   new Array();
        $.each($("input[name='chb_neighborhood[]']:checked"), function() {
            neigh_values.push("'"+$(this).val()+"'");
        });

        var current_page    =   Number($("#page_now").val());
        var total_page      =   Number($("#toal_pages").val());

        if(current_page > 0)
        {
            var pager_current_val =   $("#pager_current").val();
            var pager_new_val   =   pager_current_val - 30;

            if(pager_new_val < 31) {
                pager_limit   =   "0,30";
                $("#pager_current").val(30);
                $("#page_now").val(1);
            }
            else {
                pager_limit  =  (pager_new_val-30)+",30";
                $("#pager_current").val(pager_new_val);
                var pagenow =   Number(current_page)-Number(1);
                $("#page_now").val(pagenow);
            }

            var page_info_txt   =   $("#toal_property").val()+" Properties Found. Page "+$("#page_now").val()+" of "+total_page;
            $("#div_pageinfo").html(page_info_txt);

            $.ajax({
                type: "GET",
                url: "map/ajax_new_map_listing.php",
                data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit="+pager_limit+"&neigb="+neigh_values+"&mopt="+mopt_values,
                success: function(html){
                    $("#showprop").html(html);
                    $("#div_loading_gif").css('visibility','hidden');
                }
            });
        }
    });

    $("#nxt_100").click(function(){ // next 100 records

        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        var price   =   $("#price_start").val()+"_"+$("#price_end").val();
        var size    =   $("#size_start").val()+"_"+$("#size_end").val();
        var sqft    =   $("#sqft_start").val()+"_"+$("#sqft_end").val();
        var filter_type=$("#hid_filter").val();
        var sort_val    =   $("#lst_sort").val();

        // menu options
        var mopt_values=   new Array();
        $.each($("input[name='chb_moreopt[]']:checked"), function() {
            mopt_values.push($(this).val());
        });

        var neigh_values=   new Array();
        $.each($("input[name='chb_neighborhood[]']:checked"), function() {
            neigh_values.push("'"+$(this).val()+"'");
        });

        var current_page    =   Number($("#page_now").val());
        var total_page      =   Number($("#toal_pages").val());        

        if(current_page <= total_page)
        {
            var pager_current_val =   $("#pager_current").val();
            var pager_new_val   =   Number(pager_current_val) + Number(30);

            if(pager_new_val < 31) {
                pager_limit   =   "0,30";
                $("#page_now").val(1);

            }
            else {
                pager_limit  =  (pager_current_val)+",30";
                $("#pager_current").val(pager_new_val);
                var pagenow =   Number(current_page)+Number(1);
                $("#page_now").val(pagenow);
            }

            var page_info_txt   =   $("#toal_property").val()+" Properties Found. Page "+$("#page_now").val()+" of "+total_page;
            $("#div_pageinfo").html(page_info_txt);

            $.ajax({
                type: "GET",
                url: "map/ajax_new_map_listing.php",
                data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit="+pager_limit+"&neigb="+neigh_values+"&mopt="+mopt_values,
                success: function(html){
                    $("#showprop").html(html);
                    $("#div_loading_gif").css('visibility','hidden');
                }
            });
        }
        
    });

    $("#last_100").click(function(){ // previous 100 records

        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        var price   =   $("#price_start").val()+"_"+$("#price_end").val();
        var size    =   $("#size_start").val()+"_"+$("#size_end").val();
        var sqft    =   $("#sqft_start").val()+"_"+$("#sqft_end").val();
        var filter_type=$("#hid_filter").val();
        var sort_val    =   $("#lst_sort").val();

        // menu options
        var mopt_values=   new Array();
        $.each($("input[name='chb_moreopt[]']:checked"), function() {
            mopt_values.push($(this).val());
        });

        var neigh_values=   new Array();
        $.each($("input[name='chb_neighborhood[]']:checked"), function() {
            neigh_values.push("'"+$(this).val()+"'");
        });

        var current_page    =   Number($("#page_now").val());
        var total_page      =   Number($("#toal_pages").val());

        if(current_page > 0)
        {
            var pager_current_val =   $("#pager_current").val();
            var pager_new_val   =   pager_current_val - 30;

            if(pager_new_val < 31) {
                pager_limit   =   "0,30";
                $("#pager_current").val(30);
                $("#page_now").val(1);
            }
            else {
                pager_limit  =  (pager_new_val-30)+",30";
                $("#pager_current").val(pager_new_val);
                var pagenow =   Number(current_page)-Number(1);
                $("#page_now").val(pagenow);
            }

            var page_info_txt   =   $("#toal_property").val()+" Properties Found. Page "+$("#page_now").val()+" of "+total_page;
            $("#div_pageinfo").html(page_info_txt);

            $.ajax({
                type: "GET",
                url: "map/ajax_new_map_listing.php",
                data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit="+pager_limit+"&neigb="+neigh_values+"&mopt="+mopt_values,
                success: function(html){
                    $("#showprop").html(html);
                    $("#div_loading_gif").css('visibility','hidden');
                }
            });
        }
    });

    $("#next_100").click(function(){ // next 100 records

        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        var price   =   $("#price_start").val()+"_"+$("#price_end").val();
        var size    =   $("#size_start").val()+"_"+$("#size_end").val();
        var sqft    =   $("#sqft_start").val()+"_"+$("#sqft_end").val();
        var filter_type=$("#hid_filter").val();
        var sort_val    =   $("#lst_sort").val();

        // menu options
        var mopt_values=   new Array();
        $.each($("input[name='chb_moreopt[]']:checked"), function() {
            mopt_values.push($(this).val());
        });

        var neigh_values=   new Array();
        $.each($("input[name='chb_neighborhood[]']:checked"), function() {
            neigh_values.push("'"+$(this).val()+"'");
        });

        var current_page    =   Number($("#page_now").val());
        var total_page      =   Number($("#toal_pages").val());

        if(current_page < total_page)
        {
            var pager_current_val =   $("#pager_current").val();
            var pager_new_val   =   Number(pager_current_val) + Number(30);

            if(pager_new_val < 31) {
                pager_limit   =   "0,30";
                $("#page_now").val(1);

            }
            else {
                pager_limit  =  (pager_current_val)+",30";
                $("#pager_current").val(pager_new_val);
                var pagenow =   Number(current_page)+Number(1);
                $("#page_now").val(pagenow);
            }

            var page_info_txt   =   $("#toal_property").val()+" Properties Found. Page "+$("#page_now").val()+" of "+total_page;
            $("#div_pageinfo").html(page_info_txt);

            $.ajax({
                type: "GET",
                url: "map/ajax_new_map_listing.php",
                data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit="+pager_limit+"&neigb="+neigh_values+"&mopt="+mopt_values,
                success: function(html){
                    $("#showprop").html(html);
                    $("#div_loading_gif").css('visibility','hidden');
                }
            });
        }

    });

    // dropdown menu neighborhood

    $('#td_neighbour').click(function() {
         if ($("#neighbor_div").is(":hidden")) {
             $('#neighbor_div').slideDown("slow");
             $('#td_neighbour').css("background-image", "url(images/close-arrow.png)");
         }else{
             $('#neighbor_div').slideUp("slow");
             $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");
         }
          $('#moreopt_div').slideUp("slow");
          $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");
    });
    $('label.lbl_neig').mouseover(function() {
      $(this).css('color','#000000');
    });

    $('label.lbl_neig').mouseout(function() {
      $(this).css('color','#07519A');
    });

    $('#chb_neighborhood_all').click(function() {
        $("input[name='chb_neighborhood[]']").attr('checked',false);
    });

    $("input[name='chb_neighborhood[]']").click(function() {
        if($("input[name='chb_neighborhood[]']").is(":checked"))
        {
            $('#chb_neighborhood_all').attr('checked',false);
        }
        else{
            $('#chb_neighborhood_all').attr('checked',true);
        }
        
    });
    $('#but_close').click(function() {
        $('#neighbor_div').hide("slow");
        $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");
//        $('#chb_neighborhood_all').attr('checked',false);
//        $("input[name='chb_neighborhood[]']").attr('checked',false);

    });

    // neighborhood Search
    $('#but_search').click(function(){
        outerLayout.close("east");
        var neigh_values=   new Array();
        $.each($("input[name='chb_neighborhood[]']:checked"), function() {
        neigh_values.push("'"+$(this).val()+"'");
        });

        var mopt_values=   new Array();
        $.each($("input[name='chb_moreopt[]']:checked"), function() {
            mopt_values.push($(this).val());
        });
        
        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        var price   =   $("#price_start").val()+"_"+$("#price_end").val();
        var size    =   $("#size_start").val()+"_"+$("#size_end").val();
        var sqft    =   $("#sqft_start").val()+"_"+$("#sqft_end").val();
        var filter_type=$("#hid_filter").val();
        var sort_val    =   $("#lst_sort").val();

        $("#pager_current").val(30);
        $("#page_now").val(1);

        
               
      // for initial values
			$.ajax({
                    type: "GET",
                    url: "map/ajax_new_map_includes.php",
                    data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
                    success: function(html){
                        var html_array  =   html.split('#nsj#');
                        var page_info_txt   =   html_array[0]+" Properties Found. Page 1 of "+html_array[1];
                        $("#toal_property",window.parent.document).val(html_array[0]);
                        $("#toal_pages",window.parent.document).val(html_array[1]);
                        $("#div_pageinfo",window.parent.document).html(page_info_txt);

                        // re-set pager value
                        if(html_array[0]>30){
                            $("#pager_current",window.parent.document).val(30);
                        }else{
                            $("#pager_current",window.parent.document).val(0);
                        }
                        $("#page_now",window.parent.document).val(1);
                    }
                });

               // for display
                $.ajax({
                    type: "GET",
                    url: "map/ajax_new_map_listing.php",
                    data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
                    success: function(html){
                        $("#showprop",window.parent.document).html(html);
                        
                        
                        if(filter_type == 'newdev') {
							initialize("map/xmlnewdev.php?neigb="+neigh_values+"&mopt="+mopt_values);
					    } if(filter_type == 'rental')  {
							initialize("map/xmlrent.php?price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&neigb="+neigh_values+"&mopt="+mopt_values);
						} if(filter_type == 'buildings') {
							initialize("map/xmlbuildings.php?neigb="+neigh_values+"&mopt="+mopt_values); 	
						} if(filter_type == 'sales') {
							initialize("map/xmlsales.php?price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&neigb="+neigh_values+"&mopt="+mopt_values);
						}				    
					                            
					    $("#div_loading_gif").css('visibility','hidden');
                    }              
                });   
                
                $('#neighbor_div').hide("slow");
                $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");  	
         });       
       
    /* // for initial values
        $.ajax({
            type: "GET",
            url: "ajax_new_map_includes.php",
            data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
            success: function(html){
                var html_array  =   html.split('#nsj#');

                //var page_info_txt   =   html_array[0]+" Properties Found. Page 1 of "+html_array[1];
                var page_info_txt   =   addCommas(html_array[0])+" Properties Found. Page 1 of "+html_array[1];
                $("#toal_property").val(addCommas(html_array[0]));
                $("#toal_pages").val(html_array[1]);
                $("#div_pageinfo").html(page_info_txt);
            }
        });

        // for display
        $.ajax({
            type: "GET",
            url: "ajax_new_map_listing.php",
            data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
            success: function(html){
                $("#showprop").html(html);
                $("#div_loading_gif").css('visibility','hidden');
            }
        });
        $('#neighbor_div').hide("slow");
        $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");
     });*/


    // more options
    $('#td_moreopt').click(function() {
        //if($("#hid_filter").val()!='newdev'){
             if ($("#moreopt_div").is(":hidden")) {
                 $('#moreopt_div').slideDown("slow");
                 $('#td_moreopt').css("background-image", "url(images/close-arrow.png)");
             }else{
                 $('#moreopt_div').slideUp("slow");
                 $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");
             }
             $('#neighbor_div').slideUp("slow");
             $('#td_neighbour').css("background-image", "url(images/Open-arrow.png)");
       // }
    });
    
    $('#chb_moreopt_all').click(function() {
        $("input[name='chb_moreopt[]']").attr('checked',false);
    });

    $("input[name='chb_moreopt[]']").click(function() {
        if($("input[name='chb_moreopt[]']").is(":checked"))
        {
            $('#chb_moreopt_all').attr('checked',false);
        }
        else{
            $('#chb_moreopt_all').attr('checked',true);
        }

    });
    $('#but_close2').click(function() {
        $('#moreopt_div').hide("slow");
        $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");

    }); 
   
   
    // neighborhood Search
    $('#but_search2').click(function(){
		outerLayout.close("east");		
		   var neigh_values=   new Array();
        $.each($("input[name='chb_neighborhood[]']:checked"), function() {
            neigh_values.push("'"+$(this).val()+"'");
        });

        var mopt_values=   new Array();
        $.each($("input[name='chb_moreopt[]']:checked"), function() {
            mopt_values.push($(this).val());
        });
      
        // re-assign all the values
        $("#div_loading_gif").css('visibility','visible');
        var price   =   $("#price_start").val()+"_"+$("#price_end").val();
        var size    =   $("#size_start").val()+"_"+$("#size_end").val();
        var sqft    =   $("#sqft_start").val()+"_"+$("#sqft_end").val();
        var filter_type=$("#hid_filter").val();
        var sort_val    =   $("#lst_sort").val();

        $("#pager_current").val(30);
        $("#page_now").val(1);

               
      // for initial values
			$.ajax({
                    type: "GET",
                    url: "map/ajax_new_map_includes.php",
                    data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
                    success: function(html){
                        var html_array  =   html.split('#nsj#');
                        var page_info_txt   =   html_array[0]+" Properties Found. Page 1 of "+html_array[1];
                        $("#toal_property",window.parent.document).val(html_array[0]);
                        $("#toal_pages",window.parent.document).val(html_array[1]);
                        $("#div_pageinfo",window.parent.document).html(page_info_txt);

                        // re-set pager value
                        if(html_array[0]>30){
                            $("#pager_current",window.parent.document).val(30);
                        }else{
                            $("#pager_current",window.parent.document).val(0);
                        }
                        $("#page_now",window.parent.document).val(1);
                    }
                });

               // for display
                $.ajax({
                    type: "GET",
                    url: "map/ajax_new_map_listing.php",
                    data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
                    success: function(html){
                        $("#showprop",window.parent.document).html(html);
                        
                        
                        if(filter_type == 'newdev') {
							initialize("map/xmlnewdev.php?neigb="+neigh_values+"&mopt="+mopt_values);
					    } if(filter_type == 'rental')  {
							initialize("map/xmlrent.php?price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&neigb="+neigh_values+"&mopt="+mopt_values);
						} if(filter_type == 'buildings') {
							initialize("map/xmlbuildings.php?neigb="+neigh_values+"&mopt="+mopt_values); 	
						} if(filter_type == 'sales') {
							initialize("map/xmlsales.php?price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&neigb="+neigh_values+"&mopt="+mopt_values);
						}				    
					                            
					    $("#div_loading_gif").css('visibility','hidden');
                    }              
                });   
                
                 $('#moreopt_div').hide("slow");
                 $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");	
         }); 
    /*

       // for initial values
        $.ajax({
            type: "GET",
            url: "ajax_new_map_includes.php",
            data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
            success: function(html){
                var html_array  =   html.split('#nsj#');

                //var page_info_txt   =   html_array[0]+" Properties Found. Page 1 of "+html_array[1];
                var page_info_txt   =   addCommas(html_array[0])+" Properties Found. Page 1 of "+html_array[1];
                $("#toal_property").val(addCommas(html_array[0]));
                $("#toal_pages").val(html_array[1]);
                $("#div_pageinfo").html(page_info_txt);
            }
        });

        // for display
        $.ajax({
            type: "GET",
            url: "ajax_new_map_listing.php",
            data: "type="+filter_type+"&price_range="+price+"&size_val="+size+"&sqft_val="+sqft+"&sort="+sort_val+"&limit=0,30&neigb="+neigh_values+"&mopt="+mopt_values,
            success: function(html){
                $("#showprop").html(html);
                $("#div_loading_gif").css('visibility','hidden');
            }
        });
        $('#moreopt_div').hide("slow");
        $('#td_moreopt').css("background-image", "url(images/Open-arrow.png)");

    });*/

    function manage_sort_by_list(type)
    {
        if(type=='rental' || type=='sales'){
            $("#lst_sort").append('<optgroup label="Address">');
            $("#lst_sort").append('<option value="1_ASC" style="padding-left: 10px">&nbsp;&nbsp;A-Z</option>');
            $("#lst_sort").append('<option value="1_DESC" style="padding-left: 10px">&nbsp;&nbsp;Z-A</option>');
            $("#lst_sort").append('</optgroup>');

            $("#lst_sort").append('<optgroup label="Price">');
            $("#lst_sort").append('<option value="2_ASC" style="padding-left: 10px">&nbsp;&nbsp;Lowest - Highest</option>');
            $("#lst_sort").append('<option value="2_DESC" style="padding-left: 10px">&nbsp;&nbsp;Highest - Lowest</option>');
            $("#lst_sort").append('</optgroup>');

            $("#lst_sort").append('<optgroup label="SqFt">');
            $("#lst_sort").append('<option value="3_ASC" style="padding-left: 10px">&nbsp;&nbsp;Lowest - Highest</option>');
            $("#lst_sort").append('<option value="3_DESC" style="padding-left: 10px">&nbsp;&nbsp;Highest - Lowest</option>');
            $("#lst_sort").append('</optgroup>');

            $("#lst_sort").append('<optgroup label="Size">');
            $("#lst_sort").append('<option value="4_ASC" style="padding-left: 10px">&nbsp;&nbsp;Lowest - Highest</option>');
            $("#lst_sort").append('<option value="4_DESC" style="padding-left: 10px">&nbsp;&nbsp;Highest - Lowest</option>');
            $("#lst_sort").append('</optgroup>');

            $("#lst_sort").append('<optgroup label="Beds">');
            $("#lst_sort").append('<option value="5_ASC" style="padding-left: 10px">&nbsp;&nbsp;Lowest - Highest</option>');
            $("#lst_sort").append('<option value="5_DESC" style="padding-left: 10px">&nbsp;&nbsp;Highest - Lowest</option>');
            $("#lst_sort").append('</optgroup>');

            $("#lst_sort").append('<optgroup label="Top Rated">');
            $("#lst_sort").append('<option value="6_ASC" style="padding-left: 10px">&nbsp;&nbsp;(F-) - (A+)</option>');
            $("#lst_sort").append('<option value="6_DESC" style="padding-left: 10px">&nbsp;&nbsp;(A+) - (F-)</option>');
            $("#lst_sort").append('</optgroup>');

        }else{
            $("#lst_sort").append('<optgroup label="Address">');
            $("#lst_sort").append('<option value="1_ASC"  style="padding-left: 10px">&nbsp;&nbsp;A-Z</option>');
            $("#lst_sort").append('<option value="1_DESC"  style="padding-left: 10px">&nbsp;&nbsp;Z-A</option>');
            $("#lst_sort").append('</optgroup>');

            $("#lst_sort").append('<optgroup label="Top Rated">');
            $("#lst_sort").append('<option value="6_ASC"  style="padding-left: 10px">&nbsp;&nbsp;(F-) - (A+)</option>');
            $("#lst_sort").append('<option value="6_DESC"  style="padding-left: 10px">&nbsp;&nbsp;(A+) - (F-)</option>');
            $("#lst_sort").append('</optgroup>');
        }
        
    }
    
});



