

    function show_hide_alert(){
        if(wait_for_ajax==0){
            $('#show_alert').unbind('click').remove();            
        }else{
            $('.middle_r').prepend('<div id="show_alert" style="height:117px;position:absolute;width:260px;left:1px"></div>');
             $('#show_alert').css({'opacity':'0.02','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()
            }
        }
        
    })
   

    
    
    $('#period_for_potholes a').click(function(e){
        e.preventDefault();
        if(wait_for_ajax==0){
            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');
            $('#filterUnfilled, #filterRepaired, #filterWithStories').removeAttr('checked');
            $('#id_spinner').show();
            wait_for_ajax=4;
            removemarkersU();
            removemarkersUS();
            removemarkersR();
            removemarkersRS();                        
        }else{
            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 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'
            };
            
        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;
        }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;
            }
        }
    }
    
    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);
                    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);
                    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);
                    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);
                    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 type_limit_from_click=0;
    var interval_for_function=10;
    var Ui=0;
    var USi=0;
    var Ri=0;
    var RSi=0;
    var typeU=false;
    var typeUS=false;
    var typeR=false;
    var typeRS=false;
    
    
    var clU2,clUS2,clR2,clRS2;
    
    $("#filterUnfilled").click(function() {
        if(wait_for_ajax==0){            
            Ui=0;USi=0;Ri=0;RSi=0;
            clearTimeout(clU2);
            clearTimeout(clUS2);
            clearTimeout(clR2);
            clearTimeout(clRS2);
            if(type_limit_from_click==0){
                typeR=false;
                typeRS=false;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                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;
                wait_for_ajax=4;
                $('#id_spinner').show();
                show_hide_alert();
                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;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                clU2=setTimeout("ShowHide_unfilled()",5);
                clRS2=setTimeout("ShowHide_repairedStory()",10);             
            }
            type_limit_from_click=1;
        }else{
            alert('Please wait')
        }
    });
   
    $("#filterRepaired").click(function() {
        if(wait_for_ajax==0){
            Ui=0;USi=0;Ri=0;RSi=0;
            clearTimeout(clU2);
            clearTimeout(clUS2);
            clearTimeout(clR2);
            clearTimeout(clRS2);
            if(type_limit_from_click==0){
                typeU=false;
                typeUS=false;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                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;
                wait_for_ajax=4;
                $('#id_spinner').show();
                show_hide_alert();
                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;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                clR2=setTimeout("ShowHide_repaired()",5);
                clUS2=setTimeout("ShowHide_unfilledStory()",10);
            }
            type_limit_from_click=2;
        }else{
            alert('Please wait')
        }
    });
    
    $("#filterWithStories").click(function() {
        if(wait_for_ajax==0){
            Ui=0;USi=0;Ri=0;RSi=0;
            clearTimeout(clU2);
            clearTimeout(clUS2);
            clearTimeout(clR2);
            clearTimeout(clRS2);
            if(type_limit_from_click==0){
                typeU=false;
                typeR=false;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                clU2=setTimeout("ShowHide_unfilled()",5);
                clR2=setTimeout("ShowHide_repaired()",10);
            }else if(type_limit_from_click==1){
                typeUS=true;
                typeU=false;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                clRS2=setTimeout("ShowHide_repairedStory()",5);
                clU2=setTimeout("ShowHide_unfilled()",10);            
            }else if(type_limit_from_click==2){
                typeUS=true;
                typeR=false;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                clUS2=setTimeout("ShowHide_unfilledStory()",5);             
                clR2=setTimeout("ShowHide_repaired()",10);
            }
            type_limit_from_click=3;
        }else{
            alert('Please wait')
        }
    });
    
    $("#filterAllPotholes").click(function() {
        if(wait_for_ajax==0){
            Ui=0;USi=0;Ri=0;RSi=0;
            clearTimeout(clU2);
            clearTimeout(clUS2);
            clearTimeout(clR2);
            clearTimeout(clRS2);            
            if(type_limit_from_click==1){
                typeR=true;
                typeRS=true;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                clR2=setTimeout("ShowHide_repaired()",5);
                clRS2=setTimeout("ShowHide_repairedStory()",10);
            }else if(type_limit_from_click==2){
                typeUS=true;
                typeU=true;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                clUS2=setTimeout("ShowHide_unfilledStory()",5);
                clU2=setTimeout("ShowHide_unfilled()",10);            
            }else if(type_limit_from_click==3){
                typeR=true;
                typeU=true;
                wait_for_ajax=2;
                $('#id_spinner').show();
                show_hide_alert();
                clR2=setTimeout("ShowHide_repaired()",5);
                clU2=setTimeout("ShowHide_unfilled()",10);
            }
            type_limit_from_click=0;
        }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;
            }
        }
    }
   