//--------------------------------------------------------Global---------------------------------------------------------
//--------------------------------------------------------Global---------------------------------------------------------
var MaxMessageLength = 2083;
//var EMAP_HOST_DOMAIN = "http://kerenc-ags92-vm/";
var EMAP_HOST_DOMAIN = "http://www4.emap.co.il/";
var isIE;

if(navigator.userAgent.indexOf("Gecko") != -1){
    isIE = false;
}else{
    isIE = true;
}

function emapAPI(containerID){
    if(emapAPI.instance != null)
        return emapAPI.instance;
    emapAPI.instance = this;
    this.Type = "emapAPI";
    this.Message = "";
    this.MessageIndex  = 0;
    this.Elements = new Array();
    this.DefaultInterval = 100;
    this.QueueInterval = 200;
    this.ListenerTimer = setInterval(emapAPI.checkForMessages, this.DefaultInterval);
    this.HF = null;
    this.User = "";
    //for backward compatibility
    if(containerID!=null){
        return this.AddElement("Map",containerID);
    }    
}
emapAPI.instance = null;
emapAPI.prototype.AddElement = function(type , startParams)
{
     var ELEMENT = this.Elements[this.Elements.length] = eval("new eMap_" + type + "(" + this.Elements.length + ",'" + startParams + "');");
     ELEMENT.User = this.User;
     return ELEMENT
}
emapAPI.prototype.GetElementByID = function(id){
    for(var i=0;i<this.Elements.length;i++)
        if(this.Elements[i].ID==id)
            return this.Elements[i];
    return;
}
emapAPI.prototype.GetHF = function(){
    if(this.HF==null){
        var e = this.AddElement("Element","body");
        if(e.Container==null)
            e.Container = document.body;
        e.DocumentUrl = EMAP_HOST_DOMAIN + "Map0/RequestHandler.aspx";
        e.BuildFrame();
        e.Frame.style.display = 'none';
        this.HF = e;
    }
    return this.HF;
}
emapAPI.checkForMessages = function(){
    var api_message = location.hash.replace('#','');
    if(( api_message != "1")&&( api_message != "")){
	    var api = emapAPI.instance;
	    api_message = api.Message + api_message;
	    //api.LastMessage = api_message;
	    document.location.href = document.location.href.split("#")[0] + "#1";
	    //handle message
	    if(api_message.substr(0,4)=="part"){
	        if(api.MessageIndex+1 == api_message.substr(4,1)){
	            api.Message += api_message.substr(5);
	            if(api.MessageIndex==0){
	                clearInterval(api.ListenerTimer);
	                api.ListenerTimer = setInterval(emapAPI.checkForMessages, api.QueueInterval);
	            }
	            api.MessageIndex++;
	        }else{
	            alert("Error with handling long URLs")
	        }
	    }else{
	        var api_message_array = api_message.split(":::");
	        var element = emapAPI.instance.GetElementByID(api_message_array[0])
	        if(element!=null)
	            element.processMessage(api_message_array[1]);
	        api.LastMessage = "";
	        if(api.MessageIndex>0){
	            clearInterval(api.ListenerTimer);
	            api.ListenerTimer = setInterval(emapAPI.checkForMessages, api.DefaultInterval);
	        }
	        api.MessageIndex = 0;
	   }
	}
}
//----------------------------Base Element Class-----------------------------------------------------------------
//----------------------------Base Element Class-----------------------------------------------------------------

function eMap_Element(index,containerID){
    this.Type = "Element";
    this.ID;
    this.Index = index;
    this.Container = document.getElementById(containerID);
    this.Frame = null;
    this.initialized = false;
    this.documentUrl = "";
    this.User = "";
    //Notice: message and form are optional!
    this.Init = function(width,height,message,form){
        this.BuildFrame();
        this.ResizeFrame(width,height);
        this.DoSubmit(message,form)
    }
    this.BuildFrame = function(){
        if(this.frame==null){
            var frameID = "eMap" + this.Type + "Frame" + this.Index;
            if(isIE)
            {
                var ifrm=document.createElement("<IFRAME name='" + frameID + "' frameborder='0'>");
                ifrm.id = frameID;
            }
            else
            {
                var ifrm=document.createElement("IFRAME");
                ifrm.setAttribute("name", frameID);
                ifrm.setAttribute("id", frameID);
                ifrm.setAttribute("frameborder", "0");
            }
            ifrm.frameborder="0";
            ifrm.scrolling="no";
            ifrm.style.margin="0px";
            ifrm.style.padding="0px";
            this.Frame = this.Container.appendChild(ifrm);
        }
    }
    this.ResizeFrame = function(width,height){
        this.Frame.width = width;
        this.Frame.height = height;
    }
    this.DoSubmit = function(m,f,m2){
        var isTemp = false;
        if(f==null){
            f=document.createElement("FORM");
            this.Container.appendChild(f);
            isTemp = true;
        }
        f.method = "POST";
        f.target = this.Frame.id;
//        m += ((m!="")?"&":"") + this.buildMessage();
        var addInput = function(name,value,form){
            if(isIE)
            {
                var input = document.createElement("<INPUT type='hidden' name='" + name + "' id='" + name + "' >");
            }
            else
            {
                var input=document.createElement("INPUT");
                input.setAttribute("name", name);
                input.setAttribute("id", name);
                input.setAttribute("type", "hidden");
            }
            input.value = value;
            form.appendChild(input);
        }
        if(this.User!="")
        {
            if(m!=null)
            {
                if(m!="")
                    m = "user=" + this.User + "&" + m;
                else
                    m = "user=" + this.User;
            }
        }
        if(m!=null)
            addInput("message",m,f);
        if(m2!=null)
            addInput("message2",m2,f);       
//        if(isIE)
//        {
//            var input = document.createElement("<INPUT type='hidden' name='message' id='message' >");
//        }
//        else
//        {
//            var input=document.createElement("INPUT");
//            input.setAttribute("name", "message");
//            input.setAttribute("id", "message");
//            input.setAttribute("type", "hidden");
//        }
//        input.value = m;
//        f.appendChild(input);
        f.action = this.DocumentUrl + "#ID=" + this.ID + "&CallerURL=" + document.location.href.split("#")[0] ;
        f.submit();
        this.initialized = true;
        if(isTemp)
            this.Container.removeChild(f);
    }
    this.SendMessage = function(m){
        if(this.Frame==null){
            alert("Map must be initialized before calling this function")
            return;
        }
        if(m!=""){
            if(((this.DocumentUrl + "#" + m).length > MaxMessageLength)&&(isIE)){
                emapAPI.instance.GetHF().DoSubmit(m,null);
                this.Frame.src = this.DocumentUrl + "#HRQ" ;
                //alert("Not implemented - please contact Systematics!")
            }else
                this.Frame.src = this.DocumentUrl + "#" + m;
        }
    }
}

//----------------------------------------------------Map Class-----------------------------------------------------
//----------------------------------------------------Map Class-----------------------------------------------------
function eMap_Map(index,containerID){
    this.InheriteFrom = eMap_Element;
    this.InheriteFrom(index,containerID);
    if(this.Container==null){
        alert("Cannot initiate the map: the document does not have an element with '" + containerID + "' id!")
        return null;
    }
    this.Type = "Map";
    this.ID = "M" + index;
    var ind = this.calcVDir();
    if(ind>2)
        return alert("Cannot handle more then 3 maps per page!");
    this.DocumentUrl = EMAP_HOST_DOMAIN + this.Type + ind + "/default.aspx";
    if(document.domain.indexOf("winwin")>-1)
        this.DocumentUrl = EMAP_HOST_DOMAIN + this.Type + ind + "/winwin.aspx";
    if(document.domain.indexOf("zvz")>-1)
        this.DocumentUrl = EMAP_HOST_DOMAIN + this.Type + ind + "/zvz.aspx";    
    this.Route = new eMap_Route(this);
    this.Features = new eMap_Features(this);
}
//Map Listeners
eMap_Map.prototype.ExtentChangeListener = null;
eMap_Map.prototype.RectangleListener = null;
eMap_Map.prototype.LevelChangeListener = null;
eMap_Map.prototype.PrinterListener = null;
eMap_Map.prototype.DefaultListener = null;
eMap_Map.prototype.PointListener = null;
//Map Attributes
//private
eMap_Map.prototype.center = "";       //used for setting the center of the map
eMap_Map.prototype.Size = "";         //used for setting the map control size
eMap_Map.prototype.Level = "";        //used for setting the map zooom level
eMap_Map.prototype.Graphics = "";     //used for clearing the client graphics
eMap_Map.prototype.Style = "";
eMap_Map.prototype.Background = "";   //used for setting the map layers (ortho,hybrid,etc)
eMap_Map.prototype.Data = "";         //used for setting the user service visibility
eMap_Map.prototype.SLayers = "";         //used for setting the user Layers visibility
eMap_Map.prototype.HLayers = "";         //used for setting the user Layers visibility
eMap_Map.prototype.Tools = "";        //used for adding a small toolbar (pan & zoom)
eMap_Map.prototype.ActiveTool = "";
eMap_Map.prototype.Scroll = "";       //used for setting the map's mouse scroll behavior
eMap_Map.prototype.MapTips = "";      //used for setting the tips mouse over to show tip header
eMap_Map.prototype.Lang = "";         //used for setting the application language
eMap_Map.prototype.Extent = "";
eMap_Map.prototype.ClickAction = "";
eMap_Map.prototype.DblClickAction = "";
eMap_Map.prototype.TipsAction = "";
eMap_Map.prototype.ExtentListenerSens = "";
eMap_Map.prototype.listen = false;
//Map Methods
//private
//Processing a message that was sent to the map control
eMap_Map.prototype.processMessage = function(incomingMessage){
    var messages = incomingMessage.split("&");
    for(var j=0;j<messages.length;j++){
        var message = messages[j].split("::");
        switch(message[0]){
            case "ex":
                if(this.ExtentChangeListener!=null){
                    var att = message[1].split("|");
                    //API_OBJ.ExtentChangeListener(att[0],att[1],att[2],att[3]);
                    //this.ExtentChangeListener(new ExtentEventArgs(att[0],att[1],att[2],att[3]));
                    this.ExtentChangeListener(eval("({minx:" + att[0] + ",miny:" + att[1]  + ",maxx:" + att[2] +  ",maxy:" + att[3] + "})"));
                }
                break;
            case "lvl":
                if(this.LevelChangeListener!=null)
                    this.LevelChangeListener(message[1]);
                break;
            case "id":
                if(this.FeaturesListener!=null)
                    //this.FeaturesListener(eval("({" + message[1].replace(/~/g,'&') + "})" ));
                    this.FeaturesListener(eval("({" + message[1].replace('~~','?').replace(/~/g,'&') + "})" ));
                break;
            case "ses":
                if ((this.Route.DirectionsContainerId != null) || (this.Route.RouteListener != null))
                    sendRequest(this.Route.DirectionsContainerId,message[1]);
                else
                    alert('לא הוגדר DirectionsContainerId ולכן לא ניתן להציג את התוצאות הטקסטואליות');
                break;
            case "img":
                if(this.PrinterListener!=null)
                    this.PrinterListener(message[1]);
                break;
            case "rect":
                if(this.RectangleListener!=null){
                    var att = message[1].split("|");
                    //API_OBJ.ExtentChangeListener(att[0],att[1],att[2],att[3]);
                    //this.ExtentChangeListener(new ExtentEventArgs(att[0],att[1],att[2],att[3]));
                    this.RectangleListener(eval("({minx:" + att[0] + ",miny:" + att[1]  + ",maxx:" + att[2] +  ",maxy:" + att[3] + "})"));
                }
                break;
            case "pt":
                if(this.PointListener!=null){
                    var att = message[1].split("|");
                    //API_OBJ.ExtentChangeListener(att[0],att[1],att[2],att[3]);
                    //this.ExtentChangeListener(new ExtentEventArgs(att[0],att[1],att[2],att[3]));
                    this.PointListener(eval("({x:" + att[0] + ",y:" + att[1]+ "})"));
                }
                break;
            default:
                if(this.DefaultListener!=null)
                    this.DefaultListener(messages[j]);
        }
    }
}
eMap_Map.prototype.buildResourceMessage= function(){
    var m ="";
    if(this.Lang!="")
        m += ((m!="")?"&":"") + this.Lang;
    this.Lang="";
    if(this.Style!="")
        m += ((m!="")?"&":"") + this.Style;
    this.Style="";
    return m;
}
//Bulding a message for the map control
eMap_Map.prototype.buildMessage = function(){
    var m ="";
    var tmp ="";
    if(!this.listen)
        if((this.ExtentChangeListener!=null)||(this.LevelChangeListener!=null)||(this.FeaturesListener!=null)||(this.RectangleListener!=null)||(this.PointListener!=null)){
             m += ((m!="")?"&":"") + "ls";
             this.listen = true;
        }
    if(this.Tools!="")
        m += ((m!="")?"&":"") + this.Tools;
    this.Tools = "";
    if(this.ActiveTool!="")
        m += ((m!="")?"&":"") + this.ActiveTool;
    this.ActiveTool = "";
    if(this.Scroll!="")
        m += ((m!="")?"&":"") + this.Scroll;
    this.Scroll = "";
    if(this.Graphics!="")
        m += ((m!="")?"&":"") + this.Graphics;
    this.Graphics="";
    if(this.Style!="")
        m += ((m!="")?"&":"") + this.Style;
    this.Style="";
    if(this.Data!="")
        m += ((m!="")?"&":"") +this.Data;
    this.Data = "";
    if(this.SLayers!="")
        m += ((m!="")?"&":"") +this.SLayers;
    this.SLayers = "";
    if(this.HLayers!="")
        m += ((m!="")?"&":"") +this.HLayers;
    this.HLayers = "";
    if(this.initialized)
    {
        if(this.Level!="")
            m += ((m!="")?"&":"") + this.Level;
        if(this.center!="")
            m += ((m!="")?"&":"") +this.center;
    }else{
        if(this.center!="")
            m += ((m!="")?"&":"") +this.center;
        if(this.Level!="")
            m += ((m!="")?"&":"") + this.Level;
    }
    this.Level = "";
    this.center = "";

    if(this.Extent!="")
        m += ((m!="")?"&":"") +this.Extent;
    this.Extent = "";

    if(this.Background!="")
        m += ((m!="")?"&":"") +this.Background;
    this.Background = "";
    if(this.MapTips!="")
        m += ((m!="")?"&":"") +this.MapTips;
    this.MapTips = "";
    if(this.TipsAction!="")
        m += ((m!="")?"&":"") +this.TipsAction;
    this.TipsAction = "";

    if(this.ClickAction!="")
        m += ((m!="")?"&":"") +this.ClickAction;
    this.ClickAction = "";

    if(this.DblClickAction!="")
        m += ((m!="")?"&":"") +this.DblClickAction;
    this.DblClickAction = "";

    if(this.Lang!="")
        m += ((m!="")?"&":"") + this.Lang;
    this.Lang="";

    if(this.ExtentListenerSens!="")
        m += ((m!="")?"&":"") + this.ExtentListenerSens;
    this.ExtentListenerSens="";

    //add Route Requests
    tmp = this.Route.buildMessage();
    if(tmp!="")
        m += ((m!="")?"&":"") + tmp;
    tmp = "";
    //Features MUST STAY LAST!!!!
    if(this.Features.count>0)
        m += ((m!="")?"&":"") + this.Features.buildMessage();
    return m.replace(/\?/g,'^');
}
eMap_Map.prototype.calcVDir = function(){
    lastMapIndex = -1;
    for(var i=0;i<emapAPI.instance.Elements.length;i++)
        if(emapAPI.instance.Elements[i].Type == "Map")
            lastMapIndex++;
    return lastMapIndex+1;
}
//public
//Initialization methods
eMap_Map.prototype.SubmitForm = function(formID){
    if(formID!=null){
        this.BuildFrame();
        var form = document.getElementById(formID);
        if(form==null){
            alert("Wrong form ID")
            return;
        }
        this.ResizeFrame(form.Size.value.split(",")[0]||400,form.Size.value.split(",")[1]||400);
        form.method = "Post";
        this.documentUrl = this.mapUrl;
        var resourceMessage = this.buildResourceMessage();
        this.DoSubmit(this.buildMessage(),form,resourceMessage);
        this.form=null;
    }
}
eMap_Map.prototype.SetParams = function(pString){
     this.BuildFrame();
     var w = 400;
     var h = 400;
     var pString = "";
     if((sPos=pString.indexOf("Size="))>-1){
        ePos = pString.indexOf(";",sPos);
        if(ePos==-1)ePos=pString.length;
        s = pString.substr(sPos+5,ePos).split(",");
        w = s[0]||400;
        h = s[1]||400;
     }else
     {
        if(pString!="")
            pString += "&";
        if(this.Size!=''){
            s = this.Size.substr(5).split(",");
            w = s[0]||400;
            h = s[1]||400;
        }
        pString += "Size=" + w + "," + h;
     }

     this.ResizeFrame(w,h);
     var resourceMessage = this.buildResourceMessage();
     pString += ((pString!="")?"&":"") + this.buildMessage();

     this.DoSubmit(pString,null,resourceMessage);
}
eMap_Map.prototype.RefreshMap = function(){
    //m = this.buildMessage();
    if(this.Frame!=null)
        this.SendMessage(this.buildMessage(""));
    else
    {
        this.SetParams();
    }
}
//methods that does not require mapRefresh
eMap_Map.prototype.ResizeMap  = function(w,h){
     this.Size = "Size=" + w + "," + h;
     if(this.Frame!=null)
     {
        this.ResizeFrame(w,h);
        this.SendMessage("Size=" + w + "," + h);
     }
}
eMap_Map.prototype.ShowDetails = function(layer,id){
    this.SendMessage("OpenTip=" + layer + "|" + id);
}
eMap_Map.prototype.ZoomToFull = function(){
    this.SendMessage("zoomToFull");
}
eMap_Map.prototype.PrintMap = function(w,h){
    this.SendMessage("Img=" + w + "," + h);
}
//methods that requires mapRefresh
eMap_Map.prototype.CenterAt = function(x,y,doAutoRefresh){
    var center = "Center=" + x + "," + y;
    if(doAutoRefresh)
        this.SendMessage(center);
    else
        this.center = center;
}
eMap_Map.prototype.SetLevel = function(l,doAutoRefresh){
    var level = "Level=" + l;
    if(doAutoRefresh)
        this.SendMessage(level);
    else
        this.Level = level;
}
//doAutoRefresh is optional
eMap_Map.prototype.SetExtent = function(env,doAutoRefresh){
    var env = "Env=" + env.minx + "," + env.miny + "," + env.maxx + "," + env.maxy ;
    if(doAutoRefresh)
        this.SendMessage(env);
    else
        this.Extent = env;
}
eMap_Map.prototype.ShowOrtho = function(){
    this.Background = "Back=Ortho";
}
eMap_Map.prototype.ShowDefault = function(){
    this.Background = "Back=Default";
}
eMap_Map.prototype.ShowHybrid = function(){
    this.Background = "Back=Hybrid";
}
eMap_Map.prototype.ShowMyData = function(){
    this.Data = "Data=1";
}
eMap_Map.prototype.HideMyData = function(){
    this.Data = "Data=0";
}
eMap_Map.prototype.HideLayer= function(l){
    if(this.HLayers=="")
        this.HLayers = "HL=" + l;
    else
        this.HLayers += "," + l;
}
eMap_Map.prototype.ShowLayer= function(l){
    if(this.SLayers=="")
        this.SLayers = "SL=" + l;
    else
        this.SLayers += "," + l;
}
eMap_Map.prototype.ShowToolBar = function(t){
    if(!t)
        t=1;
    if(this.Tools=="")
        this.Tools = "ToolBar=1" + t;
    else
        this.Tools += ",1" + t;
}
eMap_Map.prototype.HideToolBar = function(t){
     if(!t)
        t=1;
    if(this.Tools=="")
        this.Tools = "ToolBar=0" + t;
    else
        this.Tools += ",0" + t;
}
eMap_Map.prototype.SetActiveTool = function(toolname,toolAction,toolCursor){
     this.ActiveTool = "TA=" + toolname + ",";
     if(toolAction!=null)
        this.ActiveTool +=  toolAction;
     this.ActiveTool += ",";
     if(toolCursor!=null){
        if(!isIE)
            this.ActiveTool +=  "pointer";        
        else
            this.ActiveTool +=  toolCursor;        
     }
}
eMap_Map.prototype.DisableScroll = function(){
    this.Scroll = "NoScroll"
}
eMap_Map.prototype.ShowTitles = function(){
    this.MapTips += ((this.MapTips!="")?"&":"") + "ShowTitles";
}
eMap_Map.prototype.ReturnIDs = function(){
    this.MapTips += ((this.MapTips!="")?"&":"") + "ReturnIDs";
}
eMap_Map.prototype.ChangeLang = function(l){
    this.Lang = "Lang=" + l;
}
//Graphics functions and objects
eMap_Map.prototype.CleanGraphics = function(){
    this.Graphics = "CG";
}
eMap_Map.prototype.HideGraphics = function(){
    this.Graphics = "HG";
}
eMap_Map.prototype.ShowGraphics = function(){
    this.Graphics = "SG";
}
eMap_Map.prototype.ChangeStyle = function(s, turnOffLabels) {
    if (!turnOffLabels)
        turnOffLabels = "0";
    else
        turnOffLabels = "1";
    if (this.Style == "")
        this.Style = "Style=" + s + "," + turnOffLabels;
}
eMap_Map.prototype.SetTipAction = function(mapTipsAction){
    this.TipsAction = "MT=" + mapTipsAction;
}

eMap_Map.prototype.SetClickAction = function(clickAction){
    this.ClickAction = "CA=" + clickAction;
}

eMap_Map.prototype.SetDblClickAction = function(dblclickAction){
    this.DblClickAction = "DCA=" + dblclickAction;
}

eMap_Map.prototype.SetExtentListenerSensitivity = function(precent){
    this.ExtentListenerSens = "SEN=" + precent;
}

//-----------------------------------------------Map.Route---------------------------------------------------
//eMap_Map.prototype.Route = new Array();
function eMap_Route(map){
    this.Map = map;
}
eMap_Route.prototype.pointsString = "";
eMap_Route.prototype.send = false;
eMap_Route.prototype.count = 0;
eMap_Route.prototype.message = "";
eMap_Route.prototype.RouteListener = null;
eMap_Route.prototype.Clear = function(){
   //this.message = "CG";
   this.message += ((this.message!="")?"&":"") + "CR";
}
eMap_Route.prototype.CalcRoute = function(){
   this.send = true;
}
eMap_Route.prototype.buildMessage = function(){
    var m = this.message;
    this.message = "";
//        m = "Rt=34.786546,32.084727|34.7815116604585,32.0707288127156";
    if(!this.send)
      return m;
    this.send = false;
////        this.pointsString = "";
    if(this.count<2){
        alert("Please Enter more points to the Route.")
        return "";
    }
    this.count = 0;
    var p ="Rp=";
    p += (this.Quickest)?"T":"F";
    p += (this.UseToll)?"T":"F";
    p += (this.Optimized)?"T":"F";
    p += (this.NoWestBank)?"T":"F";
    p += this.Map.ID.substr(1);
    m += ((m!="")?"&":"") + p + "&" + this.pointsString
    this.pointsString = "";
    return m;
}
eMap_Route.prototype.DirectionsContainerId;
eMap_Route.prototype.Quickest = true;
eMap_Route.prototype.UseToll = true;
eMap_Route.prototype.Optimized = false;
eMap_Route.prototype.NoWestBank = true;
eMap_Route.prototype.Add = function(x,y,desc){
    if(this.pointsString == "")
        this.pointsString = "Rt=";
    else
        this.pointsString += "|";
        
    if(!desc)desc=""
    this.pointsString +=  x + "," + y + "," + desc;
    this.count++;
}
//-----------------------------------------------Map.Features---------------------------------------------------
function eMap_Features(map){
    this.Map = map;
}
eMap_Features.prototype.FeaturesListener = null;
//eMap_Features.prototype.Features = new Array();
eMap_Features.prototype.IconsVDir = "";
eMap_Features.prototype.tipHTML = "";
eMap_Features.prototype.count = 0;
eMap_Features.prototype.labels = new Array();
eMap_Features.prototype.headers = new Array();
eMap_Features.prototype.bodies = new Array();
eMap_Features.prototype.ids = new Array();
eMap_Features.prototype.icons = new Array();
eMap_Features.prototype.Add = function(x,y,identifier,header,body,label,icon){
    this[this.count] = x + "," + y;
    if(header!=null)
        this.headers[this.count] = header;
    if(body!=null)
        this.bodies[this.count] = body;
    if(label!=null)
        this.labels[this.count] = label;
    if(identifier!=null)
        this.ids[this.count] = identifier;
    if(icon!=null)
        this.icons[this.count] = icon;
    this.count++;
}
eMap_Features.prototype.buildMessage = function(){
    var delimiter = "";
    if(this.count==0)
        return m;
    var coords = "";
    coords += "Crds=" ;
    var labels = (this.labels.length>0)?"lbl=":"";
    var headers = (this.headers.length>0)?"hd=":"";
    var ids = (this.ids.length>0)?"id=":"";
    var bodies = (this.bodies.length>0)?"bd=":"";
    var icons = (this.icons.length>0)?"ic=":"";
    for(var c=0;c<this.count;c++){
        coords += delimiter + this[c];
        if(this.labels.length>0)
            labels += delimiter + ((this.labels[c]==null)?"":this.labels[c]);
        if(this.headers.length>0)
            headers += delimiter + ((this.headers[c]==null)?"":this.headers[c])
        if(this.bodies.length>0)
            bodies += delimiter + ((this.bodies[c]==null)?"":this.bodies[c]);
        if(this.ids.length>0)
            ids += delimiter + ((this.ids[c]==null)?"":this.ids[c]);
        if(this.icons.length>0)
            icons += delimiter + ((this.icons[c]==null)?"":this.icons[c]);
        delimiter = "|";
    }
    this.count = 0;
    if(this.bodies.length>0){
        coords = bodies + "&" + coords;
        this.bodies = new Array();
    }
    if(this.IconsVDir!="")
        coords = "vd=" + this.IconsVDir + "&" + coords;
    if(this.tipHTML != "")
        coords = "ht=" + this.tipHTML + "&" + coords;
    this.tipHTML = "";
    if(this.labels.length>0){
        coords = labels + "&" + coords;
        this.labels = new Array();
    }
    if(this.headers.length>0){
        coords = headers + "&" + coords;
        this.headers = new Array();
    }
    if(this.ids.length>0){
        coords = ids + "&" + coords;
        this.ids = new Array();
    }
    if(this.icons.length>0){
        coords = icons + "&" + coords;
        this.icons = new Array();
    }
    return coords;
}
eMap_Features.prototype.SetIconsVDir = function ( virtualDirectory){
    this.IconsVDir = virtualDirectory;
}
eMap_Features.prototype.SetTipHTML = function ( htmlString){
    this.tipHTML = htmlString;
}
eMap_Features.prototype.UpdateFeature = function(featureID,x,y,header,body){
    if(!header) header = "";
    if(!body) body = "";              
    this.Map.MapTips += ((this.Map.MapTips!="")?"&":"") + "UF=" + featureID+ "," + x + "," + y + "," + header + "," + body;
}
//-----------------------------------------------General functions for the Route--------------------------------------------------------
function sendRequest(txtControlName,  id)
{
    //var id=$get(idControlName).value;
    var listener = {
                   ctrl: txtControlName,
                   onLoad: function(response,txtControlName ) { getResultOK(response,txtControlName);},
                   onError: function(status, statusText, response) { getResultError(status,statusText, txtControlName); }
                   };
    ctrl=txtControlName;
    Dsr.clear();
    //Dsr.send('http://www4.emap.co.il/webservices/emapwebservices/EmapRouteDirectionProxy.aspx?id=' + id, listener,'EmapRouteDirections');
    Dsr.send('http://212.150.51.242/WebServices/EMapWebServices/EmapRouteDirectionProxy.aspx?id=' + id, listener,'EmapRouteDirections');
    //Dsr.send('http://michael-2k3-vm2/WebServices/EMapWebServices/EmapRouteDirectionProxy.aspx?id=' + id, listener,'EmapRouteDirections');
}
function getResultOK(res,txtControlName)
{
    var txt = document.getElementById(txtControlName);
    if (emapAPI.instance.Elements[0].Route.RouteListener != null)
        emapAPI.instance.Elements[0].Route.RouteListener(res);
    else
        if (txt==null)
            return alert("לא נמצא בדף: DirectionsContainerId");
    if (txt != null)
        txt.innerHTML = res;
}
function getResultError(status,statusText,txtControlName)
{
    if (emapAPI.instance.Elements[0].Route.RouteListener != null)
        emapAPI.instance.Elements[0].Route.RouteListener(res);
    //var txt=document.getElementById(emapAPI.instance.Route.DirectionsContainerId);
    var txt=document.getElementById(txtControlName);
    if (txt==null)
        return alert("לא נמצא בדף: DirectionsContainerId");
    txt.innerHTML = "<font color='red'><b>" + status + ": " + statusText + "</b></font>";
}


