








function OnTimeOut(args) {
alert("Service call timed out.");

}

function OnError(args) {
alert("Error calling service method.");
}
////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

var nizU2 = [];
var pU2 = [];
var polyline
var map;
var marker;
var markerU = [];
var markerU2 = [];
var geocoder;
var icons = {};

function marlos() {
    document.getElementById("gs").value=''
    document.getElementById("gd").value = ''
}

function Adrlokac() {

    ret = FilterService.Adrlokac(document.getElementById("gs").value + "_" + document.getElementById("gd").value, OnCompleteAdrlokac, OnTimeOut, OnError);
    return (true);
}
///////////////////////////////////////////////

function OnCompleteAdrlokac(args) {
    document.getElementById("lokacija").value = args
    LokacPol(args)

}
//////////////////////////////////////////////////////////////////
function LokacPol(ulaz) {

    if (ulaz.length < 2) {
       // document.getElementById("Text227").value = ('Upisite Lokaciju')
        return
    }
    ret = FilterService.lokiv(ulaz, OnComLokacPol, OnTimeOut, OnError);
    return (true);
}

//////////////////////////////////////////////////////////////////////
function OnComLokacPol(args) {

    if (polyline != null) { map.removeOverlay(polyline); }

    if (args.length < 2) {
        //document.getElementById("Text227").value = ('Lokacija nije na mapi. ')
        return
    }
    var p1

    var blueIcon = new GIcon(G_DEFAULT_ICON);
    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/red/blank.png";

    blueIcon.iconSize = new GSize(7, 7);
    blueIcon.shadowSize = new GSize(0, 0);
    blueIcon.iconAnchor = new GPoint(6, 20);
    blueIcon.infoWindowAnchor = new GPoint(5, 1);
    markerOptions = { icon: blueIcon };


    var niz = [];
    niz = args


    for (var i in niz) {

        var mySplitResult = niz[i].split(",");


        niz[i] = new GLatLng(eval(mySplitResult[0]), eval(mySplitResult[1]));
   
        if (i == 0) { map.setCenter(niz[0]) };

        //map.addOverlay(new GMarker(p1, markerOptions));
    }

    //document.getElementById("Text227").value = "Lokacija je na mapi"

    //  var polygon = new GPolygon(niz, null, 1, 0.7, "#ff0000", 0.1, { clickable: false });
    //  map.addOverlay(polygon);
    polyline = new GPolyline(niz, "#ff0000", 4, 1);
    map.addOverlay(polyline);

}
///////////////////////////////////////////////////////////////
///////////////////////ulice//////////////////////////////////////////////
function ul(ulaz) {
  
    
    if (ulaz.length < 2) {
  //  document.getElementById("Text226").value = ('upisite Adresu')  
     return
      
     }
     
     
    //document.getElementById("Text226").value = "Ulica nece biti na mapi"
    
    
    ret = FilterService.prikaziulice(ulaz, OnCompleteG1, OnTimeOut, OnError);
    return (true);
}
////////////////////////////////////////
function OnCompleteG1(args) {
    var cc
    cc = '' + args

    if (cc.length < 2) {
        //document.getElementById("Text226").value = "Adresa nije na mapi"
        return
      }

    var address = cc + " , Beograd" //document.forms[0].q.value;
    geocoder.getLocations(address, addAddressToMap);



}
////////////////////////////////
function addAddressToMap(response) {
    if (markerU != null) { map.removeOverlay(markerU); }
 
    for (ctr = 0; ctr < markerU2.length; ctr++)
    { map.removeOverlay(  markerU2[ctr]) }
    

    if (!response || response.Status.code != 200) {

        Gadre2(document.getElementById('adresa').value);

        //alert("Sorry, we were unable to geocode that address");
    } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);



        if (place.address.length < 16) {

            Gadre2(document.getElementById('Tabs_Panel1_ctl00_adresa').innerHTML);
        }

        else {
            markerU = new GMarker(point);
            map.addOverlay(markerU);
          

             map.setCenter(point)
            //document.getElementById("Text226").value = "Adresa na mapi"   
        }

    }


}
//////////////////////////////////////////////////
function Gadre2(ulaz) {

  
    if (ulaz.length < 2) {
       // document.getElementById("Text226").value = ('upisite Adresu')
        return
    }
    ret = FilterService.brzo(ulaz, OnComplete, OnTimeOut, OnError);
    return (true);
}




function OnComplete(args) {
    var prikaz
    prikaz=false
    if (args.length < 2) {
        //document.getElementById("Text226").value = ('Adresa nije na mapi. ')
        return
    }

    var blueIcon = new GIcon(G_DEFAULT_ICON);
//    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/blank.png";

//    blueIcon.iconSize = new GSize(9, 9);
//    blueIcon.shadowSize = new GSize(1, 1);
//    blueIcon.iconAnchor = new GPoint(6, 20);
//    blueIcon.infoWindowAnchor = new GPoint(5, 1);
//    markerOptions = { icon: blueIcon };

   
    nizU2 = args

  

    for (var i in nizU2) {
prikaz=true
        var mySplitResult = nizU2[i].split(",");
        pU2[i] = new GLatLng(eval(mySplitResult[0]), eval(mySplitResult[1]));

        if (i == 0) { map.setCenter(pU2[0])
        //map.addOverlay(new GMarker(pU, markerOptions));


        markerU2[i] = new GMarker(pU2[i], blueIcon);
        map.addOverlay(markerU2[i]);
 };
    }
//if(prikaz==true){document.getElementById("Text226").value = "Adresa je na mapi"}
//else { document.getElementById("Text226").value = "Adresa nije na mapi" }



}
///////////////detaljno///////////////////////////////////////////////////////////////////////////
function ulD(ulaz) {

    if (ulaz.length < 2) {
        //document.getElementById("Text226").value = ('upisite Adresu')
        return
  }
  
    ret = FilterService.prikaziulice(ulaz, OnCompleteG1, OnTimeOut, OnError);
    return (true);
}
//////////////////////////////////////////////////////
function mapprik()
{

alert("cc")
}
