ifrm = document.createElement("IFRAME"); 
ifrm.setAttribute("src", ""); 
ifrm.setAttribute("id", "ppLoc"); 
ifrm.setAttribute("style", "position: absolute; width: 250px; height: 250px; z-index: 2500; visibility: hidden;"); 
ifrm.style.position = "absolute";
ifrm.style.width = 500;
ifrm.style.height = 500;
ifrm.style.left = 350;
ifrm.style.top = 10;
ifrm.style.zIndex = 2500;
ifrm.style.visibility = "visible";
ifrm.style.border = "none";
ifrm.src = "Lokator.aspx?lid=91219f5b-81fd-4b73-a2f3-fbc808fe54e9";
document.body.appendChild(ifrm);
var mapAPI = ifrm.contentWindow;


//Map window manipulation
function ShowMap(x, y)
{
	ifrm.style.visibility = "visible";
	ifrm.style.left = x + "px";
	ifrm.style.top = y + "px";
}

function ResizeMap(w, h)
{
	if(w < 200) w = 200;
	if(h < 200) h = 200;
	ifrm.style.width = w + "px";
	ifrm.style.height = h + "px";
}

function HideMap()
{
	ifrm.style.visibility = "hidden";
}

//Move and zoom
function MoveWGS(x, y) {
    try {
        mapAPI.MoveMapWGS(x, y);
    }
    catch (ex) {
        alert("Map not loaded yet.");
    }
}


function ZoomIn() {
    try {
        mapAPI.ZoomIn();
    }
    catch (ex) {
        alert(ex);
    }
}

function ZoomOut() {
    try {
        mapAPI.ZoomOut();
    }
    catch (ex) {
        alert(ex);
    }
}

function ZoomSet() {
    try {
        mapAPI.ZoomSet(3);
    }
    catch (ex) {
        alert(ex);
    }
}

function getPositionInfo() {
    var tlWGS = mapAPI.GetTopLeftWGS();
    var cWGS = mapAPI.GetCenterWGS();
    var brWGS = mapAPI.GetBottomRightWGS();

    alert("Top left WGS:           " + tlWGS.X + "; " + tlWGS.Y + "\n" +
          "Center WGS:            " + cWGS.X + "; " + cWGS.Y + "\n" +
          "Bottom right WGS:   " + brWGS.X + "; " + brWGS.Y + "\n");

}


//ObjectsOnTheMap

function addMarker(x, y) {
    mapAPI.AddMarkerWGS(1, "Test<br>marker", "blue", 1, x, y, "http://www.planplus.rs/Images/src/bgbluem.png", 30, 36, "bc", null, true, true, 3, "");
}

function removeMarker() {
    mapAPI.RemoveMarker(1);
}

function removeAllMarkers() {
    mapAPI.RemoveMarkers();
}

function showMarker() {
    mapAPI.ShowMarker(1);
}

function hideMarker() {
    mapAPI.HideMarker(1);
}

function addPath() {
    mapAPI.AddLineWGS(20.40888, 44.81769, 20.44591, 44.79957, "testGroup1", "red", 4);
    mapAPI.AddLineWGS(20.44591, 44.79957, 20.46591, 44.79957, "testGroup1", "blue", 6);
    mapAPI.AddLineWGS(20.46591, 44.79957, 20.45591, 44.77957, "testGroup1", "black", 2);
}

function removePathByGroupName() {
    mapAPI.RemoveLineGroup("testGroup1");
}

function removePath() {
    mapAPI.RemoveLines();
}

function setRouteStartWGS(x, y) {
    mapAPI.SetStartWGS(x, y);
}

function setRouteStartGauss(x, y) {
    mapAPI.SetStartGauss(x, y);
}

function setRouteEndWGS(x, y) {
    mapAPI.SetEndWGS(x, y);
}

function setRouteEndGauss(x, y) {
    mapAPI.SetEndGauss(x, y);
}

function resetRoute() {
    mapAPI.ClearRoute();
}

function bAddMarker() {
    executeAjaxRequest("sample.aspx", "bAddMarkerPush(response)", "baddmarker");
}
function bAddMarkerPush(objectsXML) {
    try {

        var objlMaxX = 0;
        var objlMaxY = 0;
        var objlMinX = 396000;
        var objlMinY = 636000;

        var xmlDoc = XMLParser(objectsXML);
        if (xmlDoc) {
            var red;

            var objekti = xmlDoc.documentElement.getElementsByTagName("o");


            for (var i = 0; i < objekti.length; i++) {
                var tR = objekti[i];
                red = new yObject();

                red.RB = tR.getAttribute("RB");
                red.ID = tR.getAttribute("ID");
                red.x = tR.getAttribute("X");
                red.y = tR.getAttribute("Y");

                red.BrojObjekata = tR.getAttribute("BO");
                red.PID = tR.getAttribute("PID");

                if (parseInt(red.x) > objlMaxX && parseInt(red.x) > 0) objlMaxX = red.x;
                if (parseInt(red.y) > objlMaxY && parseInt(red.y) > 0) objlMaxY = red.y;
                if (parseInt(red.x) < objlMinX && parseInt(red.x) > 0) objlMinX = red.x;
                if (parseInt(red.y) < objlMinY && parseInt(red.y) > 0) objlMinY = red.y;
                
                
                mapAPI.bulkAddObject(red.ID, red.ID, "black", "", red.x, red.y, "http://www.planplus.rs/Services/Visual/GetMapIcon.aspx?t=1&c=b&n=" + red.RB, 30, 36, "bc", null, true, false, 1, "<div style='width:150px;height:100px;padding:6px;background-color:white;border:1px solid silver;'>Object ID:" + red.ID + "<br><br>Put any HTML in this popup. Use HidePopup() function for close button. <a href='javascript:HidePopup();'>Close</a></div>", true);

                if (i == 1 || i == 19) {
                    var point = new yObject();
                    point.X = red.x;
                    point.Y = red.y;
                    mapAPI.bulkAddCircle(point, 200, "", "gray", "blue", 10);
                }
                
            }
        }

        mapAPI.RefreshLayers();

    }
    catch (ex) {
    }
}

function bAddVectorPathWGS() {
    var Points = [];
    var Point1 = new mapPoint();
    Point1.X = 20.40888;
    Point1.Y = 44.81769;
    Points[Points.length] = Point1;
    var Point2 = new mapPoint();
    Point2.X = 20.44591;
    Point2.Y = 44.79957;
    Points[Points.length] = Point2;
    var Point3 = new mapPoint();
    Point3.X = 20.46591;
    Point3.Y = 44.77957;
    Points[Points.length] = Point3;
    var Point4 = new mapPoint();
    Point4.X = 20.48591;
    Point4.Y = 44.78957;
    Points[Points.length] = Point4;
    
    mapAPI.BulkAddPathWGS(Points, "testGroup1", "blue", 5);

    Points = [];
    Point1 = new mapPoint();
    Point1.X = 20.42888;
    Point1.Y = 44.81769;
    Points[Points.length] = Point1;
    Point2 = new mapPoint();
    Point2.X = 20.46591;
    Point2.Y = 44.79957;
    Points[Points.length] = Point2;
    Point3 = new mapPoint();
    Point3.X = 20.48591;
    Point3.Y = 44.77957;
    Points[Points.length] = Point3;
    Point4 = new mapPoint();
    Point4.X = 20.50591;
    Point4.Y = 44.78957;
    Points[Points.length] = Point4;

    mapAPI.BulkAddPathWGS(Points, "testGroup2", "red", 3);

    mapAPI.RefreshPaths();
}

function apiRefreshObjects() {
    mapAPI.RefreshObjects();
}

function apiRefreshPaths() {
    mapAPI.RefreshPaths();
}

function mapPoint() {
}

function yObject() {
}























//helper


var isIe, isMoz, isIE9 = false;
var mode = "GET";

var browserversion = 999;
if (navigator.appVersion.indexOf("MSIE") != -1)
    browserversion = parseFloat(navigator.appVersion.split("MSIE")[1]);


var cwl = document.body.clientWidth;
var chl = document.body.clientHeight;


function gi(str) {
    return document.getElementById(str);
}

function browserCheck() {

    var body = document.body || null;
    var range;
    isIe = body && typeof body.insertAdjacentHTML != "undefined";
    isMoz = (body && !isIe &&
		typeof body.appendChild != "undefined" &&
		typeof document.createRange != "undefined" &&
		typeof (range = document.createRange()).setStartBefore != "undefined" &&
		typeof range.createContextualFragment != "undefined");
    isIe = isIe && document.all && !window.opera;

    isMoz = isMoz && typeof body.style.MozOpacity != "undefined";

    if (window.msPerformance)
        isIE9 = true;
}

browserCheck();

function getClickedObject(e) {

    var clickedObject;

    if (isIe) {
        clickedObject = event.srcElement;
    } else {
        if (e && e.target)
            clickedObject = e.target;
    }
    return clickedObject

}


function getKeyCode(e) {
    if (isIe) {
        return window.event.keyCode;
    } else {
        var retVal = e.which;
        e.preventDefault();
        return retVal;
    }
}


function isShift(e) {
    if (isIe) {
        return window.event['shiftKey'];
    } else {
        return e.shiftKey;
    }
}


function getMouseX(e) {
    var delta;
    if (isIe) delta = 4; else delta = 0;

    var scrollLeft = document.body.scrollLeft;

    if (isIe) return scrollLeft + window.event.clientX - delta; else return e.pageX - delta;
}


function getMouseY(e) {
    var delta;
    if (isIe) delta = 4; else delta = 0;

    var scrollTop = document.body.scrollTop;

    if (isIe) return scrollTop + window.event.clientY - delta; else return e.pageY - delta;
}


function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    } else if (obj.x)
        curleft += obj.x;

    return curleft;
}


function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    } else if (obj.y)
        curtop += obj.y;
    return curtop;
}


function getWindowWidth() {
    if (isIe) return document.body.clientWidth;
    else return window.innerWidth;

}


function getWindowHeight() {
    if (isIe) return document.body.clientHeight;
    else return window.innerHeight;
}


function getStyleLeft(obj) {
    if (isIe) return parseInt(obj.style.posLeft); else return parseInt(obj.style.left);
}


function setStyleLeft(obj, left) {
    if (isIe) obj.style.posLeft = left; else obj.style.left = left;
}


function getStyleTop(obj) {
    if (isIe) return parseInt(obj.style.posTop); else return parseInt(obj.style.top);
}


function setStyleTop(obj, top) {
    if (isIe) obj.style.posTop = top; else obj.style.top = top;
}


function getStyleWidth(obj) {
    if (isIe) return parseInt(obj.style.posWidth); else return parseInt(obj.style.width);
}


function setStyleWidth(obj, width) {
    if (isIe) obj.style.posWidth = width; else obj.style.width = width;
}


function getStyleHeight(obj) {
    if (isIe) return parseInt(obj.style.posHeight); else return parseInt(obj.style.height);
}


function setStyleHeight(obj, height) {
    if (isIe) obj.style.posHeight = height; else obj.style.height = height;
}


function setElementStyle(element, property, value) {
    element.style[property] = value;
}


function getElementStyle(element, property) {
    return element.style[property];
}


function sv(element, v) {
    if (v)
        element.style.visibility = "visible";
    else
        element.style.visibility = "hidden";
}


function sd(element, v) {
    if (v) {
        if (isIe)
            element.display = "block";
        else
            element.display = "";
    }
    else
        element.display = "none";
}


function setCursor(cursorStyle) {
    document.body.style.cursor = cursorStyle;
}


function XMLParser(sXML) {

    var xmlDoc;

    if (isIe) {
        if (sXML.documentElement) {
            xmlDoc = sXML; //already XML document
        }
        else {
            try {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async = "false";
                xmlDoc.loadXML(sXML);
            }
            catch (ex) {
                reportError("XMLParser", ex);
            }
        }
    } else {
        var parser = new DOMParser();
        xmlDoc = parser.parseFromString(sXML, "text/xml");
    }
    return xmlDoc;
}


//AJAX and REPLACEMENT for ActiveX problem
var myRequestId = 0;
var myRequestObjects = [];

function executeAjaxRequest(url, callBackFunction, type) {

    setCursor('progress');
    var xmlhttp = false;

    if (type != "preview")
        CheckAjaxRequestAndAbort(type);

    //if(!window.XMLHttpRequest) {	
    if (isIe) {
        // jednog dana sa vezijom IE 7 XMLHttp object nece biti ActiveX i moci ce da radi normalno kao u Mozilli ili u Intranetu
        //xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                // Something went wrong
                return false;
            }
        }
        //xmlhttp = new myXMLHttpRequest(type);
    } else {
        //allow cross-domain-xmlhttprequest
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
        } catch (e) {
            //alert("Permission UniversalBrowserRead denied.");
        }
        xmlhttp = new XMLHttpRequest(type);
    }

    xmlhttp.open("GET", url, true);
    xmlhttp.send(true);

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            //var response = xmlhttp.responseText.toString();	
            var response = xmlhttp.responseText;
            eval(callBackFunction);
        }
        setCursor('default');
    }
}


function ShowAjax() {
    var s = "";
    for (var i = 0; i < myRequestObjects.length; i++) {
        try {
            s += "ID: " + myRequestObjects[i].i + " Type: " + myRequestObjects[i].type + "\n";
        } catch (ex) { }
    }
    alert(s);
    alert(myRequestObjects.length);
}


function myXMLHttpRequest(type) {
    var i = 0;
    var url = '';
    var responseText = '';
    this.onreadystatechange = function() {
        return false;
    }
    this.type = type;

    this.open = function(method, url) {
        this.i = ++myRequestId; // id number of this request
        this.url = url;

        var iframe;

        //if (browserversion == 9) {
        iframe = document.createElement("iframe");
        iframe.setAttribute("id", "myRequestIframe_" + this.i);
        iframe.style.visibility = "hidden";
        setStyleLeft(iframe, -500);
        setStyleTop(iframe, -500);

        //	    }
        //	    else
        //	        iframe = document.createElement('<xml id="myRequestIframe_' + this.i + '" type="text/javascript" src=""></xml>');


        document.body.appendChild(iframe);
    }
    this.send = function(postdata) {

        var myIframe = document.getElementById('myRequestIframe_' + this.i);
        myIframe.src = this.url;
        myRequestObjects[this.i] = this;
        setTimeout('myXMLHttpRequestCheckState(' + this.i + ',"' + type + '")', 500);
    }
    return true;
}


function CheckAjaxRequestAndAbort(type) {
    if (type) {
        for (var i = 0; i < myRequestObjects.length; i++) {
            var xmlhttp = myRequestObjects[i];
            if (xmlhttp)
                if (xmlhttp.type == type) {
                xmlhttp.onreadystatechange = function() { return false; };
                var myIframe = document.getElementById('myRequestIframe_' + xmlhttp.i);
                myIframe.innerHTML = "";
                myIframe = null;
                xmlhttp = null;
                myRequestObjects[i] = null;
            }
        }
    }
}


function myXMLHttpRequestCheckState(inst, type) {

    if (myRequestObjects[inst]) {
        var myIframe = document.getElementById('myRequestIframe_' + inst);

        if (myIframe.readyState == 'complete') { //for iframe and xml
            //if(myIframe.readyState == 'loaded'){ //for script

            var responseText = ""; // for script nothing - already in code
            //.document.body.childNodes[0].data; //for iframe html
            //var responseText = window.frames['myRequestIframe_'+inst].document.body.innerText; //for iframe XML
            responseText = myIframe.XMLDocument; //for xml

            myRequestObjects[inst].responseText = responseText;
            myRequestObjects[inst].readyState = 4;
            myRequestObjects[inst].status = 200;
            myRequestObjects[inst].onreadystatechange();
            if (myIframe.parentNode) {
                myIframe.parentNode.removeChild(myIframe);
            }
        } else {
            setTimeout('myXMLHttpRequestCheckState(' + inst + ')', 500);
        }
    }
}
//end AJAX and REPLACEMENT for ActiveX problem


function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}

function whichKeyPressed(e) {
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    var character = String.fromCharCode(code);
    alert('Character was ' + character);
}


function whichMouseButton(e) {
    var rightclick;
    if (!e) var e = window.event;
    if (e.which) rightclick = (e.which == 3);
    else if (e.button) rightclick = (e.button == 2);

    return rightclick;
}


function mousePosition(e) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft;
        posy = e.clientY + document.body.scrollTop;
    }
}


function getURLParam(strParamName) {
    var strReturn = "";
    var strHref = document.location.href;
    if (strHref.indexOf("?") > -1) {
        /*var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();*/
        var strQueryString = strHref.substr(strHref.indexOf("?"));
        var aQueryString = strQueryString.split("&");
        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            if (aQueryString[iParam].indexOf(strParamName + "=") > -1) {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                if (aParam[2] != null) {
                    strReturn += "=" + aParam[2];
                }
                break;
            }
        }
    }

    return strReturn;
}

function getURL() {
    var strHref = document.location.href;
    var urlString = strHref.split("?");
    return urlString[0];
}


function ReplaceEmptySpace(str) {
    var pom = str;
    var res = "";

    for (var i = 0; i < pom.length; i++) {
        if (pom.charCodeAt(i) == 32)
            res += "&nbsp;";
        else
            res += pom.charAt(i);

    }

    return res;
}




