

    function show_hide_alert(){        
        if(wait_for_ajax==0){
            $('#show_alert').unbind('click').remove();
            $('#id_spinner').hide();
        }else{
            $('#show_alert').unbind('click').remove();
            $('.middle_r').prepend('<div id="show_alert" style="height:130px;position:absolute;width:260px;left:1px"></div>');
            $('#show_alert').css({'opacity':'0.1','background':'#edeae3'});
            $('#show_alert').click(function(e){
                e.preventDefault();
                e.stopPropagation();                
                alert('Please wait')
            })
        }
        
    }

    var currentdate=new Date();
    $("#years option[value='"+currentdate.getFullYear()+"']").attr('selected','selected');
    $("#months option[value='"+(currentdate.getMonth()+1)+"']").attr('selected','selected');
    var old_option=$('#months').val();
    $('#id_spinner').show();
    show_hide_alert();
    if($.browser.safari ){
      $('#period_for_potholes .ri').css({'padding-top':'4px'});
      $('#id_spinner div').css({'padding-top':'10px'});
      $('#id_spinner img').css({'padding-top':'8px'});
    }
    
    
    $('#months').mouseover(function(){ 
        if($("#years").val()==2009){
            $("#months option:lt(9)").addClass('noclick');
            $("#months option:gt(8)").removeClass('noclick');
        }else if($("#years").val()==currentdate.getFullYear()){
            $("#months option:gt("+(currentdate.getMonth())+")").addClass('noclick');
            $("#months option:lt("+(currentdate.getMonth()+1)+")").removeClass('noclick');
            
        }else{
           $("#months option").removeClass('noclick'); 
        }
    })

    $('#months').change(function(){        
        if($("#months option[value='"+$(this).val()+"']").attr('class')=='noclick'){            
            $("#months option[value='"+$(this).val()+"']").removeAttr('selected');
            $("#months option[value='"+old_option+"']").attr('selected','selected');
            
        }else{
           old_option=$('#months').val() 
        }
    })
    
    $('#years').change(function(){
        
        if($("#years").val()==2009){
            $("#months option:lt(9)").addClass('noclick');
            $("#months option:gt(8)").removeClass('noclick');
        }else if($("#years").val()==currentdate.getFullYear()){
            $("#months option:gt("+(currentdate.getMonth())+")").addClass('noclick');
            $("#months option:lt("+(currentdate.getMonth()+1)+")").removeClass('noclick');
            
        }else{
           $("#months option").removeClass('noclick'); 
        }
        if($("#months option[value='"+$("#months").val()+"']").attr('class')=='noclick'){
            $("#months option[value='"+$("#months").val()+"']").removeAttr('selected');
            if($("#years").val()==2009){
                $("#months option[value='10']").attr('selected','selected');
                old_option=$('#months').val()
            }else{
                $("#months option[value='"+(currentdate.getMonth()+1)+"']").attr('selected','selected');
                old_option=$('#months').val()
            }
        }
        
    })
   

    
    
    var potholes_nominated_default=true;
    $('#period_for_potholes a').click(function(e){
        e.preventDefault();        
        if(wait_for_ajax==0){
            potholes_nominated_default=false;
            showUi=0;showRi=0;showUSi=0;showRSi=0;
            type_limit_from_click=0;
            $('#JSmarkers').html('');
            map.setZoom(6);
            map.setCenter(new google.maps.LatLng(54.521081,-4.416504));
            $('#period_for_potholes .ti').hide();
            $('#filterAllPotholes').attr('checked','checked');
            $('#filterWithContest,#filterUnfilled, #filterRepaired, #filterWithStories').removeAttr('checked');
            $('#id_spinner').show();
            wait_for_ajax=4;
            listC_U=Array();
            listC_US=Array();
            listC_R=Array();
            listC_RS=Array();
            listCN_U=Array();
            listCN_US=Array();
            listCN_R=Array();
            listCN_RS=Array();          
            removemarkersU();
            removemarkersUS();
            removemarkersR();
            removemarkersRS();
            show_hide_alert();
        }else{
            show_hide_alert();
            alert('Please wait')
        }
    });

    function removemarkersU(){
         
       for(i=0;i<=12;i++){
            if(Ui<LTableUnfilled){
                if(i==12){
                    clearTimeout(clU2);
                    clU2=setTimeout("removemarkersU()",10);
                    google.maps.event.removeListener(listUE[Ui]);
                    google.maps.event.clearInstanceListeners(listU[Ui]);                    
                    listU[Ui].setMap(null);
                    Ui=Ui+1;
                }else{
                    google.maps.event.removeListener(listUE[Ui]);
                    google.maps.event.clearInstanceListeners(listU[Ui]);                    
                    listU[Ui].setMap(null);
                    Ui=Ui+1;
                }
            }else{
                clearTimeout(clU2);                
                Ui=0;
                LTableUnfilled=0;
                listU=Array();
                listUE=Array();
                find_potholesAJAX('unfilled',$('#years').val()+'-'+$('#months').val());
                break;
            }
        }
        
    }


    function removemarkersUS(){
       for(i=0;i<=3;i++){
            if(USi<LTableUnfilledStory){
                if(i==3){
                    clearTimeout(clUS2);
                    clUS2=setTimeout("removemarkersUS()",10);
                    google.maps.event.removeListener(listUSE[USi]);
                    google.maps.event.clearInstanceListeners(listUS[USi]);                    
                    listUS[USi].setMap(null);
                    USi=USi+1;
                }else{
                    google.maps.event.removeListener(listUSE[USi]);
                    google.maps.event.clearInstanceListeners(listUS[USi]);                    
                    listUS[USi].setMap(null);
                    USi=USi+1;
                }
            }else{
                clearTimeout(clUS2);                
                USi=0;
                LTableUnfilledStory=0;
                listUS=Array();
                listUSE=Array();
                find_potholesAJAX('unfilledStory',$('#years').val()+'-'+$('#months').val());
                break;
            }
        } 
    }


    function removemarkersR(){
       
       for(i=0;i<=2;i++){
            if(Ri<LTableRepaired){
                if(i==2){
                    clearTimeout(clR2);
                    clR2=setTimeout("removemarkersR()",10);
                    google.maps.event.removeListener(listRE[Ri]);
                    google.maps.event.clearInstanceListeners(listR[Ri]);                    
                    listR[Ri].setMap(null);
                    Ri=Ri+1;
                }else{
                    google.maps.event.removeListener(listRE[Ri]);
                    google.maps.event.clearInstanceListeners(listR[Ri]);                    
                    listR[Ri].setMap(null);
                    Ri=Ri+1;                   
                }
            }else{
                clearTimeout(clR2);                
                Ri=0;
                LTableRepaired=0;
                listR=Array();
                listRE=Array();
                find_potholesAJAX('repaired',$('#years').val()+'-'+$('#months').val());
                break;
            }
        } 
    }

    function removemarkersRS(){
       for(i=0;i<=2;i++){
            if(RSi<LTableRepairedStory){
                if(i==2){
                    clearTimeout(clRS2);
                    clRS2=setTimeout("removemarkersRS()",10);
                    google.maps.event.removeListener(listRSE[RSi]);
                    google.maps.event.clearInstanceListeners(listRS[RSi]);                    
                    listRS[RSi].setMap(null);
                    RSi=RSi+1;
                }else{
                    google.maps.event.removeListener(listRSE[RSi]);
                    google.maps.event.clearInstanceListeners(listRS[RSi]);                    
                    listRS[RSi].setMap(null);
                    RSi=RSi+1;
                }
            }else{
                clearTimeout(clRS2);                
                RSi=0;
                LTableRepairedStory=0;
                listRS=Array();
                listRSE=Array();
                find_potholesAJAX('repairedStory',$('#years').val()+'-'+$('#months').val());
                break;
            }
        } 
    }







    var LTableUnfilled=0;
    var LTableRepaired=0;
    var LTableUnfilledStory=0;
    var LTableRepairedStory=0;    
    var old_description=null;
    var map,geocoder;
    var wait_for_ajax=4;
    var wait_for_ajax2=0;
    var markers=Array();

    var listU=Array();
    var listUS=Array();
    var listR=Array();
    var listRS=Array();
    var listUE=Array();
    var listUSE=Array();
    var listRE=Array();
    var listRSE=Array();
    var listC_U=Array();
    var listC_US=Array();
    var listC_R=Array();
    var listC_RS=Array();
    var listCN_U=Array();
    var listCN_US=Array();
    var listCN_R=Array();
    var listCN_RS=Array();
   
    var showUi=0;
    var showUSi=0;
    var showRi=0;
    var showRSi=0;
    var image_unfilled, shape_unfilled, image_unfilledStory, shape_unfilledStory, image_repaired, shape_repaired, image_repairedStory, shape_repairedStory;
    var clU,clUS,clR,clRS;

    var myParser;
    function initialize(){        
        var myOptions = {
            zoom: 6,
            center: new google.maps.LatLng(54.521081,-4.416504),
            disableDefaultUI: true,
            navigationControl: true,
            scaleControl: false,
            scrollwheel: false,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          
        map = new google.maps.Map(document.getElementById("map"), myOptions);
        geocoder = new google.maps.Geocoder();
        google.maps.event.addListener(map, 'click', function() {
            if(old_description!=null)
                old_description.close();
        });
        var infowindow = new google.maps.InfoWindow({
            content: '<div id="description_'+$(this).attr('id')+'" style="width:250px;"><img src="'+STATIC_IMG_DIR+'spinner.gif" alt="" style="padding:30px 0 30px 119px" /></div>'
        });
        image_unfilled = new google.maps.MarkerImage(STATIC_IMG_DIR+'icons/small/unfilled.png',
                                new google.maps.Size(32, 32),
                                new google.maps.Point(0,0),
                                new google.maps.Point(7, 32));        
        shape_unfilled  = {
                coord: [1, 9, 14, 30],
                type: 'rect'
            };
        image_unfilledStory = new google.maps.MarkerImage(STATIC_IMG_DIR+'icons/small/unfilled_story.png',
                                new google.maps.Size(32, 32),
                                new google.maps.Point(0,0),
                                new google.maps.Point(7, 32));        
        shape_unfilledStory  = {
                coord: [1, 1, 15, 30],
                type: 'rect'
            };            
        image_repaired = new google.maps.MarkerImage(STATIC_IMG_DIR+'icons/small/filled.png',
                                new google.maps.Size(32, 32),
                                new google.maps.Point(0,0),
                                new google.maps.Point(7, 32));        
        shape_repaired  = {
                coord: [1, 9, 14, 30],
                type: 'rect'
            };            
        image_repairedStory = new google.maps.MarkerImage(STATIC_IMG_DIR+'icons/small/filled_story.png',
                                new google.maps.Size(32, 32),
                                new google.maps.Point(0,0),
                                new google.maps.Point(7, 32));        
        shape_repairedStory  = {
                coord: [1, 1, 15, 30],
                type: 'rect'
            };
        $('#filterAllPotholes').attr('checked','checked');
        $('#filterUnfilled, #filterRepaired, #filterWithStories').removeAttr('checked');            
        type_limit_from_click=0;
        find_potholesAJAX('unfilled','');
        find_potholesAJAX('unfilledStory','');
        find_potholesAJAX('repaired','');
        find_potholesAJAX('repairedStory','');       
    }


    function geocode() {
        var address = document.getElementById("location").value;
        geocoder.geocode({
          'address': address,
          'partialmatch': true, 'region':'GB'}, geocodeResult);
    }
  
    function geocodeResult(results, status) {
        if (status == 'OK' && results.length > 0) {
          map.fitBounds(results[0].geometry.viewport);
          
            var icon = new google.maps.MarkerImage(STATIC_IMG_DIR+'icons/my-location.png',
                        new google.maps.Size(20, 20),
                        new google.maps.Point(0,0),
                        new google.maps.Point(9, 11));         
          
          var marker = new google.maps.Marker({
                position: map.getCenter(),
                map: map,
                icon: icon,
                clickable:false,
                zIndex:100000
            });
        } else {
          alert("This is not good address. Please try again");
        }
    }

    function handleEnter(event) {
        if (event.keyCode==13){
            geocode();
            return false;
        }
        else return true;
    }

    function find_potholesAJAX(type_hole,period){
        
        $.ajax({
            type:"POST",
            url: URL+'potholes/find_potholesAJAX/'+type_hole+'/'+period,
            data: 'start=1',
            timeout:25000,
            beforeSend: function(){
            },
            success: function(msg){
                $('#JSmarkers').append(msg);
            },
            error: function(){
            }
        }); 
    };

    function show_descriptionAJAX(id,infowindow){
        
         $.ajax({
            type:"POST",
            url: URL+'potholes/show_descriptionAJAX/'+id+'/'+current_user_id,
            data: 'start=1',
            timeout:25000,
            beforeSend: function(){
            },
            success: function(msg){
                infowindow.setContent('<div style="width:250px;">'+msg+'</div>');
            },
            error: function(){
            }
        });        
    }


    function show_markers(action){
        
        if(action=='table_is_empty'){            
            wait_for_ajax=wait_for_ajax-1;
            show_hide_alert();
        }else{
            switch (action)
            {
                case 'unfilled':                
                    LTableUnfilled=markers_unfilled.length;
                    clU=setTimeout("showUnfilled()",1);
                break;
                case 'unfilledStory':
                    LTableUnfilledStory=markers_unfilledStory.length;
                    clUS=setTimeout("showUnfilledStory()",1);
                break;
                case 'repaired':
                    LTableRepaired=markers_repaired.length;
                    clR=setTimeout("Repaired()",1);
                break;
                case 'repairedStory':
                    LTableRepairedStory=markers_repairedStory.length;
                    clRS=setTimeout("RepairedStory()",1);                    
                break;
            }
        }
    }
    
    
    var type_limit_from_click=0;    
    initialize(); // start for google maps 
    

 
    function showUnfilled(){
        for(i=0;i<=10;i++){
            if(showUi<LTableUnfilled){
                if(i==10){
                    clearTimeout(clU);
                    clU=setTimeout("showUnfilled()",50); 
                }else{
                    marker = markers_unfilled[showUi];
                    showUi=showUi+1;
                    myLatLng = new google.maps.LatLng(marker[0],marker[1]);
                    markerevent = new google.maps.Marker({
                        position: myLatLng,
                        map: map,
                        icon: image_unfilled,
                        shape: shape_unfilled,
                        id: marker[2]
                    });               
                    listU.push(markerevent);
                    //if(marker[3]==1){
                        listC_U.push(markerevent);
                    //}else{                        
                        //listCN_U.push(markerevent);
                       // if(potholes_nominated_default){
                       //     markerevent.setVisible(false);
                       // }
                    //} 
                    eventmarker=google.maps.event.addListener(markerevent, 'click', function() {
                        var infowindow = new google.maps.InfoWindow({
                            content: '<div id="description_'+$(this).attr('id')+'" style="width:250px;"><img src="'+STATIC_IMG_DIR+'spinner.gif" alt="" style="padding:30px 0 30px 119px" /></div>'
                        });
                        if(old_description!=null)
                            old_description.close();
                        infowindow.open(map,this);
                        old_description=infowindow;
                        show_descriptionAJAX($(this).attr('id'),infowindow);
                    });
                    listUE.push(eventmarker);
                }
            }else{
                clearTimeout(clU);
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                }                
                break;
            }
        }
    }

    
    function showUnfilledStory(){
        for(i=0;i<=3;i++){
            if(showUSi<LTableUnfilledStory){
                if(i==3){
                    clearTimeout(clUS);
                    clUS=setTimeout("showUnfilledStory()",10); 
                }else{
                    marker = markers_unfilledStory[showUSi];
                    showUSi=showUSi+1;
                    myLatLng = new google.maps.LatLng(marker[0],marker[1]);
                    markerevent = new google.maps.Marker({
                        position: myLatLng,
                        map: map,
                        icon: image_unfilledStory,
                        shape: shape_unfilledStory,
                        id: marker[2]
                    });               
                    listUS.push(markerevent);
                    //if(marker[3]==1){
                        listC_US.push(markerevent);
                    //}else{
                       // listCN_US.push(markerevent);
                       // if(potholes_nominated_default){
                       //     markerevent.setVisible(false);
                       // }
                   // }
                    eventmarker=google.maps.event.addListener(markerevent, 'click', function() {
                        var infowindow = new google.maps.InfoWindow({
                            content: '<div id="description_'+$(this).attr('id')+'" style="width:250px;"><img src="'+STATIC_IMG_DIR+'spinner.gif" alt="" style="padding:30px 0 30px 119px" /></div>'
                        });
                        if(old_description!=null)
                            old_description.close();
                        infowindow.open(map,this);
                        old_description=infowindow;
                        show_descriptionAJAX($(this).attr('id'),infowindow);
                    });
                    listUSE.push(eventmarker);
                }
            }else{
                clearTimeout(clUS);
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                }                
                break;
            }
        }
    }
    
    function Repaired(){
        for(i=0;i<=2;i++){
            if(showRi<LTableRepaired){
                if(i==2){
                    clearTimeout(clR);
                    clR=setTimeout("Repaired()",10);
                }else{
                    marker = markers_repaired[showRi];
                    showRi=showRi+1;
                    myLatLng = new google.maps.LatLng(marker[0],marker[1]);
                    markerevent = new google.maps.Marker({
                        position: myLatLng,
                        map: map,
                        icon: image_repaired,
                        shape: shape_repaired,
                        id: marker[2]
                    });               
                    listR.push(markerevent);
                    //if(marker[3]==1){
                        listC_R.push(markerevent);
                    //}else{
                    //    listCN_R.push(markerevent);
                    //    if(potholes_nominated_default){
                    //        markerevent.setVisible(false);
                    //    }
                   // }
                    eventmarker=google.maps.event.addListener(markerevent, 'click', function() {
                        var infowindow = new google.maps.InfoWindow({
                            content: '<div id="description_'+$(this).attr('id')+'" style="width:250px;"><img src="'+STATIC_IMG_DIR+'spinner.gif" alt="" style="padding:30px 0 30px 119px" /></div>'
                        });
                        if(old_description!=null)
                            old_description.close();
                        infowindow.open(map,this);
                        old_description=infowindow;
                        show_descriptionAJAX($(this).attr('id'),infowindow);
                    });
                    listRE.push(eventmarker);
                }
            }else{
                clearTimeout(clR);
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                }                
                break;
            }
        }
    }
    function RepairedStory(){
        for(i=0;i<=2;i++){
            if(showRSi<LTableRepairedStory){
                if(i==2){
                    clearTimeout(clRS);
                    clRS=setTimeout("RepairedStory()",10);
                }else{
                    marker = markers_repairedStory[showRSi];
                    showRSi=showRSi+1;
                    myLatLng = new google.maps.LatLng(marker[0],marker[1]);
                    markerevent = new google.maps.Marker({
                        position: myLatLng,
                        map: map,
                        icon: image_repairedStory,
                        shape: shape_repairedStory,
                        id: marker[2]
                    });               
                    listRS.push(markerevent);
                    //if(marker[3]==1){
                        listC_RS.push(markerevent);
                    //}else{
                     //   listCN_RS.push(markerevent);
                    //    if(potholes_nominated_default){
                    //        markerevent.setVisible(false);
                    //    }
                   // }
                    eventmarker=google.maps.event.addListener(markerevent, 'click', function() {
                        var infowindow = new google.maps.InfoWindow({
                            content: '<div id="description_'+$(this).attr('id')+'" style="width:250px;"><img src="'+STATIC_IMG_DIR+'spinner.gif" alt="" style="padding:30px 0 30px 119px" /></div>'
                        });
                        if(old_description!=null)
                            old_description.close();
                        infowindow.open(map,this);
                        old_description=infowindow;
                        show_descriptionAJAX($(this).attr('id'),infowindow);
                    });
                    listRSE.push(eventmarker);
                }
            }else{
                clearTimeout(clRS);
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                }                
                break;
            }
        }
    }
 
 
    
    
    
    
    var interval_for_function=10;
    var Ui=0;
    var USi=0;
    var Ri=0;
    var RSi=0;
    var C_Ui=0;
    var C_USi=0;
    var C_Ri=0;
    var C_RSi=0;
    var CN_Ui=0;
    var CN_USi=0;
    var CN_Ri=0;
    var CN_RSi=0;
    var typeU=false;
    var typeUS=false;
    var typeR=false;
    var typeRS=false;
    var C_typeU=false;
    var C_typeUS=false;
    var C_typeR=false;
    var C_typeRS=false;
    var CN_typeU=false;
    var CN_typeUS=false;
    var CN_typeR=false;
    var CN_typeRS=false;
    
    
    var clC_U2,clC_US2,clC_R2,clC_RS2,clCN_U2,clCN_US2,clCN_R2,clCN_RS2,clU2,clUS2,clR2,clRS2;
    function clear_everything(){
        CN_Ui=0;CN_USi=0;CN_Ri=0;CN_RSi=0;C_Ui=0;C_USi=0;C_Ri=0;C_RSi=0;Ui=0;USi=0;Ri=0;RSi=0;
        clearTimeout(clU2);clearTimeout(clUS2);clearTimeout(clR2);clearTimeout(clRS2);clearTimeout(clC_U2);
        clearTimeout(clC_US2);clearTimeout(clC_R2);clearTimeout(clC_RS2);clearTimeout(clCN_U2);
        clearTimeout(clCN_US2);clearTimeout(clCN_R2);clearTimeout(clCN_RS2);
    }
    function show_spinner(value_for_wait){
        wait_for_ajax=value_for_wait;
        $('#id_spinner').show();
        show_hide_alert();
    }
    $("#filterUnfilled").click(function() {
        if(wait_for_ajax==0){            
            clear_everything();
            if(type_limit_from_click==0){
                typeR=false;
                typeRS=false;
                show_spinner(2);
                clR2=setTimeout("ShowHide_repaired()",5);
                clRS2=setTimeout("ShowHide_repairedStory()",10);            
            }else if(type_limit_from_click==2){
                typeU=true;
                typeUS=true;
                typeR=false;
                typeRS=false;
                show_spinner(4);
                clU2=setTimeout("ShowHide_unfilled()",5);
                clUS2=setTimeout("ShowHide_unfilledStory()",10);
                clR2=setTimeout("ShowHide_repaired()",15);
                clRS2=setTimeout("ShowHide_repairedStory()",20);  
            }else if(type_limit_from_click==3){
                typeU=true;
                typeRS=false;
                show_spinner(2);
                clU2=setTimeout("ShowHide_unfilled()",5);
                clRS2=setTimeout("ShowHide_repairedStory()",10);             
            }else if(type_limit_from_click==4){
                C_typeR=false;
                C_typeRS=false;
                CN_typeU=true;
                CN_typeUS=true;
                show_spinner(4);
                clC_R2=setTimeout("ShowHide_C_repaired()",5);
                clC_RS2=setTimeout("ShowHide_C_repairedStory()",10);
                clCN_U2=setTimeout("ShowHide_CN_unfilled()",5);
                clCN_US2=setTimeout("ShowHide_CN_unfilledStory()",10);
            }
            type_limit_from_click=1;
        }else{
            alert('Please wait')
        }
    });
   
    $("#filterRepaired").click(function() {
        if(wait_for_ajax==0){
            clear_everything();
            if(type_limit_from_click==0){
                typeU=false;
                typeUS=false;
                show_spinner(2);
                clU2=setTimeout("ShowHide_unfilled()",5);
                clUS2=setTimeout("ShowHide_unfilledStory()",10);
            }else if(type_limit_from_click==1){
                typeU=false;
                typeUS=false;
                typeR=true;
                typeRS=true;
                show_spinner(4);
                clR2=setTimeout("ShowHide_repaired()",5);
                clRS2=setTimeout("ShowHide_repairedStory()",10);            
                clU2=setTimeout("ShowHide_unfilled()",15);
                clUS2=setTimeout("ShowHide_unfilledStory()",20);  
            }else if(type_limit_from_click==3){
                typeR=true;
                typeUS=false;
                show_spinner(2);
                clR2=setTimeout("ShowHide_repaired()",5);
                clUS2=setTimeout("ShowHide_unfilledStory()",10);
            }else if(type_limit_from_click==4){
                CN_typeR=true;
                CN_typeRS=true;
                C_typeU=false;
                C_typeUS=false;
                show_spinner(4);
                clCN_R2=setTimeout("ShowHide_CN_repaired()",5);
                clCN_RS2=setTimeout("ShowHide_CN_repairedStory()",10);
                clC_U2=setTimeout("ShowHide_C_unfilled()",5);
                clC_US2=setTimeout("ShowHide_C_unfilledStory()",10);
            }
            type_limit_from_click=2;
        }else{
            alert('Please wait')
        }
    });
    
    $("#filterWithStories").click(function() {
        if(wait_for_ajax==0){
            clear_everything();
            if(type_limit_from_click==0){
                typeU=false;
                typeR=false;
                show_spinner(2);
                clU2=setTimeout("ShowHide_unfilled()",5);
                clR2=setTimeout("ShowHide_repaired()",10);
            }else if(type_limit_from_click==1){
                typeUS=true;
                typeU=false;
                show_spinner(2);
                clRS2=setTimeout("ShowHide_repairedStory()",5);
                clU2=setTimeout("ShowHide_unfilled()",10);            
            }else if(type_limit_from_click==2){
                typeUS=true;
                typeR=false;
                show_spinner(2);
                clUS2=setTimeout("ShowHide_unfilledStory()",5);             
                clR2=setTimeout("ShowHide_repaired()",10);
            }else if(type_limit_from_click==4){                
                CN_typeRS=true;
                CN_typeUS=true;
                C_typeR=false;
                C_typeU=false;
                show_spinner(4);               
                clCN_RS2=setTimeout("ShowHide_CN_repairedStory()",10);
                clCN_US2=setTimeout("ShowHide_CN_unfilledStory()",10);                
                clC_R2=setTimeout("ShowHide_C_repaired()",10);
                clC_U2=setTimeout("ShowHide_C_unfilled()",10);
            }
            type_limit_from_click=3;
        }else{
            alert('Please wait')
        }
    });
    
    $("#filterAllPotholes").click(function() {
        if(wait_for_ajax==0){
            clear_everything();            
            if(type_limit_from_click==1){
                typeR=true;
                typeRS=true;
                show_spinner(2);
                clR2=setTimeout("ShowHide_repaired()",5);
                clRS2=setTimeout("ShowHide_repairedStory()",10);
            }else if(type_limit_from_click==2){
                typeUS=true;
                typeU=true;
                show_spinner(2);
                clUS2=setTimeout("ShowHide_unfilledStory()",5);
                clU2=setTimeout("ShowHide_unfilled()",10);            
            }else if(type_limit_from_click==3){
                typeR=true;
                typeU=true;
                show_spinner(2);
                clR2=setTimeout("ShowHide_repaired()",5);
                clU2=setTimeout("ShowHide_unfilled()",10);
            }else if(type_limit_from_click==4){                
                CN_typeRS=true;
                CN_typeUS=true;
                CN_typeR=true;
                CN_typeU=true;
                show_spinner(4);               
                clCN_RS2=setTimeout("ShowHide_CN_repairedStory()",10);
                clCN_US2=setTimeout("ShowHide_CN_unfilledStory()",10);                
                clCN_R2=setTimeout("ShowHide_CN_repaired()",10);
                clCN_U2=setTimeout("ShowHide_CN_unfilled()",10);
            }
            type_limit_from_click=0;
        }else{
            alert('Please wait')
        }
    });
   
    $("#filterWithContest").click(function() {
        if(wait_for_ajax==0){
            clear_everything();
            if(type_limit_from_click==0){
                CN_typeUS=false; 
                CN_typeU=false;
                CN_typeR=false;
                CN_typeRS=false;
                show_spinner(4);
                clCN_US2=setTimeout("ShowHide_CN_unfilledStory()",5);
                clCN_U2=setTimeout("ShowHide_CN_unfilled()",10);
                clCN_R2=setTimeout("ShowHide_CN_repaired()",5);
                clCN_RS2=setTimeout("ShowHide_CN_repairedStory()",10);                 
            }else if(type_limit_from_click==1){
                C_typeR=true;
                C_typeRS=true;
                CN_typeUS=false;
                CN_typeU=false;
                show_spinner(4);
                clC_R2=setTimeout("ShowHide_C_repaired()",5);
                clC_RS2=setTimeout("ShowHide_C_repairedStory()",10);
                clCN_US2=setTimeout("ShowHide_CN_unfilledStory()",5);
                clCN_U2=setTimeout("ShowHide_CN_unfilled()",10);                
            }else if(type_limit_from_click==2){
                CN_typeR=false;
                CN_typeRS=false;
                C_typeUS=true;
                C_typeU=true;               
                show_spinner(4);                
                clCN_R2=setTimeout("ShowHide_CN_repaired()",5);
                clCN_RS2=setTimeout("ShowHide_CN_repairedStory()",10);                
                clC_US2=setTimeout("ShowHide_C_unfilledStory()",5);
                clC_U2=setTimeout("ShowHide_C_unfilled()",10);            
            }else if(type_limit_from_click==3){
                CN_typeRS=false;
                CN_typeUS=false;
                C_typeU=true;
                C_typeR=true;
                show_spinner(4);
                clCN_RS2=setTimeout("ShowHide_CN_repairedStory()",10);
                clCN_US2=setTimeout("ShowHide_CN_unfilledStory()",5);
                clC_U2=setTimeout("ShowHide_C_unfilled()",10);
                clC_R2=setTimeout("ShowHide_C_repaired()",5);
            }
            type_limit_from_click=4;
        }else{
            alert('Please wait')
        }
    });

 
    
    function ShowHide_unfilled(){
        for(i=0;i<=12;i++){
            if(Ui<LTableUnfilled){
                if(i==12){
                    clearTimeout(clU2);
                    clU2=setTimeout("ShowHide_unfilled()",50);
                    listU[Ui].setVisible(typeU);
                    Ui=Ui+1;
                }else{
                    listU[Ui].setVisible(typeU);
                    Ui=Ui+1;
                }
            }else{
                clearTimeout(clU2);                
                Ui=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();                    
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
        
    }
    function ShowHide_unfilledStory(){
        for(i=0;i<=3;i++){
            if(USi<LTableUnfilledStory){
                if(i==3){
                    clearTimeout(clUS2);
                    clUS2=setTimeout("ShowHide_unfilledStory()",interval_for_function);
                    listUS[USi].setVisible(typeUS);
                    USi=USi+1;
                }else{
                    listUS[USi].setVisible(typeUS);
                    USi=USi+1;
                }
            }else{                
                clearTimeout(clUS2);
                USi=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
    function ShowHide_repaired(){
        
        for(i=0;i<=2;i++){            
            if(Ri<LTableRepaired){
                if(i==2){
                    clearTimeout(clR2);
                    clR2=setTimeout("ShowHide_repaired()",interval_for_function);
                    listR[Ri].setVisible(typeR);
                    Ri=Ri+1;
                }else{
                    listR[Ri].setVisible(typeR);
                    Ri=Ri+1;
                }
            }else{                
                clearTimeout(clR2);
                Ri=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
    function ShowHide_repairedStory(){
        for(i=0;i<=2;i++){
            if(RSi<LTableRepairedStory){
                if(i==2){
                    clearTimeout(clRS2);
                    clRS2=setTimeout("ShowHide_repairedStory()",interval_for_function);
                    listRS[RSi].setVisible(typeRS);
                    RSi=RSi+1;
                }else{
                    listRS[RSi].setVisible(typeRS);
                    RSi=RSi+1;
                }
            }else{
                clearTimeout(clRS2);
                RSi=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
 
    function ShowHide_C_unfilled(){
        for(i=0;i<=12;i++){
            if(C_Ui<listC_U.length){
                if(i==12){
                    clearTimeout(clC_U2);
                    clC_U2=setTimeout("ShowHide_C_unfilled()",50);
                    listC_U[C_Ui].setVisible(C_typeU);
                    C_Ui=C_Ui+1;
                }else{
                    listC_U[C_Ui].setVisible(C_typeU);
                    C_Ui=C_Ui+1;
                }
            }else{
                clearTimeout(clC_U2);                
                C_Ui=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();                    
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
        
    }
    function ShowHide_C_unfilledStory(){
        for(i=0;i<=3;i++){
            if(C_USi<listC_US.length){
                if(i==3){
                    clearTimeout(clC_US2);
                    clC_US2=setTimeout("ShowHide_C_unfilledStory()",interval_for_function);
                    listC_US[C_USi].setVisible(C_typeUS);
                    C_USi=C_USi+1;
                }else{
                    listC_US[C_USi].setVisible(C_typeUS);
                    C_USi=C_USi+1;
                }
            }else{                
                clearTimeout(clC_US2);
                C_USi=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
    function ShowHide_C_repaired(){
        
        for(i=0;i<=2;i++){            
            if(C_Ri<listC_R.length){
                if(i==2){
                    clearTimeout(clC_R2);
                    clC_R2=setTimeout("ShowHide_C_repaired()",interval_for_function);
                    listC_R[C_Ri].setVisible(C_typeR);
                    C_Ri=C_Ri+1;
                }else{
                    listC_R[C_Ri].setVisible(C_typeR);
                    C_Ri=C_Ri+1;
                }
            }else{                
                clearTimeout(clC_R2);
                C_Ri=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
    function ShowHide_C_repairedStory(){
        for(i=0;i<=2;i++){
            if(C_RSi<listC_RS.length){
                if(i==2){
                    clearTimeout(clC_RS2);
                    clC_RS2=setTimeout("ShowHide_C_repairedStory()",interval_for_function);
                    listC_RS[C_RSi].setVisible(C_typeRS);
                    C_RSi=C_RSi+1;
                }else{
                    listC_RS[C_RSi].setVisible(C_typeRS);
                    C_RSi=C_RSi+1;
                }
            }else{
                clearTimeout(clC_RS2);
                C_RSi=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
 
    function ShowHide_CN_unfilled(){        
        for(i=0;i<=12;i++){
            if(CN_Ui<listCN_U.length){
                if(i==12){
                    clearTimeout(clCN_U2);
                    clCN_U2=setTimeout("ShowHide_CN_unfilled()",50);
                    listCN_U[CN_Ui].setVisible(CN_typeU);
                    CN_Ui=CN_Ui+1;
                }else{
                    listCN_U[CN_Ui].setVisible(CN_typeU);
                    CN_Ui=CN_Ui+1;
                }
            }else{
                clearTimeout(clCN_U2);                
                CN_Ui=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();                    
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
        
    }
    function ShowHide_CN_unfilledStory(){
        for(i=0;i<=3;i++){
            if(CN_USi<listCN_US.length){
                if(i==3){
                    clearTimeout(clCN_US2);
                    clCN_US2=setTimeout("ShowHide_CN_unfilledStory()",interval_for_function);
                    listCN_US[CN_USi].setVisible(CN_typeUS);
                    CN_USi=CN_USi+1;
                }else{
                    listCN_US[CN_USi].setVisible(CN_typeUS);
                    CN_USi=CN_USi+1;
                }
            }else{                
                clearTimeout(clCN_US2);
                CN_USi=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
    function ShowHide_CN_repaired(){
        
        for(i=0;i<=2;i++){            
            if(CN_Ri<listCN_R.length){
                if(i==2){
                    clearTimeout(clCN_R2);
                    clCN_R2=setTimeout("ShowHide_CN_repaired()",interval_for_function);
                    listCN_R[CN_Ri].setVisible(CN_typeR);
                    CN_Ri=CN_Ri+1;
                }else{
                    listCN_R[CN_Ri].setVisible(CN_typeR);
                    CN_Ri=CN_Ri+1;
                }
            }else{                
                clearTimeout(clCN_R2);
                CN_Ri=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
    function ShowHide_CN_repairedStory(){
        for(i=0;i<=2;i++){
            if(CN_RSi<listCN_RS.length){
                if(i==2){
                    clearTimeout(clCN_RS2);
                    clCN_RS2=setTimeout("ShowHide_CN_repairedStory()",interval_for_function);
                    listCN_RS[CN_RSi].setVisible(CN_typeRS);
                    CN_RSi=CN_RSi+1;
                }else{
                    listCN_RS[CN_RSi].setVisible(CN_typeRS);
                    CN_RSi=CN_RSi+1;
                }
            }else{
                clearTimeout(clCN_RS2);
                CN_RSi=0;
                wait_for_ajax=wait_for_ajax-1;
                if(wait_for_ajax==0){
                    show_hide_alert();
                    $('#id_spinner').hide();
                } 
                break;
            }
        }
    }
 
   
