var isOnCall = [];
var showIl = true;
var showRe = true;

function showIllegal(show){
      showIl = show;      
      for(i in isOnCall){
            if (isOnCall[i].status==1){
                  isOnCall[i].show=show;
                  if(show)                        
                        isOnCall[i].marker.show();
                  else
                        isOnCall[i].marker.hide();
            }
                  
      }
      
      
}

function showRemoved(show){
      showRe = show;
      for(i in isOnCall){
            if (isOnCall[i].status==4){
                  isOnCall[i].show=show;
                  if(show)                        
                        isOnCall[i].marker.show();
                  else
                        isOnCall[i].marker.hide();
            }
      }      
}


function showIllegalSigns() {
      var b = map.getBounds();
      var bounds = {'southwest':{'lat':b.getSouthWest().lat(), 'lng':b.getSouthWest().lng()},'northeast':{'lat':b.getNorthEast().lat(), 'lng':b.getNorthEast().lng()}};
      mobGeo.showIllegalSigns(getNewIllegalSigns,bounds);      
}

function getNewIllegalSigns(data) {      
      //alert(data.reports);      
      illegal_signs = data[0].reports;      
        for (var i in illegal_signs) {
          var is = illegal_signs[i];
          if((isOnCall[is.id]==undefined)&&(is.status==1)) addIS(is);
          if((isOnCall[is.id]==undefined)&&(is.status==4)) addIS(is);
        }        
        groupMarkersByLatLng();
}

function addIS(is) {
    isOnCall[is.id] = is;    
    isOnCall[is.id].onmap=false;
  
  //**************** FUNCTION FOR MASS MARKER DISPLAY IN getNewIllegalSigns()******************  
//    GEvent.addListener(m,'click',function(){ this.openInfoWindow(getISInfo(this.isdata)); });
//    map.addOverlay(m);    
    
}

function groupMarkersByLatLng(){      
      var currentLat,currentLng;
      var counter;
      var id_array;
      for (i=0;i<isOnCall.length;i++){            
            counter=0;
            if(isOnCall[i]){
                  if (!isOnCall[i].onmap){
                     id_array=[];
                     var icon = mobGeo._getMarkerIcon('Default');
                     if(isOnCall[i].status==4) icon = mobGeo._getMarkerIcon('Trans');                     
                     var m = new GMarker(new GLatLng(isOnCall[i].lat,isOnCall[i].lng),{'icon':icon});                         
                     isOnCall[i].marker = m;
                     
                     counter++;
                     isOnCall[i].onmap=true;
                     
                     currentLat = isOnCall[i].lat;
                     currentLng = isOnCall[i].lng;
                     
                     for(j=i;j<isOnCall.length;j++){
                        if(isOnCall[j]){
                              if((currentLat==isOnCall[j].lat)&&(currentLng==isOnCall[j].lng)){                                    
                                    counter++;
                                    id_array.push(isOnCall[j].id);
                                    isOnCall[j].marker = m;
                                    isOnCall[j].onmap=true;
                              }
                        }
                     }                     
                     if(counter>0){
                        m.id_array = id_array;
                        GEvent.addListener(m,'click',function(){ this.openInfoWindow(getMassISInfo(this.id_array)); });
                        map.addOverlay(m);    
                     }
                  }
            }
      }      
}

function getISInfo(is){  
  var res = '<div align="left" style="width:300px">';
  res += '<b><a href="http://www.illegalsigns.gov.gr/?page_id=71&id_kataggelias='+is.id+'">'+is.address+'</a></b><br />';
  res += '<a href="http://www.illegalsigns.gov.gr/?page_id=71&id_kataggelias='+is.id+'">'+is.comments+'</a><br />';
  
  if(is.photo!=''){
	res += '<a href="http://www.illegalsigns.gov.gr/?page_id=71&id_kataggelias='+is.id+'" style="border:none"><img src="http://www.illegalsigns.gov.gr:8080/illegalsigns/photos_uploaded/'+is.photo+'" width="100" height="100"></a><br>';  
  }  
  res += '</div>';
  return res;
}

function getMassISInfo(ids){      
      var res='';
      var is;
      if(ids.length==1){
            res = getISInfo(isOnCall[ids[0]]);
            return res;
      }
      for(i in ids){
            is = isOnCall[ids[i]];
          res += '<b><a href="http://www.illegalsigns.gov.gr/?page_id=71&id_kataggelias='+is.id+'">Αριθμός Καταγγελίας:&nbsp;'+is.id+'</a></b><br>';
      }
      return res;
}

function updateIllegalSigns(){
	    var b = map.getBounds();
	    var bounds = {'southwest':{'lat':b.getSouthWest().lat(), 'lng':b.getSouthWest().lng()},'northeast':{'lat':b.getNorthEast().lat(), 'lng':b.getNorthEast().lng()}};      
	    mobGeo.showIllegalSigns(getNewIllegalSigns,bounds);      
}

function getSignType(type){	
	if(type==0) return "Πινακίδα1"
	else if(type==1) return "ΠΙνακίδα2"
	else if(type==2) return "Πινακίδα3"
	else if(type==3) return "Πινακίδα4"
}


